Skip to content

Commit

Permalink
[TI] ICD support for TI CC13x4 (#32823)
Browse files Browse the repository at this point in the history
* ICD support for TI CC13x4

* spelling fix

* Restyled by whitespace

* Restyled by clang-format

* Restyled by gn

* Restyled by prettier-markdown

* replaced SED define with ICD server defines + other code cleanup

* Restyled by whitespace

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
abiradarti and restyled-commits authored Apr 3, 2024
1 parent 0c0c6d6 commit 978dfcb
Show file tree
Hide file tree
Showing 42 changed files with 948 additions and 578 deletions.
59 changes: 59 additions & 0 deletions docs/guides/ti/enabling_icd_on_ti_devices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Configuring Intermittently Connected Devices on TI CC13x4 Platforms

## Overview

Intermittently Connected Devices are devices in a network that do not always
need to be active. Matter has defined a cluster that helps capture this
behavior; this configuration is ideal for devices that need to operate with low
power consumption or do not have a need to always be on the network. Matter
examples on the TI CC13x4 platform can be configured to act as ICDs.

## Platform Code Changes

To configure a TI example as an ICD, open up the `args.gni` file of the example
and set the following parameter to true:

```
chip_enable_icd_server = true
```

TI examples have only been tested with the ICD Server configuration. To enable
the client configuration, set `chip_enable_icd_client` to true.

Persistent subscriptions allow devices to attempt resuming existing
subscriptions following a device reset. To enable persistent subscriptions, set
the following parameter to true:

```
chip_persist_subscriptions = true
```

Subscription timeout resumption allows devices to attempt re-establishing
subscriptions that may have expired. This feature is disabled out of box.

In addition, various ICD parameters such as idle/active mode duration, active
mode threshold, and polling intervals can be configured in
`src/platform/cc13xx_26xx/cc13x4_26x4/CHIPPlatformConfig.h`

```
#define CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS 1000
#define CHIP_CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS 500
#define CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC 300
#define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL chip::System::Clock::Milliseconds32(5000)
#define CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL chip::System::Clock::Milliseconds32(100)
```

## ZAP File Changes

Open up the ZAP file (in `examples/<example-name>/<example-name>-common`) for
the example being configured as an ICD. Add the ICD Management Cluster for
Endpoint 0.

Open up the .matter file (in `examples/<example-name>/<example-name>-common`)
corresponding to the example and add in the ICDManagement cluster.

In addition, each endpoint has a list of clusters that it supports. Add the
ICDManagement cluster to this list.

The lock-app example's .matter file can be used as a reference. These additions
allow the ICDManagement cluster's callbacks to be accessed.
12 changes: 8 additions & 4 deletions examples/all-clusters-app/cc13x4_26x4/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ ti_sysconfig("sysconfig") {

cflags = [
"-Wno-comment",
"@" + rebase_path("${target_gen_dir}/sysconfig/ti_ble_app_config.opt",
root_build_dir),
"@" + rebase_path("${target_gen_dir}/sysconfig/ti_build_config.opt",
"@" + rebase_path("${target_gen_dir}/sysconfig/ti_utils_build_compiler.opt",
root_build_dir),
]
}
Expand Down Expand Up @@ -117,8 +115,14 @@ ti_simplelink_executable("all-clusters-app") {
deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ]
}

defines = []

if (custom_factory_data) {
defines = [ "CC13XX_26XX_FACTORY_DATA" ]
defines += [ "CC13XX_26XX_FACTORY_DATA" ]
}

if (chip_enable_icd_server) {
defines += [ "TI_ICD_ENABLE_SERVER" ]
}

include_dirs = [
Expand Down
8 changes: 8 additions & 0 deletions examples/all-clusters-app/cc13x4_26x4/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import("//build_overrides/chip.gni")
import("//build_overrides/freertos.gni")
import("${chip_root}/config/standalone/args.gni")
import("${chip_root}/examples/platform/cc13x4_26x4/args.gni")

Expand Down Expand Up @@ -52,3 +53,10 @@ matter_software_ver = "0x0001"
matter_software_ver_str = "1.0.1+1"

custom_factory_data = true

# ICD Default configurations
chip_enable_icd_server = false
chip_persist_subscriptions = false
chip_subscription_timeout_resumption = false

freertos_root = "//third_party/connectedhomeip/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx/source/third_party/freertos"
163 changes: 92 additions & 71 deletions examples/all-clusters-app/cc13x4_26x4/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
#define APP_TASK_PRIORITY 4
#define APP_EVENT_QUEUE_SIZE 10

#if (CHIP_CONFIG_ENABLE_ICD_SERVER == 1)
#define LED_ENABLE 0
#else
#define LED_ENABLE 1
#endif
#define BUTTON_ENABLE 1

using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;
Expand Down Expand Up @@ -164,38 +171,9 @@ int AppTask::StartAppTask()

int AppTask::Init()
{
LED_Params ledParams;
Button_Params buttonParams;

cc13xx_26xxLogInit();

// Initialize LEDs
PLAT_LOG("Initialize LEDs");
LED_init();

LED_Params_init(&ledParams); // default PWM LED
sAppRedHandle = LED_open(CONFIG_LED_RED, &ledParams);
LED_setOff(sAppRedHandle);

LED_Params_init(&ledParams); // default PWM LED
sAppGreenHandle = LED_open(CONFIG_LED_GREEN, &ledParams);
LED_setOff(sAppGreenHandle);

// Initialize buttons
PLAT_LOG("Initialize buttons");
Button_init();

Button_Params_init(&buttonParams);
buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED;
buttonParams.longPressDuration = 1000U; // ms
sAppLeftHandle = Button_open(CONFIG_BTN_LEFT, &buttonParams);
Button_setCallback(sAppLeftHandle, ButtonLeftEventHandler);

Button_Params_init(&buttonParams);
buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED;
buttonParams.longPressDuration = 1000U; // ms
sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, &buttonParams);
Button_setCallback(sAppRightHandle, ButtonRightEventHandler);
uiInit();

// Init Chip memory management before the stack
Platform::MemoryInit();
Expand All @@ -218,11 +196,12 @@ int AppTask::Init()

#if CHIP_DEVICE_CONFIG_THREAD_FTD
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
#elif CONFIG_OPENTHREAD_MTD_SED
#elif CHIP_CONFIG_ENABLE_ICD_SERVER
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice);
#else
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
#endif

if (ret != CHIP_NO_ERROR)
{
PLAT_LOG("ConnectivityMgr().SetThreadDeviceType() failed");
Expand Down Expand Up @@ -312,46 +291,6 @@ void AppTask::PostEvent(const AppEvent * aEvent)
}
}

