Merge feat/tickless into main
This commit is contained in:
commit
6b7fcbe889
3 files changed
+47
-1
No files matched your search
@@ -356,6 +356,16 @@ An idle TWIM costs nothing measurable, so `Wire.end()` on an empty bus is kept
|
||||
only because it is harmless. The tick is worth about 0.34 mA (5 % of this node):
|
||||
ten times fewer wake-ups. That is close to the ceiling of a tickless `loop()`
|
||||
(issue tth #20), which would remove the remaining ~100 wakes a second too.
|
||||
|
||||
**Tickless loop, implemented (3. 12. 2026).** `NRF52Board::sleep()` now blocks
|
||||
the loop task on a FreeRTOS task notification (at most 50 ms,
|
||||
`NRF52_TICKLESS_MAX_MS`; 0 = the old `sd_app_evt_wait()`), so the idle task
|
||||
runs and `configUSE_TICKLESS_IDLE` suppresses the tick; the DIO1 interrupt
|
||||
gives the notification, so a received packet is handled at once, and a queued
|
||||
TX keeps the loop awake (`hasPendingWork()`). Same rig, A/T/A/T/A, both images
|
||||
from one tree: A 7.06 / 7.10 / 7.10 mA, T **6.73 / 6.74 mA**, i.e. **−0.35 mA**,
|
||||
the whole ceiling of the 100 Hz test. Reception checked with x1 as the
|
||||
sender (3 of 3 zero-hop adverts). Only nodes with `powersaving on` sleep at all.
|
||||
A first try of this image hung: it ended the bus while sensors were still
|
||||
listed, and the local framework (symlink, without the Wire timeout of PR #873)
|
||||
waits forever on a disabled TWIM. A main loop that hangs still answers buttonless
|
||||
|
||||
@@ -344,6 +344,30 @@ extern uint64_t g_pkt_proc_us;
|
||||
extern uint32_t g_pkt_proc_count;
|
||||
#endif
|
||||
|
||||
// CUSTOM (TeTeHacko): tickless idle for the loop (tth #20). sd_app_evt_wait()
|
||||
// inside loop_task never lets FreeRTOS reach its idle task, so the 1024 Hz
|
||||
// RTC1 tick wakes the CPU ~1000x a second (measured: a 100 Hz tick alone saves
|
||||
// 0.34 mA on XIAO at 3.3 V). Blocking the loop task on a task notification
|
||||
// instead hands the CPU to the idle task, whose vPortSuppressTicksAndSleep()
|
||||
// (configUSE_TICKLESS_IDLE=1, clears FPU/CRYPTOCELL pending itself) sleeps
|
||||
// until the next real deadline. The DIO1 ISR (RadioLibWrappers setFlag) gives
|
||||
// the notification, so a received packet is handled at once; everything else
|
||||
// that only polls (USB/BLE console, timers) waits at most the timeout.
|
||||
// Queued TX never waits: hasPendingWork() keeps the loop from sleeping at all.
|
||||
// 0 = old behaviour (sd_app_evt_wait in the loop task).
|
||||
#ifndef NRF52_TICKLESS_MAX_MS
|
||||
#define NRF52_TICKLESS_MAX_MS 50
|
||||
#endif
|
||||
static TaskHandle_t s_sleep_task = NULL;
|
||||
|
||||
extern "C" void nrf52WakeFromISR(void) {
|
||||
TaskHandle_t t = s_sleep_task;
|
||||
if (t == NULL) return;
|
||||
BaseType_t woken = pdFALSE;
|
||||
vTaskNotifyGiveFromISR(t, &woken);
|
||||
portYIELD_FROM_ISR(woken);
|
||||
}
|
||||
|
||||
void NRF52Board::sleep(uint32_t secs) {
|
||||
// Clear FPU interrupt flags to avoid insomnia
|
||||
// see errata 87 for details https://docs.nordicsemi.com/bundle/errata_nRF52840_Rev3/page/ERR/nRF52840/Rev3/latest/anomaly_840_87.html
|
||||
@@ -371,7 +395,12 @@ void NRF52Board::sleep(uint32_t secs) {
|
||||
if (s_have_exit) s_awake_us += (uint32_t)(t_enter - s_last_exit_us);
|
||||
#endif
|
||||
|
||||
if (sd_enabled) {
|
||||
if (sd_enabled && NRF52_TICKLESS_MAX_MS > 0 && xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {
|
||||
// A notification given before this point (ISR raced the loop) is counted,
|
||||
// so the take returns at once instead of sleeping on a ready packet.
|
||||
s_sleep_task = xTaskGetCurrentTaskHandle();
|
||||
ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(NRF52_TICKLESS_MAX_MS));
|
||||
} else if (sd_enabled) {
|
||||
// first call processes pending softdevice events, second call sleeps.
|
||||
sd_app_evt_wait();
|
||||
sd_app_evt_wait();
|
||||
|
||||
@@ -23,6 +23,10 @@ static volatile uint32_t diag_isr_count = 0; // DIO1 edges that reached the MC
|
||||
static volatile uint32_t diag_isr_ms = 0; // millis() of the last one
|
||||
#endif
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
extern "C" void nrf52WakeFromISR(void); // NRF52Board.cpp: ends the loop's tickless wait
|
||||
#endif
|
||||
|
||||
// this function is called when a complete packet
|
||||
// is transmitted by the module
|
||||
static
|
||||
@@ -32,6 +36,9 @@ static
|
||||
void setFlag(void) {
|
||||
// we sent a packet, set the flag
|
||||
state |= STATE_INT_READY;
|
||||
#if defined(NRF52_PLATFORM)
|
||||
nrf52WakeFromISR();
|
||||
#endif
|
||||
#ifdef RADIO_DIAG
|
||||
diag_isr_count++;
|
||||
diag_isr_ms = millis();
|
||||
|
||||
Reference in new issue
Block a user