|
30 | 30 | #include <platform/ConfigurationManager.h>
|
31 | 31 | #include <platform/ESP32/ESP32Config.h>
|
32 | 32 | #include <platform/ESP32/ESP32Utils.h>
|
| 33 | +#include <platform/ESP32/ScopedNvsHandle.h> |
33 | 34 | #include <platform/internal/GenericConfigurationManagerImpl.ipp>
|
34 | 35 |
|
35 | 36 | #if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
|
@@ -57,14 +58,9 @@ uint32_t ConfigurationManagerImpl::mTotalOperationalHours = 0;
|
57 | 58 |
|
58 | 59 | void ConfigurationManagerImpl::TotalOperationalHoursTimerCallback(TimerHandle_t timer)
|
59 | 60 | {
|
60 |
| - mTotalOperationalHours++; |
61 |
| - |
62 |
| - CHIP_ERROR err = ConfigurationMgrImpl().StoreTotalOperationalHours(mTotalOperationalHours); |
63 |
| - |
64 |
| - if (err != CHIP_NO_ERROR) |
65 |
| - { |
66 |
| - ChipLogError(DeviceLayer, "Failed to store total operational hours: %" CHIP_ERROR_FORMAT, err.Format()); |
67 |
| - } |
| 61 | + // This function is called from the FreeRTOS timer task. Since the task stack is limited, |
| 62 | + // we avoid logging error messages here to prevent stack overflows. |
| 63 | + (void) ConfigurationMgrImpl().StoreTotalOperationalHours(++mTotalOperationalHours); |
68 | 64 | }
|
69 | 65 |
|
70 | 66 | CHIP_ERROR ConfigurationManagerImpl::Init()
|
@@ -182,6 +178,9 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
|
182 | 178 | }
|
183 | 179 |
|
184 | 180 | {
|
| 181 | + // The total-operational-hours is critical information. It intentionally uses the FreeRTOS timer |
| 182 | + // to increment the value, this ensures it is not affected by PostEvent failures. |
| 183 | + |
185 | 184 | // Start a timer which reloads every one hour and bumps the total operational hours
|
186 | 185 | TickType_t reloadPeriod = (1000 * 60 * 60) / portTICK_PERIOD_MS;
|
187 | 186 | TimerHandle_t timerHandle = xTimerCreate("tOpHrs", reloadPeriod, pdPASS, nullptr, TotalOperationalHoursTimerCallback);
|
@@ -226,7 +225,13 @@ CHIP_ERROR ConfigurationManagerImpl::GetTotalOperationalHours(uint32_t & totalOp
|
226 | 225 |
|
227 | 226 | CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOperationalHours)
|
228 | 227 | {
|
229 |
| - return WriteConfigValue(ESP32Config::kCounterKey_TotalOperationalHours, totalOperationalHours); |
| 228 | + ScopedNvsHandle handle; |
| 229 | + ESP32Config::Key key = ESP32Config::kCounterKey_TotalOperationalHours; |
| 230 | + |
| 231 | + ReturnErrorOnFailure(handle.Open(key.Namespace, NVS_READWRITE, ESP32Config::GetPartitionLabelByNamespace(key.Namespace))); |
| 232 | + ReturnMappedErrorOnFailure(nvs_set_u32(handle, key.Name, totalOperationalHours)); |
| 233 | + ReturnMappedErrorOnFailure(nvs_commit(handle)); |
| 234 | + return CHIP_NO_ERROR; |
230 | 235 | }
|
231 | 236 |
|
232 | 237 | CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersionString(char * buf, size_t bufSize)
|
|
0 commit comments