2 Task Management Flashcards
What is a task?
A task is a functioned block in the overall application. A task is like C void function. It has no return, it has an infinite loop.
Describe the ready state
Ready: A task in ready state is a task that can execute however its waiting for a higher priority task before it can execute.
Describe the running state
Running: A task that is currently executing. Only one task can be in the Running state.
Describe the suspended state
Suspended: A task can be suspended by vTaskSuspend API call and can be resumed by xTaskResume() API call.
It can only return to the ready state through xTaskResume()
Describe the blocked state
- Waiting for an external or temporal event.
- Can be blocked waiting for a queue, semaphore.
- Blocked task do not use any CPU resources.
- vTaskDelay() function will block task.
- Blocked state can have a timeout after which it will be unblocked and return to Ready State.
What API call would you use to start and stop a task?
vTaskSuspend() API call suspends a task.
xTaskResume() resumes a task.
What is the difference between suspended v blocked task states.
Suspended state: Uses CPU resources, xTaskResume() sets the state to ready, vTaskSuspend() sets the state to suspended.
Blocked state: Doesn’t use CPU resources, An external/ temporal event sets the state to ready, Can have a timeout after which it will return to the ready state.
What is the range of task priorities?
The range is 0 to configMAX_PRIORITIES -1, where configMAX_PRIORITIES is set in FREERTOSConfig.h file.
If set to 7 the priority range is 0-6.
0 should ever be used.
Why should 0 priority not be used?
It is used for the idle task which runs when all other task are blocked or suspended.
Idle task frees up memory.
What API call would block a task?
vTaskDelay().
It takes in a tick time to block the task.
Using pdMS_TO_TICKS() we can set the amount of ms to delay the task.