pub trait SchedulerImplementation:
Send
+ Sync
+ 'static {
Show 13 methods
// Required methods
fn initialized(&self) -> bool;
fn yield_task(&self);
fn yield_task_from_isr(&self);
fn current_task(&self) -> ThreadPtr;
fn max_task_priority(&self) -> u32;
fn task_create(
&self,
name: &str,
task: extern "C" fn(*mut c_void),
param: *mut c_void,
priority: u32,
core_id: Option<u32>,
task_stack_size: usize,
) -> ThreadPtr;
fn schedule_task_deletion(&self, task_handle: Option<ThreadPtr>);
fn current_task_thread_semaphore(&self) -> SemaphorePtr;
unsafe fn task_priority(&self, task: ThreadPtr) -> u32;
unsafe fn set_task_priority(&self, task: ThreadPtr, priority: u32);
fn usleep(&self, us: u32);
fn usleep_until(&self, target: u64);
fn now(&self) -> u64;
}Expand description
The scheduler interface.
This trait needs to be implemented by a driver crate to integrate esp-radio with a software platform.
The following snippet demonstrates the boilerplate necessary to implement a scheduler using the
Scheduler trait:
use esp_radio_rtos_driver::{ThreadPtr, SchedulerImplementation, register_scheduler_implementation};
struct MyScheduler {}
impl SchedulerImplementation for MyScheduler {
fn initialized(&self) -> bool {
unimplemented!()
}
fn yield_task(&self) {
unimplemented!()
}
fn yield_task_from_isr(&self) {
unimplemented!()
}
fn max_task_priority(&self) -> u32 {
unimplemented!()
}
fn task_create(
&self,
name: &str,
task: extern "C" fn(*mut c_void),
param: *mut c_void,
priority: u32,
pin_to_core: Option<u32>,
task_stack_size: usize,
) -> ThreadPtr {
unimplemented!()
}
fn current_task(&self) -> ThreadPtr {
unimplemented!()
}
fn schedule_task_deletion(&self, task_handle: Option<ThreadPtr>) {
unimplemented!()
}
fn current_task_thread_semaphore(&self) -> SemaphorePtr {
unimplemented!()
}
fn task_priority(&self, task: ThreadPtr) -> u32 {
unimplemented!()
}
fn set_task_priority(&self, task: ThreadPtr, priority: u32) {
unimplemented!()
}
fn usleep(&self, us: u32) {
unimplemented!()
}
fn usleep_until(&self, target: u64) {
unimplemented!()
}
fn now(&self) -> u64 {
unimplemented!()
}
}
register_scheduler_implementation!(static SCHEDULER: MyScheduler = MyScheduler {});Required Methods§
Sourcefn initialized(&self) -> bool
fn initialized(&self) -> bool
This function is called by esp_radio::init to verify that the scheduler is properly set
up.
Sourcefn yield_task(&self)
fn yield_task(&self)
This function is called by esp_radio to yield control to another task.
Sourcefn yield_task_from_isr(&self)
fn yield_task_from_isr(&self)
This function is called by esp_radio to yield control to another task.
Sourcefn current_task(&self) -> ThreadPtr
fn current_task(&self) -> ThreadPtr
This function is called by esp_radio::init to retrieve a pointer to the current task.
Sourcefn max_task_priority(&self) -> u32
fn max_task_priority(&self) -> u32
This function returns the maximum task priority level. Higher number is considered to be higher priority.
Sourcefn task_create(
&self,
name: &str,
task: extern "C" fn(*mut c_void),
param: *mut c_void,
priority: u32,
core_id: Option<u32>,
task_stack_size: usize,
) -> ThreadPtr
fn task_create( &self, name: &str, task: extern "C" fn(*mut c_void), param: *mut c_void, priority: u32, core_id: Option<u32>, task_stack_size: usize, ) -> ThreadPtr
This function is used to create threads. It should allocate the stack.
Sourcefn schedule_task_deletion(&self, task_handle: Option<ThreadPtr>)
fn schedule_task_deletion(&self, task_handle: Option<ThreadPtr>)
This function is called to let the scheduler know this thread is not needed anymore and should be deleted. After this function is called, the thread should not be scheduled anymore. The thread stack can be free’ed.
Passing None as the task handle should delete the currently running task.
Sourcefn current_task_thread_semaphore(&self) -> SemaphorePtr
fn current_task_thread_semaphore(&self) -> SemaphorePtr
This function should return an opaque per-thread pointer to an usize-sized memory location, which will be used to store a pointer to a semaphore for this thread.
Sourceunsafe fn task_priority(&self, task: ThreadPtr) -> u32
unsafe fn task_priority(&self, task: ThreadPtr) -> u32
This function returns the priority of the given task.
§Safety
The task pointer must be valid and point to a task that was created using
Self::task_create.
Sourceunsafe fn set_task_priority(&self, task: ThreadPtr, priority: u32)
unsafe fn set_task_priority(&self, task: ThreadPtr, priority: u32)
This function sets the priority of the given task.
§Safety
The task pointer must be valid and point to a task that was created using
Self::task_create.
Sourcefn usleep(&self, us: u32)
fn usleep(&self, us: u32)
This function is called by a task to sleep for the specified number of microseconds.
Sourcefn usleep_until(&self, target: u64)
fn usleep_until(&self, target: u64)
This function is called by a task to sleep until the specified timestamp.
The timestamp is measured in microseconds, from the time the timer was started.