mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-26 20:00:32 +00:00
Delete task when it exits (#4185)
This commit is contained in:
parent
693b99a7e3
commit
a6a6747409
@ -262,6 +262,12 @@ pub(crate) struct Task {
|
|||||||
const STACK_CANARY: u32 =
|
const STACK_CANARY: u32 =
|
||||||
const { esp_config::esp_config_int!(u32, "ESP_HAL_CONFIG_STACK_GUARD_VALUE") };
|
const { esp_config::esp_config_int!(u32, "ESP_HAL_CONFIG_STACK_GUARD_VALUE") };
|
||||||
|
|
||||||
|
#[cfg(feature = "esp-radio")]
|
||||||
|
extern "C" fn task_wrapper(task_fn: extern "C" fn(*mut c_void), param: *mut c_void) {
|
||||||
|
task_fn(param);
|
||||||
|
schedule_task_deletion(core::ptr::null_mut());
|
||||||
|
}
|
||||||
|
|
||||||
impl Task {
|
impl Task {
|
||||||
#[cfg(feature = "esp-radio")]
|
#[cfg(feature = "esp-radio")]
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
|
@ -128,8 +128,9 @@ pub(crate) fn new_task_context(
|
|||||||
let stack_top = stack_top - (stack_top % 16);
|
let stack_top = stack_top - (stack_top % 16);
|
||||||
|
|
||||||
CpuContext {
|
CpuContext {
|
||||||
pc: task as usize,
|
pc: super::task_wrapper as usize,
|
||||||
a0: param as usize,
|
a0: task as usize,
|
||||||
|
a1: param as usize,
|
||||||
sp: stack_top,
|
sp: stack_top,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,11 @@ pub(crate) fn new_task_context(
|
|||||||
}
|
}
|
||||||
|
|
||||||
CpuContext {
|
CpuContext {
|
||||||
PC: task_fn as usize as u32,
|
PC: super::task_wrapper as usize as u32,
|
||||||
A0: 0,
|
A0: 0,
|
||||||
A1: stack_top,
|
A1: stack_top,
|
||||||
A6: param as usize as u32,
|
A6: task_fn as usize as u32,
|
||||||
|
A7: param as usize as u32,
|
||||||
|
|
||||||
// For windowed ABI set WOE and CALLINC (pretend task was 'call4'd)
|
// For windowed ABI set WOE and CALLINC (pretend task was 'call4'd)
|
||||||
PS: 0x00040000 | ((1 & 3) << 16),
|
PS: 0x00040000 | ((1 & 3) << 16),
|
||||||
|
@ -247,11 +247,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
context.time_slice_observed.give();
|
context.time_slice_observed.give();
|
||||||
|
|
||||||
// TODO: support one-shot tasks in esp-preempt
|
|
||||||
unsafe {
|
|
||||||
preempt::schedule_task_deletion(core::ptr::null_mut());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -337,11 +332,6 @@ mod tests {
|
|||||||
|
|
||||||
info!("High: released mutex");
|
info!("High: released mutex");
|
||||||
context.mutex.give();
|
context.mutex.give();
|
||||||
|
|
||||||
// TODO: support one-shot tasks in esp-preempt
|
|
||||||
unsafe {
|
|
||||||
preempt::schedule_task_deletion(core::ptr::null_mut());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
extern "C" fn medium_priority_task(context: *mut c_void) {
|
extern "C" fn medium_priority_task(context: *mut c_void) {
|
||||||
let context = unsafe { &*(context as *const TestContext) };
|
let context = unsafe { &*(context as *const TestContext) };
|
||||||
@ -351,11 +341,6 @@ mod tests {
|
|||||||
|
|
||||||
info!("Medium: marking test finished");
|
info!("Medium: marking test finished");
|
||||||
context.ready_semaphore.give();
|
context.ready_semaphore.give();
|
||||||
|
|
||||||
// TODO: support one-shot tasks in esp-preempt
|
|
||||||
unsafe {
|
|
||||||
preempt::schedule_task_deletion(core::ptr::null_mut());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -426,21 +411,11 @@ mod tests {
|
|||||||
let context = unsafe { &*(context as *const TestContext) };
|
let context = unsafe { &*(context as *const TestContext) };
|
||||||
|
|
||||||
count_impl(context, Cpu::AppCpu);
|
count_impl(context, Cpu::AppCpu);
|
||||||
|
|
||||||
// TODO: support one-shot tasks in esp-preempt
|
|
||||||
unsafe {
|
|
||||||
preempt::schedule_task_deletion(core::ptr::null_mut());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
extern "C" fn count_on_pro_core(context: *mut c_void) {
|
extern "C" fn count_on_pro_core(context: *mut c_void) {
|
||||||
let context = unsafe { &*(context as *const TestContext) };
|
let context = unsafe { &*(context as *const TestContext) };
|
||||||
|
|
||||||
count_impl(context, Cpu::ProCpu);
|
count_impl(context, Cpu::ProCpu);
|
||||||
|
|
||||||
// TODO: support one-shot tasks in esp-preempt
|
|
||||||
unsafe {
|
|
||||||
preempt::schedule_task_deletion(core::ptr::null_mut());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_preempt::start(
|
esp_preempt::start(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user