Patched version of nrf51822 FOTA compatible driver, with GPTIO disabled, as it clashed with the mbed definitions...

Fork of nRF51822 by Nordic Semiconductor

Embed: (wiki syntax)

« Back to documentation index

Scheduler

Scheduler

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

Typedefs

typedef void(* app_sched_event_handler_t )(void *p_event_data, uint16_t event_size)
 Scheduler event handler type.

Functions

uint32_t app_sched_init (uint16_t max_event_size, uint16_t queue_size, void *p_evt_buffer)
 Function for initializing the Scheduler.
void app_sched_execute (void)
 Function for executing all scheduled events.
uint32_t app_sched_event_put (void *p_event_data, uint16_t event_size, app_sched_event_handler_t handler)
 Function for scheduling an event.
void app_sched_pause (void)
 A function to pause the scheduler.
void app_sched_resume (void)
 A function to resume a scheduler.

Detailed Description

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

See seq_diagrams_sched for sequence diagrams illustrating the flow of events when using the Scheduler.

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.

(

scheduler_working.jpg

The high level design of the scheduler


Typedef Documentation

typedef void(* app_sched_event_handler_t)(void *p_event_data, uint16_t event_size)

Scheduler event handler type.

Definition at line 70 of file app_scheduler.h.


Function Documentation

uint32_t app_sched_event_put ( void *  p_event_data,
uint16_t  event_size,
app_sched_event_handler_t  handler 
)

Function for scheduling an event.

Puts an event into the event queue.

Parameters:
[in]p_event_dataPointer to event data to be scheduled.
[in]event_sizeSize of event data to be scheduled.
[in]handlerEvent handler to receive the event.
Returns:
NRF_SUCCESS on success, otherwise an error code.

Definition at line 79 of file app_scheduler.c.

void app_sched_execute ( void   )

Function for executing all scheduled events.

This function must be called from within the main loop. It will execute all events scheduled since the last time it was called.

Definition at line 168 of file app_scheduler.c.

uint32_t app_sched_init ( uint16_t  max_event_size,
uint16_t  queue_size,
void *  p_evt_buffer 
)

Function for initializing the Scheduler.

It must be called before entering the main loop.

Parameters:
[in]max_event_sizeMaximum size of events to be passed through the scheduler.
[in]queue_sizeNumber of entries in scheduler queue (i.e. the maximum number of events that can be scheduled for execution).
[in]p_evt_bufferPointer to memory buffer for holding the scheduler queue. It must be dimensioned using the APP_SCHED_BUFFER_SIZE() macro. The buffer must be aligned to a 4 byte boundary.
Note:
Normally initialization should be done using the APP_SCHED_INIT() macro, as that will both allocate the scheduler buffer, and also align the buffer correctly.
Return values:
NRF_SUCCESSSuccessful initialization.
NRF_ERROR_INVALID_PARAMInvalid parameter (buffer not aligned to a 4 byte boundary).

Definition at line 57 of file app_scheduler.c.

void app_sched_pause ( void   )

A function to pause the scheduler.

When the scheduler is paused events are not pulled from the scheduler queue for processing. The function can be called multiple times. To unblock the scheduler the function app_sched_resume has to be called the same number of times.

void app_sched_resume ( void   )

A function to resume a scheduler.

To unblock the scheduler this function has to be called the same number of times as app_sched_pause function.