@@ -108,54 +108,63 @@ impl<const SIZE: usize> Stack<SIZE> {
108
108
}
109
109
}
110
110
111
- #[ cfg( all( feature = "rt" , feature = "rp2040" ) ) ]
112
- #[ interrupt]
111
+ #[ cfg( feature = "fifo-handler" ) ]
112
+ extern "Rust" {
113
+ fn handle_fifo_token ( token : u32 ) -> bool ;
114
+ }
115
+
116
+ #[ cfg( feature = "rt" ) ]
113
117
#[ link_section = ".data.ram_func" ]
114
- unsafe fn SIO_IRQ_PROC1 ( ) {
118
+ #[ inline]
119
+ unsafe fn sio_handler ( ) {
115
120
let sio = pac:: SIO ;
116
121
// Clear IRQ
117
122
sio. fifo ( ) . st ( ) . write ( |w| w. set_wof ( false ) ) ;
118
123
119
124
while sio. fifo ( ) . st ( ) . read ( ) . vld ( ) {
120
- // Pause CORE1 execution and disable interrupts
121
- if fifo_read_wfe ( ) == PAUSE_TOKEN {
125
+ let token = fifo_read_wfe ( ) ;
126
+
127
+ // Forward to user handler.
128
+ #[ cfg( feature = "fifo-handler" ) ]
129
+ if handle_fifo_token ( token) {
130
+ continue ;
131
+ }
132
+
133
+ // Pause this core's execution and disable interrupts
134
+ if token == PAUSE_TOKEN {
122
135
cortex_m:: interrupt:: disable ( ) ;
123
- // Signal to CORE0 that execution is paused
136
+ // Signal to other that execution is paused
124
137
fifo_write ( PAUSE_TOKEN ) ;
125
- // Wait for `resume` signal from CORE0
138
+ // Wait for `resume` signal from other core
126
139
while fifo_read_wfe ( ) != RESUME_TOKEN {
127
140
cortex_m:: asm:: nop ( ) ;
128
141
}
129
142
cortex_m:: interrupt:: enable ( ) ;
130
- // Signal to CORE0 that execution is resumed
143
+ // Signal to other core that execution is resumed
131
144
fifo_write ( RESUME_TOKEN ) ;
132
145
}
133
146
}
134
147
}
135
148
149
+ #[ cfg( all( feature = "rt" , feature = "rp2040" ) ) ]
150
+ #[ interrupt]
151
+ #[ link_section = ".data.ram_func" ]
152
+ unsafe fn SIO_IRQ_PROC0 ( ) {
153
+ sio_handler ( ) ;
154
+ }
155
+
156
+ #[ cfg( all( feature = "rt" , feature = "rp2040" ) ) ]
157
+ #[ interrupt]
158
+ #[ link_section = ".data.ram_func" ]
159
+ unsafe fn SIO_IRQ_PROC1 ( ) {
160
+ sio_handler ( ) ;
161
+ }
162
+
136
163
#[ cfg( all( feature = "rt" , feature = "_rp235x" ) ) ]
137
164
#[ interrupt]
138
165
#[ link_section = ".data.ram_func" ]
139
166
unsafe fn SIO_IRQ_FIFO ( ) {
140
- let sio = pac:: SIO ;
141
- // Clear IRQ
142
- sio. fifo ( ) . st ( ) . write ( |w| w. set_wof ( false ) ) ;
143
-
144
- while sio. fifo ( ) . st ( ) . read ( ) . vld ( ) {
145
- // Pause CORE1 execution and disable interrupts
146
- if fifo_read_wfe ( ) == PAUSE_TOKEN {
147
- cortex_m:: interrupt:: disable ( ) ;
148
- // Signal to CORE0 that execution is paused
149
- fifo_write ( PAUSE_TOKEN ) ;
150
- // Wait for `resume` signal from CORE0
151
- while fifo_read_wfe ( ) != RESUME_TOKEN {
152
- cortex_m:: asm:: nop ( ) ;
153
- }
154
- cortex_m:: interrupt:: enable ( ) ;
155
- // Signal to CORE0 that execution is resumed
156
- fifo_write ( RESUME_TOKEN ) ;
157
- }
158
- }
167
+ sio_handler ( ) ;
159
168
}
160
169
161
170
/// Spawn a function on this core
@@ -286,23 +295,55 @@ where
286
295
287
296
// Wait until the other core has copied `entry` before returning.
288
297
fifo_read ( ) ;
298
+
299
+ // Enable FIFO interrupts from core1.
300
+ #[ cfg( feature = "rp2040" ) ]
301
+ unsafe {
302
+ interrupt:: SIO_IRQ_PROC0 . enable ( )
303
+ } ;
304
+ #[ cfg( feature = "_rp235x" ) ]
305
+ unsafe {
306
+ interrupt:: SIO_IRQ_FIFO . enable ( )
307
+ } ;
289
308
}
290
309
291
310
/// Pause execution on CORE1.
292
311
pub fn pause_core1 ( ) {
293
312
if IS_CORE1_INIT . load ( Ordering :: Acquire ) {
294
- fifo_write ( PAUSE_TOKEN ) ;
295
- // Wait for CORE1 to signal it has paused execution.
296
- while fifo_read ( ) != PAUSE_TOKEN { }
313
+ cortex_m:: interrupt:: free ( |_| {
314
+ fifo_write ( PAUSE_TOKEN ) ;
315
+ // Wait for CORE1 to signal it has paused execution.
316
+ loop {
317
+ let token = fifo_read ( ) ;
318
+ if token == PAUSE_TOKEN {
319
+ break ;
320
+ }
321
+ #[ cfg( feature = "fifo-handler" ) ]
322
+ unsafe {
323
+ handle_fifo_token ( token) ;
324
+ }
325
+ }
326
+ } )
297
327
}
298
328
}
299
329
300
330
/// Resume CORE1 execution.
301
331
pub fn resume_core1 ( ) {
302
332
if IS_CORE1_INIT . load ( Ordering :: Acquire ) {
303
- fifo_write ( RESUME_TOKEN ) ;
304
- // Wait for CORE1 to signal it has resumed execution.
305
- while fifo_read ( ) != RESUME_TOKEN { }
333
+ cortex_m:: interrupt:: free ( |_| {
334
+ fifo_write ( RESUME_TOKEN ) ;
335
+ // Wait for CORE1 to signal it has resumed execution.
336
+ loop {
337
+ let token = fifo_read ( ) ;
338
+ if token == RESUME_TOKEN {
339
+ break ;
340
+ }
341
+ #[ cfg( feature = "fifo-handler" ) ]
342
+ unsafe {
343
+ handle_fifo_token ( token) ;
344
+ }
345
+ }
346
+ } )
306
347
}
307
348
}
308
349
0 commit comments