Macros | |
#define | ZB_MAX_TIME_VAL ZB_UINT32_MAX |
#define | ZB_MIN_TIME_VAL ZB_UINT32_MIN |
#define | ZB_HALF_MAX_TIME_VAL (ZB_MAX_TIME_VAL / 2) |
#define | ZB_TIMER_GET() (zb_timer_get()) |
#define | ZB_TIME_SUBTRACT(a, b) ((zb_time_t)((a) - (b)) < ZB_HALF_MAX_TIME_VAL ? (zb_time_t)((a) - (b)) : (zb_time_t)((b) - (a))) |
#define | ZB_TIME_ADD(a, b) (zb_time_t)((a) + (b)) |
#define | ZB_TIME_GE(a, b) ((zb_time_t)((a) - (b)) < ZB_HALF_MAX_TIME_VAL) |
#define | ZB_TIME_ONE_SECOND ZB_MILLISECONDS_TO_BEACON_INTERVAL(1000) |
#define | ZB_MILLISECONDS_TO_BEACON_INTERVAL(ms) (((zb_time_t)(ms) * 1000) / ZB_BEACON_INTERVAL_USEC) |
#define | ZB_SYMBOL_DURATION_USEC 16 /* 1 symbol = 16e-6 sec (mac spec 6.5.3.2 Symbol rate) */ |
Symbol duration. More... | |
#define | ZB_ABASE_SUPERFRAME_DURATION 960 |
#define | ZB_BEACON_INTERVAL_USEC (ZB_SYMBOL_DURATION_USEC * ZB_ABASE_SUPERFRAME_DURATION) |
#define | ZB_TIME_BEACON_INTERVAL_TO_MSEC(t) ((ZB_BEACON_INTERVAL_USEC * (zb_time_t)(t)) / 1000) |
#define | ZB_TIME_BEACON_INTERVAL_TO_USEC(t) ((zb_uint64_t)ZB_BEACON_INTERVAL_USEC * (t)) |
#define | ZB_TIME_QUARTERECONDS(n) (ZB_TIME_BEACON_INTERVAL_TO_MSEC((n)) / 250) |
#define | ZB_QUARTERECONDS_TO_MSEC(n) 250*(n) |
#define | ZB_QUARTERECONDS_TO_BEACON_INTERVAL(qsec) ZB_MILLISECONDS_TO_BEACON_INTERVAL(250*qsec) |
#define | ZB_SECONDS_TO_MILLISECONDS(_s) (1000l*(_s)) |
#define | ZB_MILLISECONDS_TO_USEC(ms) ((ms) * (1000)) |
#define | ZB_USECS_TO_MILLISECONDS(usec) ((usec) / (1000)) |
Typedefs | |
typedef zb_uint32_t | zb_time_t |
Functions | |
zb_time_t | zb_timer_get () |
More... | |
#define ZB_ABASE_SUPERFRAME_DURATION 960 |
#define ZB_BEACON_INTERVAL_USEC (ZB_SYMBOL_DURATION_USEC * ZB_ABASE_SUPERFRAME_DURATION) |
Beacon interval in microseconds
1 beacon interval = aBaseSuperframeDuration * symbol duration
1 symbol = 16e-6 sec (mac spec 6.5.3.2 Symbol rate) for 2.4GHz ZB. 1 beacon interval = 15.360 ms.
#define ZB_MILLISECONDS_TO_BEACON_INTERVAL | ( | ms | ) | (((zb_time_t)(ms) * 1000) / ZB_BEACON_INTERVAL_USEC) |
Convert time from milliseconds to beacon intervals (32-bit platforms).
#define ZB_MILLISECONDS_TO_USEC | ( | ms | ) | ((ms) * (1000)) |
Convert from milliseconds to microseconds
#define ZB_QUARTERECONDS_TO_BEACON_INTERVAL | ( | qsec | ) | ZB_MILLISECONDS_TO_BEACON_INTERVAL(250*qsec) |
Convert from quarterseconds to beacon
#define ZB_QUARTERECONDS_TO_MSEC | ( | n | ) | 250*(n) |
Convert from quarterseconds to msec
#define ZB_SECONDS_TO_MILLISECONDS | ( | _s | ) | (1000l*(_s)) |
Convert from seconds to milliseconds
#define ZB_SYMBOL_DURATION_USEC 16 /* 1 symbol = 16e-6 sec (mac spec 6.5.3.2 Symbol rate) */ |
Symbol duration.
#define ZB_TIME_ADD | ( | a, | |
b | |||
) | (zb_time_t)((a) + (b)) |
Time add: add 'a' to 'b'
Overflow is possible, but this is ok - it handled by subtraction and compare macros.
a | - time to add to |
b | - value to add |
#define ZB_TIME_BEACON_INTERVAL_TO_MSEC | ( | t | ) | ((ZB_BEACON_INTERVAL_USEC * (zb_time_t)(t)) / 1000) |
Convert time from beacon intervals to milliseconds (32-bit platform).
#define ZB_TIME_BEACON_INTERVAL_TO_USEC | ( | t | ) | ((zb_uint64_t)ZB_BEACON_INTERVAL_USEC * (t)) |
Convert time from beacon intervals to microseconds
#define ZB_TIME_GE | ( | a, | |
b | |||
) | ((zb_time_t)((a) - (b)) < ZB_HALF_MAX_TIME_VAL) |
Compare times a and b - check that a >= b
Taking into account overflow and unsigned values arithmetic and supposing difference between a and b can't be > 1/2 of the overall time values diapason, a >= b only if a - b < values_diapason/2
a | - first time value to compare |
b | - second time value to compare |
#define ZB_TIME_ONE_SECOND ZB_MILLISECONDS_TO_BEACON_INTERVAL(1000) |
One second timeout
#define ZB_TIME_QUARTERECONDS | ( | n | ) | (ZB_TIME_BEACON_INTERVAL_TO_MSEC((n)) / 250) |
Quarterseconds timeout
#define ZB_TIME_SUBTRACT | ( | a, | |
b | |||
) | ((zb_time_t)((a) - (b)) < ZB_HALF_MAX_TIME_VAL ? (zb_time_t)((a) - (b)) : (zb_time_t)((b) - (a))) |
Time subtraction: subtract 'b' from 'a'
Take overflow into account: change sign (subtraction order) if result > values_diapasin/2. Suppose a always >= b, so result is never negative. This macro will be used to calculate, for example, amount of time to sleep
a | - time to subtract from |
b | - time to subtract |
#define ZB_TIMER_GET | ( | ) | (zb_timer_get()) |
#define ZB_USECS_TO_MILLISECONDS | ( | usec | ) | ((usec) / (1000)) |
Convert from microseconds to milliseconds
typedef zb_uint32_t zb_time_t |
The idea is: platform has some timer which can be stopped or run. When run, it increments (or decrements - depends on platform) some counter until counter overflow (underflow), then issues interrupt - wakeups main loop if it sleeping. Time stored in ticks; time resolution is platform dependent, its usual value is 15.36 usec - 1 beacon interval. Note that time type has limited capacity (usually 16 bits) and can overflow. Macros which works with time handles overflow. It is supposed that time values will not differ to more then 1/2 of the maximum time value.
All that timer macros will not be used directly by the application code - it is scheduler internals. The only API for timer is ZB_SCHEDULE_ALARM() call. Timer type.
zb_time_t zb_timer_get | ( | ) |