Skip to content

Commit 3db0d30

Browse files
authored
Enable LIT for NXP K32W0/K32W1 platforms (project-chip#32258) (project-chip#32290)
* [nxp][k32w0][k32w1][comtact-sensor] update zap file Boolean state cluster * enable missing mandatory attributes (EventList) General commissioning cluster * enable missing mandatory attributes (GeneratedCommandList, AcceptedCommandList, EventList, AttributeList, FeatureMap) Basic Information Cluster * enable missing mandatory attributes (GeneratedCommandList, AcceptedCommandList, EventList, AttributeList) General Diagnostics Cluster * enable mandatory attributes introduced in Matter 1.3 (UpTime, TimeSnapshot, TimeSnapshotResponse) * enable missing mandatory attributes (GeneratedCommandList, AcceptedCommandList, EventList, AttributeList) Network Commissioning Cluster * enable optional attributes introduced in Matter 1.3 (SupportedThreadFeatures, ThreadVersion) * update cluster revision * enable missing mandatory attributes (GeneratedCommandList, AcceptedCommandList, EventList, AttributeList) Thread Network Diagnostics: * update cluster revision Access Control * enable missing mandatory attributes (GeneratedCommandList, AcceptedCommandList, EventList, AttributeList) * [nxp][k32w0][k32w1][contact-sensor] Refactor files for LIT enablement * examples/contact-sensor-app/nxp/zap was renamed to examples/contact-sensor-app/nxp/zap-sit * created a new set of zap files for lit: examples/contact-sensor-app/nxp/zap-lit * moved icd common defines to nxp_sdk.gni * fixed naming around icd parameters * added lit application code (see READMEs for detailed instructions) * [nxp][k32w1] update software version allow configuration of CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING/ CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION through gn arguments. * [nxp][k32w0][k32w1] fix restyle and readme --------- Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>
1 parent fe5d6a4 commit 3db0d30

File tree

25 files changed

+6636
-63
lines changed

25 files changed

+6636
-63
lines changed

examples/contact-sensor-app/nxp/k32w/k32w0/BUILD.gn

+13-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import("//build_overrides/openthread.gni")
1919
import("${k32w0_sdk_build_root}/k32w0_executable.gni")
2020
import("${k32w0_sdk_build_root}/k32w0_sdk.gni")
2121

22+
import("${chip_root}/src/app/icd/icd.gni")
2223
import("${chip_root}/src/crypto/crypto.gni")
2324
import("${chip_root}/src/lib/core/core.gni")
2425
import("${chip_root}/src/platform/device.gni")
@@ -75,6 +76,8 @@ k32w0_sdk("sdk") {
7576
k32w0_executable("contact_sensor_app") {
7677
output_name = "chip-k32w0x-contact-example"
7778

79+
defines = []
80+
7881
sources = [
7982
"${k32w0_platform_dir}/util/LEDWidget.cpp",
8083
"${k32w0_platform_dir}/util/include/LEDWidget.h",
@@ -93,13 +96,12 @@ k32w0_executable("contact_sensor_app") {
9396
"${k32w0_platform_dir}/common/CustomFactoryDataProvider.h",
9497
]
9598

96-
defines = [ "CHIP_DEVICE_CONFIG_USE_CUSTOM_PROVIDER=1" ]
99+
defines += [ "CHIP_DEVICE_CONFIG_USE_CUSTOM_PROVIDER=1" ]
97100
}
98101

99102
deps = [
100103
":sdk",
101104
"${chip_root}/examples/common/QRCode",
102-
"${chip_root}/examples/contact-sensor-app/contact-sensor-common",
103105
"${chip_root}/examples/providers:device_info_provider",
104106
"${chip_root}/src/lib",
105107
"${chip_root}/src/platform:syscalls_stub",
@@ -119,6 +121,15 @@ k32w0_executable("contact_sensor_app") {
119121
]
120122
}
121123

124+
#lit and sit are using different zap files
125+
if (chip_enable_icd_lit) {
126+
deps += [ "${chip_root}/examples/contact-sensor-app/nxp/zap-lit/" ]
127+
128+
defines += [ "CHIP_ENABLE_LIT=1" ]
129+
} else {
130+
deps += [ "${chip_root}/examples/contact-sensor-app/nxp/zap-sit/" ]
131+
}
132+
122133
cflags = [ "-Wconversion" ]
123134

124135
output_dir = root_out_dir

examples/contact-sensor-app/nxp/k32w/k32w0/README.md

+42
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ network.
2222
- [Building](#building)
2323
- [Overwrite board config files](#overwrite-board-config-files)
2424
- [Known issues building](#known-issues-building)
25+
- [Long Idle Time ICD Support](#long-idle-time-icd-support)
2526
- [Manufacturing data](#manufacturing-data)
2627
- [Flashing and debugging](#flashing-and-debugging)
2728
- [Pigweed Tokenizer](#pigweed-tokenizer)
@@ -95,6 +96,11 @@ be discoverable over Bluetooth LE. For security reasons, you must start
9596
Bluetooth LE advertising manually after powering up the device by pressing
9697
Button USERINTERFACE.
9798

99+
## LIT ICD Active Mode
100+
101+
If the device is acting as a LIT ICD and it's already commissioned, then Button
102+
USERINTERFACE can be pressed for forcing the switch to Active Mode.
103+
98104
### Bluetooth LE Rendezvous
99105

100106
In this example, the commissioning procedure (called rendezvous) is done over
@@ -258,6 +264,42 @@ pycryptodome 3.9.8
258264
259265
The resulting output file can be found in out/debug/chip-k32w0x-contact-example.
260266
267+
## Long Idle Time ICD Support
268+
269+
By default, contact-sensor is compiled as SIT ICD (Short Idle Time
270+
Intermittently Connected Device) - see rules from k32w0_sdk.gni:
271+
272+
```
273+
chip_ot_idle_interval_ms = 2000 # 2s Idle Intervals
274+
chip_ot_active_interval_ms = 500 # 500ms Active Intervals
275+
276+
nxp_idle_mode_duration_s = 600 # 10min Idle Mode Interval
277+
nxp_active_mode_duration_ms = 10000 # 10s Active Mode Interval
278+
nxp_active_mode_threshold_ms = 1000 # 1s Active Mode Threshold
279+
nxp_icd_supported_clients_per_fabric = 2 # 2 registration slots per fabric
280+
```
281+
282+
If LIT ICD support is needed then `chip_enable_icd_lit=true` must be specified
283+
as gn argument and the above parameters can be modified to comply with LIT
284+
requirements (e.g.: LIT devices must configure
285+
`chip_ot_idle_interval_ms > 15000`). Example LIT configuration:
286+
287+
```
288+
chip_ot_idle_interval_ms = 15000 # 15s Idle Intervals
289+
chip_ot_active_interval_ms = 500 # 500ms Active Intervals
290+
291+
nxp_idle_mode_duration_s = 3600 # 60min Idle Mode Interval
292+
nxp_active_mode_duration_ms = 0 # 0 Active Mode Interval
293+
nxp_active_mode_threshold_ms = 30000 # 30s Active Mode Threshold
294+
```
295+
296+
ICD parameters that may be disabled once LIT functionality is enabled:
297+
298+
```
299+
chip_persist_subscriptions: try to re-establish subscriptions from the server side after reboot
300+
chip_subscription_timeout_resumption: same as above but retries are using a Fibonacci backoff
301+
```
302+
261303
### Overwrite board config files
262304
263305
The example uses template/reference board configuration files.

examples/contact-sensor-app/nxp/k32w/k32w0/args.gni

+2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ chip_stack_lock_tracking = "fatal"
2424
chip_enable_ble = true
2525

2626
chip_enable_icd_server = true
27+
chip_enable_icd_lit = false
28+
icd_enforce_sit_slow_poll_limit = true
2729
chip_persist_subscriptions = true
2830
chip_subscription_timeout_resumption = true

examples/contact-sensor-app/nxp/k32w/k32w0/main/AppTask.cpp

+56-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ static LEDWidget sContactSensorLED;
7171

7272
static bool sIsThreadProvisioned = false;
7373
static bool sHaveBLEConnections = false;
74+
#if CHIP_ENABLE_LIT
75+
static bool sIsDeviceCommissioned = false;
76+
#endif
7477

7578
static uint32_t eventMask = 0;
7679

@@ -448,6 +451,12 @@ void AppTask::ButtonEventHandler(uint8_t pin_no, uint8_t button_action)
448451
{
449452
button_event.Handler = ResetActionEventHandler;
450453
}
454+
#endif
455+
#if CHIP_ENABLE_LIT
456+
if (button_action == USER_ACTIVE_MODE_TRIGGER_PUSH)
457+
{
458+
button_event.Handler = UserActiveModeHandler;
459+
}
451460
#endif
452461
}
453462

@@ -486,6 +495,16 @@ void AppTask::HandleKeyboard(void)
486495
#if (defined OM15082)
487496
ButtonEventHandler(RESET_BUTTON, RESET_BUTTON_PUSH);
488497
break;
498+
#elif CHIP_ENABLE_LIT
499+
if (sIsDeviceCommissioned)
500+
{
501+
ButtonEventHandler(BLE_BUTTON, USER_ACTIVE_MODE_TRIGGER_PUSH);
502+
}
503+
else
504+
{
505+
ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH);
506+
}
507+
break;
489508
#else
490509
ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH);
491510
break;
@@ -497,7 +516,15 @@ void AppTask::HandleKeyboard(void)
497516
ButtonEventHandler(OTA_BUTTON, OTA_BUTTON_PUSH);
498517
break;
499518
case gKBD_EventPB4_c:
500-
ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH);
519+
#if CHIP_ENABLE_LIT
520+
if (sIsDeviceCommissioned)
521+
{
522+
ButtonEventHandler(BLE_BUTTON, USER_ACTIVE_MODE_TRIGGER_PUSH);
523+
}
524+
else
525+
#endif
526+
527+
ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH);
501528
break;
502529
#if !(defined OM15082)
503530
case gKBD_EventLongPB1_c:
@@ -694,6 +721,28 @@ void AppTask::BleStartAdvertising(intptr_t arg)
694721
}
695722
}
696723

724+
#if CHIP_ENABLE_LIT
725+
void AppTask::UserActiveModeHandler(void * aGenericEvent)
726+
{
727+
AppEvent * aEvent = (AppEvent *) aGenericEvent;
728+
729+
if (aEvent->ButtonEvent.PinNo != BLE_BUTTON)
730+
return;
731+
732+
if (sAppTask.mFunction != Function::kNoneSelected)
733+
{
734+
K32W_LOG("Another function is scheduled. Could not request ICD Active Mode!");
735+
return;
736+
}
737+
PlatformMgr().ScheduleWork(AppTask::UserActiveModeTrigger, 0);
738+
}
739+
740+
void AppTask::UserActiveModeTrigger(intptr_t arg)
741+
{
742+
ICDNotifier::GetInstance().NotifyNetworkActivityNotification();
743+
}
744+
#endif
745+
697746
void AppTask::MatterEventHandler(const ChipDeviceEvent * event, intptr_t)
698747
{
699748
if (event->Type == DeviceEventType::kServiceProvisioningChange && event->ServiceProvisioningChange.IsServiceProvisioned)
@@ -707,6 +756,12 @@ void AppTask::MatterEventHandler(const ChipDeviceEvent * event, intptr_t)
707756
sIsThreadProvisioned = FALSE;
708757
}
709758
}
759+
#if CHIP_ENABLE_LIT
760+
else if (event->Type == DeviceEventType::kCommissioningComplete)
761+
{
762+
sIsDeviceCommissioned = TRUE;
763+
}
764+
#endif
710765

711766
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
712767
if (event->Type == DeviceEventType::kDnssdInitialized)

examples/contact-sensor-app/nxp/k32w/k32w0/main/include/AppTask.h

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class AppTask
8585
static void ContactActionEventHandler(void * aGenericEvent);
8686
static void ResetActionEventHandler(void * aGenericEvent);
8787
static void InstallEventHandler(void * aGenericEvent);
88+
#if CHIP_ENABLE_LIT
89+
static void UserActiveModeHandler(void * aGenericEvent);
90+
static void UserActiveModeTrigger(intptr_t arg);
91+
#endif
8892

8993
static void ButtonEventHandler(uint8_t pin_no, uint8_t button_action);
9094
static void TimerEventHandler(TimerHandle_t xTimer);

examples/contact-sensor-app/nxp/k32w/k32w0/main/include/app_config.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define CONTACT_SENSOR_BUTTON_PUSH 2
3232
#define OTA_BUTTON_PUSH 3
3333
#define BLE_BUTTON_PUSH 4
34+
#define USER_ACTIVE_MODE_TRIGGER_PUSH 5
3435

3536
#define APP_BUTTON_PUSH 1
3637

examples/contact-sensor-app/nxp/k32w/k32w1/BUILD.gn

+12-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import("${nxp_sdk_build_root}/${nxp_sdk_name}/nxp_executable.gni")
2323

2424
import("${nxp_sdk_build_root}/${nxp_sdk_name}/${nxp_sdk_name}.gni")
2525

26+
import("${chip_root}/src/app/icd/icd.gni")
2627
import("${chip_root}/src/crypto/crypto.gni")
2728
import("${chip_root}/src/lib/core/core.gni")
2829
import("${chip_root}/src/platform/device.gni")
@@ -74,6 +75,8 @@ k32w1_sdk("sdk") {
7475
k32w1_executable("contact_sensor_app") {
7576
output_name = "chip-k32w1-contact-example"
7677

78+
defines = []
79+
7780
sources = [
7881
"${k32w1_platform_dir}/util/LEDWidget.cpp",
7982
"${k32w1_platform_dir}/util/include/LEDWidget.h",
@@ -89,7 +92,6 @@ k32w1_executable("contact_sensor_app") {
8992
deps = [
9093
":sdk",
9194
"${chip_root}/examples/common/QRCode",
92-
"${chip_root}/examples/contact-sensor-app/nxp/zap",
9395
"${chip_root}/examples/providers:device_info_provider",
9496
"${chip_root}/src/lib",
9597
"${chip_root}/src/platform:syscalls_stub",
@@ -109,6 +111,15 @@ k32w1_executable("contact_sensor_app") {
109111
]
110112
}
111113

114+
#lit and sit are using different zap files
115+
if (chip_enable_icd_lit) {
116+
deps += [ "${chip_root}/examples/contact-sensor-app/nxp/zap-lit/" ]
117+
118+
defines += [ "CHIP_ENABLE_LIT=1" ]
119+
} else {
120+
deps += [ "${chip_root}/examples/contact-sensor-app/nxp/zap-sit/" ]
121+
}
122+
112123
cflags = [ "-Wconversion" ]
113124

114125
output_dir = root_out_dir

examples/contact-sensor-app/nxp/k32w/k32w1/README.md

+47-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ into an existing Matter network and can be controlled by this network.
1919
- [Bluetooth LE Rendezvous](#bluetooth-le-rendezvous)
2020
- [Device UI](#device-ui)
2121
- [Building](#building)
22+
- [Long Idle Time ICD Support](#long-idle-time-icd-support)
2223
- [Manufacturing data](#manufacturing-data)
2324
- [Flashing](#flashing)
2425
- [Flashing the NBU image](#flashing-the-nbu-image)
@@ -100,13 +101,15 @@ will not work.
100101
**RGB LED** shows the state of the simulated contact sensor. when the LED is
101102
lit, the sensor is contacted, when not lit, the sensor is non-contacted.
102103

103-
**Button SW2** can be used to start BLE advertising. A SHORT press of the button
104-
will enable Bluetooth LE advertising for a predefined period of time. A LONG
105-
Press Button SW2 initiates a factory reset. After an initial period of 3
106-
seconds, LED 2 and RGB LED will flash in unison to signal the pending reset.
107-
After 6 seconds will cause the device to reset its persistent configuration and
108-
initiate a reboot. The reset action can be cancelled by press SW2 button at any
109-
point before the 6 second limit.
104+
**Button SW2**. SHORT press function is overloaded depending on the device type
105+
and commissioning state. If the device is not commissioned, a SHORT press of the
106+
button will enable Bluetooth LE advertising for a predefined period of time. If
107+
the device is commissioned and is acting as a LIT ICD then a SHORT press of the
108+
button will enable Active Mode. A LONG Press of Button SW2 initiates a factory
109+
reset. After an initial period of 3 seconds, LED 2 and RGB LED will flash in
110+
unison to signal the pending reset. After 6 seconds will cause the device to
111+
reset its persistent configuration and initiate a reboot. The reset action can
112+
be cancelled by press SW2 button at any point before the 6 second limit.
110113

111114
**Button SW3** can be used to change the state of the simulated contact sensor.
112115
The button behaves as a toggle, swapping the state every time it is short
@@ -141,6 +144,43 @@ After a successful build, the `elf` and `srec` files are found in `out/debug/` -
141144
build, the `elf` and `srec` files are found in `out/debug/` -
142145
`see the files prefixed with chip-k32w1-contact-example`.
143146

147+
## Long Idle Time ICD Support
148+
149+
By default, contact-sensor is compiled as SIT ICD (Short Idle Time
150+
Intermittently Connected Device) - see rules from k32w1_sdk.gni:
151+
152+
```
153+
chip_ot_idle_interval_ms = 2000 # 2s Idle Intervals
154+
chip_ot_active_interval_ms = 500 # 500ms Active Intervals
155+
156+
nxp_idle_mode_duration_s = 600 # 10min Idle Mode Interval
157+
nxp_active_mode_duration_ms = 10000 # 10s Active Mode Interval
158+
nxp_active_mode_threshold_ms = 1000 # 1s Active Mode Threshold
159+
nxp_icd_supported_clients_per_fabric = 2 # 2 registration slots per fabric
160+
```
161+
162+
If LIT ICD support is needed then `chip_enable_icd_lit=true` must be specified
163+
as gn argument and the above parameters can be modified to comply with LIT
164+
requirements (e.g.: LIT devices must configure
165+
`chip_ot_idle_interval_ms > 15000`). Example LIT configuration:
166+
167+
```
168+
chip_ot_idle_interval_ms = 15000 # 15s Idle Intervals
169+
chip_ot_active_interval_ms = 500 # 500ms Active Intervals
170+
171+
nxp_idle_mode_duration_s = 3600 # 60min Idle Mode Interval
172+
nxp_active_mode_duration_ms = 0 # 0 Active Mode Interval
173+
nxp_active_mode_threshold_ms = 30000 # 30s Active Mode Threshold
174+
```
175+
176+
ICD parameters that may be disabled once LIT functionality is enabled:
177+
178+
```
179+
chip_persist_subscriptions: try once to re-establish subscriptions from the server side after reboot
180+
chip_subscription_timeout_resumption: same as above + try to re-establish timeout out subscriptions
181+
using Fibonacci backoff for retries pacing.
182+
```
183+
144184
## Manufacturing data
145185

146186
Use `chip_with_factory_data=1` in the gn build command to enable factory data.

examples/contact-sensor-app/nxp/k32w/k32w1/args.gni

+2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ chip_stack_lock_tracking = "fatal"
2424
chip_enable_ble = true
2525

2626
chip_enable_icd_server = true
27+
chip_enable_icd_lit = false
28+
icd_enforce_sit_slow_poll_limit = true
2729
chip_persist_subscriptions = true
2830
chip_subscription_timeout_resumption = true

examples/contact-sensor-app/nxp/k32w/k32w1/include/CHIPProjectConfig.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@
132132
* {MAJOR_VERSION}.0d{MINOR_VERSION}
133133
*/
134134
#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING
135-
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING "03-2022-te8"
135+
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING NXP_CONFIG_DEVICE_SOFTWARE_VERSION_STRING
136136
#endif
137137

138138
#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION
139-
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION 42020
139+
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION NXP_CONFIG_DEVICE_SOFTWARE_VERSION
140140
#endif
141141

142142
#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME

0 commit comments

Comments
 (0)