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

Enable LIT for NXP K32W0/K32W1 platforms #32258

Merged
merged 4 commits into from
Feb 22, 2024
Merged
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
15 changes: 13 additions & 2 deletions examples/contact-sensor-app/nxp/k32w/k32w0/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import("//build_overrides/openthread.gni")
import("${k32w0_sdk_build_root}/k32w0_executable.gni")
import("${k32w0_sdk_build_root}/k32w0_sdk.gni")

import("${chip_root}/src/app/icd/icd.gni")
import("${chip_root}/src/crypto/crypto.gni")
import("${chip_root}/src/lib/core/core.gni")
import("${chip_root}/src/platform/device.gni")
Expand Down Expand Up @@ -75,6 +76,8 @@ k32w0_sdk("sdk") {
k32w0_executable("contact_sensor_app") {
output_name = "chip-k32w0x-contact-example"

defines = []

sources = [
"${k32w0_platform_dir}/util/LEDWidget.cpp",
"${k32w0_platform_dir}/util/include/LEDWidget.h",
Expand All @@ -93,13 +96,12 @@ k32w0_executable("contact_sensor_app") {
"${k32w0_platform_dir}/common/CustomFactoryDataProvider.h",
]

defines = [ "CHIP_DEVICE_CONFIG_USE_CUSTOM_PROVIDER=1" ]
defines += [ "CHIP_DEVICE_CONFIG_USE_CUSTOM_PROVIDER=1" ]
}

deps = [
":sdk",
"${chip_root}/examples/common/QRCode",
"${chip_root}/examples/contact-sensor-app/contact-sensor-common",
"${chip_root}/examples/providers:device_info_provider",
"${chip_root}/src/lib",
"${chip_root}/src/platform:syscalls_stub",
Expand All @@ -119,6 +121,15 @@ k32w0_executable("contact_sensor_app") {
]
}

#lit and sit are using different zap files
if (chip_enable_icd_lit) {
deps += [ "${chip_root}/examples/contact-sensor-app/nxp/zap-lit/" ]

defines += [ "CHIP_ENABLE_LIT=1" ]
} else {
deps += [ "${chip_root}/examples/contact-sensor-app/nxp/zap-sit/" ]
}

cflags = [ "-Wconversion" ]

output_dir = root_out_dir
Expand Down
42 changes: 42 additions & 0 deletions examples/contact-sensor-app/nxp/k32w/k32w0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ network.
- [Building](#building)
- [Overwrite board config files](#overwrite-board-config-files)
- [Known issues building](#known-issues-building)
- [Long Idle Time ICD Support](#long-idle-time-icd-support)
- [Manufacturing data](#manufacturing-data)
- [Flashing and debugging](#flashing-and-debugging)
- [Pigweed Tokenizer](#pigweed-tokenizer)
Expand Down Expand Up @@ -95,6 +96,11 @@ be discoverable over Bluetooth LE. For security reasons, you must start
Bluetooth LE advertising manually after powering up the device by pressing
Button USERINTERFACE.

## LIT ICD Active Mode

If the device is acting as a LIT ICD and it's already commissioned, then Button
USERINTERFACE can be pressed for forcing the switch to Active Mode.

### Bluetooth LE Rendezvous

In this example, the commissioning procedure (called rendezvous) is done over
Expand Down Expand Up @@ -258,6 +264,42 @@ pycryptodome 3.9.8

The resulting output file can be found in out/debug/chip-k32w0x-contact-example.

## Long Idle Time ICD Support

By default, contact-sensor is compiled as SIT ICD (Short Idle Time
Intermittently Connected Device) - see rules from k32w0_sdk.gni:

```
chip_ot_idle_interval_ms = 2000 # 2s Idle Intervals
chip_ot_active_interval_ms = 500 # 500ms Active Intervals

nxp_idle_mode_duration_s = 600 # 10min Idle Mode Interval
nxp_active_mode_duration_ms = 10000 # 10s Active Mode Interval
nxp_active_mode_threshold_ms = 1000 # 1s Active Mode Threshold
nxp_icd_supported_clients_per_fabric = 2 # 2 registration slots per fabric
```

If LIT ICD support is needed then `chip_enable_icd_lit=true` must be specified
as gn argument and the above parameters can be modified to comply with LIT
requirements (e.g.: LIT devices must configure
`chip_ot_idle_interval_ms > 15000`). Example LIT configuration:

```
chip_ot_idle_interval_ms = 15000 # 15s Idle Intervals
chip_ot_active_interval_ms = 500 # 500ms Active Intervals

nxp_idle_mode_duration_s = 3600 # 60min Idle Mode Interval
nxp_active_mode_duration_ms = 0 # 0 Active Mode Interval
nxp_active_mode_threshold_ms = 30000 # 30s Active Mode Threshold
```

ICD parameters that may be disabled once LIT functionality is enabled:

```
chip_persist_subscriptions: try to re-establish subscriptions from the server side after reboot
chip_subscription_timeout_resumption: same as above but retries are using a Fibonacci backoff
```

### Overwrite board config files

The example uses template/reference board configuration files.
Expand Down
2 changes: 2 additions & 0 deletions examples/contact-sensor-app/nxp/k32w/k32w0/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ chip_stack_lock_tracking = "fatal"
chip_enable_ble = true

chip_enable_icd_server = true
chip_enable_icd_lit = false
icd_enforce_sit_slow_poll_limit = true
chip_persist_subscriptions = true
chip_subscription_timeout_resumption = true
57 changes: 56 additions & 1 deletion examples/contact-sensor-app/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ static LEDWidget sContactSensorLED;

static bool sIsThreadProvisioned = false;
static bool sHaveBLEConnections = false;
#if CHIP_ENABLE_LIT
static bool sIsDeviceCommissioned = false;
#endif

static uint32_t eventMask = 0;

Expand Down Expand Up @@ -448,6 +451,12 @@ void AppTask::ButtonEventHandler(uint8_t pin_no, uint8_t button_action)
{
button_event.Handler = ResetActionEventHandler;
}
#endif
#if CHIP_ENABLE_LIT
if (button_action == USER_ACTIVE_MODE_TRIGGER_PUSH)
{
button_event.Handler = UserActiveModeHandler;
}
#endif
}

Expand Down Expand Up @@ -486,6 +495,16 @@ void AppTask::HandleKeyboard(void)
#if (defined OM15082)
ButtonEventHandler(RESET_BUTTON, RESET_BUTTON_PUSH);
break;
#elif CHIP_ENABLE_LIT
if (sIsDeviceCommissioned)
{
ButtonEventHandler(BLE_BUTTON, USER_ACTIVE_MODE_TRIGGER_PUSH);
}
else
{
ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH);
}
break;
#else
ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH);
break;
Expand All @@ -497,7 +516,15 @@ void AppTask::HandleKeyboard(void)
ButtonEventHandler(OTA_BUTTON, OTA_BUTTON_PUSH);
break;
case gKBD_EventPB4_c:
ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH);
#if CHIP_ENABLE_LIT
if (sIsDeviceCommissioned)
{
ButtonEventHandler(BLE_BUTTON, USER_ACTIVE_MODE_TRIGGER_PUSH);
}
else
#endif

ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH);
break;
#if !(defined OM15082)
case gKBD_EventLongPB1_c:
Expand Down Expand Up @@ -694,6 +721,28 @@ void AppTask::BleStartAdvertising(intptr_t arg)
}
}

#if CHIP_ENABLE_LIT
void AppTask::UserActiveModeHandler(void * aGenericEvent)
{
AppEvent * aEvent = (AppEvent *) aGenericEvent;

if (aEvent->ButtonEvent.PinNo != BLE_BUTTON)
return;

if (sAppTask.mFunction != Function::kNoneSelected)
{
K32W_LOG("Another function is scheduled. Could not request ICD Active Mode!");
return;
}
PlatformMgr().ScheduleWork(AppTask::UserActiveModeTrigger, 0);
}

void AppTask::UserActiveModeTrigger(intptr_t arg)
{
ICDNotifier::GetInstance().NotifyNetworkActivityNotification();
}
#endif

void AppTask::MatterEventHandler(const ChipDeviceEvent * event, intptr_t)
{
if (event->Type == DeviceEventType::kServiceProvisioningChange && event->ServiceProvisioningChange.IsServiceProvisioned)
Expand All @@ -707,6 +756,12 @@ void AppTask::MatterEventHandler(const ChipDeviceEvent * event, intptr_t)
sIsThreadProvisioned = FALSE;
}
}
#if CHIP_ENABLE_LIT
else if (event->Type == DeviceEventType::kCommissioningComplete)
{
sIsDeviceCommissioned = TRUE;
}
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
if (event->Type == DeviceEventType::kDnssdInitialized)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class AppTask
static void ContactActionEventHandler(void * aGenericEvent);
static void ResetActionEventHandler(void * aGenericEvent);
static void InstallEventHandler(void * aGenericEvent);
#if CHIP_ENABLE_LIT
static void UserActiveModeHandler(void * aGenericEvent);
static void UserActiveModeTrigger(intptr_t arg);
#endif

static void ButtonEventHandler(uint8_t pin_no, uint8_t button_action);
static void TimerEventHandler(TimerHandle_t xTimer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define CONTACT_SENSOR_BUTTON_PUSH 2
#define OTA_BUTTON_PUSH 3
#define BLE_BUTTON_PUSH 4
#define USER_ACTIVE_MODE_TRIGGER_PUSH 5

#define APP_BUTTON_PUSH 1

Expand Down
13 changes: 12 additions & 1 deletion examples/contact-sensor-app/nxp/k32w/k32w1/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import("${nxp_sdk_build_root}/${nxp_sdk_name}/nxp_executable.gni")

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

import("${chip_root}/src/app/icd/icd.gni")
import("${chip_root}/src/crypto/crypto.gni")
import("${chip_root}/src/lib/core/core.gni")
import("${chip_root}/src/platform/device.gni")
Expand Down Expand Up @@ -74,6 +75,8 @@ k32w1_sdk("sdk") {
k32w1_executable("contact_sensor_app") {
output_name = "chip-k32w1-contact-example"

defines = []

sources = [
"${k32w1_platform_dir}/util/LEDWidget.cpp",
"${k32w1_platform_dir}/util/include/LEDWidget.h",
Expand All @@ -89,7 +92,6 @@ k32w1_executable("contact_sensor_app") {
deps = [
":sdk",
"${chip_root}/examples/common/QRCode",
"${chip_root}/examples/contact-sensor-app/nxp/zap",
"${chip_root}/examples/providers:device_info_provider",
"${chip_root}/src/lib",
"${chip_root}/src/platform:syscalls_stub",
Expand All @@ -109,6 +111,15 @@ k32w1_executable("contact_sensor_app") {
]
}

#lit and sit are using different zap files
if (chip_enable_icd_lit) {
deps += [ "${chip_root}/examples/contact-sensor-app/nxp/zap-lit/" ]

defines += [ "CHIP_ENABLE_LIT=1" ]
} else {
deps += [ "${chip_root}/examples/contact-sensor-app/nxp/zap-sit/" ]
}

cflags = [ "-Wconversion" ]

output_dir = root_out_dir
Expand Down
54 changes: 47 additions & 7 deletions examples/contact-sensor-app/nxp/k32w/k32w1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ into an existing Matter network and can be controlled by this network.
- [Bluetooth LE Rendezvous](#bluetooth-le-rendezvous)
- [Device UI](#device-ui)
- [Building](#building)
- [Long Idle Time ICD Support](#long-idle-time-icd-support)
- [Manufacturing data](#manufacturing-data)
- [Flashing](#flashing)
- [Flashing the NBU image](#flashing-the-nbu-image)
Expand Down Expand Up @@ -100,13 +101,15 @@ will not work.
**RGB LED** shows the state of the simulated contact sensor. when the LED is
lit, the sensor is contacted, when not lit, the sensor is non-contacted.

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

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

## Long Idle Time ICD Support

By default, contact-sensor is compiled as SIT ICD (Short Idle Time
Intermittently Connected Device) - see rules from k32w1_sdk.gni:

```
chip_ot_idle_interval_ms = 2000 # 2s Idle Intervals
chip_ot_active_interval_ms = 500 # 500ms Active Intervals

nxp_idle_mode_duration_s = 600 # 10min Idle Mode Interval
nxp_active_mode_duration_ms = 10000 # 10s Active Mode Interval
nxp_active_mode_threshold_ms = 1000 # 1s Active Mode Threshold
nxp_icd_supported_clients_per_fabric = 2 # 2 registration slots per fabric
```

If LIT ICD support is needed then `chip_enable_icd_lit=true` must be specified
as gn argument and the above parameters can be modified to comply with LIT
requirements (e.g.: LIT devices must configure
`chip_ot_idle_interval_ms > 15000`). Example LIT configuration:

```
chip_ot_idle_interval_ms = 15000 # 15s Idle Intervals
chip_ot_active_interval_ms = 500 # 500ms Active Intervals

nxp_idle_mode_duration_s = 3600 # 60min Idle Mode Interval
nxp_active_mode_duration_ms = 0 # 0 Active Mode Interval
nxp_active_mode_threshold_ms = 30000 # 30s Active Mode Threshold
```

ICD parameters that may be disabled once LIT functionality is enabled:

```
chip_persist_subscriptions: try once to re-establish subscriptions from the server side after reboot
chip_subscription_timeout_resumption: same as above + try to re-establish timeout out subscriptions
using Fibonacci backoff for retries pacing.
```

## Manufacturing data

Use `chip_with_factory_data=1` in the gn build command to enable factory data.
Expand Down
2 changes: 2 additions & 0 deletions examples/contact-sensor-app/nxp/k32w/k32w1/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ chip_stack_lock_tracking = "fatal"
chip_enable_ble = true

chip_enable_icd_server = true
chip_enable_icd_lit = false
icd_enforce_sit_slow_poll_limit = true
chip_persist_subscriptions = true
chip_subscription_timeout_resumption = true
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@
* {MAJOR_VERSION}.0d{MINOR_VERSION}
*/
#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING "03-2022-te8"
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING NXP_CONFIG_DEVICE_SOFTWARE_VERSION_STRING
#endif

#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION 42020
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION NXP_CONFIG_DEVICE_SOFTWARE_VERSION
#endif

#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME
Expand Down
Loading
Loading