Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

riscv: telink: adjust analog register and deferred storage for tl3218 #371

Open
wants to merge 1 commit into
base: develop_dual
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/chef.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/examples-telink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
24 changes: 18 additions & 6 deletions examples/platform/telink/common/src/AppTaskCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

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

#include "BLEManagerImpl.h"
#include "ButtonManager.h"
Expand Down Expand Up @@ -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)
Expand All @@ -504,7 +517,6 @@ bool OtaGetAnaFlag(void)
return false;
}
}
#endif // CONFIG_SOC_RISCV_TELINK_B92
#endif // CONFIG_STORAGE_OTA_STATUS

/**
Expand Down
Loading