From 88dac247996f6c2d7a534954259e3668671d59ac Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Mon, 5 Feb 2024 03:40:14 -0500 Subject: [PATCH] Move getting the reboot cause to platform abstraction. Set a getter for the reboot cause so different stacks can obtain it (#31891) --- src/platform/silabs/ConfigurationManagerImpl.h | 1 - .../silabs/efr32/ConfigurationManagerImpl.cpp | 16 +++++----------- .../silabs/platformAbstraction/GsdkSpam.cpp | 5 +++++ .../silabs/platformAbstraction/SilabsPlatform.h | 2 ++ .../platformAbstraction/SilabsPlatformBase.h | 1 + 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/platform/silabs/ConfigurationManagerImpl.h b/src/platform/silabs/ConfigurationManagerImpl.h index c025f51de40041..f34e37ed91bb52 100644 --- a/src/platform/silabs/ConfigurationManagerImpl.h +++ b/src/platform/silabs/ConfigurationManagerImpl.h @@ -73,7 +73,6 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp void RunConfigUnitTest(void) override; // ===== Private members reserved for use by this class only. - uint32_t rebootCause; static void DoFactoryReset(intptr_t arg); }; diff --git a/src/platform/silabs/efr32/ConfigurationManagerImpl.cpp b/src/platform/silabs/efr32/ConfigurationManagerImpl.cpp index ed0aaad8e1d61f..14da9b5d9bb8c2 100644 --- a/src/platform/silabs/efr32/ConfigurationManagerImpl.cpp +++ b/src/platform/silabs/efr32/ConfigurationManagerImpl.cpp @@ -22,15 +22,12 @@ * for EFR32 platforms using the Silicon Labs SDK. */ /* this file behaves like a config.h, comes first */ -#include - -#include - #include #include +#include +#include #include - -#include "em_rmu.h" +#include #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION #include "wfx_host_events.h" @@ -55,12 +52,7 @@ CHIP_ERROR ConfigurationManagerImpl::Init() err = Internal::GenericConfigurationManagerImpl::Init(); SuccessOrExit(err); - // TODO: Initialize the global GroupKeyStore object here (#1626) - IncreaseBootCount(); - rebootCause = RMU_ResetCauseGet(); - RMU_ResetCauseClear(); - err = CHIP_NO_ERROR; exit: @@ -99,6 +91,8 @@ CHIP_ERROR ConfigurationManagerImpl::GetBootReason(uint32_t & bootReason) { // rebootCause is obtained at bootup. BootReasonType matterBootCause; + uint32_t rebootCause = Silabs::GetPlatform().GetRebootCause(); + #if defined(_SILICON_LABS_32B_SERIES_1) if (rebootCause & RMU_RSTCAUSE_PORST || rebootCause & RMU_RSTCAUSE_EXTRST) // PowerOn or External pin reset { diff --git a/src/platform/silabs/platformAbstraction/GsdkSpam.cpp b/src/platform/silabs/platformAbstraction/GsdkSpam.cpp index 49f8ed48b17ad9..dda1b7e0e19dac 100644 --- a/src/platform/silabs/platformAbstraction/GsdkSpam.cpp +++ b/src/platform/silabs/platformAbstraction/GsdkSpam.cpp @@ -17,6 +17,7 @@ #include +#include "em_rmu.h" #include "sl_system_kernel.h" #ifdef ENABLE_WSTK_LEDS @@ -69,6 +70,10 @@ CHIP_ERROR SilabsPlatform::Init(void) { sl_system_init(); + mRebootCause = RMU_ResetCauseGet(); + // Clear register so it does accumualate the causes of each reset + RMU_ResetCauseClear(); + #if CHIP_ENABLE_OPENTHREAD sl_ot_sys_init(); #endif diff --git a/src/platform/silabs/platformAbstraction/SilabsPlatform.h b/src/platform/silabs/platformAbstraction/SilabsPlatform.h index 4e5e4b2ba57396..4c42a79996b3f0 100644 --- a/src/platform/silabs/platformAbstraction/SilabsPlatform.h +++ b/src/platform/silabs/platformAbstraction/SilabsPlatform.h @@ -49,6 +49,7 @@ class SilabsPlatform : virtual public SilabsPlatformAbstractionBase #endif inline void SetButtonsCb(SilabsButtonCb callback) override { mButtonCallback = callback; } + inline uint32_t GetRebootCause() { return mRebootCause; } static SilabsButtonCb mButtonCallback; @@ -64,6 +65,7 @@ class SilabsPlatform : virtual public SilabsPlatformAbstractionBase SilabsPlatform(){}; virtual ~SilabsPlatform() = default; + uint32_t mRebootCause = 0; static SilabsPlatform sSilabsPlatformAbstractionManager; }; diff --git a/src/platform/silabs/platformAbstraction/SilabsPlatformBase.h b/src/platform/silabs/platformAbstraction/SilabsPlatformBase.h index f5630ddbb0c0b3..fa387228ab2885 100644 --- a/src/platform/silabs/platformAbstraction/SilabsPlatformBase.h +++ b/src/platform/silabs/platformAbstraction/SilabsPlatformBase.h @@ -35,6 +35,7 @@ class SilabsPlatformAbstractionBase virtual CHIP_ERROR InitLCD() { return CHIP_ERROR_NOT_IMPLEMENTED; } virtual CHIP_ERROR SetGPIO(uint32_t port, uint32_t pin, bool state) { return CHIP_ERROR_NOT_IMPLEMENTED; } virtual bool GetGPIO(uint32_t port, uint32_t pin) { return false; } + virtual uint32_t GetRebootCause() = 0; // Scheduler virtual void StartScheduler(void) = 0;