void AppTask::ButtonLeftEventHandler(Button_Handle handle, Button_EventMask events)
{
AppEvent event;
event.Type = AppEvent::kEventType_ButtonLeft;

if (events & Button_EV_CLICKED)
{
event.ButtonEvent.Type = AppEvent::kAppEventButtonType_Clicked;
}
else if (events & Button_EV_LONGCLICKED)
{
event.ButtonEvent.Type = AppEvent::kAppEventButtonType_LongClicked;
}
// button callbacks are in ISR context
if (xQueueSendFromISR(sAppEventQueue, &event, NULL) != pdPASS)
{
/* Failed to post the message */
}
}

void AppTask::ButtonRightEventHandler(Button_Handle handle, Button_EventMask events)
{
AppEvent event;
event.Type = AppEvent::kEventType_ButtonRight;

if (events & Button_EV_CLICKED)
{
event.ButtonEvent.Type = AppEvent::kAppEventButtonType_Clicked;
}
else if (events & Button_EV_LONGCLICKED)
{
event.ButtonEvent.Type = AppEvent::kAppEventButtonType_LongClicked;
}
// button callbacks are in ISR context
if (xQueueSendFromISR(sAppEventQueue, &event, NULL) != pdPASS)
{
/* Failed to post the message */
}
}

void AppTask::DispatchEvent(AppEvent * aEvent)
{
switch (aEvent->Type)
Expand Down Expand Up @@ -405,3 +344,85 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
break;
}
}

#if (BUTTON_ENABLE == 1)
void AppTask::ButtonLeftEventHandler(Button_Handle handle, Button_EventMask events)
{
AppEvent event;
event.Type = AppEvent::kEventType_ButtonLeft;

if (events & Button_EV_CLICKED)
{
event.ButtonEvent.Type = AppEvent::kAppEventButtonType_Clicked;
}
else if (events & Button_EV_LONGCLICKED)
{
event.ButtonEvent.Type = AppEvent::kAppEventButtonType_LongClicked;
}
// button callbacks are in ISR context
if (xQueueSendFromISR(sAppEventQueue, &event, NULL) != pdPASS)
{
/* Failed to post the message */
}
}

void AppTask::ButtonRightEventHandler(Button_Handle handle, Button_EventMask events)
{
AppEvent event;
event.Type = AppEvent::kEventType_ButtonRight;

if (events & Button_EV_CLICKED)
{
event.ButtonEvent.Type = AppEvent::kAppEventButtonType_Clicked;
}
else if (events & Button_EV_LONGCLICKED)
{
event.ButtonEvent.Type = AppEvent::kAppEventButtonType_LongClicked;
}
// button callbacks are in ISR context
if (xQueueSendFromISR(sAppEventQueue, &event, NULL) != pdPASS)
{
/* Failed to post the message */
}
}
#endif // BUTTON_ENABLE

