Skip to content

Commit a5afbec

Browse files
committed
1 parent 2775463 commit a5afbec

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,27 @@ void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
227227
diff = xExpectedIdleTime;
228228
}
229229

230-
if (diff > 0)
230+
// nRF-provided fix for delay() wakeup 1ms spin-loop power waste
231+
// See https://devzone.nordicsemi.com/f/nordic-q-a/63828/vtaskdelay-on-nrf52-freertos-port-wastes-cpu-power
232+
BaseType_t switch_req = pdFALSE;
233+
234+
if (diff > 1)
235+
{
236+
vTaskStepTick(diff - 1);
237+
switch_req = xTaskIncrementTick();
238+
}
239+
else if (diff == 1)
240+
{
241+
switch_req = xTaskIncrementTick();
242+
}
243+
244+
/* Increment the RTOS tick as usual which checks if there is a need for rescheduling */
245+
if ( switch_req != pdFALSE )
231246
{
232-
vTaskStepTick(diff);
247+
/* A context switch is required. Context switching is performed in
248+
the PendSV interrupt. Pend the PendSV interrupt. */
249+
SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
250+
__SEV();
233251
}
234252
}
235253
}

0 commit comments

Comments
 (0)