Event System#

Zigbee event system API.

See zigbee_app_framework_event.h for source code.

Following a brief usage example that demonstrate how to create an event, initialize it and use it. In this example, the event is initialized and set to pending, then it gets rescheduled every second.

// Declare event as global
sl_zigbee_af_event_t my_event;
sl_zigbee_af_event_t my_isr_event;

void SOME_IRQHandler(void)
{
   // Activates the ISR type event from IRQ Handler.
   sl_zigbee_af_event_set_active(&my_isr_event);
}

void my_isr_event_handler(sl_zigbee_af_event_t *event)
{
   // Event expired, do something
}

void my_event_hendler(sl_zigbee_af_event_t *event)
{
   // Event expired, do something

   // Reschedule the event to expire again in 1 second
   sl_zigbee_af_event_set_delay_ms(&my_event, 1000);
}

void app_init(void)
{
   // Initialize event
   sl_zigbee_af_event_init(&my_event, my_event_handler);

   // Initialise an event type that can be activated from the ISR.
   sl_zigbee_af_isr_event_init(&my_isr_event, my_isr_event_handler);

   // Set the event to expire immediately (that is, in the next iteration of the main loop)
   sl_zigbee_af_event_set_active(&my_event);
}

API#

void
sl_zigbee_af_isr_event_init(sl_zigbee_af_event_t *event, void(*handler)(sl_zigbee_af_event_t *))

Application event initialization routine for events intended to be activated in ISR. An event that is activated in ISR context must be initialized using this API. Such event can only be scheduled to expire immediately using sl_zigbee_af_event_set_active. The event handler will be executed from DSR context either from the application main loop in a bare metal setup or in the Application Framework Task main loop in an OS setup. Any attempt to schedule a non zero delay or deactivation for an event initialized as ISR event will result in an assert.

void
sl_zigbee_af_event_init(sl_zigbee_af_event_t *event, void(*handler)(sl_zigbee_af_event_t *))

Application event initialization routine. Every application event must be initialized.

void
sl_zigbee_af_event_set_delay_ms(sl_zigbee_af_event_t *event, uint32_t delay)

Schedule an event to run after a delay expressed in milliseconds.

void
sl_zigbee_af_event_set_active(sl_zigbee_af_event_t *event)

Schedule an event to run immediately.

void
sl_zigbee_af_event_set_inactive(sl_zigbee_af_event_t *event)

Cancel an event.

bool
sl_zigbee_af_event_is_scheduled(sl_zigbee_af_event_t *event)

Returns true if the event is scheduled to run, false otherwise.

uint32_t
sl_zigbee_af_event_get_remaining_ms(sl_zigbee_af_event_t *event)

Returns the number of milliseconds before the event runs, or -1 if the event is not scheduled to run.

API Documentation#

sl_zigbee_af_isr_event_init#

void sl_zigbee_af_isr_event_init (sl_zigbee_af_event_t * event, void(*)(sl_zigbee_af_event_t *) handler)

Application event initialization routine for events intended to be activated in ISR. An event that is activated in ISR context must be initialized using this API. Such event can only be scheduled to expire immediately using sl_zigbee_af_event_set_active. The event handler will be executed from DSR context either from the application main loop in a bare metal setup or in the Application Framework Task main loop in an OS setup. Any attempt to schedule a non zero delay or deactivation for an event initialized as ISR event will result in an assert.

Parameters
[in]event

A pointer to the sl_zigbee_af_event_t object to be initialized. Event objects must be global.

[in]handler

Handler function that shall be called when the event runs.


Definition at line 121 of file app/framework/common/zigbee_app_framework_event.h

sl_zigbee_af_event_init#

void sl_zigbee_af_event_init (sl_zigbee_af_event_t * event, void(*)(sl_zigbee_af_event_t *) handler)

Application event initialization routine. Every application event must be initialized.

Parameters
[in]event

A pointer to the sl_zigbee_af_event_t object to be initalized. Event objects must be global.

[in]handler

Handler function that shall be called when the event runs.


Definition at line 133 of file app/framework/common/zigbee_app_framework_event.h

sl_zigbee_af_event_set_delay_ms#

void sl_zigbee_af_event_set_delay_ms (sl_zigbee_af_event_t * event, uint32_t delay)

Schedule an event to run after a delay expressed in milliseconds.

Parameters
[in]event

A pointer to the sl_zigbee_af_event_t object to be scheduled to run after a delay.

[in]delay

The delay in milliseconds after which the event shall run.


Definition at line 153 of file app/framework/common/zigbee_app_framework_event.h

sl_zigbee_af_event_set_active#

void sl_zigbee_af_event_set_active (sl_zigbee_af_event_t * event)

Schedule an event to run immediately.

Parameters
[in]event

A pointer to the sl_zigbee_af_event_t object to be scheduled to run immediately.


Definition at line 165 of file app/framework/common/zigbee_app_framework_event.h

sl_zigbee_af_event_set_inactive#

void sl_zigbee_af_event_set_inactive (sl_zigbee_af_event_t * event)

Cancel an event.

Parameters
[in]event

A pointer to the sl_zigbee_af_event_t object to be cancelled.


Definition at line 177 of file app/framework/common/zigbee_app_framework_event.h

sl_zigbee_af_event_is_scheduled#

bool sl_zigbee_af_event_is_scheduled (sl_zigbee_af_event_t * event)

Returns true if the event is scheduled to run, false otherwise.

Parameters
[in]event

A pointer to an sl_zigbee_af_event_t object.

Returns

  • true if the passed event is scheduled to run, false otherwise.


Definition at line 190 of file app/framework/common/zigbee_app_framework_event.h

sl_zigbee_af_event_get_remaining_ms#

uint32_t sl_zigbee_af_event_get_remaining_ms (sl_zigbee_af_event_t * event)

Returns the number of milliseconds before the event runs, or -1 if the event is not scheduled to run.

Parameters
[in]event

A pointer to an sl_zigbee_af_event_t object.

Returns

  • The number of milliseconds before the event runs, or -1 if the event is not scheduled to run.


Definition at line 205 of file app/framework/common/zigbee_app_framework_event.h