ruuvi.drivers.c ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
Interface for scheduling tasks to be executed later.

Files

file  ruuvi_interface_scheduler_test.h
 Test interface functions to scheduler.
 
file  ruuvi_interface_scheduler.h
 Interface functions to scheduler.
 

Typedefs

typedef void(* ruuvi_scheduler_event_handler_t) (void *p_event_data, uint16_t event_size)
 Type definition for scheduler event handler.
 

Functions

bool ri_scheduler_run_integration_test (const rd_test_print_fp printfp)
 Run all scheduler integration tests.
 
rd_status_t ri_scheduler_init (void)
 Enable implementation selected by application.
 
rd_status_t ri_scheduler_execute (void)
 Executes all scheduled tasks.
 
rd_status_t ri_scheduler_event_put (const void *const p_event_data, const uint16_t event_size, const ruuvi_scheduler_event_handler_t handler)
 Schedule given task to be executed on next call to ri_scheduler_execute.
 
rd_status_t ri_scheduler_uninit (void)
 Uninitialize scheduler.
 
bool ri_scheduler_is_init (void)
 Check if scheduler is initialized.
 

Detailed Description

Typedef Documentation

◆ ruuvi_scheduler_event_handler_t

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

Type definition for scheduler event handler.

Parameters
[in]p_event_dataData for the event handler.
[in]event_sizeSize of the event data. Must be smaller than or equal to max_event_size.

Definition at line 48 of file ruuvi_interface_scheduler.h.

Function Documentation

◆ ri_scheduler_event_put()

rd_status_t ri_scheduler_event_put ( const void *const  p_event_data,
const uint16_t  event_size,
const ruuvi_scheduler_event_handler_t  handler 
)

Schedule given task to be executed on next call to ri_scheduler_execute.

Parameters
[in]p_event_dataContext for the scheduled event, will be stored to scheduler queue. Use NULL if there is no context for the task.
[in]event_sizeSize of context in bytes. Use 0 if there is no context for the task.
[in]handlerFunction to handle the event. Must not be NULL
Return values
RD_SUCCESSon success.
RD_ERROR_NULLif handler is NULL
RD_ERROR_INVALID_LENGTHif event data is larger than task queue event size.
RD_ERROR_NO_MEMif the task cannot be added to queue due to queue full.

◆ ri_scheduler_execute()

rd_status_t ri_scheduler_execute ( void  )

Executes all scheduled tasks.

If task schedules itself to be run immediately this will be run in a never-ending loop, without sleeping.

Return values
RD_SUCCESSif queue was executed successfully.
errorcode from the stack if error occurs.

◆ ri_scheduler_init()

rd_status_t ri_scheduler_init ( void  )

Enable implementation selected by application.

Initialize scheduler.

Allocates memory for scheduler task queue. Because memory allocation is static, the size has to be defined in macors RI_SCHEDULER_SIZE and RI_SCHEDULER_LENGTH. The RI_SCHEDULER_SIZE defines maximum size of scheduler event and RI_SCHEDULER_LENGTH defines maximum number of events that can be queued.

Return values
RD_SUCCESSon success.
errorcode from stack on error.

◆ ri_scheduler_is_init()

bool ri_scheduler_is_init ( void  )

Check if scheduler is initialized.

Return values
trueIf scheduler is initialized.
falseIf scheduler is not initialized.

◆ ri_scheduler_run_integration_test()

bool ri_scheduler_run_integration_test ( const rd_test_print_fp  printfp)

Run all scheduler integration tests.

Parameters
[in]printfpFunction to which test JSON is passed.
Return values
falseif no errors occured.
trueif error occured.

◆ ri_scheduler_uninit()

rd_status_t ri_scheduler_uninit ( void  )

Uninitialize scheduler.

Scheduler has to be re-initialized after uninitialization, and all the previous tasks not yet executed are discarded. As the memory is statically allocated, no memory is freed.