Skip to content

Commit

Permalink
riscv: telink: adjust analog register, deferred storage for tl3218
Browse files Browse the repository at this point in the history
 - update commit id for zephyr .
 - add read and write interface of analog register for TL3218X .
 - add deferred storage attributes for provider .

Signed-off-by: Fengtai Xie <[email protected]>
  • Loading branch information
fengtai-telink committed Jan 14, 2025
1 parent 2758b03 commit 22fe645
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
4 changes: 4 additions & 0 deletions config/telink/chip-module/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ config EXPOSE_CHIPID_VIA_BLE
bool "Get CHIP ID via ble"
default n

config DEFERRED_ATTR_STORAGE
bool "Defer the storage time of attributes"
default n

# Set multiplicator of Name Value Storage (NVS) as 1 to reach NVS sector size 4KB
# nvs_sector_size = flash_page_size * mult = 4KB * 1 = 4KB
config SETTINGS_NVS_SECTOR_SIZE_MULT
Expand Down
1 change: 1 addition & 0 deletions examples/lighting-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ target_include_directories(app PRIVATE
target_sources(app PRIVATE
src/AppTask.cpp
src/ZclCallbacks.cpp
${CHIP_ROOT}/src/app/util/persistence/DeferredAttributePersistenceProvider.cpp
${TELINK_COMMON}/common/src/mainCommon.cpp
${TELINK_COMMON}/common/src/AppTaskCommon.cpp
${TELINK_COMMON}/util/src/LEDManager.cpp
Expand Down
33 changes: 33 additions & 0 deletions examples/lighting-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <zephyr/kernel.h>

#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/util/persistence/DeferredAttributePersistenceProvider.h>

LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);

Expand All @@ -44,6 +45,35 @@ RgbColor_t sLedRgb;

AppTask AppTask::sAppTask;

/**
* @brief Set deferred attributes storage
*
* @see Define a custom attribute persister which makes actual write of the CurrentHue, CurrentSaturation, CurrentLevel attributes
* value to the non-volatile storage only when it has remained constant for 5 seconds. This is to reduce the flash wearout when the
* attribute changes frequently as a result of MoveToLevel command. DeferredAttribute object describes a deferred attribute, but
* also holds a buffer with a value to be written, so it must live so long as the DeferredAttributePersistenceProvider object.
*
* @param ATTRIBUTES_ARRAY_SIZE The lenght of the DeferredAttribute array
* @param DEFERRED_STORAGE_TIME The deferred time(ms) to store attributes
*/
#define ATTRIBUTES_ARRAY_SIZE (3U)
#define DEFERRED_STORAGE_TIME (5000U)

DeferredAttribute gPersisters[] = {
#if CONFIG_DEFERRED_ATTR_STORAGE
DeferredAttribute(
ConcreteAttributePath(kExampleEndpointId, Clusters::ColorControl::Id, Clusters::ColorControl::Attributes::CurrentHue::Id)),
DeferredAttribute(ConcreteAttributePath(kExampleEndpointId, Clusters::ColorControl::Id,
Clusters::ColorControl::Attributes::CurrentSaturation::Id)),
DeferredAttribute(
ConcreteAttributePath(kExampleEndpointId, Clusters::LevelControl::Id, Clusters::LevelControl::Attributes::CurrentLevel::Id))
#endif // CONFIG_DEFERRED_ATTR_STORAGE
};

DeferredAttributePersistenceProvider gDeferredAttributePersister(Server::GetInstance().GetDefaultAttributePersister(),
Span<DeferredAttribute>(gPersisters, ATTRIBUTES_ARRAY_SIZE),
System::Clock::Milliseconds32(DEFERRED_STORAGE_TIME));

bool AppTask::IsTurnedOn() const
{
return sfixture_on;
Expand Down Expand Up @@ -267,6 +297,9 @@ CHIP_ERROR AppTask::Init(void)
SetExampleButtonCallbacks(LightingActionEventHandler);
InitCommonParts();

/* add deferred storage attribute for provider */
app::SetAttributePersistenceProvider(&gDeferredAttributePersister);

#if CONFIG_CUSTOMER_MODE
if (user_para.val == USER_ZB_SW_VAL)
{
Expand Down
6 changes: 4 additions & 2 deletions examples/platform/telink/common/src/AppTaskCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

#include "AppTaskCommon.h"
#include "AppTask.h"
#if CONFIG_SOC_RISCV_TELINK_B92
#include <analog.h>
#elif CONFIG_SOC_RISCV_TELINK_TL321X
#include <analog_user.h>
#endif

#include "BLEManagerImpl.h"
#include "ButtonManager.h"
Expand Down Expand Up @@ -484,7 +488,6 @@ void AppTaskCommon::PrintFirmwareInfo(void)
* AppTaskCommon::OtaEventsHandler, please embed it as needed.
*/
#if CONFIG_STORAGE_OTA_STATUS
#if CONFIG_SOC_RISCV_TELINK_B92
#define ANALOG_REG_ADR 0x3b
#define ANALOG_OTA_FLAG_VAL 0x55

Expand All @@ -504,7 +507,6 @@ bool OtaGetAnaFlag(void)
return false;
}
}
#endif // CONFIG_SOC_RISCV_TELINK_B92
#endif // CONFIG_STORAGE_OTA_STATUS

/**
Expand Down

0 comments on commit 22fe645

Please sign in to comment.