Wirepas SDK
app_scheduler.h File Reference

Detailed Description

Application scheduler library. Allows scheduling of multiple application tasks concurrently.

Note
Unlike most services, this library is safe to be used from fast interrupt execution context

Definition in file app_scheduler.h.

Go to the source code of this file.

Typedefs

typedef uint32_t(* task_cb_f) ()
 Task callback to be registered. More...
 

Functions

void App_Scheduler_init (void)
 Initialize scheduler. More...
 
app_scheduler_res_e App_Scheduler_addTask_execTime (task_cb_f cb, uint32_t delay_ms, uint32_t exec_time_us)
 Add a task. More...
 
app_scheduler_res_e App_Scheduler_cancelTask (task_cb_f cb)
 Add a task without execution time (deprecated) More...
 

Enumerations

enum  app_scheduler_res_e { APP_SCHEDULER_RES_OK = 0, APP_SCHEDULER_RES_NO_MORE_TASK = 1, APP_SCHEDULER_RES_UNKNOWN_TASK = 2, APP_SCHEDULER_RES_UNINITIALIZED = 3 }
 List of return code. More...
 

Macros

#define APP_SCHEDULER_STOP_TASK   ((uint32_t)(-1))
 Value to return from task to remove it. More...
 
#define APP_SCHEDULER_SCHEDULE_ASAP   (0)
 Value to return from task or as initial time to be executed ASAP. More...
 

Typedef Documentation

◆ task_cb_f

typedef uint32_t(* task_cb_f) ()

Task callback to be registered.

Returns
Delay before being executed again in ms
Note
Return value in ms is aligned on system coarse timesatmp boundaries that has a 1/128s granularity. So asking 3 or 7 ms will result in same scheduling. If a better accuracy is needed, hardware timer must be used

Definition at line 32 of file app_scheduler.h.

Function Documentation

◆ App_Scheduler_addTask_execTime()

app_scheduler_res_e App_Scheduler_addTask_execTime ( task_cb_f  cb,
uint32_t  delay_ms,
uint32_t  exec_time_us 
)

Add a task.

Example on use:

static uint32_t periodic_task_50ms()
{
...
return 50;
}
static uint32_t periodic_task_500ms()
{
...
return 500;
}
void App_init(const app_global_functions_t * functions)
{
// Launch two periodic task with different period
App_Scheduler_addTask(periodic_task_50ms, APP_SCHEDULER_SCHEDULE_ASAP);
App_Scheduler_addTask(periodic_task_500ms, APP_SCHEDULER_SCHEDULE_ASAP);
...
// Start the stack
lib_state->startStack();
}
Parameters
cbCallback to be called from main periodic task. Same cb can only be added once. Calling this function with an already registered cb will update the next scheduled time.
delay_msdelay in ms to be scheduled (0 to be scheduled asap)
exec_time_usMaximum execution time required for the task to be executed
Returns
True if able to add, false otherwise
Examples
scheduler/app.c.

◆ App_Scheduler_cancelTask()

app_scheduler_res_e App_Scheduler_cancelTask ( task_cb_f  cb)

Add a task without execution time (deprecated)

Parameters
cbCallback to be called from main periodic task. Same cb can only be added once. Calling this function with an already registered cb will update the next scheduled time.
delay_msdelay in ms to be scheduled (0 to be scheduled asap)
Returns
True if able to add, false otherwise
Note
This call is deprecated and you should use App_Scheduler_addTask_execTime instead

Cancel a task

Parameters
cbCallback already registered from App_Scheduler_addTask.
Returns
True if able to cancel, false otherwise (not existing)
Examples
inventory_app_tag/app.c, ruuvi_evk/app.c, and scheduler/app.c.

◆ App_Scheduler_init()

void App_Scheduler_init ( void  )

Initialize scheduler.

Example on use:

void App_init(const app_global_functions_t * functions)
{
...
// Start the stack
lib_state->startStack();
}
Note
If App scheduler is used in application, the periodicWork offered by system library MUST NOT be used outside of this module
Examples
dualmcu_app/app.c, inventory_app_router/app.c, inventory_app_tag/app.c, nfc/app.c, positioning_app/app.c, provisioning_joining_node/app.c, ruuvi_evk/app.c, and scheduler/app.c.

Enumeration Type Documentation

◆ app_scheduler_res_e

List of return code.

Enumerator
APP_SCHEDULER_RES_OK 

Operation is successful

APP_SCHEDULER_RES_NO_MORE_TASK 

No more tasks available

APP_SCHEDULER_RES_UNKNOWN_TASK 

Trying to cancel a task that doesn't exist

APP_SCHEDULER_RES_UNINITIALIZED 

Using the library without previous initialization

Definition at line 47 of file app_scheduler.h.

Macro Definition Documentation

◆ APP_SCHEDULER_SCHEDULE_ASAP

#define APP_SCHEDULER_SCHEDULE_ASAP   (0)

Value to return from task or as initial time to be executed ASAP.

Examples
inventory_app_tag/app.c, positioning_app/app.c, ruuvi_evk/app.c, and scheduler/app.c.

Definition at line 42 of file app_scheduler.h.

◆ APP_SCHEDULER_STOP_TASK

#define APP_SCHEDULER_STOP_TASK   ((uint32_t)(-1))

Value to return from task to remove it.

Examples
inventory_app_tag/app.c, nfc/app.c, positioning_app/app.c, and scheduler/app.c.

Definition at line 37 of file app_scheduler.h.

APP_SCHEDULER_RES_UNINITIALIZED
@ APP_SCHEDULER_RES_UNINITIALIZED
Definition: app_scheduler.h:56
APP_SCHEDULER_RES_OK
@ APP_SCHEDULER_RES_OK
Definition: app_scheduler.h:50
App_Scheduler_init
void App_Scheduler_init(void)
Initialize scheduler.
APP_SCHEDULER_RES_NO_MORE_TASK
@ APP_SCHEDULER_RES_NO_MORE_TASK
Definition: app_scheduler.h:52
APP_SCHEDULER_RES_UNKNOWN_TASK
@ APP_SCHEDULER_RES_UNKNOWN_TASK
Definition: app_scheduler.h:54
app_scheduler_res_e
app_scheduler_res_e
List of return code.
Definition: app_scheduler.h:47
app_global_functions_t
List of global functions, passed to App_entrypoint()
Definition: app.h:157
APP_SCHEDULER_SCHEDULE_ASAP
#define APP_SCHEDULER_SCHEDULE_ASAP
Value to return from task or as initial time to be executed ASAP.
Definition: app_scheduler.h:42