diff --git a/gcc_nrf52.ld b/gcc_nrf52.ld index 98e133aa..b40dc06b 100644 --- a/gcc_nrf52.ld +++ b/gcc_nrf52.ld @@ -3,14 +3,23 @@ SEARCH_DIR(.) GROUP(-lgcc -lc -lnosys) +NO_INIT_SIZE = 0x100; +RAM_MAX = 64K; MEMORY { FLASH (rx) : ORIGIN = 0x00000, LENGTH = 0x78000 - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000 + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = RAM_MAX - NO_INIT_SIZE + NOINIT (rwx): ORIGIN = ORIGIN(RAM) + LENGTH(RAM), LENGTH = NO_INIT_SIZE } SECTIONS { + noinit (NOLOAD): + { + PROVIDE(__start_noinit_data = .); + KEEP(*(.noinit)) + PROVIDE(__stop_noinit_data = .); + } >NOINIT } SECTIONS diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index d6aa83c8..77c5be4e 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -5,6 +5,10 @@ using namespace Pinetime::Controllers; +void DateTime::SetCurrentTime(std::chrono::time_point t) { + this->currentDateTime = t; +} + void DateTime::SetTime( uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter) { std::tm tm = { @@ -67,11 +71,12 @@ void DateTime::UpdateTime(uint32_t systickCounter) { // Notify new day to SystemTask if (hour == 0 and not isMidnightAlreadyNotified) { isMidnightAlreadyNotified = true; - if(systemTask != nullptr) + if (systemTask != nullptr) systemTask->PushMessage(System::Messages::OnNewDay); } else if (hour != 0) { isMidnightAlreadyNotified = false; } + BackUpTime = currentDateTime; } const char* DateTime::MonthShortToString() { diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h index 265d6e9d..ed7b0861 100644 --- a/src/components/datetime/DateTimeController.h +++ b/src/components/datetime/DateTimeController.h @@ -2,6 +2,7 @@ #include #include +extern std::chrono::time_point BackUpTime; namespace Pinetime { namespace System { @@ -74,6 +75,7 @@ namespace Pinetime { } void Register(System::SystemTask* systemTask); + void SetCurrentTime(std::chrono::time_point t); private: uint16_t year = 0; diff --git a/src/main.cpp b/src/main.cpp index d301be67..9c384a8b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -124,7 +124,6 @@ Pinetime::Controllers::FS fs {spiNorFlash}; Pinetime::Controllers::Settings settingsController {fs}; Pinetime::Controllers::MotorController motorController {settingsController}; - Pinetime::Applications::DisplayApp displayApp(lcd, lvgl, touchPanel, @@ -161,6 +160,9 @@ Pinetime::System::SystemTask systemTask(spi, heartRateApp, fs); +uint32_t MAGIC_RAM __attribute__((section(".noinit"))); +std::chrono::time_point BackUpTime __attribute__((section(".noinit"))); + void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { if (pin == pinTouchIrq) { systemTask.OnTouchEvent(); @@ -321,6 +323,13 @@ int main(void) { // retrieve version stored by bootloader Pinetime::BootloaderVersion::SetVersion(NRF_TIMER2->CC[0]); + // Check Magic Ram and reset lost variables + if (MAGIC_RAM == 0xDEADBEEF) { + dateTimeController.SetCurrentTime(BackUpTime); + } else { + MAGIC_RAM = 0xDEADBEEF; + } + lvgl.Init(); systemTask.Start();