Skip to content

Commit 9db16cf

Browse files
projectgusdpgeorge
authored andcommitted
rp2: Fix wakeup from WFE on core1.
If core1 executes `mp_wfe_or_timeout()` then it needs to receive an interrupt or a SEV to resume execution, but the soft timer interrupt only fires on core 0. This fix adds a SEV to the soft timer interrupt handler. This issue was masked by the issue fixed in the previous commit, as WFE previously wasn't suspending properly. Verified via the existing thread_sleep2 test. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent eced9d8 commit 9db16cf

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

ports/rp2/mphalport.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ static void soft_timer_hardware_callback(unsigned int alarm_num) {
228228
// The timer alarm ISR needs to call here and trigger PendSV dispatch via
229229
// a second ISR, as PendSV may be currently suspended by the other CPU.
230230
pendsv_schedule_dispatch(PENDSV_DISPATCH_SOFT_TIMER, soft_timer_handler);
231+
232+
// This ISR only runs on core0, but if core1 is running Python code then it
233+
// may be blocked in WFE so wake it up as well. Unfortunately this also sets
234+
// the event flag on core0, so a subsequent WFE on this core will not suspend
235+
if (core1_entry != NULL) {
236+
__sev();
237+
}
231238
}
232239

233240
void soft_timer_init(void) {

ports/rp2/mpthreadport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extern uint8_t __StackTop, __StackBottom;
3939
void *core_state[2];
4040

4141
// This will be non-NULL while Python code is executing.
42-
static void *(*core1_entry)(void *) = NULL;
42+
core_entry_func_t core1_entry = NULL;
4343

4444
static void *core1_arg = NULL;
4545
static uint32_t *core1_stack = NULL;

ports/rp2/mpthreadport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ typedef struct mutex mp_thread_mutex_t;
3232

3333
extern void *core_state[2];
3434

35+
typedef void *(*core_entry_func_t)(void *);
36+
37+
extern core_entry_func_t core1_entry;
38+
3539
void mp_thread_init(void);
3640
void mp_thread_deinit(void);
3741
void mp_thread_gc_others(void);

0 commit comments

Comments
 (0)