Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/helpers/NRF52Board.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#if defined(NRF52_PLATFORM)
#include "NRF52Board.h"

// Single definitions for noinit backup variables (declared extern in NRF52Board.h)
uint32_t _noinit_backup_time __attribute__((section(".noinit")));
uint32_t _noinit_backup_magic __attribute__((section(".noinit")));

#include <bluefruit.h>
#include <nrf_soc.h>

Expand Down
41 changes: 41 additions & 0 deletions src/helpers/NRF52Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,47 @@

#if defined(NRF52_PLATFORM)

// noinit variables survive watchdog, soft, pin, and lockup resets (RAM retained).
// Lost on power-on and System OFF (magic check handles this).
extern uint32_t _noinit_backup_time __attribute__((section(".noinit")));
extern uint32_t _noinit_backup_magic __attribute__((section(".noinit")));
#define NRF52_BACKUP_MAGIC 0xAA55CC33
#define NRF52_TIME_MIN 1772323200 // 1 Mar 2026

class NRF52RTCClock : public mesh::RTCClock {
uint32_t base_time;
uint64_t accumulator;
unsigned long prev_millis;
public:
NRF52RTCClock() {
if (_noinit_backup_magic == NRF52_BACKUP_MAGIC && _noinit_backup_time > NRF52_TIME_MIN) {
base_time = _noinit_backup_time;
} else {
base_time = NRF52_TIME_MIN;
}
accumulator = 0;
prev_millis = millis();
}
uint32_t getCurrentTime() override { return base_time + accumulator / 1000; }
void setCurrentTime(uint32_t time) override {
base_time = time;
accumulator = 0;
prev_millis = millis();
_noinit_backup_time = time;
_noinit_backup_magic = NRF52_BACKUP_MAGIC;
}
void tick() override {
unsigned long now = millis();
accumulator += (now - prev_millis);
prev_millis = now;
uint32_t current = base_time + accumulator / 1000;
if (current > NRF52_TIME_MIN && current != _noinit_backup_time) {
_noinit_backup_time = current;
_noinit_backup_magic = NRF52_BACKUP_MAGIC;
}
}
};

#ifdef NRF52_POWER_MANAGEMENT
// Shutdown Reason Codes (stored in GPREGRET before SYSTEMOFF)
#define SHUTDOWN_REASON_NONE 0x00
Expand Down
2 changes: 1 addition & 1 deletion variants/heltec_mesh_solar/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
SolarSensorManager sensors = SolarSensorManager(nmea);
Expand Down
2 changes: 1 addition & 1 deletion variants/heltec_t114/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);

#if ENV_INCLUDE_GPS
Expand Down
2 changes: 1 addition & 1 deletion variants/ikoka_handheld_nrf/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);

EnvironmentSensorManager sensors;
Expand Down
2 changes: 1 addition & 1 deletion variants/ikoka_nano_nrf/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
EnvironmentSensorManager sensors;

Expand Down
2 changes: 1 addition & 1 deletion variants/ikoka_stick_nrf/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
EnvironmentSensorManager sensors;

Expand Down
2 changes: 1 addition & 1 deletion variants/keepteen_lt1/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#if ENV_INCLUDE_GPS
#include <helpers/sensors/MicroNMEALocationProvider.h>
Expand Down
2 changes: 1 addition & 1 deletion variants/lilygo_techo/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);

#ifdef ENV_INCLUDE_GPS
Expand Down
2 changes: 1 addition & 1 deletion variants/lilygo_techo_lite/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);

#ifdef ENV_INCLUDE_GPS
Expand Down
2 changes: 1 addition & 1 deletion variants/mesh_pocket/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ WRAPPER_CLASS radio_driver(radio, board);

SensorManager sensors = SensorManager();

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);

#ifdef DISPLAY_CLASS
Expand Down
2 changes: 1 addition & 1 deletion variants/meshtiny/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
EnvironmentSensorManager sensors = EnvironmentSensorManager();

Expand Down
2 changes: 1 addition & 1 deletion variants/minewsemi_me25ls01/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock rtc_clock;
NRF52RTCClock rtc_clock;
extern EnvironmentSensorManager sensors;
#if ENV_INCLUDE_GPS
#include <helpers/sensors/MicroNMEALocationProvider.h>
Expand Down
2 changes: 1 addition & 1 deletion variants/minewsemi_me25ls01/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

extern MinewsemiME25LS01Board board;
extern WRAPPER_CLASS radio_driver;
extern VolatileRTCClock rtc_clock;
extern NRF52RTCClock rtc_clock;
extern EnvironmentSensorManager sensors;

bool radio_init();
Expand Down
2 changes: 1 addition & 1 deletion variants/nano_g2_ultra/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
NanoG2UltraSensorManager sensors = NanoG2UltraSensorManager(nmea);
Expand Down
2 changes: 1 addition & 1 deletion variants/promicro/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#if ENV_INCLUDE_GPS
#include <helpers/sensors/MicroNMEALocationProvider.h>
Expand Down
2 changes: 1 addition & 1 deletion variants/rak3401/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);

#if ENV_INCLUDE_GPS
Expand Down
2 changes: 1 addition & 1 deletion variants/rak4631/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);

#if ENV_INCLUDE_GPS
Expand Down
2 changes: 1 addition & 1 deletion variants/rak_wismesh_tag/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);

#if ENV_INCLUDE_GPS
Expand Down
2 changes: 1 addition & 1 deletion variants/sensecap_solar/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#ifdef ENV_INCLUDE_GPS
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
Expand Down
2 changes: 1 addition & 1 deletion variants/t1000-e/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock rtc_clock;
NRF52RTCClock rtc_clock;
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
T1000SensorManager sensors = T1000SensorManager(nmea);

Expand Down
2 changes: 1 addition & 1 deletion variants/t1000-e/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class T1000SensorManager: public SensorManager {

extern T1000eBoard board;
extern WRAPPER_CLASS radio_driver;
extern VolatileRTCClock rtc_clock;
extern NRF52RTCClock rtc_clock;
extern T1000SensorManager sensors;

bool radio_init();
Expand Down
2 changes: 1 addition & 1 deletion variants/thinknode_m1/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
ThinkNodeM1SensorManager sensors = ThinkNodeM1SensorManager(nmea);
Expand Down
2 changes: 1 addition & 1 deletion variants/thinknode_m3/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#ifdef ENV_INCLUDE_GPS
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
Expand Down
2 changes: 1 addition & 1 deletion variants/thinknode_m6/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
#ifdef ENV_INCLUDE_GPS
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
Expand Down
2 changes: 1 addition & 1 deletion variants/wio-tracker-l1/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);

#ifdef ENV_INCLUDE_GPS
Expand Down
2 changes: 1 addition & 1 deletion variants/wio_wm1110/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock rtc_clock;
NRF52RTCClock rtc_clock;
EnvironmentSensorManager sensors;

#ifndef LORA_CR
Expand Down
2 changes: 1 addition & 1 deletion variants/wio_wm1110/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

extern WioWM1110Board board;
extern WRAPPER_CLASS radio_driver;
extern VolatileRTCClock rtc_clock;
extern NRF52RTCClock rtc_clock;
extern EnvironmentSensorManager sensors;

bool radio_init();
Expand Down
2 changes: 1 addition & 1 deletion variants/xiao_nrf52/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock fallback_clock;
NRF52RTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);

EnvironmentSensorManager sensors;
Expand Down