Skip to content

Commit b24d57d

Browse files
committed
Update TI Applications with correct OTA startup handling
1 parent 50971be commit b24d57d

File tree

36 files changed

+773
-119
lines changed

36 files changed

+773
-119
lines changed

examples/all-clusters-app/cc13x4_26x4/BUILD.gn

+5
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,18 @@ ti_simplelink_executable("all-clusters-app") {
7878
"${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseDelegateImpl.cpp",
7979
"${chip_root}/examples/energy-management-app/energy-management-common/src/EnergyEvseManager.cpp",
8080
"${chip_root}/examples/providers/DeviceInfoProviderImpl.cpp",
81+
"${chip_root}/src/app/clusters/general-diagnostics-server/GenericFaultTestEventTriggerHandler.cpp",
8182
"${project_dir}/main/AppTask.cpp",
8283
"${project_dir}/main/ClusterManager.cpp",
8384
"${project_dir}/main/Globals.cpp",
8485
"${project_dir}/main/ZclCallbacks.cpp",
8586
"${project_dir}/main/main.cpp",
8687
]
8788

89+
public = [
90+
"${chip_root}/src/platform/cc13xx_26xx/DefaultTestEventTriggerDelegate.h",
91+
]
92+
8893
deps = [
8994
":sdk",
9095
":sysconfig",

examples/all-clusters-app/cc13x4_26x4/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,16 @@ guide assumes that the environment is linux based, and recommends Ubuntu 20.04.
6565
```
6666
6767
- Run the bootstrap script to setup the build environment.
68+
- Note, a recursive submodule checkout is required to utilize TI's Openthread
69+
reference commit.
70+
- Note, in order to build the chip-tool and ota-provider examples, a recursive
71+
submodule checkout is required for the linux platform as seen in the command
72+
below.
6873
6974
```
7075
$ cd ~/connectedhomeip
7176
$ source ./scripts/bootstrap.sh
77+
$ ./scripts/checkout_submodules.py --shallow --platform cc13xx_26xx linux --recursive
7278
7379
```
7480

examples/all-clusters-app/cc13x4_26x4/args.gni

+10-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ chip_enable_ota_requestor = true
3232

3333
openthread_external_platform =
3434
"${chip_root}/third_party/openthread/platforms/ti:libopenthread-ti"
35-
chip_openthread_target = ""
35+
36+
# When using TI Certified Openthread libs set to ${chip_root}/third_party/openthread/platforms/ti:ot-ti-cert
37+
# For source builds, set to empty string.
38+
chip_openthread_target =
39+
"${chip_root}/third_party/openthread/platforms/ti:ot-ti-cert"
3640

3741
chip_openthread_ftd = true
3842

@@ -61,3 +65,8 @@ chip_persist_subscriptions = false
6165
chip_subscription_timeout_resumption = false
6266

6367
freertos_root = "//third_party/connectedhomeip/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx/source/third_party/freertos"
68+
69+
if (chip_openthread_target != "") {
70+
openthread_root =
71+
"//third_party/connectedhomeip/third_party/openthread/ot-ti/openthread"
72+
}

examples/all-clusters-app/cc13x4_26x4/chip.syscfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ CCFG.enableCodeGeneration = false;
8989

9090
/* NVS */
9191
NVS1.$name = "CONFIG_NVSINTERNAL";
92-
NVS1.internalFlash.regionBase = 0xFB800;
93-
NVS1.internalFlash.regionSize = 0x2800;
92+
NVS1.internalFlash.regionBase = 0xF8800;
93+
NVS1.internalFlash.regionSize = 0x6000;
9494

9595

9696
NVS2.$name = "CONFIG_NVSEXTERNAL";

examples/all-clusters-app/cc13x4_26x4/main/AppTask.cpp

+104-9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
#endif
4646
#include <app/server/OnboardingCodesUtil.h>
4747

48+
#include <app/TestEventTriggerDelegate.h>
49+
#include <app/clusters/general-diagnostics-server/GenericFaultTestEventTriggerHandler.h>
50+
#include <src/platform/cc13xx_26xx/DefaultTestEventTriggerDelegate.h>
51+
4852
#include <ti/drivers/apps/Button.h>
4953
#include <ti/drivers/apps/LED.h>
5054

@@ -56,6 +60,8 @@
5660
#define APP_EVENT_QUEUE_SIZE 10
5761
#define BUTTON_ENABLE 1
5862

63+
#define OTAREQUESTOR_INIT_TIMER_DELAY_MS 10000
64+
5965
using namespace ::chip;
6066
using namespace ::chip::Credentials;
6167
using namespace ::chip::DeviceLayer;
@@ -70,6 +76,12 @@ AppTask AppTask::sAppTask;
7076

7177
constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;
7278

79+
void StartTimer(uint32_t aTimeoutMs);
80+
void CancelTimer(void);
81+
82+
uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
83+
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
84+
7385
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
7486
static DefaultOTARequestor sRequestorCore;
7587
static DefaultOTARequestorStorage sRequestorStorage;
@@ -90,6 +102,15 @@ void InitializeOTARequestor(void)
90102
}
91103
#endif
92104

105+
TimerHandle_t sOTAInitTimer = 0;
106+
107+
// The OTA Init Timer is only started upon the first Thread State Change
108+
// detected if the device is already on a Thread Network, or during the AppTask
109+
// Init sequence if the device is not yet on a Thread Network. Once the timer
110+
// has been started once, it does not need to be started again so the flag will
111+
// be set to false.
112+
bool isAppStarting = true;
113+
93114
#ifdef AUTO_PRINT_METRICS
94115
static void printMetrics(void)
95116
{
@@ -132,13 +153,31 @@ void DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg)
132153
case DeviceEventType::kCommissioningComplete:
133154
PLAT_LOG("Commissioning complete");
134155
break;
156+
case DeviceEventType::kThreadStateChange:
157+
PLAT_LOG("Thread State Change");
158+
bool isThreadAttached = ThreadStackMgrImpl().IsThreadAttached();
159+
160+
if(isThreadAttached){
161+
PLAT_LOG("Device is on the Thread Network");
162+
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
163+
if(isAppStarting){
164+
StartTimer(OTAREQUESTOR_INIT_TIMER_DELAY_MS);
165+
isAppStarting = false;
166+
}
167+
#endif
168+
}
169+
break;
135170
}
136171

137172
#ifdef AUTO_PRINT_METRICS
138173
printMetrics();
139174
#endif
140175
}
141176

177+
void OTAInitTimerEventHandler(TimerHandle_t xTimer){
178+
InitializeOTARequestor();
179+
}
180+
142181
int AppTask::StartAppTask()
143182
{
144183
int ret = 0;
@@ -171,6 +210,9 @@ int AppTask::Init()
171210
// Init Chip memory management before the stack
172211
Platform::MemoryInit();
173212

213+
PLAT_LOG("Software Version: %d", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION);
214+
PLAT_LOG("Software Version String: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);
215+
174216
CHIP_ERROR ret = PlatformMgr().InitChipStack();
175217
if (ret != CHIP_NO_ERROR)
176218
{
@@ -179,6 +221,23 @@ int AppTask::Init()
179221
;
180222
}
181223

224+
// Create FreeRTOS sw timer for OTA timer.
225+
sOTAInitTimer = xTimerCreate("OTAInitTmr", // Just a text name, not used by the RTOS kernel
226+
OTAREQUESTOR_INIT_TIMER_DELAY_MS, // timer period (mS)
227+
false, // no timer reload (==one-shot)
228+
(void *) this, // init timer id = light obj context
229+
OTAInitTimerEventHandler // timer callback handler
230+
);
231+
232+
if (sOTAInitTimer == NULL)
233+
{
234+
PLAT_LOG("sOTAInitTimer timer create failed");
235+
}
236+
else
237+
{
238+
PLAT_LOG("sOTAInitTimer timer created successfully ");
239+
}
240+
182241
ret = ThreadStackMgr().InitThreadStack();
183242
if (ret != CHIP_NO_ERROR)
184243
{
@@ -202,14 +261,6 @@ int AppTask::Init()
202261
;
203262
}
204263

205-
ret = PlatformMgr().StartEventLoopTask();
206-
if (ret != CHIP_NO_ERROR)
207-
{
208-
PLAT_LOG("PlatformMgr().StartEventLoopTask() failed");
209-
while (1)
210-
;
211-
}
212-
213264
ret = ThreadStackMgrImpl().StartThreadTask();
214265
if (ret != CHIP_NO_ERROR)
215266
{
@@ -234,6 +285,9 @@ int AppTask::Init()
234285
// Init ZCL Data Model and start server
235286
PLAT_LOG("Initialize Server");
236287
static chip::CommonCaseDeviceServerInitParams initParams;
288+
static DefaultTestEventTriggerDelegate sTestEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) };
289+
initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;
290+
237291
(void) initParams.InitializeStaticResourcesBeforeServerInit();
238292

239293
// Initialize info provider
@@ -242,18 +296,32 @@ int AppTask::Init()
242296

243297
chip::Server::GetInstance().Init(initParams);
244298

299+
ret = PlatformMgr().StartEventLoopTask();
300+
if (ret != CHIP_NO_ERROR)
301+
{
302+
PLAT_LOG("PlatformMgr().StartEventLoopTask() failed");
303+
while (1)
304+
;
305+
}
306+
245307
ConfigurationMgr().LogDeviceConfig();
246308

247309
// We only have network commissioning on endpoint 0.
248310
emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false);
249311

312+
250313
// Register a function to receive events from the CHIP device layer. Note that calls to
251314
// this function will happen on the CHIP event loop thread, not the app_main thread.
252315
PlatformMgr().AddEventHandler(DeviceEventCallback, reinterpret_cast<intptr_t>(nullptr));
253316

317+
bool isThreadEnabled = ThreadStackMgrImpl().IsThreadEnabled();
318+
if(!isThreadEnabled && isAppStarting){
254319
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
255-
InitializeOTARequestor();
320+
PLAT_LOG("Thread is Disabled, enable OTA Requestor");
321+
StartTimer(OTAREQUESTOR_INIT_TIMER_DELAY_MS);
322+
isAppStarting = false;
256323
#endif
324+
}
257325
// QR code will be used with CHIP Tool
258326
PrintOnboardingCodes(RendezvousInformationFlags(RendezvousInformationFlag::kBLE));
259327

@@ -276,6 +344,33 @@ void AppTask::AppTaskMain(void * pvParameter)
276344
}
277345
}
278346

347+
void StartTimer(uint32_t aTimeoutMs)
348+
{
349+
PLAT_LOG("Start OTA Init Timer")
350+
if (xTimerIsTimerActive(sOTAInitTimer))
351+
{
352+
PLAT_LOG("app timer already started!");
353+
CancelTimer();
354+
}
355+
356+
// timer is not active, change its period to required value (== restart).
357+
// FreeRTOS- Block for a maximum of 100 ticks if the change period command
358+
// cannot immediately be sent to the timer command queue.
359+
if (xTimerChangePeriod(sOTAInitTimer, pdMS_TO_TICKS(aTimeoutMs), 100) != pdPASS)
360+
{
361+
PLAT_LOG("sOTAInitTimer timer start() failed");
362+
}
363+
}
364+
365+
void CancelTimer(void)
366+
{
367+
if (xTimerStop(sOTAInitTimer, 0) == pdFAIL)
368+
{
369+
PLAT_LOG("sOTAInitTimer stop() failed");
370+
}
371+
}
372+
373+
279374
void AppTask::PostEvent(const AppEvent * aEvent)
280375
{
281376
if (xQueueSend(sAppEventQueue, aEvent, 0) != pdPASS)

examples/lighting-app/cc13x4_26x4/BUILD.gn

+5
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,17 @@ ti_simplelink_executable("lighting_app") {
6565

6666
sources = [
6767
"${chip_root}/examples/providers/DeviceInfoProviderImpl.cpp",
68+
"${chip_root}/src/app/clusters/general-diagnostics-server/GenericFaultTestEventTriggerHandler.cpp",
6869
"${project_dir}/src/AppTask.cpp",
6970
"${project_dir}/src/LightingManager.cpp",
7071
"${project_dir}/src/ZclCallbacks.cpp",
7172
"${project_dir}/src/main.cpp",
7273
]
7374

75+
public = [
76+
"${chip_root}/src/platform/cc13xx_26xx/DefaultTestEventTriggerDelegate.h",
77+
]
78+
7479
deps = [
7580
":sdk",
7681
":sysconfig",

examples/lighting-app/cc13x4_26x4/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,16 @@ guide assumes that the environment is linux based, and recommends Ubuntu 20.04.
6464
```
6565
6666
- Run the bootstrap script to setup the build environment.
67+
- Note, a recursive submodule checkout is required to utilize TI's Openthread
68+
reference commit.
69+
- Note, in order to build the chip-tool and ota-provider examples, a recursive
70+
submodule checkout is required for the linux platform as seen in the command
71+
below.
6772
6873
```
6974
$ cd ~/connectedhomeip
7075
$ source ./scripts/bootstrap.sh
76+
$ ./scripts/checkout_submodules.py --shallow --platform cc13xx_26xx linux --recursive
7177
7278
```
7379
@@ -101,7 +107,6 @@ Ninja to build the executable.
101107
If you would like to define arguments on the command line you may add them
102108
to the GN call.
103109
104-
105110
```
106111
gn gen out/debug --args="ti_sysconfig_root=\"$HOME/ti/sysconfig_1.18.1\" target_defines=[\"CC13X4_26X4_ATTESTATION_CREDENTIALS=1\"]"
107112
```

examples/lighting-app/cc13x4_26x4/args.gni

+11-3
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ lwip_debug = false
3030

3131
chip_enable_ota_requestor = true
3232

33-
chip_openthread_ftd = true
33+
chip_openthread_ftd = false
3434

3535
ot_ti_lib_dir = ""
3636
openthread_external_platform =
3737
"${chip_root}/third_party/openthread/platforms/ti:libopenthread-ti"
3838

39-
chip_openthread_target = ""
39+
# When using TI Certified Openthread libs set to ${chip_root}/third_party/openthread/platforms/ti:ot-ti-cert
40+
# For source builds, set to empty string.
41+
chip_openthread_target =
42+
"${chip_root}/third_party/openthread/platforms/ti:ot-ti-cert"
4043

4144
# Disable CHIP Logging
4245
chip_progress_logging = true
@@ -55,7 +58,7 @@ matter_device_pid = "0x8005"
5558
matter_software_ver = "0x0001"
5659
matter_software_ver_str = "1.0.1+1"
5760

58-
custom_factory_data = true
61+
custom_factory_data = false
5962

6063
# ICD Default configurations
6164
# when enabled the device will be configured as a sleepy end device
@@ -64,3 +67,8 @@ chip_persist_subscriptions = false
6467
chip_subscription_timeout_resumption = false
6568

6669
freertos_root = "//third_party/connectedhomeip/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx/source/third_party/freertos"
70+
71+
if (chip_openthread_target != "") {
72+
openthread_root =
73+
"//third_party/connectedhomeip/third_party/openthread/ot-ti/openthread"
74+
}

examples/lighting-app/cc13x4_26x4/chip.syscfg

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
2019
/* Modules */
2120
var AESCCM = scripting.addModule("/ti/drivers/AESCCM");
2221
var AESECB = scripting.addModule("/ti/drivers/AESECB");
@@ -89,8 +88,8 @@ CCFG.enableCodeGeneration = false;
8988

9089
/* NVS */
9190
NVS1.$name = "CONFIG_NVSINTERNAL";
92-
NVS1.internalFlash.regionBase = 0xFB800;
93-
NVS1.internalFlash.regionSize = 0x2800;
91+
NVS1.internalFlash.regionBase = 0xF8800;
92+
NVS1.internalFlash.regionSize = 0x6000;
9493

9594

9695
NVS2.$name = "CONFIG_NVSEXTERNAL";

examples/lighting-app/cc13x4_26x4/src/AppEvent.h

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct AppEvent
3434
kEventType_IdentifyStop,
3535
kEventType_Light,
3636
kEventType_Timer,
37+
kEventType_Identify,
3738
};
3839

3940
enum AppEventButtonType

0 commit comments

Comments
 (0)