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

[TI] ICD support for TI CC13x4 #32823

Merged
merged 12 commits into from
Apr 3, 2024
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.
11 changes: 8 additions & 3 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 @@ -121,6 +119,13 @@ ti_simplelink_executable("all-clusters-app") {
defines = [ "CC13XX_26XX_FACTORY_DATA" ]
}

if (chip_enable_icd_server) {
defines += [
"CHIP_DEVICE_CONFIG_ENABLE_SED",
abiradarti marked this conversation as resolved.
Show resolved Hide resolved
"TI_ICD_ENABLE_SERVER",
]
}

include_dirs = [
"${project_dir}",
"${project_dir}/main",
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"
2 changes: 0 additions & 2 deletions examples/all-clusters-app/cc13x4_26x4/chip.syscfg
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,12 @@ LED1.$name = "CONFIG_LED_RED";
LED1.$hardware = system.deviceData.board.components.LED_RED;
LED1.gpioPin.$name = "CONFIG_GPIO_RLED";
LED1.gpioPin.mode = "Output";
LED1.gpioPin.callbackFunction = "";

/* Green LED */
LED2.$name = "CONFIG_LED_GREEN";
LED2.$hardware = system.deviceData.board.components.LED_GREEN;
LED2.gpioPin.$name = "CONFIG_GPIO_GLED";
LED2.gpioPin.mode = "Output";
LED2.gpioPin.callbackFunction = "";

/* Debug UART */
UART2.$hardware = system.deviceData.board.components.XDS110UART;
Expand Down
162 changes: 91 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,7 +196,7 @@ int AppTask::Init()

#if CHIP_DEVICE_CONFIG_THREAD_FTD
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
#elif CONFIG_OPENTHREAD_MTD_SED
#elif CHIP_DEVICE_CONFIG_ENABLE_SED
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice);
#else
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
Expand Down Expand Up @@ -312,46 +290,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 +343,85 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
break;
}
}

#ifdef BUTTON_ENABLE
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)
{
#ifdef LED_ENABLE

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

#ifdef BUTTON_ENABLE
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
11 changes: 8 additions & 3 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 @@ -103,6 +101,13 @@ ti_simplelink_executable("lighting_app") {
defines = [ "CC13XX_26XX_FACTORY_DATA" ]
}

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

include_dirs = [
"${project_dir}",
"${chip_root}/examples/providers/",
Expand Down
Loading
Loading