Skip to content

Class TaskAPI

ClassList > TaskAPI

Public Functions

Type Name
int8_t createBackground (task_function_t routine)
Creates a background task. Background tasks are asynchronous tasks that run in the background when there is no critical task running.
int8_t createCritical (task_function_t periodic_task, uint32_t task_period_us, scheduling_interrupt_source_t int_source=source_hrtim)
Creates a time critial task. A critical task is an Uninterruptible Synchronous Task that uses a precise timer to execute a periodic, non-interruptible user task. Use this function to define such a task. Only one task of this kind can be defined. This function can be used to redefine (replace) a previously defined uninterruptible synchronous task, but the previously defined task must have been suspended (or never started). An error will be returned if the previously defined task is still running.
void startBackground (uint8_t task_number)
Use this function to start a previously defined background task using its task number.
void startCritical (bool manage_data_acquisition=true)
Use this function to start a previously defined a critical task.
void stopBackground (uint8_t task_number)
Use this function to stop a previously started background task using its task number.
void stopCritical ()
Stop the previously started critical task. A critical task is an Uninterruptible Synchronous Task that uses a precise timer to execute a periodic, non-interruptible user task. The task can be then resumed by calling startCritical() again.
void suspendBackgroundMs (uint32_t duration_ms)
This function allows to suspend a background task for a specified duration expressed in milliseconds. For example, you can call this function at the end of a background task function, when there is no need for the task to run permanently.
void suspendBackgroundUs (uint32_t duration_us)
This function allows to suspend a background task for a specified duration expressed in microseconds. For example, you can call this function at the end of a background task function, when there is no need for the task to run permanently.

Public Functions Documentation

function createBackground

Creates a background task. Background tasks are asynchronous tasks that run in the background when there is no critical task running.

int8_t TaskAPI::createBackground (
    task_function_t routine
) 

Parameters:

  • routine Pointer to the void(void) function that will act as the task main function.

Returns:

Number assigned to the task. Will be -1 if max number of asynchronous task has been reached. In such a case, the task definition is ignored. Increase maximum number of asynchronous tasks in prj.conf if required.


function createCritical

Creates a time critial task. A critical task is an Uninterruptible Synchronous Task that uses a precise timer to execute a periodic, non-interruptible user task. Use this function to define such a task. Only one task of this kind can be defined. This function can be used to redefine (replace) a previously defined uninterruptible synchronous task, but the previously defined task must have been suspended (or never started). An error will be returned if the previously defined task is still running.

int8_t TaskAPI::createCritical (
    task_function_t periodic_task,
    uint32_t task_period_us,
    scheduling_interrupt_source_t int_source=source_hrtim
) 

Parameters:

  • periodic_task Pointer to the void(void) function to be executed periodically.
  • task_period_us Period of the function in µs. Allowed range: 1 to 6553 µs. If interrupt source is HRTIM, this value MUST be an integer multiple of the HRTIM period.
  • int_source Interrupt source that triggers the task. By default, the HRTIM is the source, but this optional parameter can be provided to set TIM6 as the source in case the HRTIM is not used or if the task can't be correlated to an HRTIM event. Allowed values are source_hrtim and source_tim6.

Returns:

0 if everything went well, -1 if there was an error defining the task. An error can occur notably when an uninterruptible task has already been defined previously.


function startBackground

Use this function to start a previously defined background task using its task number.

void TaskAPI::startBackground (
    uint8_t task_number
) 

Background tasks are asynchronous tasks that run in the background when there is no critical task running.

Parameters:

  • task_number Number of the task to start, obtained using the defineAsynchronousTask() function.

function startCritical

Use this function to start a previously defined a critical task.

void TaskAPI::startCritical (
    bool manage_data_acquisition=true
) 

A critical task is an Uninterruptible Synchronous Task that uses a precise timer to execute a periodic, non-interruptible user task.

If no value is provided for the parameter and Data Acquisition has not been started yet, Scheduling will automatically start Data Acquisition. Thus, make sure all ADC configuration has been carried out before starting the uninterruptible task.

Parameters:

  • manage_data_acquisition Set to false if you want the Scheduling module to not be in charge of Data Acquisition scheduling. If set to false, Data Acquisition has to be manually started if you want to use it.

function stopBackground

Use this function to stop a previously started background task using its task number.

void TaskAPI::stopBackground (
    uint8_t task_number
) 

Background tasks are asynchronous tasks that run in the background when there is no critical task running. The task can be then resumed by calling startAsynchronousTask() again.

Parameters:

  • task_number Number of the task to start, obtained using the defineAsynchronousTask() function.

function stopCritical

void TaskAPI::stopCritical () 

function suspendBackgroundMs

This function allows to suspend a background task for a specified duration expressed in milliseconds. For example, you can call this function at the end of a background task function, when there is no need for the task to run permanently.

void TaskAPI::suspendBackgroundMs (
    uint32_t duration_ms
) 

DO NOT use this function in a critical task!


function suspendBackgroundUs

This function allows to suspend a background task for a specified duration expressed in microseconds. For example, you can call this function at the end of a background task function, when there is no need for the task to run permanently.

void TaskAPI::suspendBackgroundUs (
    uint32_t duration_us
) 

DO NOT use this function in a critical task!



The documentation for this class was generated from the following file docs/core/zephyr/modules/owntech_task_api/zephyr/public_api/TaskAPI.h