0% found this document useful (0 votes)
48 views12 pages

FreeRTOS Aperiodic Task Management

Uploaded by

bbb.dd101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views12 pages

FreeRTOS Aperiodic Task Management

Uploaded by

bbb.dd101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

FreeRTOS: Aperiodic Tasks

FreeRTOS
• In previous examples, we looked at tasks that
executes in an infinite loop.
• vTaskDelayUntil() allows for creating tasks
that executes periodically.
• In many cases, tasks are required to execute
once or execute in response to an event
(example: condition in another task, interrupt,
etc.).
• As the task is not allowed to exit, the task
should be deleted or suspended.
vTaskDelete()
• VTaskDelete() function allows for deleting
the task stack and TCB from the heap and
hence permanently deleting the task.
• A task can easily delete itself by calling
vTaskDelete(NULL); from the task.

Example: write a C code that executes a task


once at the beginning of the program.
Example
Write a FreeRTOS application with one task
that prints something before it delete itself
vTaskDelete()
• A task can also be deleted from another task
or an ISR as follows:
1) Create a handle for the task:

2) Pass a reference of the task handle to the last


argument of vTaskCreate() when creating the
task:

3) Delete the task from another task or ISR:


Example
Write a FreeRTOS application with one task
deleting another task using a task handle.
vTaskSuspend()
• When deleting a task all of its local variable
are lost.
• A task can be suspended using the function:

• All the data of the task is retained, and the


task will only resume when the following
function is called from another task:
vTaskSuspend()
• When deleting a task all of its local variable
are lost.
• A task can be suspended using the function:

• All the data of the task is retained, and the


task will only resume when the following
function is called from another task:
FreeRTOS Task States
FreeRTOS Task States
• Running: When a task is actually executing it
is said to be in the Running state. It is
currently utilising the processor.
• Ready: Ready tasks are those that are able to
execute (they are not in the Blocked or
Suspended state) but are not currently
executing because a different task of equal or
higher priority is already in the Running state.
FreeRTOS Task States
• Blocked: A task is said to be in the Blocked
state if it is currently waiting for either a
temporal or external event. For example, if a
task calls vTaskDelay() it will block (be
placed into the Blocked state) until the delay
period has expired – a temporal event. Tasks
in the Blocked state normally have a
‘timeout’ period, after which the task will be
timeout, and be unblocked, even if the event
the task was waiting for has not occurred.
FreeRTOS Task States
• Suspended: Like tasks that are in the
Blocked state, tasks in the Suspended state
cannot be selected to enter the Running state,
but tasks in the Suspended state do not have a
time out. Instead, tasks only enter or exit the
Suspended state when explicitly commanded
to do so through the vTaskSuspend() and
xTaskResume() API calls respectively.

You might also like