void AppTask::uiInit(void)
{
#if (LED_ENABLE == 1)

LED_Params ledParams;

// Initialize LEDs
PLAT_LOG("Initialize LEDs");
LED_init();

LED_Params_init(&ledParams); // default PWM LED
sAppRedHandle = LED_open(CONFIG_LED_RED, &ledParams);
LED_setOff(sAppRedHandle);

LED_Params_init(&ledParams); // default PWM LED
sAppGreenHandle = LED_open(CONFIG_LED_GREEN, &ledParams);
LED_setOff(sAppGreenHandle);
#endif // LED ENABLE

#if (BUTTON_ENABLE == 1)
Button_Params buttonParams;

// Initialize buttons
PLAT_LOG("Initialize buttons");
Button_init();

Button_Params_init(&buttonParams);
buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED;
buttonParams.longPressDuration = 1000U; // ms
sAppLeftHandle = Button_open(CONFIG_BTN_LEFT, &buttonParams);
Button_setCallback(sAppLeftHandle, ButtonLeftEventHandler);

Button_Params_init(&buttonParams);
buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED;
buttonParams.longPressDuration = 1000U; // ms
sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, &buttonParams);
Button_setCallback(sAppRightHandle, ButtonRightEventHandler);
#endif // BUTTON ENABLE
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class AppTask
int Init();

void DispatchEvent(AppEvent * event);
void uiInit();

static void ButtonLeftEventHandler(Button_Handle handle, Button_EventMask events);
static void ButtonRightEventHandler(Button_Handle handle, Button_EventMask events);
Expand Down
8 changes: 0 additions & 8 deletions examples/all-clusters-app/cc13x4_26x4/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ uint32_t heapSize = TOTAL_ICALL_HEAP_SIZE;
// ================================================================================
// FreeRTOS Callbacks
// ================================================================================
extern "C" void vApplicationStackOverflowHook(void)
{
while (1)
{
;
}
}

/* Wrapper functions for using the queue registry regardless of whether it is enabled or disabled */
extern "C" void vQueueAddToRegistryWrapper(QueueHandle_t xQueue, const char * pcQueueName)
{
Expand Down
12 changes: 8 additions & 4 deletions examples/lighting-app/cc13x4_26x4/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ ti_sysconfig("sysconfig") {

cflags = [
"-Wno-comment",
"@" + rebase_path("${target_gen_dir}/sysconfig/ti_ble_app_config.opt",
root_build_dir),
"@" + rebase_path("${target_gen_dir}/sysconfig/ti_build_config.opt",
"@" + rebase_path("${target_gen_dir}/sysconfig/ti_utils_build_compiler.opt",
root_build_dir),
]
}
Expand Down Expand Up @@ -99,8 +97,14 @@ ti_simplelink_executable("lighting_app") {
deps += [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ]
}

defines = []

if (custom_factory_data) {
defines = [ "CC13XX_26XX_FACTORY_DATA" ]
defines += [ "CC13XX_26XX_FACTORY_DATA" ]
}

if (chip_enable_icd_server) {
defines += [ "TI_ICD_ENABLE_SERVER" ]
}

include_dirs = [
Expand Down
17 changes: 13 additions & 4 deletions examples/lighting-app/cc13x4_26x4/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import("//build_overrides/chip.gni")
import("//build_overrides/freertos.gni")
import("${chip_root}/config/standalone/args.gni")
import("${chip_root}/examples/platform/cc13x4_26x4/args.gni")

Expand All @@ -29,13 +30,13 @@ lwip_debug = false

chip_enable_ota_requestor = true

chip_openthread_ftd = true
chip_openthread_ftd = false
openthread_external_platform = "${chip_root}/third_party/openthread/platforms/cc13x4_26x4:libopenthread-cc13x4_cc26x4"

# Disable CHIP Logging
#chip_progress_logging = false
#chip_detail_logging = false
#chip_automation_logging = false
chip_progress_logging = true
chip_detail_logging = true
chip_automation_logging = true

# BLE options
chip_config_network_layer_ble = true
Expand All @@ -50,3 +51,11 @@ matter_software_ver = "0x0001"
matter_software_ver_str = "1.0.1+1"

custom_factory_data = true

# ICD Default configurations
# when enabled the device will be configured as a sleepy end device
chip_enable_icd_server = false
chip_persist_subscriptions = false
chip_subscription_timeout_resumption = false

freertos_root = "//third_party/connectedhomeip/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx/source/third_party/freertos"
Loading

0 comments on commit 978dfcb

Please sign in to comment.