Macros | |
#define | ZB_SCHEDULE_CALLBACK(func, param) zb_schedule_callback(func, param, ZB_FALSE, 0, ZB_FALSE) |
#define | ZB_SCHEDULE_CALLBACK2(func, param, user_param) zb_schedule_callback((zb_callback_t)func, param, ZB_TRUE, user_param, ZB_FALSE) |
#define | ZB_SCHEDULE_ALARM(func, param, timeout_bi) zb_schedule_alarm(func, param, timeout_bi) |
#define | ZB_ALARM_ANY_PARAM (zb_uint8_t)(-1) |
#define | ZB_ALARM_ALL_CB (zb_uint8_t)(-2) |
#define | ZB_SCHEDULE_ALARM_CANCEL(func, param) zb_schedule_alarm_cancel((func), (param), NULL) |
#define | ZB_SCHEDULE_ALARM_CANCEL_AND_GET_BUF(func, param, p_param) zb_schedule_alarm_cancel((func), (param), p_param) |
#define | ZB_SCHEDULE_GET_ALARM_TIME(func, param, timeout_bi) zb_schedule_get_alarm_time(func, param, timeout_bi) |
Typedefs | |
typedef void(* | zb_callback_t )(zb_uint8_t param) |
typedef zb_ret_t(* | zb_ret_callback_t )(zb_uint8_t param) |
typedef void(* | zb_callback_void_t )(void) |
typedef void(* | zb_callback2_t )(zb_uint8_t param, zb_uint16_t cb_param) |
Use cooperative multitasking. Trivial scheduler: do all in callbacks. No 'task' primitive. Base primitive - callback call. Callback will be called indirectly, via scheduler. Callback call can be treated as event send. Callbacks schedule done via scheduler in the main scheduler loop. Can pass 1 parameter (void*) to the callback. Callback initiated using call schedule_callback(func, param). Scheduling callback does not block currently running callback. More then one callback can be scheduled. It will be called later, when current function will return to the scheduler.
Before main loop call application-dependent initialization functions. It can schedule some callbacks. Callbacks will be called later, in the main loop.
Data structure for callbacks support - fixed-size ring buffer of callbacks control structure. Callbacks served in FIFO order, no priorities.
When no callbacks to call, scheduler put device asleep (stop CPU for 8051, wait inside select() for Linux); it can be waked by interrupt (8051) or data arrive or timeout (Linux).
There are 2 possible kinds of routines: callbacks running in the main loop and interrupt handlers. Interrupt handlers works with SPI, UART, timer, transceiver interrupt (what else?). Interrupt handler can't schedule callback call.
To work with data shared between interrupt handler and main loop introduced "global lock" operation. It means interrupts disable when running not in the interrupt context. In Linux it means either mutex lock or nothing (depending on i/o implementation).
#define ZB_ALARM_ALL_CB (zb_uint8_t)(-2) |
Special parameter for zb_schedule_alarm_cancel(): cancel alarm for all parameters
#define ZB_ALARM_ANY_PARAM (zb_uint8_t)(-1) |
Special parameter for zb_schedule_alarm_cancel(): cancel alarm once without parameter check
Cancel only one alarm without check for parameter
#define ZB_SCHEDULE_ALARM | ( | func, | |
param, | |||
timeout_bi | |||
) | zb_schedule_alarm(func, param, timeout_bi) |
Schedule alarm - callback to be executed after timeout.
Function will be called via scheduler after timeout expired (maybe, plus some additional time). Timer resolution depends on implementation. Same callback can be scheduled for execution more then once.
func | - function to call via scheduler |
param | - parameter to pass to the function |
timeout_bi | - timeout, in beacon intervals |
See any sample
#define ZB_SCHEDULE_ALARM_CANCEL | ( | func, | |
param | |||
) | zb_schedule_alarm_cancel((func), (param), NULL) |
Cancel scheduled alarm.
This function cancel previously scheduled alarm. Function is identified by the pointer.
func | - function to cancel |
param | - parameter to cancel. |
See reporting_srv sample
#define ZB_SCHEDULE_ALARM_CANCEL_AND_GET_BUF | ( | func, | |
param, | |||
p_param | |||
) | zb_schedule_alarm_cancel((func), (param), p_param) |
Cancel scheduled alarm and get buffer.
This function cancel previously scheduled alarm and returns buffer ref associated with alarm. Function is identified by the pointer.
func | - function to cancel |
param | - parameter to cancel. |
p_param | - [out] pointer of ref buffer from cancelled flag: free buffer if its alarm will be cancel |
Example:
See reporting_srv sample
#define ZB_SCHEDULE_CALLBACK | ( | func, | |
param | |||
) | zb_schedule_callback(func, param, ZB_FALSE, 0, ZB_FALSE) |
Schedule single-param callback execution.
Schedule execution of function `func' in the main scheduler loop.
func | - function to execute |
param | - callback parameter - usually, but not always ref to packet buffer |
See sched sample
#define ZB_SCHEDULE_CALLBACK2 | ( | func, | |
param, | |||
user_param | |||
) | zb_schedule_callback((zb_callback_t)func, param, ZB_TRUE, user_param, ZB_FALSE) |
Schedule two-param callback execution. Schedule execution of function `func' in the main scheduler loop.
func | - function to execute |
param | - zb_uint8_t callback parameter - usually, but not always ref to packet buffer |
user_param | - zb_uint16_t user parameter - usually, but not always short address |
#define ZB_SCHEDULE_GET_ALARM_TIME | ( | func, | |
param, | |||
timeout_bi | |||
) | zb_schedule_get_alarm_time(func, param, timeout_bi) |
Get Schedule alarm time - seek alarm and return alarm time
func | - function to call via scheduler |
param | - parameter to pass to the function |
timeout_bi | - pointer on alarm timeout, in beacon intervals |
typedef void( * zb_callback2_t)(zb_uint8_t param, zb_uint16_t cb_param) |
Callback function with 2 parameters typedef. Callback is function planned to execute by another function. Note that callback must be declared as reentrant for sdcc.
param | - callback parameter - usually, but not always, ref to packet buf |
cb_param | - additional 2-byte callback parameter, user data. |
See any sample
typedef void( * zb_callback_t)(zb_uint8_t param) |
Callback function typedef. Callback is function planned to execute by another function. Note that callback must be declared as reentrant for sdcc.
param | - callback parameter - usually, but not always, ref to packet buf |
See any sample