Schedule handling library

nRF5 SDK v15.2.0

The scheduler is used for transferring execution from the interrupt context to the main context.

Requirements:

Logic in main context:

  • Define an event handler for each type of event expected.
  • Initialize the scheduler by calling the APP_SCHED_INIT() macro before entering the application main loop.
  • Call app_sched_execute() from the main loop each time the application wakes up because of an event (typically when sd_app_evt_wait() returns).

Logic in interrupt context:

  • In the interrupt handler, call app_sched_event_put() with the appropriate data and event handler. This will insert an event into the scheduler's queue. The app_sched_execute() function will pull this event and call its handler in the main context.

For an example usage of the scheduler, see the implementations of HID Mouse Application and HID Keyboard Application .

Page-1 Sheet.227 Sheet.228 Sheet.229 Application handlers Application handlers Sheet.230 Handler 1 Handler 1 Sheet.231 Handler 2 Handler 2 Sheet.232 Handler 3 Handler 3 Sheet.236 Sheet.237 Timer Timer Sheet.238 Scheduler Scheduler Sheet.239 RTC RTC Sheet.240 Hardware drivers and interrupts (e.g. push buttons) Hardware drivers and interrupts (e.g. push buttons) Sheet.241 Sheet.242 Sheet.243 Sheet.244 Sheet.245 Sheet.246 Sheet.247 Sheet.248
The high level design of the scheduler

Applications using the Scheduler

Sequence diagrams illustrating the flow of events for various scenarios in the example applications when using the Scheduler.

ble_event_with_scheduler.svg
Figure 1: Receiving an event from the ble stack causing a service event


battery_timer_with_scheduler.svg
Figure 2: The battery timer expires


Applications not using the Scheduler

Sequence diagrams illustrating the flow of events for various scenarios in the example applications when not using the Scheduler.

ble_event_without_scheduler.svg
Figure 3: Receiving an event from the ble stack causing a service event


battery_timer_without_scheduler.svg
Figure 4: The battery timer expires