mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-30 05:40:39 +00:00
Add Cpu::COUNT
and clean up in esp-hal-embassy
(#2411)
* Add Cpu::COUNT and simplify * Avoid a bounds check during pending
This commit is contained in:
parent
6bf03f63a9
commit
f3c5286028
@ -99,7 +99,7 @@ impl<const SWI: u8> InterruptExecutor<SWI> {
|
||||
unsafe {
|
||||
(*self.executor.get())
|
||||
.as_mut_ptr()
|
||||
.write(raw::Executor::new(SWI as *mut ()));
|
||||
.write(raw::Executor::new((SWI as usize) as *mut ()));
|
||||
|
||||
EXECUTORS[SWI as usize].set((*self.executor.get()).as_mut_ptr());
|
||||
}
|
||||
|
@ -7,19 +7,18 @@ mod thread;
|
||||
fn __pender(context: *mut ()) {
|
||||
use esp_hal::interrupt::software::SoftwareInterrupt;
|
||||
|
||||
let context = (context as usize).to_le_bytes();
|
||||
|
||||
match context[0] {
|
||||
match context as usize {
|
||||
// For interrupt executors, the context value is the
|
||||
// software interrupt number
|
||||
0 => unsafe { SoftwareInterrupt::<0>::steal().raise() },
|
||||
1 => unsafe { SoftwareInterrupt::<1>::steal().raise() },
|
||||
2 => unsafe { SoftwareInterrupt::<2>::steal().raise() },
|
||||
#[cfg(not(multi_core))]
|
||||
3 => unsafe { SoftwareInterrupt::<3>::steal().raise() },
|
||||
other => {
|
||||
assert_eq!(other, THREAD_MODE_CONTEXT);
|
||||
// THREAD_MODE_CONTEXT id is reserved for thread mode executors
|
||||
thread::pend_thread_mode(context[1] as usize)
|
||||
}
|
||||
// THREAD_MODE_CONTEXT + core ID
|
||||
16 => thread::pend_thread_mode(0),
|
||||
#[cfg(multi_core)]
|
||||
17 => thread::pend_thread_mode(1),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
@ -3,19 +3,17 @@
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use embassy_executor::{raw, Spawner};
|
||||
use esp_hal::get_core;
|
||||
use esp_hal::{get_core, Cpu};
|
||||
#[cfg(multi_core)]
|
||||
use esp_hal::{interrupt::software::SoftwareInterrupt, macros::handler};
|
||||
use portable_atomic::{AtomicBool, Ordering};
|
||||
|
||||
pub(crate) const THREAD_MODE_CONTEXT: u8 = 16;
|
||||
pub(crate) const THREAD_MODE_CONTEXT: usize = 16;
|
||||
|
||||
/// global atomic used to keep track of whether there is work to do since sev()
|
||||
/// is not available on either Xtensa or RISC-V
|
||||
#[cfg(not(multi_core))]
|
||||
static SIGNAL_WORK_THREAD_MODE: [AtomicBool; 1] = [AtomicBool::new(false)];
|
||||
#[cfg(multi_core)]
|
||||
static SIGNAL_WORK_THREAD_MODE: [AtomicBool; 2] = [AtomicBool::new(false), AtomicBool::new(false)];
|
||||
static SIGNAL_WORK_THREAD_MODE: [AtomicBool; Cpu::COUNT] =
|
||||
[const { AtomicBool::new(false) }; Cpu::COUNT];
|
||||
|
||||
#[cfg(multi_core)]
|
||||
#[handler]
|
||||
@ -72,12 +70,7 @@ This will use software-interrupt 3 which isn't available for anything else to wa
|
||||
}
|
||||
|
||||
Self {
|
||||
inner: raw::Executor::new(usize::from_le_bytes([
|
||||
THREAD_MODE_CONTEXT,
|
||||
get_core() as u8,
|
||||
0,
|
||||
0,
|
||||
]) as *mut ()),
|
||||
inner: raw::Executor::new((THREAD_MODE_CONTEXT + get_core() as usize) as *mut ()),
|
||||
not_send: PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- `Pins::steal()` to unsafely obtain GPIO. (#2335)
|
||||
- `I2c::with_timeout` (#2361)
|
||||
- `Spi::half_duplex_read` and `Spi::half_duplex_write` (#2373)
|
||||
- `Cpu::COUNT` and `Cpu::current()` (#?)
|
||||
|
||||
### Changed
|
||||
|
||||
|
@ -363,6 +363,17 @@ pub enum Cpu {
|
||||
AppCpu = 1,
|
||||
}
|
||||
|
||||
impl Cpu {
|
||||
/// The number of available cores.
|
||||
pub const COUNT: usize = 1 + cfg!(multi_core) as usize;
|
||||
|
||||
/// Returns the core the application is currently executing on
|
||||
#[inline(always)]
|
||||
pub fn current() -> Self {
|
||||
get_core()
|
||||
}
|
||||
}
|
||||
|
||||
/// Which core the application is currently executing on
|
||||
#[inline(always)]
|
||||
pub fn get_core() -> Cpu {
|
||||
|
Loading…
x
Reference in New Issue
Block a user