Skip to content

Commit

Permalink
[ESP32]: increment the total operational hours inline without log
Browse files Browse the repository at this point in the history
Since total-operational-hours is a critical information, it
intentionally uses the FreeRTOS timer to increment the values, so that
it should not be a victim of PostEvent failures.

Earlier it used to call WriteConfigValues which has the ChipLogProgress
and logging from the timer stack may overflow the timer stack. So,
inlined the implementation which do not log.
  • Loading branch information
shubhamdp committed Jan 14, 2025
1 parent 5bd63d5 commit a84d314
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <platform/ConfigurationManager.h>
#include <platform/ESP32/ESP32Config.h>
#include <platform/ESP32/ESP32Utils.h>
#include <platform/ESP32/ScopedNvsHandle.h>
#include <platform/internal/GenericConfigurationManagerImpl.ipp>

#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
Expand Down Expand Up @@ -57,14 +58,7 @@ uint32_t ConfigurationManagerImpl::mTotalOperationalHours = 0;

void ConfigurationManagerImpl::TotalOperationalHoursTimerCallback(TimerHandle_t timer)
{
mTotalOperationalHours++;

CHIP_ERROR err = ConfigurationMgrImpl().StoreTotalOperationalHours(mTotalOperationalHours);

if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Failed to store total operational hours: %" CHIP_ERROR_FORMAT, err.Format());
}
(void)ConfigurationMgrImpl().StoreTotalOperationalHours(++mTotalOperationalHours);
}

CHIP_ERROR ConfigurationManagerImpl::Init()
Expand Down Expand Up @@ -226,7 +220,13 @@ CHIP_ERROR ConfigurationManagerImpl::GetTotalOperationalHours(uint32_t & totalOp

CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOperationalHours)
{
return WriteConfigValue(ESP32Config::kCounterKey_TotalOperationalHours, totalOperationalHours);
ScopedNvsHandle handle;
ESP32Config::Key key = ESP32Config::kCounterKey_TotalOperationalHours;

ReturnErrorOnFailure(handle.Open(key.Namespace, NVS_READWRITE, ESP32Config::GetPartitionLabelByNamespace(key.Namespace)));
ReturnMappedErrorOnFailure(nvs_set_u32(handle, key.Name, totalOperationalHours));
ReturnMappedErrorOnFailure(nvs_commit(handle));
return CHIP_NO_ERROR;
}

CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersionString(char * buf, size_t bufSize)
Expand Down
1 change: 0 additions & 1 deletion src/platform/ESP32/ESP32Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class ESP32Config

static void RunConfigUnitTest(void);

private:
static const char * GetPartitionLabelByNamespace(const char * ns);
};

Expand Down

0 comments on commit a84d314

Please sign in to comment.