Expand description
FreeRTOS task creation and management.
Any method of creating a task will return a TaskHandle.
This handle can be used to control the task.
A handle to the current task can be obtained with current.
Tasks can be created with the spawn function or, for more control, with a task Builder.
§Example
use pros::task::{spawn, TaskPriority};
spawn(|| {
println!("Hello from a task!");
});Task locals can be created with the os_task_local! macro.
See the local module for more info on the custom task local implementation used.
Modules§
- local
- A custom TLS implementation that allows for more than 5 entries in TLS.
Structs§
- Builder
- An ergonomic builder for tasks. Alternatively you can use
spawn. - Interval
- An interval that can be used to repeatedly run code at a given rate.
- Scheduler
Suspend Guard - A guard that can be used to suspend the FreeRTOS scheduler. When dropped, the scheduler will be resumed.
- Task
Handle - An owned permission to perform actions on a task.
Enums§
- Spawn
Error - Errors that can occur when spawning a task.
- Task
Priority - Represents how much time the cpu should spend on this task. (Otherwise known as the priority)
- Task
Stack Depth - Represents how large of a stack the task should get. Tasks that don’t have any or many variables and/or don’t need floats can use the low stack depth option.
- Task
State - Represents the current state of a task.
Functions§
- current
- Returns the task the function was called from.
- delay
- Blocks the current FreeRTOS task for the given amount of time.
- get_
notification - Gets the first notification in the queue. If there is none, blocks until a notification is received. I am unsure what happens if the thread is unblocked while waiting. returns the value of the notification
- spawn
- Creates a task to be run ‘asynchronously’ (More information at the FreeRTOS docs).
Takes in a closure that can move variables if needed.
If your task has a loop it is advised to use
delayso that the task does not take up necessary system resources. Tasks should be long-living; starting many tasks can be slow and is usually not necessary. - suspend_
all ⚠ - Suspends the scheduler, preventing context switches. No other tasks will be run until the returned guard is dropped.