2018-11-14 15:54:13 +00:00
|
|
|
/* mbed Microcontroller Library
|
|
|
|
* Copyright (c) 2018 ARM Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLE_COMMON_DURATION_H_
|
|
|
|
#define BLE_COMMON_DURATION_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2018-11-15 21:19:40 +00:00
|
|
|
#include <stddef.h>
|
2018-11-14 15:54:13 +00:00
|
|
|
#include "platform/mbed_assert.h"
|
|
|
|
|
|
|
|
namespace ble {
|
|
|
|
|
2018-11-25 11:34:21 +00:00
|
|
|
#if !defined(DOXYGEN_ONLY)
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Define a compile time range.
|
|
|
|
* @tparam Min left-bound
|
|
|
|
* @tparam Max right-bound
|
|
|
|
*/
|
2018-11-14 15:54:13 +00:00
|
|
|
template<uint32_t Min, uint32_t Max>
|
|
|
|
struct Range {
|
2018-11-21 11:13:51 +00:00
|
|
|
static const uint32_t MIN = Min;
|
|
|
|
static const uint32_t MAX = Max;
|
2018-11-14 15:54:13 +00:00
|
|
|
};
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Deduce default range for C++ basic integer types.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @tparam Rep The C++ integer type.
|
|
|
|
*/
|
2018-11-14 15:54:13 +00:00
|
|
|
template<typename Rep>
|
|
|
|
struct DefaultRange;
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* DefaultRange specialization for uint8_t.
|
|
|
|
*/
|
2018-11-14 15:54:13 +00:00
|
|
|
template<>
|
|
|
|
struct DefaultRange<uint8_t> {
|
|
|
|
typedef Range<0, 0xFF> type;
|
|
|
|
};
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* DefaultRange specialization for uint16_t.
|
|
|
|
*/
|
2018-11-14 15:54:13 +00:00
|
|
|
template<>
|
|
|
|
struct DefaultRange<uint16_t > {
|
|
|
|
typedef Range<0, 0xFFFF> type;
|
|
|
|
};
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* DefaultRange specialization for uint32_t
|
|
|
|
*/
|
2018-11-14 15:54:13 +00:00
|
|
|
template<>
|
|
|
|
struct DefaultRange<uint32_t> {
|
|
|
|
typedef Range<0, 0xFFFFFFFF> type;
|
|
|
|
};
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
2018-11-23 15:41:08 +00:00
|
|
|
* Represent an integral compile time value that can be used in Duration.
|
2018-11-21 11:52:13 +00:00
|
|
|
*
|
2018-11-23 15:41:08 +00:00
|
|
|
* @tparam T Type of the integral value.
|
2018-11-21 11:52:13 +00:00
|
|
|
* @tparam V The integer value representing a never ending duration.
|
|
|
|
*/
|
2018-11-23 15:41:08 +00:00
|
|
|
template<typename T, T V>
|
|
|
|
struct Value {
|
|
|
|
static const T VALUE = V;
|
2018-11-21 10:22:21 +00:00
|
|
|
};
|
|
|
|
|
2018-11-25 11:34:21 +00:00
|
|
|
#endif
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Model BLE durations.
|
|
|
|
*
|
|
|
|
* @tparam Rep The representation type of the duration.
|
2018-11-27 12:17:47 +00:00
|
|
|
* @tparam TB The time base in micro seconds.
|
2018-11-21 11:52:13 +00:00
|
|
|
* @tparam Range Closed interval of the duration
|
|
|
|
* @tparam Forever The special value (if applicable) that represents a forever
|
|
|
|
* duration.
|
|
|
|
*/
|
2018-11-21 10:22:21 +00:00
|
|
|
template<
|
|
|
|
typename Rep,
|
|
|
|
uint32_t TB,
|
|
|
|
typename Range = typename DefaultRange<Rep>::type,
|
|
|
|
typename Forever = void*
|
|
|
|
>
|
2018-11-14 15:54:13 +00:00
|
|
|
struct Duration {
|
2018-11-23 21:26:10 +00:00
|
|
|
/**
|
|
|
|
* Type of the actual representation.
|
|
|
|
*/
|
|
|
|
typedef Rep representation_t;
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Construct a default Duration.
|
|
|
|
*
|
|
|
|
* It is initialized with the minimum value acceptable.
|
|
|
|
*/
|
2018-11-23 14:28:34 +00:00
|
|
|
Duration() : duration(Range::MIN)
|
|
|
|
{
|
|
|
|
}
|
2018-11-21 11:52:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a Duration from an integer value.
|
|
|
|
*
|
2018-11-27 12:17:47 +00:00
|
|
|
* @param v The value of the duration in TIME_BASE units.
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-23 14:28:34 +00:00
|
|
|
explicit Duration(Rep v) : duration(clamp(v))
|
|
|
|
{
|
|
|
|
}
|
2018-11-14 15:54:13 +00:00
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Construct a Duration from another Duration.
|
|
|
|
*
|
2018-11-27 12:17:47 +00:00
|
|
|
* @note The operation fail at compile time if there is a loss of precision.
|
2018-11-21 11:52:13 +00:00
|
|
|
*
|
2018-11-27 00:16:33 +00:00
|
|
|
* @tparam OtherRep The type used to represent the other Duration.
|
2018-11-27 12:17:47 +00:00
|
|
|
* @tparam OtherTB The time base in micro seconds of the other Duration.
|
2018-11-27 00:16:33 +00:00
|
|
|
* @tparam OtherRange The range of the other Duration.
|
2018-11-21 11:52:13 +00:00
|
|
|
* @tparam OtherF The forever value of the other type.
|
|
|
|
*
|
2018-11-27 00:16:33 +00:00
|
|
|
* @param other The Duration used to construct this object.
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
|
|
|
template<typename OtherRep, uint32_t OtherTB, typename OtherRange, typename OtherF>
|
|
|
|
Duration(Duration<OtherRep, OtherTB, OtherRange, OtherF> other) :
|
2018-11-14 15:54:13 +00:00
|
|
|
duration(clamp(other.value() * (OtherTB / TB)))
|
|
|
|
{
|
|
|
|
MBED_STATIC_ASSERT(OtherTB >= TB && (OtherTB % TB) == 0, "Incompatible units");
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Construct a new Duration from a Duration in milliseconds.
|
|
|
|
*
|
|
|
|
* @note The result of the conversion is rounded up.
|
|
|
|
*
|
|
|
|
* @tparam OtherRep The representation type used by other_ms.
|
|
|
|
* @tparam OtherRange The range used by other_ms.
|
|
|
|
* @tparam OtherF The forever value used by other_ms.
|
|
|
|
*
|
2018-11-27 12:17:47 +00:00
|
|
|
* @param other_ms The Duration in millisecond to convert.
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
|
|
|
template<typename OtherRep, typename OtherRange, typename OtherF>
|
|
|
|
explicit Duration(Duration<OtherRep, 1000, OtherRange, OtherF> other_ms, void* = NULL) :
|
2018-11-15 21:19:40 +00:00
|
|
|
duration(clamp(((other_ms.value() * 1000) + TB - 1) / TB))
|
2018-11-23 14:28:34 +00:00
|
|
|
{
|
|
|
|
}
|
2018-11-15 21:19:40 +00:00
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Return the duration in TB units.
|
|
|
|
*
|
|
|
|
* @return The duration in TB units.
|
|
|
|
*/
|
2018-11-23 14:28:34 +00:00
|
|
|
Rep value() const
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
2018-11-22 14:01:28 +00:00
|
|
|
/**
|
|
|
|
* Return the duration in milliseconds.
|
|
|
|
*
|
|
|
|
* @return The duration in milliseconds.
|
|
|
|
*/
|
2018-11-23 14:28:34 +00:00
|
|
|
uint32_t valueInMs() const
|
|
|
|
{
|
2018-11-22 14:01:28 +00:00
|
|
|
return ((uint32_t)duration * TB) / 1000;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* The time base.
|
|
|
|
*/
|
2018-11-21 11:13:51 +00:00
|
|
|
static const uint32_t TIME_BASE = TB;
|
2018-11-21 11:52:13 +00:00
|
|
|
|
|
|
|
/**
|
2018-11-27 00:16:33 +00:00
|
|
|
* Left-bound of the duration range.
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:51 +00:00
|
|
|
static const Rep MIN = Range::MIN;
|
2018-11-21 11:52:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Right bound of the duration range.
|
|
|
|
*/
|
2018-11-21 11:13:51 +00:00
|
|
|
static const Rep MAX = Range::MAX;
|
2018-11-14 15:54:13 +00:00
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Return the minimum duration.
|
|
|
|
*
|
|
|
|
* @return The minimum duration.
|
|
|
|
*/
|
2018-11-14 15:54:13 +00:00
|
|
|
static Duration min()
|
|
|
|
{
|
|
|
|
return Duration(MIN);
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Return the maximum duration.
|
|
|
|
*
|
|
|
|
* @return The maximum duration.
|
|
|
|
*/
|
2018-11-14 15:54:13 +00:00
|
|
|
static Duration max()
|
|
|
|
{
|
|
|
|
return Duration(MAX);
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Return a pointer to the value of the duration.
|
|
|
|
*
|
|
|
|
* @return a pointer to the value of the duration.
|
|
|
|
*/
|
2018-11-14 15:54:13 +00:00
|
|
|
const Rep* storage() const
|
|
|
|
{
|
|
|
|
return &duration;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
2018-11-27 00:16:33 +00:00
|
|
|
* Return the Duration value meaning forever.
|
|
|
|
* @return the Duration value meaning forever.
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 10:22:21 +00:00
|
|
|
static Duration forever()
|
|
|
|
{
|
|
|
|
return Duration(Forever::VALUE);
|
|
|
|
}
|
|
|
|
|
2018-11-14 15:54:13 +00:00
|
|
|
private:
|
2018-11-23 14:28:34 +00:00
|
|
|
static Rep clamp(Rep in)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
if (in < MIN) {
|
|
|
|
return MIN;
|
|
|
|
} else if (in > MAX) {
|
|
|
|
return MAX;
|
|
|
|
} else {
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rep duration;
|
|
|
|
};
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Type that represents micro seconds.
|
|
|
|
*/
|
2018-11-14 15:54:13 +00:00
|
|
|
typedef Duration<uint32_t, 1> microsecond_t;
|
2018-11-21 11:52:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Type that represents milliseconds.
|
|
|
|
*/
|
2018-11-14 17:54:57 +00:00
|
|
|
typedef Duration<uint32_t, 1000 * microsecond_t::TIME_BASE> millisecond_t;
|
2018-11-21 11:52:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Type that represents seconds.
|
|
|
|
*/
|
2018-11-14 17:54:57 +00:00
|
|
|
typedef Duration<uint32_t, 1000 * millisecond_t::TIME_BASE> second_t;
|
2018-11-14 15:54:13 +00:00
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Cast a duration to another.
|
|
|
|
*
|
|
|
|
* @tparam DurationOut Type of the Duration in output.
|
|
|
|
* @tparam RepIn The representation type of duration.
|
|
|
|
* @tparam TBIn The timebase of duration.
|
|
|
|
* @tparam RangeIn The range of duration.
|
|
|
|
* @tparam FIn The Forever value of duration.
|
|
|
|
* @param duration The duration to convert.
|
2018-11-27 12:17:47 +00:00
|
|
|
* @return The converted duration. It is rounded up if precision is lost.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<typename DurationOut, typename RepIn, uint32_t TBIn, typename RangeIn, typename FIn>
|
2018-11-23 14:28:34 +00:00
|
|
|
DurationOut durationCast(Duration<RepIn, TBIn, RangeIn, FIn> duration)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return DurationOut(((duration.value() * TBIn) + DurationOut::TIME_BASE - 1) / DurationOut::TIME_BASE);
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Add two durations together and return the result in microseconds.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return The result of the addition of the two durations in microseconds.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<
|
|
|
|
typename RepLHS, uint32_t TBLHS, typename RangeLHS, typename FLHS,
|
|
|
|
typename RepRHS, uint32_t TBRHS, typename RangeRHS, typename FRHS>
|
|
|
|
microsecond_t operator+(
|
|
|
|
Duration<RepLHS, TBLHS, RangeLHS, FLHS> lhs,
|
|
|
|
Duration<RepRHS, TBRHS, RangeRHS, FRHS> rhs
|
|
|
|
)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return microsecond_t((lhs.value() * lhs.TIME_BASE) + (rhs.value() * rhs.TIME_BASE));
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Add two durations together.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return The addition of the two durations in input.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<typename Rep, uint32_t TB, typename Range, typename F>
|
|
|
|
Duration<Rep, TB, Range, F> operator+(
|
|
|
|
Duration<Rep, TB, Range, F> lhs,
|
|
|
|
Duration<Rep, TB, Range, F> rhs
|
2018-11-23 14:28:34 +00:00
|
|
|
)
|
|
|
|
{
|
2018-11-21 11:13:14 +00:00
|
|
|
return Duration<Rep, TB, Range, F>(lhs.value() + rhs.value());
|
2018-11-14 15:54:13 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Multiply a duration and a positive integer.
|
|
|
|
*
|
|
|
|
* @param lhs The duration.
|
|
|
|
* @param rhs The integer.
|
|
|
|
*
|
|
|
|
* @return A duration that represents the multiplication of lhs with rhs.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<typename Rep, uint32_t TB, typename Range, typename F>
|
2018-11-23 14:28:34 +00:00
|
|
|
Duration<Rep, TB, Range, F> operator*(Duration<Rep, TB, Range, F> lhs, uint32_t rhs)
|
|
|
|
{
|
2018-11-21 11:13:14 +00:00
|
|
|
return Duration<Rep, TB, Range, F>(lhs.value() * rhs);
|
2018-11-14 15:54:13 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Multiply a duration and a positive integer.
|
|
|
|
*
|
|
|
|
* @param lhs The integer.
|
|
|
|
* @param rhs The multiplication.
|
|
|
|
*
|
|
|
|
* @return A duration that represents the multiplication of lhs with rhs.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<typename Rep, uint32_t TB, typename Range, typename F>
|
2018-11-23 14:28:34 +00:00
|
|
|
Duration<Rep, TB, Range, F> operator*(uint32_t lhs, Duration<Rep, TB, Range, F> rhs)
|
|
|
|
{
|
2018-11-21 11:13:14 +00:00
|
|
|
return Duration<Rep, TB, Range, F>(lhs * rhs.value());
|
2018-11-14 15:54:13 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Indicate if the duration lhs is less than the duration rhs.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return true if lhs is less than rhs and false otherwise.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<
|
|
|
|
typename RepLHS, uint32_t TBLHS, typename RangeLHS, typename FLHS,
|
|
|
|
typename RepRHS, uint32_t TBRHS, typename RangeRHS, typename FRHS
|
|
|
|
>
|
2018-11-23 14:28:34 +00:00
|
|
|
bool operator<(Duration<RepLHS, TBLHS, RangeLHS, FLHS> lhs, Duration<RepRHS, TBRHS, RangeRHS, FRHS> rhs)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return lhs.value() * lhs.TIME_BASE < rhs.value() * rhs.TIME_BASE;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Indicate if the duration lhs is less than the duration rhs.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return true if lhs is less than rhs and false otherwise.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<typename Rep, uint32_t Us, typename Range, typename F>
|
2018-11-23 14:28:34 +00:00
|
|
|
bool operator<(Duration<Rep, Us, Range, F> lhs, Duration<Rep, Us, Range, F> rhs)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return lhs.value() < rhs.value();
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Indicate if the duration lhs is less than or equal to the duration rhs.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return true if lhs is less than or equal to rhs and false otherwise.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<
|
|
|
|
typename RepLHS, uint32_t TBLHS, typename RangeLHS, typename FLHS,
|
|
|
|
typename RepRHS, uint32_t TBRHS, typename RangeRHS, typename FRHS
|
|
|
|
>
|
|
|
|
bool operator<=(
|
|
|
|
Duration<RepLHS, TBLHS, RangeLHS, FLHS> lhs,
|
|
|
|
Duration<RepRHS, TBRHS, RangeRHS, FRHS> rhs
|
2018-11-23 14:28:34 +00:00
|
|
|
)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return lhs.value() * lhs.TIME_BASE <= rhs.value() * rhs.TIME_BASE;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Indicate if the duration lhs is less than or equal to the duration rhs.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return true if lhs is less than or equal to rhs and false otherwise.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-14 15:54:13 +00:00
|
|
|
template<typename Rep, uint32_t Us, typename Range>
|
2018-11-23 14:28:34 +00:00
|
|
|
bool operator<=(Duration<Rep, Us, Range> lhs, Duration<Rep, Us, Range> rhs)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return lhs.value() <= rhs.value();
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Indicate if the duration lhs is equal to the duration rhs.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return true if lhs is equal to rhs and false otherwise.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<
|
|
|
|
typename RepLHS, uint32_t TBLHS, typename RangeLHS, typename FLHS,
|
|
|
|
typename RepRHS, uint32_t TBRHS, typename RangeRHS, typename FRHS
|
|
|
|
>
|
|
|
|
bool operator==(
|
|
|
|
Duration<RepLHS, TBLHS, RangeLHS, FLHS> lhs,
|
|
|
|
Duration<RepRHS, TBRHS, RangeRHS, FRHS> rhs
|
2018-11-23 14:28:34 +00:00
|
|
|
)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return lhs.value() * lhs.TIME_BASE == rhs.value() * rhs.TIME_BASE;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Indicate if the duration lhs is equal to the duration rhs.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return true if lhs is equal to rhs and false otherwise.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<typename Rep, uint32_t Us, typename Range, typename F>
|
2018-11-23 14:28:34 +00:00
|
|
|
bool operator==(Duration<Rep, Us, Range, F> lhs, Duration<Rep, Us, Range, F> rhs)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return lhs.value() == rhs.value();
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Indicate if the duration lhs is not equal to the duration rhs.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return true if lhs is not equal to rhs and false otherwise.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<
|
|
|
|
typename RepLHS, uint32_t TBLHS, typename RangeLHS, typename FLHS,
|
|
|
|
typename RepRHS, uint32_t TBRHS, typename RangeRHS, typename FRHS
|
|
|
|
>
|
|
|
|
bool operator!=(
|
|
|
|
Duration<RepLHS, TBLHS, RangeLHS, FLHS> lhs,
|
|
|
|
Duration<RepRHS, TBRHS, RangeRHS, FRHS> rhs
|
2018-11-23 14:28:34 +00:00
|
|
|
)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Indicate if the duration lhs is not equal to the duration rhs.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return true if lhs is not equal to rhs and false otherwise.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<typename Rep, uint32_t Us, typename Range, typename F>
|
2018-11-23 14:28:34 +00:00
|
|
|
bool operator!=(Duration<Rep, Us, Range, F> lhs, Duration<Rep, Us, Range, F> rhs)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Indicate if the duration lhs greater or equal to the duration rhs.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return true if lhs is greater or equal to rhs and false otherwise.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<
|
|
|
|
typename RepLHS, uint32_t TBLHS, typename RangeLHS, typename FLHS,
|
|
|
|
typename RepRHS, uint32_t TBRHS, typename RangeRHS, typename FRHS
|
|
|
|
>
|
|
|
|
bool operator>=(
|
|
|
|
Duration<RepLHS, TBLHS, RangeLHS, FLHS> lhs,
|
|
|
|
Duration<RepRHS, TBRHS, RangeRHS, FRHS> rhs
|
2018-11-23 14:28:34 +00:00
|
|
|
)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return rhs <= lhs;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Indicate if the duration lhs greater or equal to the duration rhs.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return true if lhs is greater or equal to rhs and false otherwise.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<typename Rep, uint32_t Us, typename Range, typename F>
|
2018-11-23 14:28:34 +00:00
|
|
|
bool operator>=(Duration<Rep, Us, Range, F> lhs, Duration<Rep, Us, Range, F> rhs)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return rhs <= lhs;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Indicate if the duration lhs greater than the duration rhs.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return true if lhs is greater than rhs and false otherwise.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<
|
|
|
|
typename RepLHS, uint32_t TBLHS, typename RangeLHS, typename FLHS,
|
|
|
|
typename RepRHS, uint32_t TBRHS, typename RangeRHS, typename FRHS
|
|
|
|
>
|
|
|
|
bool operator>(
|
|
|
|
Duration<RepLHS, TBLHS, RangeLHS, FLHS> lhs,
|
|
|
|
Duration<RepRHS, TBRHS, RangeRHS, FRHS> rhs
|
2018-11-23 14:28:34 +00:00
|
|
|
)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return rhs < lhs;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:52:13 +00:00
|
|
|
/**
|
|
|
|
* Indicate if the duration lhs greater than the duration rhs.
|
|
|
|
* @param lhs Left hand side operand.
|
|
|
|
* @param rhs Right hand side operand.
|
|
|
|
* @return true if lhs is greater than rhs and false otherwise.
|
2018-11-25 11:34:21 +00:00
|
|
|
*
|
|
|
|
* @related Duration
|
2018-11-21 11:52:13 +00:00
|
|
|
*/
|
2018-11-21 11:13:14 +00:00
|
|
|
template<typename Rep, uint32_t Us, typename Range, typename F>
|
2018-11-23 14:28:34 +00:00
|
|
|
bool operator>(Duration<Rep, Us, Range, F> lhs, Duration<Rep, Us, Range, F> rhs)
|
|
|
|
{
|
2018-11-14 15:54:13 +00:00
|
|
|
return rhs < lhs;
|
|
|
|
}
|
|
|
|
|
2018-11-21 10:22:21 +00:00
|
|
|
/* ---------------------- Static variable initialization -------------------- */
|
|
|
|
|
2018-11-25 11:34:21 +00:00
|
|
|
#if !defined(DOXYGEN_ONLY)
|
|
|
|
|
2018-11-21 11:13:51 +00:00
|
|
|
template<uint32_t Min, uint32_t Max>
|
|
|
|
const uint32_t Range<Min, Max>::MIN;
|
|
|
|
|
|
|
|
template<uint32_t Min, uint32_t Max>
|
|
|
|
const uint32_t Range<Min, Max>::MAX;
|
2018-11-21 10:22:21 +00:00
|
|
|
|
2018-11-23 15:41:08 +00:00
|
|
|
template<typename T, T V>
|
|
|
|
const T Value<T, V>::VALUE;
|
2018-11-21 10:22:21 +00:00
|
|
|
|
2018-11-25 11:34:21 +00:00
|
|
|
#endif
|
|
|
|
|
2018-11-21 11:13:51 +00:00
|
|
|
template<typename Rep, uint32_t TB, typename Range, typename Forever>
|
|
|
|
const uint32_t Duration<Rep, TB, Range, Forever>::TIME_BASE;
|
|
|
|
|
|
|
|
template<typename Rep, uint32_t TB, typename Range, typename Forever>
|
|
|
|
const Rep Duration<Rep, TB, Range, Forever>::MIN;
|
|
|
|
|
|
|
|
template<typename Rep, uint32_t TB, typename Range, typename Forever>
|
|
|
|
const Rep Duration<Rep, TB, Range, Forever>::MAX;
|
|
|
|
|
2018-11-14 15:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif //BLE_COMMON_DURATION_H_
|