33
33
34
34
#include " fsl_device_registers.h"
35
35
36
+ #if CONFIG_BOOT_REASON_SDK_SUPPORT
37
+ #include " fsl_power.h"
38
+ #endif
39
+
36
40
#if CONFIG_CHIP_PLAT_LOAD_REAL_FACTORY_DATA
37
41
#include " FactoryDataProvider.h"
38
42
#endif
@@ -54,12 +58,61 @@ ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance()
54
58
return sInstance ;
55
59
}
56
60
61
+ #if CONFIG_BOOT_REASON_SDK_SUPPORT
62
+ CHIP_ERROR ConfigurationManagerImpl::DetermineBootReason (uint8_t rebootCause)
63
+ {
64
+ /*
65
+ With current implementation kBrownOutReset couldn't be catched
66
+ */
67
+ BootReasonType bootReason = BootReasonType::kUnspecified ;
68
+
69
+ if (rebootCause == 0 )
70
+ {
71
+ bootReason = BootReasonType::kPowerOnReboot ;
72
+ }
73
+
74
+ else if (rebootCause == kPOWER_ResetCauseWdt )
75
+ {
76
+ /* Reboot can be due to hardware or software watchdog */
77
+ bootReason = BootReasonType::kHardwareWatchdogReset ;
78
+ }
79
+ else if (rebootCause == kPOWER_ResetCauseSysResetReq )
80
+ {
81
+ /*
82
+ kConfigKey_SoftwareUpdateCompleted not supported for now
83
+ if (NXPConfig::ConfigValueExists(NXPConfig::kConfigKey_SoftwareUpdateCompleted))
84
+ {
85
+ bootReason = BootReasonType::kSoftwareUpdateCompleted;
86
+ }
87
+ else
88
+ {
89
+ bootReason = BootReasonType::kSoftwareReset;
90
+ }
91
+ */
92
+ bootReason = BootReasonType::kSoftwareReset ;
93
+ }
94
+
95
+ return StoreBootReason (to_underlying (bootReason));
96
+ }
97
+ #endif
98
+
99
+ CHIP_ERROR ConfigurationManagerImpl::StoreSoftwareUpdateCompleted ()
100
+ {
101
+ /* Empty implementation*/
102
+ return CHIP_NO_ERROR;
103
+ }
104
+
57
105
CHIP_ERROR ConfigurationManagerImpl::Init ()
58
106
{
59
107
CHIP_ERROR err;
60
108
uint32_t rebootCount = 0 ;
61
109
bool failSafeArmed;
62
110
111
+ #if CONFIG_BOOT_REASON_SDK_SUPPORT
112
+ uint8_t rebootCause = POWER_GetResetCause ();
113
+ POWER_ClearResetCause (rebootCause);
114
+ #endif
115
+
63
116
// Initialize the generic implementation base class.
64
117
err = Internal::GenericConfigurationManagerImpl<NXPConfig>::Init ();
65
118
SuccessOrExit (err);
@@ -84,12 +137,15 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
84
137
err = StoreTotalOperationalHours (0 );
85
138
SuccessOrExit (err);
86
139
}
87
-
140
+ #if CONFIG_BOOT_REASON_SDK_SUPPORT
141
+ SuccessOrExit (err = DetermineBootReason (rebootCause));
142
+ #else
88
143
if (!NXPConfig::ConfigValueExists (NXPConfig::kCounterKey_BootReason ))
89
144
{
90
145
err = StoreBootReason (to_underlying (BootReasonType::kUnspecified ));
91
146
SuccessOrExit (err);
92
147
}
148
+ #endif
93
149
94
150
// TODO: Initialize the global GroupKeyStore object here
95
151
0 commit comments