diff --git a/.github/workflows/examples-k32w.yaml b/.github/workflows/examples-k32w.yaml index e34c5b1d7d6d06..34bf49e0f436f1 100644 --- a/.github/workflows/examples-k32w.yaml +++ b/.github/workflows/examples-k32w.yaml @@ -69,7 +69,7 @@ jobs: timeout-minutes: 5 run: | scripts/examples/k32w_example.sh \ - examples/shell/nxp/k32w/k32w0 out/shell_app_debug + examples/shell/nxp/k32w/k32w0 out/shell_app_debug no_low_power .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ k32w k32w061+debug shell \ out/shell_app_debug/chip-k32w061-shell-example \ diff --git a/examples/lighting-app/nxp/k32w/k32w0/main/include/AppEvent.h b/examples/lighting-app/nxp/k32w/k32w0/main/include/AppEvent.h index 820d44bc68e98f..0e49456b8addd7 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/main/include/AppEvent.h +++ b/examples/lighting-app/nxp/k32w/k32w0/main/include/AppEvent.h @@ -31,7 +31,7 @@ struct AppEvent kEventType_Install, }; - uint16_t Type; + AppEventTypes Type; union { diff --git a/examples/lock-app/nxp/k32w/k32w0/main/include/AppEvent.h b/examples/lock-app/nxp/k32w/k32w0/main/include/AppEvent.h index 3ff4b79d45b43c..051eb627991917 100644 --- a/examples/lock-app/nxp/k32w/k32w0/main/include/AppEvent.h +++ b/examples/lock-app/nxp/k32w/k32w0/main/include/AppEvent.h @@ -34,7 +34,7 @@ struct AppEvent #endif }; - uint16_t Type; + AppEventTypes Type; union { diff --git a/examples/shell/nxp/k32w/k32w0/BUILD.gn b/examples/shell/nxp/k32w/k32w0/BUILD.gn index 34051517fd9375..dbb85ebe56be38 100644 --- a/examples/shell/nxp/k32w/k32w0/BUILD.gn +++ b/examples/shell/nxp/k32w/k32w0/BUILD.gn @@ -39,6 +39,7 @@ k32w0_sdk("sdk") { "main/include", "main", "include", + "${k32w0_platform_dir}/app/project_include", "${k32w0_platform_dir}/app/support", "${k32w0_platform_dir}/util/include", ] @@ -54,16 +55,20 @@ k32w0_sdk("sdk") { k32w0_executable("shell_app") { output_name = "chip-k32w061-shell-example" - sources = [ "main/main.cpp" ] + sources = [ + "${k32w0_platform_dir}/util/LEDWidget.cpp", + "${k32w0_platform_dir}/util/include/LEDWidget.h", + "main/AppTask.cpp", + "main/main.cpp", + ] deps = [ ":sdk", + "${chip_root}/examples/lock-app/lock-common", "${chip_root}/examples/shell/shell_common:shell_common", - "${chip_root}/src/lib", "${chip_root}/third_party/mbedtls:mbedtls", "${chip_root}/third_party/simw-top-mini:se05x", "${k32w0_platform_dir}/app/support:freertos_mbedtls_utils", - "${openthread_root}:libopenthread-ftd", ] cflags = [ "-Wconversion" ] diff --git a/examples/shell/nxp/k32w/k32w0/include/AppEvent.h b/examples/shell/nxp/k32w/k32w0/include/AppEvent.h new file mode 100644 index 00000000000000..0e49456b8addd7 --- /dev/null +++ b/examples/shell/nxp/k32w/k32w0/include/AppEvent.h @@ -0,0 +1,55 @@ +/* + * + * Copyright (c) 2021 Nest Labs, Inc. + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +struct AppEvent; +typedef void (*EventHandler)(AppEvent *); + +struct AppEvent +{ + enum AppEventTypes + { + kEventType_Button = 0, + kEventType_Timer, + kEventType_TurnOn, + kEventType_Install, + }; + + AppEventTypes Type; + + union + { + struct + { + uint8_t PinNo; + uint8_t Action; + } ButtonEvent; + struct + { + void * Context; + } TimerEvent; + struct + { + uint8_t Action; + int32_t Actor; + } LightEvent; + }; + + EventHandler Handler; +}; diff --git a/examples/shell/nxp/k32w/k32w0/include/AppTask.h b/examples/shell/nxp/k32w/k32w0/include/AppTask.h new file mode 100644 index 00000000000000..cdfbf664746404 --- /dev/null +++ b/examples/shell/nxp/k32w/k32w0/include/AppTask.h @@ -0,0 +1,88 @@ +/* + * + * Copyright (c) 2021 Google LLC. + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include "AppEvent.h" + +#include + +#include "FreeRTOS.h" +#include "timers.h" + +// Application-defined error codes in the CHIP_ERROR space. +#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01) +#define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02) +#define APP_ERROR_UNHANDLED_EVENT CHIP_APPLICATION_ERROR(0x03) +#define APP_ERROR_CREATE_TIMER_FAILED CHIP_APPLICATION_ERROR(0x04) +#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05) +#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06) + +class AppTask +{ +public: + CHIP_ERROR StartAppTask(); + static void AppTaskMain(void * pvParameter); + void PostEvent(const AppEvent * event); + +private: + friend AppTask & GetAppTask(void); + + CHIP_ERROR Init(); + + void CancelTimer(void); + + void DispatchEvent(AppEvent * event); + + static void FunctionTimerEventHandler(AppEvent * aEvent); + static void KBD_Callback(uint8_t events); + static void HandleKeyboard(void); + static void BleHandler(AppEvent * aEvent); + static void ResetActionEventHandler(AppEvent * aEvent); + static void InstallEventHandler(AppEvent * aEvent); + + static void ButtonEventHandler(uint8_t pin_no, uint8_t button_action); + static void TimerEventHandler(TimerHandle_t xTimer); + + static void ThreadProvisioningHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); + + static void ThreadStart(); + void StartTimer(uint32_t aTimeoutInMs); + + enum Function_t + { + kFunction_NoneSelected = 0, + kFunction_SoftwareUpdate = 0, + kFunction_FactoryReset, + + kFunction_Invalid + } Function; + + Function_t mFunction = kFunction_NoneSelected; + bool mResetTimerActive = false; + + static AppTask sAppTask; +}; + +inline AppTask & GetAppTask(void) +{ + return AppTask::sAppTask; +} diff --git a/examples/shell/nxp/k32w/k32w0/include/CHIPProjectConfig.h b/examples/shell/nxp/k32w/k32w0/include/CHIPProjectConfig.h index 63dbdb625f8cec..ba6edc693dad55 100644 --- a/examples/shell/nxp/k32w/k32w0/include/CHIPProjectConfig.h +++ b/examples/shell/nxp/k32w/k32w0/include/CHIPProjectConfig.h @@ -116,7 +116,7 @@ * * Enable support for CHIP-over-BLE (CHIPOBLE). */ -#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0 +#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 /** * CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC @@ -176,10 +176,31 @@ */ #define CHIP_DEVICE_CONFIG_BLE_ADVERTISING_TIMEOUT (15 * 60 * 1000) +/** + * CONFIG_CHIP_NFC_COMMISSIONING, CHIP_DEVICE_CONFIG_ENABLE_NFC + * + * Set these defines to 1 if NFC Commissioning is needed + */ #define CONFIG_CHIP_NFC_COMMISSIONING 0 - #define CHIP_DEVICE_CONFIG_ENABLE_NFC 0 +/** + * CHIP_DEVICE_CONFIG_THREAD_FTD + * + * Shell Demo Application is a Thread SED (Sleepy End Device) + */ +#define CHIP_DEVICE_CONFIG_THREAD_FTD 0 + +/** + * @def CHIP_CONFIG_MAX_DEVICE_ADMINS + * + * @brief + * Maximum number of administrators that can provision the device. Each admin + * can provision the device with their unique operational credentials and manage + * their access control lists. + */ +#define CHIP_CONFIG_MAX_DEVICE_ADMINS 2 // 1 fabrics + 1 for rotation slack + /** * CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE * diff --git a/examples/shell/nxp/k32w/k32w0/main/AppTask.cpp b/examples/shell/nxp/k32w/k32w0/main/AppTask.cpp new file mode 100644 index 00000000000000..b3e85d164171c3 --- /dev/null +++ b/examples/shell/nxp/k32w/k32w0/main/AppTask.cpp @@ -0,0 +1,437 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021 Google LLC. + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "AppTask.h" +#include "AppEvent.h" +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "Keyboard.h" +#include "LED.h" +#include "LEDWidget.h" +#include "TimersManager.h" +#include "app_config.h" + +#define FACTORY_RESET_TRIGGER_TIMEOUT 6000 +#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000 +#define APP_EVENT_QUEUE_SIZE 10 + +TimerHandle_t sFunctionTimer; // FreeRTOS app sw timer. + +static QueueHandle_t sAppEventQueue; + +static LEDWidget sStatusLED; + +static bool sIsThreadProvisioned = false; +static bool sIsThreadEnabled = false; +static bool sHaveBLEConnections = false; + +static uint32_t eventMask = 0; + +using namespace ::chip::Credentials; +using namespace ::chip::DeviceLayer; + +AppTask AppTask::sAppTask; + +CHIP_ERROR AppTask::StartAppTask() +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + sAppEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent)); + if (sAppEventQueue == NULL) + { + err = APP_ERROR_EVENT_QUEUE_FAILED; + K32W_LOG("Failed to allocate app event queue"); + assert(err == CHIP_NO_ERROR); + } + + return err; +} + +CHIP_ERROR AppTask::Init() +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + // Init ZCL Data Model and start server + chip::Server::GetInstance().Init(); + + // Initialize device attestation config + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); + + // QR code will be used with CHIP Tool + PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); + + TMR_Init(); + + /* HW init leds */ + LED_Init(); + + /* start with all LEDS turnedd off */ + sStatusLED.Init(SYSTEM_STATE_LED); + + /* intialize the Keyboard and button press calback */ + KBD_Init(KBD_Callback); + + // Create FreeRTOS sw timer for Function Selection. + sFunctionTimer = xTimerCreate("FnTmr", // Just a text name, not used by the RTOS kernel + 1, // == default timer period (mS) + false, // no timer reload (==one-shot) + (void *) this, // init timer id = app task obj context + TimerEventHandler // timer callback handler + ); + + if (sFunctionTimer == NULL) + { + err = APP_ERROR_CREATE_TIMER_FAILED; + K32W_LOG("app_timer_create() failed"); + assert(err == CHIP_NO_ERROR); + } + + // Print the current software version + char currentFirmwareRev[ConfigurationManager::kMaxFirmwareRevisionLength + 1] = { 0 }; + err = ConfigurationMgr().GetFirmwareRevisionString(currentFirmwareRev, sizeof(currentFirmwareRev)); + if (err != CHIP_NO_ERROR) + { + K32W_LOG("Get version error"); + assert(err == CHIP_NO_ERROR); + } + + K32W_LOG("Current Firmware Version: %s", currentFirmwareRev); + +#if CONFIG_CHIP_NFC_COMMISSIONING + PlatformMgr().AddEventHandler(ThreadProvisioningHandler, 0); +#endif + + return err; +} + +void AppTask::AppTaskMain(void * pvParameter) +{ + AppEvent event; + + CHIP_ERROR err = sAppTask.Init(); + if (err != CHIP_NO_ERROR) + { + K32W_LOG("AppTask.Init() failed"); + assert(err == CHIP_NO_ERROR); + } + + while (true) + { + BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, pdMS_TO_TICKS(10)); + while (eventReceived == pdTRUE) + { + sAppTask.DispatchEvent(&event); + eventReceived = xQueueReceive(sAppEventQueue, &event, 0); + } + + // Collect connectivity and configuration state from the CHIP stack. Because the + // CHIP event loop is being run in a separate task, the stack must be locked + // while these values are queried. However we use a non-blocking lock request + // (TryLockChipStack()) to avoid blocking other UI activities when the CHIP + // task is busy (e.g. with a long crypto operation). + if (PlatformMgr().TryLockChipStack()) + { + sIsThreadProvisioned = ConnectivityMgr().IsThreadProvisioned(); + sIsThreadEnabled = ConnectivityMgr().IsThreadEnabled(); + sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); + PlatformMgr().UnlockChipStack(); + } + + // Update the status LED if factory reset has not been initiated. + // + // If system has "full connectivity", keep the LED On constantly. + // + // If thread and service provisioned, but not attached to the thread network yet OR no + // connectivity to the service OR subscriptions are not fully established + // THEN blink the LED Off for a short period of time. + // + // If the system has ble connection(s) uptill the stage above, THEN blink the LEDs at an even + // rate of 100ms. + // + // Otherwise, blink the LED ON for a very short time. + if (sAppTask.mFunction != kFunction_FactoryReset) + { + if (sIsThreadProvisioned && sIsThreadEnabled) + { + sStatusLED.Blink(950, 50); + } + else if (sHaveBLEConnections) + { + sStatusLED.Blink(100, 100); + } + else + { + sStatusLED.Blink(50, 950); + } + } + + sStatusLED.Animate(); + HandleKeyboard(); + } +} + +void AppTask::ButtonEventHandler(uint8_t pin_no, uint8_t button_action) +{ + if ((pin_no != RESET_BUTTON) && (pin_no != BLE_BUTTON)) + { + return; + } + + AppEvent button_event; + button_event.Type = AppEvent::kEventType_Button; + button_event.ButtonEvent.PinNo = pin_no; + button_event.ButtonEvent.Action = button_action; + + if (pin_no == RESET_BUTTON) + { + button_event.Handler = ResetActionEventHandler; + } + else if (pin_no == BLE_BUTTON) + { + button_event.Handler = BleHandler; +#if !(defined OM15082) + if (button_action == RESET_BUTTON_PUSH) + { + button_event.Handler = ResetActionEventHandler; + } +#endif + } + + sAppTask.PostEvent(&button_event); +} + +void AppTask::KBD_Callback(uint8_t events) +{ + eventMask = eventMask | (uint32_t)(1 << events); +} + +void AppTask::HandleKeyboard(void) +{ + uint8_t keyEvent = 0xFF; + uint8_t pos = 0; + + while (eventMask) + { + for (pos = 0; pos < (8 * sizeof(eventMask)); pos++) + { + if (eventMask & (1 << pos)) + { + keyEvent = pos; + eventMask = eventMask & ~(1 << pos); + break; + } + } + + switch (keyEvent) + { + case gKBD_EventPB1_c: +#if (defined OM15082) + ButtonEventHandler(RESET_BUTTON, RESET_BUTTON_PUSH); + break; +#else + ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH); + break; +#endif + case gKBD_EventPB4_c: + ButtonEventHandler(BLE_BUTTON, BLE_BUTTON_PUSH); + break; +#if !(defined OM15082) + case gKBD_EventLongPB1_c: + ButtonEventHandler(BLE_BUTTON, RESET_BUTTON_PUSH); + break; +#endif + default: + break; + } + } +} + +void AppTask::TimerEventHandler(TimerHandle_t xTimer) +{ + AppEvent event; + event.Type = AppEvent::kEventType_Timer; + event.TimerEvent.Context = (void *) xTimer; + event.Handler = FunctionTimerEventHandler; + sAppTask.PostEvent(&event); +} + +void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) +{ + if (aEvent->Type != AppEvent::kEventType_Timer) + return; + + K32W_LOG("Device will factory reset..."); + + // Actually trigger Factory Reset + ConfigurationMgr().InitiateFactoryReset(); +} + +void AppTask::ResetActionEventHandler(AppEvent * aEvent) +{ + if (aEvent->ButtonEvent.PinNo != RESET_BUTTON && aEvent->ButtonEvent.PinNo != BLE_BUTTON) + return; + + if (sAppTask.mResetTimerActive) + { + sAppTask.CancelTimer(); + sAppTask.mFunction = kFunction_NoneSelected; + + K32W_LOG("Factory Reset was cancelled!"); + } + else + { + uint32_t resetTimeout = FACTORY_RESET_TRIGGER_TIMEOUT; + + if (sAppTask.mFunction != kFunction_NoneSelected) + { + K32W_LOG("Another function is scheduled. Could not initiate Factory Reset!"); + return; + } + + K32W_LOG("Factory Reset Triggered. Push the RESET button within %u ms to cancel!", resetTimeout); + sAppTask.mFunction = kFunction_FactoryReset; + + /* LEDs will start blinking to signal that a Factory Reset was scheduled */ + sStatusLED.Set(false); + sStatusLED.Blink(500); + + sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT); + } +} + +void AppTask::BleHandler(AppEvent * aEvent) +{ + if (aEvent->ButtonEvent.PinNo != BLE_BUTTON) + return; + + if (sAppTask.mFunction != kFunction_NoneSelected) + { + K32W_LOG("Another function is scheduled. Could not toggle BLE state!"); + return; + } + + if (ConnectivityMgr().IsBLEAdvertisingEnabled()) + { + ConnectivityMgr().SetBLEAdvertisingEnabled(false); + K32W_LOG("Stopped BLE Advertising!"); + } + else + { + ConnectivityMgr().SetBLEAdvertisingEnabled(true); + + if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() == CHIP_NO_ERROR) + { + K32W_LOG("Started BLE Advertising!"); + } + else + { + K32W_LOG("OpenBasicCommissioningWindow() failed"); + } + } +} + +#if CONFIG_CHIP_NFC_COMMISSIONING +void AppTask::ThreadProvisioningHandler(const ChipDeviceEvent * event, intptr_t) +{ + if (event->Type == DeviceEventType::kCHIPoBLEAdvertisingChange && event->CHIPoBLEAdvertisingChange.Result == kActivity_Stopped) + { + if (!NFCMgr().IsTagEmulationStarted()) + { + K32W_LOG("NFC Tag emulation is already stopped!"); + } + else + { + NFCMgr().StopTagEmulation(); + K32W_LOG("Stopped NFC Tag Emulation!"); + } + } + else if (event->Type == DeviceEventType::kCHIPoBLEAdvertisingChange && + event->CHIPoBLEAdvertisingChange.Result == kActivity_Started) + { + if (NFCMgr().IsTagEmulationStarted()) + { + K32W_LOG("NFC Tag emulation is already started!"); + } + else + { + ShareQRCodeOverNFC(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); + K32W_LOG("Started NFC Tag Emulation!"); + } + } +} +#endif + +void AppTask::CancelTimer() +{ + if (xTimerStop(sFunctionTimer, 0) == pdFAIL) + { + K32W_LOG("app timer stop() failed"); + } + + mResetTimerActive = false; +} + +void AppTask::StartTimer(uint32_t aTimeoutInMs) +{ + if (xTimerIsTimerActive(sFunctionTimer)) + { + K32W_LOG("app timer already started!"); + CancelTimer(); + } + + // timer is not active, change its period to required value (== restart). + // FreeRTOS- Block for a maximum of 100 ticks if the change period command + // cannot immediately be sent to the timer command queue. + if (xTimerChangePeriod(sFunctionTimer, aTimeoutInMs / portTICK_PERIOD_MS, 100) != pdPASS) + { + K32W_LOG("app timer start() failed"); + } + + mResetTimerActive = true; +} + +void AppTask::PostEvent(const AppEvent * aEvent) +{ + if (sAppEventQueue != NULL) + { + if (!xQueueSend(sAppEventQueue, aEvent, 1)) + { + K32W_LOG("Failed to post event to app task event queue"); + } + } +} + +void AppTask::DispatchEvent(AppEvent * aEvent) +{ + if (aEvent->Handler) + { + aEvent->Handler(aEvent); + } + else + { + K32W_LOG("Event received with no handler. Dropping event."); + } +} diff --git a/examples/shell/nxp/k32w/k32w0/main/main.cpp b/examples/shell/nxp/k32w/k32w0/main/main.cpp index 711e507d393df4..da20f798e4cca7 100644 --- a/examples/shell/nxp/k32w/k32w0/main/main.cpp +++ b/examples/shell/nxp/k32w/k32w0/main/main.cpp @@ -42,6 +42,11 @@ #include "radio.h" +#include + +const uint16_t shell_task_size = 3096; +const uint8_t shell_task_priority = 0; + using namespace ::chip; using namespace ::chip::Inet; using namespace ::chip::DeviceLayer; @@ -62,9 +67,15 @@ extern "C" unsigned int sleep(unsigned int seconds) return 0; } +static void shell_task(void * args) +{ + Engine::Root().RunMainLoop(); +} + extern "C" void main_task(void const * argument) { int status = 0; + BaseType_t shellTaskHandle; /* Call C++ constructors */ InitFunc * pFunc = &__init_array_start; @@ -122,19 +133,33 @@ extern "C" void main_task(void const * argument) goto exit; } - status = chip::Shell::streamer_init(chip::Shell::streamer_get()); - if (status != 0) + // cmd_otcli_init(); + cmd_ping_init(); + cmd_send_init(); + + shellTaskHandle = xTaskCreate(shell_task, "shell_task", shell_task_size / sizeof(StackType_t), NULL, shell_task_priority, NULL); + if (!shellTaskHandle) { - K32W_LOG("Error during streamer_init"); + K32W_LOG("Error while creating the shell task!"); goto exit; } - cmd_otcli_init(); - cmd_ping_init(); - cmd_send_init(); - - Engine::Root().RunMainLoop(); + ret = GetAppTask().StartAppTask(); + if (ret != CHIP_NO_ERROR) + { + K32W_LOG("Error during GetAppTask().StartAppTask()"); + goto exit; + } + GetAppTask().AppTaskMain(NULL); exit: return; } + +extern "C" void otSysEventSignalPending(void) +{ + { + BaseType_t yieldRequired = ThreadStackMgrImpl().SignalThreadActivityPendingFromISR(); + portYIELD_FROM_ISR(yieldRequired); + } +} diff --git a/scripts/examples/k32w_example.sh b/scripts/examples/k32w_example.sh index 2923e7e8da94e0..d9614e45026077 100755 --- a/scripts/examples/k32w_example.sh +++ b/scripts/examples/k32w_example.sh @@ -27,5 +27,10 @@ env "$(dirname "$0")"/../../third_party/k32w_sdk/sdk_fixes/patch_k32w_sdk.sh -gn gen --check --fail-on-unused-args --root="$1" "$2" --args="k32w0_sdk_root=\"$K32W061_SDK_ROOT\" is_debug=false chip_with_low_power=1" +if [ -z "$3" ]; then + gn gen --check --fail-on-unused-args --root="$1" "$2" --args="k32w0_sdk_root=\"$K32W061_SDK_ROOT\" is_debug=false chip_with_low_power=1" +else + gn gen --check --fail-on-unused-args --root="$1" "$2" --args="k32w0_sdk_root=\"$K32W061_SDK_ROOT\" is_debug=false chip_with_low_power=0" +fi + ninja -C "$2" diff --git a/third_party/k32w_sdk/nxp/k32w/k32w0/k32w0_sdk.gni b/third_party/k32w_sdk/nxp/k32w/k32w0/k32w0_sdk.gni index 59d298d36f2f21..4ba8446ea3a80a 100644 --- a/third_party/k32w_sdk/nxp/k32w/k32w0/k32w0_sdk.gni +++ b/third_party/k32w_sdk/nxp/k32w/k32w0/k32w0_sdk.gni @@ -123,7 +123,7 @@ template("k32w0_sdk") { defines = [ "gPWR_CpuClk_48MHz=1", - "gMainThreadPriority_c=6", + "gMainThreadPriority_c=5", "CPU_K32W061HN", "CPU_JN518X", "CPU_JN518X_REV=2",