From 79b38fca0d46b59f0c9049c561539e70114e2d2d Mon Sep 17 00:00:00 2001 From: Fengtai Xie Date: Tue, 7 Jan 2025 14:32:43 +0800 Subject: [PATCH] riscv: telink: adjust analog register, deferred storage for tl3218 - 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 --- .github/workflows/chef.yaml | 2 +- .github/workflows/examples-telink.yaml | 2 +- config/telink/chip-module/Kconfig.defaults | 4 +++ examples/lighting-app/telink/CMakeLists.txt | 1 + examples/lighting-app/telink/src/AppTask.cpp | 33 +++++++++++++++++++ .../telink/common/src/AppTaskCommon.cpp | 24 ++++++++++---- 6 files changed, 58 insertions(+), 8 deletions(-) diff --git a/.github/workflows/chef.yaml b/.github/workflows/chef.yaml index a22885729c14e0..fb1a49cbab3a42 100644 --- a/.github/workflows/chef.yaml +++ b/.github/workflows/chef.yaml @@ -111,7 +111,7 @@ jobs: platform: telink - name: Update Zephyr to specific revision (for developers purpose) shell: bash - run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py ab14605bc9bd8bfeee1e914f679478417b24de12" + run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 16b157bc4caf9a268caf11481624885f5046263f" - name: CI Examples Telink shell: bash run: | diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 1bbace9c44d93e..eaacef94217d1a 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -58,7 +58,7 @@ jobs: gh-context: ${{ toJson(github) }} - name: Update Zephyr to specific revision (for developers purpose) - run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py ab14605bc9bd8bfeee1e914f679478417b24de12" + run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 16b157bc4caf9a268caf11481624885f5046263f" - name: Build tools required for Factory Data # Run test for master and all PRs diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index 4dab0c11890739..c5e73c4703ee1a 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -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 diff --git a/examples/lighting-app/telink/CMakeLists.txt b/examples/lighting-app/telink/CMakeLists.txt index 95930946944237..5fcd960f55eb4e 100644 --- a/examples/lighting-app/telink/CMakeLists.txt +++ b/examples/lighting-app/telink/CMakeLists.txt @@ -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 diff --git a/examples/lighting-app/telink/src/AppTask.cpp b/examples/lighting-app/telink/src/AppTask.cpp index b8b416214649ef..c1368c9ffe72b4 100644 --- a/examples/lighting-app/telink/src/AppTask.cpp +++ b/examples/lighting-app/telink/src/AppTask.cpp @@ -29,6 +29,7 @@ #include #include +#include LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL); @@ -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(gPersisters, ATTRIBUTES_ARRAY_SIZE), + System::Clock::Milliseconds32(DEFERRED_STORAGE_TIME)); + bool AppTask::IsTurnedOn() const { return sfixture_on; @@ -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) { diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 3f4aac33a422b4..590e8000ae2f33 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -18,7 +18,9 @@ #include "AppTaskCommon.h" #include "AppTask.h" -#include +#if CONFIG_SOC_RISCV_TELINK_B92 || CONFIG_SOC_RISCV_TELINK_TL321X +#include +#endif #include "BLEManagerImpl.h" #include "ButtonManager.h" @@ -482,15 +484,26 @@ void AppTaskCommon::PrintFirmwareInfo(void) * * @see There are many OTA callback events in * AppTaskCommon::OtaEventsHandler, please embed it as needed. + * The available analog registers address are as follows: + * TLSR9528 - 0x3b + * TL3218X - 0x3b */ #if CONFIG_STORAGE_OTA_STATUS -#if CONFIG_SOC_RISCV_TELINK_B92 -#define ANALOG_REG_ADR 0x3b -#define ANALOG_OTA_FLAG_VAL 0x55 +#define ANALOG_REG_ADR (0x3b) +#define ANALOG_OTA_FLAG_VAL (0x55) void OtaSetAnaFlag(void) { - analog_write(ANALOG_REG_ADR, ANALOG_OTA_FLAG_VAL); + int err = analog_write(ANALOG_REG_ADR, ANALOG_OTA_FLAG_VAL); + + if (!err) + { + printk("Write successful\n"); + } + else + { + printk("The address:0x%x written is incorrect\n", ANALOG_REG_ADR); + } } bool OtaGetAnaFlag(void) @@ -504,7 +517,6 @@ bool OtaGetAnaFlag(void) return false; } } -#endif // CONFIG_SOC_RISCV_TELINK_B92 #endif // CONFIG_STORAGE_OTA_STATUS /**