Skip to main content

SchedulerImplementation

Trait SchedulerImplementation 

Source
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§

Source

fn initialized(&self) -> bool

This function is called by esp_radio::init to verify that the scheduler is properly set up.

Source

fn yield_task(&self)

This function is called by esp_radio to yield control to another task.

Source

fn yield_task_from_isr(&self)

This function is called by esp_radio to yield control to another task.

Source

fn current_task(&self) -> ThreadPtr

This function is called by esp_radio::init to retrieve a pointer to the current task.

Source

fn max_task_priority(&self) -> u32

This function returns the maximum task priority level. Higher number is considered to be higher priority.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn usleep(&self, us: u32)

This function is called by a task to sleep for the specified number of microseconds.

Source

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.

Source

fn now(&self) -> u64

Returns the current timestamp in microseconds.

The underlying timer is expected not to overflow during the lifetime of the program.

The clock that generates this timestamp must be the same one used to trigger timer events.

Implementors§