From 5cf6079054ee5d374b63ac840b95f8f7f60567b3 Mon Sep 17 00:00:00 2001 From: dimi Date: Mon, 31 Oct 2022 13:28:56 +0100 Subject: [PATCH 1/2] cpu_control::start_app_core improvements * add `Send` bound * move `#[must_use]` to `AppCoreGuard` * remove redundant `-> ()` * document guard behaviour --- esp-hal-common/src/cpu_control/esp32.rs | 11 +++++++---- esp-hal-common/src/cpu_control/esp32s3.rs | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/esp-hal-common/src/cpu_control/esp32.rs b/esp-hal-common/src/cpu_control/esp32.rs index 4d7c3ee622d..01e39ab0fba 100644 --- a/esp-hal-common/src/cpu_control/esp32.rs +++ b/esp-hal-common/src/cpu_control/esp32.rs @@ -6,8 +6,10 @@ use xtensa_lx::set_stack_pointer; use crate::Cpu; -static mut START_CORE1_FUNCTION: Option<&'static mut (dyn FnMut() -> () + 'static)> = None; +static mut START_CORE1_FUNCTION: Option<&'static mut (dyn FnMut() + 'static)> = None; +/// Will park the APP (second) core when dropped +#[must_use] pub struct AppCoreGuard<'a> { phantom: PhantomData<&'a ()>, } @@ -183,10 +185,11 @@ impl CpuControl { /// Start the APP (second) core /// /// The second core will start running the closure `entry`. - #[must_use] + /// + /// Dropping the returned guard will park the core. pub fn start_app_core<'a: 'b, 'b>( &mut self, - entry: &'a mut (dyn FnMut() -> () + 'a), + entry: &'a mut (dyn FnMut() + Send + 'a), ) -> Result, Error> { let dport_control = crate::pac::DPORT::PTR; let dport_control = unsafe { &*dport_control }; @@ -205,7 +208,7 @@ impl CpuControl { self.enable_cache(Cpu::AppCpu); unsafe { - let entry_fn: &'static mut (dyn FnMut() -> () + 'static) = core::mem::transmute(entry); + let entry_fn: &'static mut (dyn FnMut() + 'static) = core::mem::transmute(entry); START_CORE1_FUNCTION = Some(entry_fn); } diff --git a/esp-hal-common/src/cpu_control/esp32s3.rs b/esp-hal-common/src/cpu_control/esp32s3.rs index ce46a2c1b6e..baba06efe53 100644 --- a/esp-hal-common/src/cpu_control/esp32s3.rs +++ b/esp-hal-common/src/cpu_control/esp32s3.rs @@ -6,8 +6,10 @@ use xtensa_lx::set_stack_pointer; use crate::Cpu; -static mut START_CORE1_FUNCTION: Option<&'static mut (dyn FnMut() -> () + 'static)> = None; +static mut START_CORE1_FUNCTION: Option<&'static mut (dyn FnMut() + 'static)> = None; +/// Will park the APP (second) core when dropped +#[must_use] pub struct AppCoreGuard<'a> { phantom: PhantomData<&'a ()>, } @@ -118,10 +120,11 @@ impl CpuControl { /// Start the APP (second) core /// /// The second core will start running the closure `entry`. - #[must_use] + /// + /// Dropping the returned guard will park the core. pub fn start_app_core<'a: 'b, 'b>( &mut self, - entry: &'a mut (dyn FnMut() -> () + 'a), + entry: &'a mut (dyn FnMut() + Send + 'a), ) -> Result, Error> { let system_control = crate::pac::SYSTEM::PTR; let system_control = unsafe { &*system_control }; @@ -137,7 +140,7 @@ impl CpuControl { } unsafe { - let entry_fn: &'static mut (dyn FnMut() -> () + 'static) = core::mem::transmute(entry); + let entry_fn: &'static mut (dyn FnMut() + 'static) = core::mem::transmute(entry); START_CORE1_FUNCTION = Some(entry_fn); } From 2f3b6c843ca6015c6e6feac8cfbd8c3c4a004c70 Mon Sep 17 00:00:00 2001 From: dimi Date: Mon, 31 Oct 2022 14:46:31 +0100 Subject: [PATCH 2/2] remove lifetime annotations from cpu_control::start_app_core --- esp-hal-common/src/cpu_control/esp32.rs | 6 +++--- esp-hal-common/src/cpu_control/esp32s3.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/esp-hal-common/src/cpu_control/esp32.rs b/esp-hal-common/src/cpu_control/esp32.rs index 01e39ab0fba..26a2f1865b7 100644 --- a/esp-hal-common/src/cpu_control/esp32.rs +++ b/esp-hal-common/src/cpu_control/esp32.rs @@ -187,10 +187,10 @@ impl CpuControl { /// The second core will start running the closure `entry`. /// /// Dropping the returned guard will park the core. - pub fn start_app_core<'a: 'b, 'b>( + pub fn start_app_core( &mut self, - entry: &'a mut (dyn FnMut() + Send + 'a), - ) -> Result, Error> { + entry: &mut (dyn FnMut() + Send), + ) -> Result { let dport_control = crate::pac::DPORT::PTR; let dport_control = unsafe { &*dport_control }; diff --git a/esp-hal-common/src/cpu_control/esp32s3.rs b/esp-hal-common/src/cpu_control/esp32s3.rs index baba06efe53..f542e3ed17c 100644 --- a/esp-hal-common/src/cpu_control/esp32s3.rs +++ b/esp-hal-common/src/cpu_control/esp32s3.rs @@ -122,10 +122,10 @@ impl CpuControl { /// The second core will start running the closure `entry`. /// /// Dropping the returned guard will park the core. - pub fn start_app_core<'a: 'b, 'b>( + pub fn start_app_core( &mut self, - entry: &'a mut (dyn FnMut() + Send + 'a), - ) -> Result, Error> { + entry: &mut (dyn FnMut() + Send), + ) -> Result { let system_control = crate::pac::SYSTEM::PTR; let system_control = unsafe { &*system_control };