@@ -46,9 +46,12 @@ unsafe extern "Rust" {
4646 fn esp_preempt_disable ( ) ;
4747 fn esp_preempt_yield_task ( ) ;
4848 fn esp_preempt_current_task ( ) -> * mut c_void ;
49+ fn esp_preempt_max_task_priority ( ) -> u32 ;
4950 fn esp_preempt_task_create (
5051 task : extern "C" fn ( * mut c_void ) ,
5152 param : * mut c_void ,
53+ priority : u32 ,
54+ pin_to_core : Option < u32 > ,
5255 task_stack_size : usize ,
5356 ) -> * mut c_void ;
5457 fn esp_preempt_schedule_task_deletion ( task_handle : * mut c_void ) ;
@@ -96,14 +99,29 @@ macro_rules! scheduler_impl {
9699 <$t as $crate:: Scheduler >:: current_task( & $name)
97100 }
98101
102+ #[ unsafe ( no_mangle) ]
103+ #[ inline]
104+ fn esp_preempt_max_task_priority( ) -> u32 {
105+ <$t as $crate:: Scheduler >:: max_task_priority( & $name)
106+ }
107+
99108 #[ unsafe ( no_mangle) ]
100109 #[ inline]
101110 fn esp_preempt_task_create(
102111 task: extern "C" fn ( * mut c_void) ,
103112 param: * mut c_void,
113+ priority: u32 ,
114+ core_id: Option <u32 >,
104115 task_stack_size: usize ,
105116 ) -> * mut c_void {
106- <$t as $crate:: Scheduler >:: task_create( & $name, task, param, task_stack_size)
117+ <$t as $crate:: Scheduler >:: task_create(
118+ & $name,
119+ task,
120+ param,
121+ priority,
122+ core_id,
123+ task_stack_size,
124+ )
107125 }
108126
109127 #[ unsafe ( no_mangle) ]
@@ -153,12 +171,18 @@ pub trait Scheduler: Send + Sync + 'static {
153171 /// This function is called by `esp_radio::init` to retrieve a pointer to the current task.
154172 fn current_task ( & self ) -> * mut c_void ;
155173
174+ /// This function returns the maximum task priority level.
175+ /// Higher number is considered to be higher priority.
176+ fn max_task_priority ( & self ) -> u32 ;
177+
156178 /// This function is used to create threads.
157179 /// It should allocate the stack.
158180 fn task_create (
159181 & self ,
160182 task : extern "C" fn ( * mut c_void ) ,
161183 param : * mut c_void ,
184+ priority : u32 ,
185+ core_id : Option < u32 > ,
162186 task_stack_size : usize ,
163187 ) -> * mut c_void ;
164188
@@ -218,6 +242,14 @@ pub fn current_task() -> *mut c_void {
218242 unsafe { esp_preempt_current_task ( ) }
219243}
220244
245+ /// Returns the maximum priority a task can have.
246+ ///
247+ /// This function assumes that a bigger number means higher priority.
248+ #[ inline]
249+ pub fn max_task_priority ( ) -> u32 {
250+ unsafe { esp_preempt_max_task_priority ( ) }
251+ }
252+
221253/// Creates a new task with the given initial parameter and stack size.
222254///
223255/// ## Safety
@@ -228,9 +260,11 @@ pub fn current_task() -> *mut c_void {
228260pub unsafe fn task_create (
229261 task : extern "C" fn ( * mut c_void ) ,
230262 param : * mut c_void ,
263+ priority : u32 ,
264+ pin_to_core : Option < u32 > ,
231265 task_stack_size : usize ,
232266) -> * mut c_void {
233- unsafe { esp_preempt_task_create ( task, param, task_stack_size) }
267+ unsafe { esp_preempt_task_create ( task, param, priority , pin_to_core , task_stack_size) }
234268}
235269
236270/// Schedules the given task for deletion.
0 commit comments