17 #ifndef BLE_COMMON_DURATION_H_ 18 #define BLE_COMMON_DURATION_H_ 22 #include "platform/mbed_assert.h" 26 #if !defined(DOXYGEN_ONLY) 33 template<u
int32_t Min, u
int32_t Max>
35 static const uint32_t
MIN = Min;
36 static const uint32_t
MAX = Max;
45 template<
typename Rep>
52 struct DefaultRange<uint8_t> {
53 typedef Range<0, 0xFF> type;
60 struct DefaultRange<uint16_t > {
61 typedef Range<0, 0xFFFF> type;
68 struct DefaultRange<uint32_t> {
69 typedef Range<0, 0xFFFFFFFF> type;
78 template<
typename T, T V>
80 static const T VALUE = V;
97 typename Range =
typename DefaultRange<Rep>::type,
98 typename Forever =
void*
136 template<
typename OtherRep, u
int32_t OtherTB,
typename OtherRange,
typename OtherF>
138 duration(clamp(other.value() * (OtherTB / TB)))
154 template<
typename OtherRep,
typename OtherRange,
typename OtherF>
156 duration(clamp(((other_ms.value() * 1000) + TB - 1) / TB))
177 return ((uint32_t)duration * TB) / 1000;
183 static const uint32_t TIME_BASE = TB;
235 static Rep clamp(Rep in)
239 }
else if (in > MAX) {
277 template<
typename DurationOut,
typename RepIn, u
int32_t TBIn,
typename RangeIn,
typename FIn>
280 return DurationOut(((duration.
value() * TBIn) + DurationOut::TIME_BASE - 1) / DurationOut::TIME_BASE);
292 typename RepLHS, uint32_t TBLHS,
typename RangeLHS,
typename FLHS,
293 typename RepRHS, uint32_t TBRHS,
typename RangeRHS,
typename FRHS>
310 template<
typename Rep, u
int32_t TB,
typename Range,
typename F>
329 template<
typename Rep, u
int32_t TB,
typename Range,
typename F>
345 template<
typename Rep, u
int32_t TB,
typename Range,
typename F>
360 typename RepLHS, uint32_t TBLHS,
typename RangeLHS,
typename FLHS,
361 typename RepRHS, uint32_t TBRHS,
typename RangeRHS,
typename FRHS
365 return lhs.
value() * lhs.TIME_BASE < rhs.value() * rhs.TIME_BASE;
376 template<
typename Rep, u
int32_t Us,
typename Range,
typename F>
379 return lhs.
value() < rhs.value();
391 typename RepLHS, uint32_t TBLHS,
typename RangeLHS,
typename FLHS,
392 typename RepRHS, uint32_t TBRHS,
typename RangeRHS,
typename FRHS
410 template<
typename Rep, u
int32_t Us,
typename Range>
413 return lhs.
value() <= rhs.value();
425 typename RepLHS, uint32_t TBLHS,
typename RangeLHS,
typename FLHS,
426 typename RepRHS, uint32_t TBRHS,
typename RangeRHS,
typename FRHS
444 template<
typename Rep, u
int32_t Us,
typename Range,
typename F>
459 typename RepLHS, uint32_t TBLHS,
typename RangeLHS,
typename FLHS,
460 typename RepRHS, uint32_t TBRHS,
typename RangeRHS,
typename FRHS
467 return !(lhs == rhs);
478 template<
typename Rep, u
int32_t Us,
typename Range,
typename F>
481 return !(lhs == rhs);
493 typename RepLHS, uint32_t TBLHS,
typename RangeLHS,
typename FLHS,
494 typename RepRHS, uint32_t TBRHS,
typename RangeRHS,
typename FRHS
512 template<
typename Rep, u
int32_t Us,
typename Range,
typename F>
527 typename RepLHS, uint32_t TBLHS,
typename RangeLHS,
typename FLHS,
528 typename RepRHS, uint32_t TBRHS,
typename RangeRHS,
typename FRHS
546 template<
typename Rep, u
int32_t Us,
typename Range,
typename F>
554 #if !defined(DOXYGEN_ONLY) 556 template<u
int32_t Min, u
int32_t Max>
559 template<u
int32_t Min, u
int32_t Max>
562 template<
typename T, T V>
563 const T Value<T, V>::VALUE;
567 template<
typename Rep, u
int32_t TB,
typename Range,
typename Forever>
570 template<
typename Rep, u
int32_t TB,
typename Range,
typename Forever>
573 template<
typename Rep, u
int32_t TB,
typename Range,
typename Forever>
578 #endif //BLE_COMMON_DURATION_H_ Duration< Rep, TB, Range, F > operator+(Duration< Rep, TB, Range, F > lhs, Duration< Rep, TB, Range, F > rhs)
Add two durations together.
DurationOut durationCast(Duration< RepIn, TBIn, RangeIn, FIn > duration)
Cast a duration to another.
static Duration forever()
Return the Duration value meaning forever.
bool operator>=(Duration< RepLHS, TBLHS, RangeLHS, FLHS > lhs, Duration< RepRHS, TBRHS, RangeRHS, FRHS > rhs)
Indicate if the duration lhs greater or equal to the duration rhs.
Duration< uint32_t, 1000 *millisecond_t::TIME_BASE > second_t
Type that represents seconds.
Rep value() const
Return the duration in TB units.
bool operator>(Duration< RepLHS, TBLHS, RangeLHS, FLHS > lhs, Duration< RepRHS, TBRHS, RangeRHS, FRHS > rhs)
Indicate if the duration lhs greater than the duration rhs.
bool operator==(Duration< RepLHS, TBLHS, RangeLHS, FLHS > lhs, Duration< RepRHS, TBRHS, RangeRHS, FRHS > rhs)
Indicate if the duration lhs is equal to the duration rhs.
bool operator!=(Duration< Rep, Us, Range, F > lhs, Duration< Rep, Us, Range, F > rhs)
Indicate if the duration lhs is not equal to the duration rhs.
#define MAX(a, b)
Returns the maximum value between a and b.
static Duration max()
Return the maximum duration.
uint32_t valueInMs() const
Return the duration in milliseconds.
Duration< uint32_t, 1000 *microsecond_t::TIME_BASE > millisecond_t
Type that represents milliseconds.
static const uint32_t TIME_BASE
The time base.
Duration< Rep, TB, Range, F > operator*(Duration< Rep, TB, Range, F > lhs, uint32_t rhs)
Multiply a duration and a positive integer.
bool operator==(Duration< Rep, Us, Range, F > lhs, Duration< Rep, Us, Range, F > rhs)
Indicate if the duration lhs is equal to the duration rhs.
Duration(Rep v)
Construct a Duration from an integer value.
Duration< Rep, TB, Range, F > operator*(uint32_t lhs, Duration< Rep, TB, Range, F > rhs)
Multiply a duration and a positive integer.
Duration(Duration< OtherRep, 1000, OtherRange, OtherF > other_ms, void *=NULL)
Construct a new Duration from a Duration in milliseconds.
const Rep * storage() const
Return a pointer to the value of the duration.
#define MIN(a, b)
Returns the minimum value between a and b.
Duration(Duration< OtherRep, OtherTB, OtherRange, OtherF > other)
Construct a Duration from another Duration.
bool operator<=(Duration< RepLHS, TBLHS, RangeLHS, FLHS > lhs, Duration< RepRHS, TBRHS, RangeRHS, FRHS > rhs)
Indicate if the duration lhs is less than or equal to the duration rhs.
microsecond_t operator+(Duration< RepLHS, TBLHS, RangeLHS, FLHS > lhs, Duration< RepRHS, TBRHS, RangeRHS, FRHS > rhs)
Add two durations together and return the result in microseconds.
bool operator!=(Duration< RepLHS, TBLHS, RangeLHS, FLHS > lhs, Duration< RepRHS, TBRHS, RangeRHS, FRHS > rhs)
Indicate if the duration lhs is not equal to the duration rhs.
Duration()
Construct a default Duration.
Rep representation_t
Type of the actual representation.
static Duration min()
Return the minimum duration.
Entry namespace for all BLE API definitions.
bool operator>=(Duration< Rep, Us, Range, F > lhs, Duration< Rep, Us, Range, F > rhs)
Indicate if the duration lhs greater or equal to the duration rhs.
Duration< uint32_t, 1 > microsecond_t
Type that represents micro seconds.
bool operator>(Duration< Rep, Us, Range, F > lhs, Duration< Rep, Us, Range, F > rhs)
Indicate if the duration lhs greater than the duration rhs.