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)
 Cancel a task. 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,
  APP_SCHEDULER_RES_TOO_LONG_EXECUTION_TIME = 4, APP_SCHEDULER_RES_TOO_SHORT_EXECUTION_TIME = 5
}
 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
...
// 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
appconfig/app.c, custom_app/app.c, scheduler/app.c, and shared_data/app.c.

◆ App_Scheduler_cancelTask()

app_scheduler_res_e App_Scheduler_cancelTask ( task_cb_f  cb)

Cancel a task.

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

◆ App_Scheduler_init()

void App_Scheduler_init ( void  )

Initialize scheduler.

Note
If App scheduler is enabled in app, App_Scheduler_init is automatically called before App_init
If App scheduler is used in application, the periodicWork offered by system library MUST NOT be used outside of this module

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

APP_SCHEDULER_RES_TOO_LONG_EXECUTION_TIME 

Requested time is too long

APP_SCHEDULER_RES_TOO_SHORT_EXECUTION_TIME 

Requested time is too short

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
custom_app/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
scheduler/app.c, and shared_data/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_RES_NO_MORE_TASK
@ APP_SCHEDULER_RES_NO_MORE_TASK
Definition: app_scheduler.h:52
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.
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: wms_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
APP_SCHEDULER_RES_TOO_LONG_EXECUTION_TIME
@ APP_SCHEDULER_RES_TOO_LONG_EXECUTION_TIME
Definition: app_scheduler.h:58
APP_SCHEDULER_RES_TOO_SHORT_EXECUTION_TIME
@ APP_SCHEDULER_RES_TOO_SHORT_EXECUTION_TIME
Definition: app_scheduler.h:60