File tree Expand file tree Collapse file tree 5 files changed +25
-21
lines changed
esp-hal-embassy/src/executor Expand file tree Collapse file tree 5 files changed +25
-21
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ impl<const SWI: u8> InterruptExecutor<SWI> {
9999 unsafe {
100100 ( * self . executor . get ( ) )
101101 . as_mut_ptr ( )
102- . write ( raw:: Executor :: new ( SWI as * mut ( ) ) ) ;
102+ . write ( raw:: Executor :: new ( ( SWI as usize ) as * mut ( ) ) ) ;
103103
104104 EXECUTORS [ SWI as usize ] . set ( ( * self . executor . get ( ) ) . as_mut_ptr ( ) ) ;
105105 }
Original file line number Diff line number Diff line change @@ -7,19 +7,18 @@ mod thread;
77fn __pender ( context : * mut ( ) ) {
88 use esp_hal:: interrupt:: software:: SoftwareInterrupt ;
99
10- let context = ( context as usize ) . to_le_bytes ( ) ;
11-
12- match context[ 0 ] {
10+ match context as usize {
1311 // For interrupt executors, the context value is the
1412 // software interrupt number
1513 0 => unsafe { SoftwareInterrupt :: < 0 > :: steal ( ) . raise ( ) } ,
1614 1 => unsafe { SoftwareInterrupt :: < 1 > :: steal ( ) . raise ( ) } ,
1715 2 => unsafe { SoftwareInterrupt :: < 2 > :: steal ( ) . raise ( ) } ,
16+ #[ cfg( not( multi_core) ) ]
1817 3 => unsafe { SoftwareInterrupt :: < 3 > :: steal ( ) . raise ( ) } ,
19- other => {
20- assert_eq ! ( other , THREAD_MODE_CONTEXT ) ;
21- // THREAD_MODE_CONTEXT id is reserved for thread mode executors
22- thread:: pend_thread_mode ( context [ 1 ] as usize )
23- }
18+ // THREAD_MODE_CONTEXT + core ID
19+ 16 => thread :: pend_thread_mode ( 0 ) ,
20+ # [ cfg ( multi_core ) ]
21+ 17 => thread:: pend_thread_mode ( 1 ) ,
22+ _ => unreachable ! ( ) ,
2423 }
2524}
Original file line number Diff line number Diff line change 33use core:: marker:: PhantomData ;
44
55use embassy_executor:: { raw, Spawner } ;
6- use esp_hal:: get_core;
6+ use esp_hal:: { get_core, Cpu } ;
77#[ cfg( multi_core) ]
88use esp_hal:: { interrupt:: software:: SoftwareInterrupt , macros:: handler} ;
99use portable_atomic:: { AtomicBool , Ordering } ;
1010
11- pub ( crate ) const THREAD_MODE_CONTEXT : u8 = 16 ;
11+ pub ( crate ) const THREAD_MODE_CONTEXT : usize = 16 ;
1212
1313/// global atomic used to keep track of whether there is work to do since sev()
1414/// is not available on either Xtensa or RISC-V
15- #[ cfg( not( multi_core) ) ]
16- static SIGNAL_WORK_THREAD_MODE : [ AtomicBool ; 1 ] = [ AtomicBool :: new ( false ) ] ;
17- #[ cfg( multi_core) ]
18- static SIGNAL_WORK_THREAD_MODE : [ AtomicBool ; 2 ] = [ AtomicBool :: new ( false ) , AtomicBool :: new ( false ) ] ;
15+ static SIGNAL_WORK_THREAD_MODE : [ AtomicBool ; Cpu :: COUNT ] =
16+ [ const { AtomicBool :: new ( false ) } ; Cpu :: COUNT ] ;
1917
2018#[ cfg( multi_core) ]
2119#[ handler]
@@ -72,12 +70,7 @@ This will use software-interrupt 3 which isn't available for anything else to wa
7270 }
7371
7472 Self {
75- inner : raw:: Executor :: new ( usize:: from_le_bytes ( [
76- THREAD_MODE_CONTEXT ,
77- get_core ( ) as u8 ,
78- 0 ,
79- 0 ,
80- ] ) as * mut ( ) ) ,
73+ inner : raw:: Executor :: new ( ( THREAD_MODE_CONTEXT + get_core ( ) as usize ) as * mut ( ) ) ,
8174 not_send : PhantomData ,
8275 }
8376 }
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020- ` Pins::steal() ` to unsafely obtain GPIO. (#2335 )
2121- ` I2c::with_timeout ` (#2361 )
2222- ` Spi::half_duplex_read ` and ` Spi::half_duplex_write ` (#2373 )
23+ - ` Cpu::COUNT ` and ` Cpu::current() ` (#?)
2324
2425### Changed
2526
Original file line number Diff line number Diff line change @@ -363,6 +363,17 @@ pub enum Cpu {
363363 AppCpu = 1 ,
364364}
365365
366+ impl Cpu {
367+ /// The number of available cores.
368+ pub const COUNT : usize = 1 + cfg ! ( multi_core) as usize ;
369+
370+ /// Returns the core the application is currently executing on
371+ #[ inline( always) ]
372+ pub fn current ( ) -> Self {
373+ get_core ( )
374+ }
375+ }
376+
366377/// Which core the application is currently executing on
367378#[ inline( always) ]
368379pub fn get_core ( ) -> Cpu {
You can’t perform that action at this time.
0 commit comments