Merge pull request #239 from dimpolo/start_app_core_improvements

cpu_control::start_app_core improvements
This commit is contained in:
Björn Quentin 2022-10-31 15:00:08 +01:00 committed by GitHub
commit 9152792d5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 12 deletions

View File

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

View File

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