Skip to content

Commit c8e7727

Browse files
committed
To implement power saving for NRF52 using System-Idle On
1 parent 5159276 commit c8e7727

2 files changed

Lines changed: 9 additions & 25 deletions

File tree

src/helpers/NRF52Board.cpp

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
#include "nrf_sdm.h"
44
#include <bluefruit.h>
55

6-
// For PowerSaving
7-
static SoftwareTimer wakeupTimer;
8-
96
static BLEDfu bledfu;
107

118
static void connect_callback(uint16_t conn_handle) {
@@ -105,26 +102,18 @@ bool NRF52BoardOTA::startOTAUpdate(const char *id, char reply[]) {
105102
return true;
106103
}
107104

108-
static void wakeUpCallback(TimerHandle_t xTimer) {
109-
// To wake up based on timer
110-
resumeLoop();
111-
wakeupTimer.stop();
112-
}
113-
114105
void NRF52Board::enterLightSleep(uint32_t secs) {
115106
#if defined(P_LORA_DIO_1)
116-
// To prevent to enter suspendLoop when the loop has not processed the pending RX
117-
if(digitalRead(P_LORA_DIO_1) == HIGH) {
118-
return;
107+
// To mark the start of the sleep
108+
uint32_t startTime = millis();
109+
110+
// To wake up when a LoRa packet comes or sleep timeout. Safe to 49-day overflow
111+
while (digitalRead(P_LORA_DIO_1) == LOW && (millis() - startTime < secs*1000)) {
112+
// To enter System-on idle
113+
__SEV(); // To clear any stale event flag
114+
__WFE(); // To consume that event
115+
__WFE(); // To actually puts CPU to sleep
119116
}
120-
121-
// To wake up periodically to do scheduled jobs
122-
wakeupTimer.stop();
123-
wakeupTimer.begin(secs * 1000, wakeUpCallback, nullptr, false);
124-
wakeupTimer.start();
125-
126-
// To pause MCU to sleep
127-
suspendLoop();
128117
#endif
129118
}
130119

src/helpers/radiolib/RadioLibWrappers.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ void setFlag(void) {
2929
#elif defined(ESP32) && defined(P_LORA_DIO_1) // SX1262
3030
gpio_set_intr_type((gpio_num_t)P_LORA_DIO_1, GPIO_INTR_POSEDGE);
3131
#endif
32-
33-
// To wakeup when there is a LoRa message
34-
#if defined(NRF52_PLATFORM)
35-
resumeLoop();
36-
#endif
3732
}
3833

3934
void RadioLibWrapper::begin() {

0 commit comments

Comments
 (0)