Skip to content

Commit

Permalink
Merge pull request #239 from dimpolo/start_app_core_improvements
Browse files Browse the repository at this point in the history
cpu_control::start_app_core improvements
  • Loading branch information
bjoernQ authored Oct 31, 2022
2 parents 5aedd3e + 2f3b6c8 commit 9152792
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
15 changes: 9 additions & 6 deletions esp-hal-common/src/cpu_control/esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()>,
}
Expand Down Expand Up @@ -183,11 +185,12 @@ impl CpuControl {
/// Start the APP (second) core
///
/// The second core will start running the closure `entry`.
#[must_use]
pub fn start_app_core<'a: 'b, 'b>(
///
/// Dropping the returned guard will park the core.
pub fn start_app_core(
&mut self,
entry: &'a mut (dyn FnMut() -> () + 'a),
) -> Result<AppCoreGuard<'b>, Error> {
entry: &mut (dyn FnMut() + Send),
) -> Result<AppCoreGuard, Error> {
let dport_control = crate::pac::DPORT::PTR;
let dport_control = unsafe { &*dport_control };

Expand All @@ -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);
}

Expand Down
15 changes: 9 additions & 6 deletions esp-hal-common/src/cpu_control/esp32s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()>,
}
Expand Down Expand Up @@ -118,11 +120,12 @@ impl CpuControl {
/// Start the APP (second) core
///
/// The second core will start running the closure `entry`.
#[must_use]
pub fn start_app_core<'a: 'b, 'b>(
///
/// Dropping the returned guard will park the core.
pub fn start_app_core(
&mut self,
entry: &'a mut (dyn FnMut() -> () + 'a),
) -> Result<AppCoreGuard<'b>, Error> {
entry: &mut (dyn FnMut() + Send),
) -> Result<AppCoreGuard, Error> {
let system_control = crate::pac::SYSTEM::PTR;
let system_control = unsafe { &*system_control };

Expand All @@ -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);
}

Expand Down

0 comments on commit 9152792

Please sign in to comment.