diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3fb4dd6e..6b5c5741 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -160,11 +160,10 @@ list(APPEND SOURCE_FILES DisplayApp/Screens/Clock.cpp DisplayApp/Screens/Message.cpp DisplayApp/Screens/Tile.cpp -# DisplayApp/Screens/Tab.cpp main.cpp drivers/St7789.cpp drivers/SpiMaster.cpp -# Components/Gfx/Gfx.cpp + drivers/Watchdog.cpp BLE/BleManager.c Components/Battery/BatteryController.cpp Components/Ble/BleController.cpp @@ -194,6 +193,7 @@ set(INCLUDE_FILES # DisplayApp/Screens/Tab.h drivers/St7789.h drivers/SpiMaster.h + drivers/Watchdog.h BLE/BleManager.h Components/Battery/BatteryController.h Components/Ble/BleController.h diff --git a/src/SystemTask/SystemTask.cpp b/src/SystemTask/SystemTask.cpp index 91822fa2..e15846da 100644 --- a/src/SystemTask/SystemTask.cpp +++ b/src/SystemTask/SystemTask.cpp @@ -29,6 +29,9 @@ void SystemTask::Process(void *instance) { } void SystemTask::Work() { + watchdog.Setup(7); + watchdog.Start(); + NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason())); APP_GPIOTE_INIT(2); bool erase_bonds=false; nrf_sdh_freertos_init(ble_manager_start_advertising, &erase_bonds); @@ -70,7 +73,7 @@ void SystemTask::Work() { while(true) { uint8_t msg; - if (xQueueReceive(systemTaksMsgQueue, &msg, isSleeping?3600000 : 1000)) { + if (xQueueReceive(systemTaksMsgQueue, &msg, isSleeping?2500 : 1000)) { Messages message = static_cast(msg); switch(message) { case Messages::GoToRunning: isSleeping = false; break; @@ -83,6 +86,9 @@ void SystemTask::Work() { } uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG); dateTimeController.UpdateTime(systick_counter); + + if(!nrf_gpio_pin_read(pinButton)) + watchdog.Kick(); } } diff --git a/src/SystemTask/SystemTask.h b/src/SystemTask/SystemTask.h index cb913545..f5ba2d75 100644 --- a/src/SystemTask/SystemTask.h +++ b/src/SystemTask/SystemTask.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace Pinetime { namespace System { @@ -41,6 +42,7 @@ namespace Pinetime { Pinetime::Controllers::DateTime& dateTimeController; QueueHandle_t systemTaksMsgQueue; bool isSleeping = false; + Pinetime::Drivers::Watchdog watchdog; static constexpr uint8_t pinSpiSck = 2; diff --git a/src/drivers/Watchdog.cpp b/src/drivers/Watchdog.cpp new file mode 100644 index 00000000..b0dc12e5 --- /dev/null +++ b/src/drivers/Watchdog.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include "Watchdog.h" +using namespace Pinetime::Drivers; + + +void Watchdog::Setup(uint8_t timeoutSeconds) { + NRF_WDT->CONFIG &= ~(WDT_CONFIG_SLEEP_Msk << WDT_CONFIG_SLEEP_Pos); + NRF_WDT->CONFIG |= (WDT_CONFIG_HALT_Run << WDT_CONFIG_SLEEP_Pos); + + NRF_WDT->CONFIG &= ~(WDT_CONFIG_HALT_Msk << WDT_CONFIG_HALT_Pos); + NRF_WDT->CONFIG |= (WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos); + + /* timeout (s) = (CRV + 1) / 32768 */ + // JF : 7500 = 7.5s + uint32_t crv = (((timeoutSeconds*1000u) << 15u) / 1000) - 1; + NRF_WDT->CRV = crv; + + /* Enable reload requests */ + NRF_WDT->RREN = (WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos); +} + +void Watchdog::Start() { + NRF_WDT->TASKS_START = 1; +} + +void Watchdog::Kick() { + NRF_WDT->RR[0] = WDT_RR_RR_Reload; +} + +Watchdog::ResetReasons Watchdog::ResetReason() { + uint32_t resetReason; + sd_power_reset_reason_get(&resetReason); + sd_power_reset_reason_clr(0xFFFFFFFF); + if(resetReason & 0x01) return ResetReasons::ResetPin; + if((resetReason >> 1) & 0x01) return ResetReasons::Watchdog; + if((resetReason >> 2) & 0x01) return ResetReasons::SoftReset; + if((resetReason >> 3) & 0x01) return ResetReasons::CpuLockup; + if((resetReason >> 16) & 0x01) return ResetReasons::SystemOff; + if((resetReason >> 17) & 0x01) return ResetReasons::LpComp; + if((resetReason >> 18) & 0x01) return ResetReasons::DebugInterface; + if((resetReason >> 19) & 0x01) return ResetReasons::NFC; + return ResetReasons::HardReset; +} + +const char *Watchdog::ResetReasonToString(Watchdog::ResetReasons reason) { + switch(reason) { + case ResetReasons::ResetPin: return "Reset pin"; + case ResetReasons::Watchdog: return "Watchdog"; + case ResetReasons::DebugInterface: return "Debug interface"; + case ResetReasons::LpComp: return "LPCOMP"; + case ResetReasons::SystemOff: return "System OFF"; + case ResetReasons::CpuLockup: return "CPU Lock-up"; + case ResetReasons::SoftReset: return "Soft reset"; + case ResetReasons::NFC: return "NFC"; + case ResetReasons::HardReset: return "Hard reset"; + default: return "Unknown"; + } +} diff --git a/src/drivers/Watchdog.h b/src/drivers/Watchdog.h new file mode 100644 index 00000000..da192d9e --- /dev/null +++ b/src/drivers/Watchdog.h @@ -0,0 +1,17 @@ +#pragma once + +namespace Pinetime { + namespace Drivers { + class Watchdog { + public: + enum class ResetReasons { ResetPin, Watchdog, SoftReset, CpuLockup, SystemOff, LpComp, DebugInterface, NFC, HardReset }; + void Setup(uint8_t timeoutSeconds); + void Start(); + void Kick(); + + ResetReasons ResetReason(); + static const char* ResetReasonToString(ResetReasons reason); + + }; + } +} diff --git a/src/libs/lvgl b/src/libs/lvgl index 10b9c9b2..ee95d1c9 160000 --- a/src/libs/lvgl +++ b/src/libs/lvgl @@ -1 +1 @@ -Subproject commit 10b9c9b2f5344e7b2f5cc00a19ed86ed56ae9866 +Subproject commit ee95d1c9cf74899585f9165458911f2d54ca7500