diff --git a/examples/ota-requestor-app/efr32/.gn b/examples/ota-requestor-app/efr32/.gn deleted file mode 100644 index 3d48789e30ab3d..00000000000000 --- a/examples/ota-requestor-app/efr32/.gn +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2020 Project CHIP Authors -# -# 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. - -import("//build_overrides/build.gni") - -# The location of the build configuration file. -buildconfig = "${build_root}/config/BUILDCONFIG.gn" - -# CHIP uses angle bracket includes. -check_system_includes = true - -default_args = { - target_cpu = "arm" - target_os = "freertos" - - import("//args.gni") -} diff --git a/examples/ota-requestor-app/efr32/BUILD.gn b/examples/ota-requestor-app/efr32/BUILD.gn deleted file mode 100644 index 9e56b9d900cfcd..00000000000000 --- a/examples/ota-requestor-app/efr32/BUILD.gn +++ /dev/null @@ -1,208 +0,0 @@ -# Copyright (c) 2020 Project CHIP Authors -# -# 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. - -import("//build_overrides/build.gni") -import("//build_overrides/chip.gni") -import("//build_overrides/efr32_sdk.gni") -import("//build_overrides/pigweed.gni") - -import("${build_root}/config/defaults.gni") -import("${efr32_sdk_build_root}/efr32_executable.gni") -import("${efr32_sdk_build_root}/efr32_sdk.gni") - -import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") -import("${chip_root}/src/platform/device.gni") - -if (chip_enable_pw_rpc) { - import("//build_overrides/pigweed.gni") - import("$dir_pw_build/target_types.gni") -} - -assert(current_os == "freertos") - -efr32_project_dir = "${chip_root}/examples/ota-requestor-app/efr32" -examples_plat_dir = "${chip_root}/examples/platform/efr32" - -declare_args() { - # Dump memory usage at link time. - chip_print_memory_usage = false - - # PIN code for PASE session establishment. - setupPinCode = 20202021 - setupDiscriminator = 3840 - - # Monitor & log memory usage at runtime. - enable_heap_monitoring = false - - # Disable LCD on supported devices - disable_lcd = false -} - -declare_args() { - # Enables LCD Qr Code on supported devices - show_qr_code = !disable_lcd -} - -# qr code cannot be true if lcd is disabled -assert(!(disable_lcd && show_qr_code)) - -# BRD4166A --> ThunderBoard Sense 2 (No LCD) -if (efr32_board == "BRD4166A" || efr32_board == "BRD4180A") { - show_qr_code = false - disable_lcd = true -} - -efr32_sdk("sdk") { - sources = [ - "${efr32_project_dir}/include/CHIPProjectConfig.h", - "${examples_plat_dir}/FreeRTOSConfig.h", - ] - - include_dirs = [ - "${chip_root}/src/platform/EFR32", - "${efr32_project_dir}/include", - "${examples_plat_dir}", - "${chip_root}/src/lib", - ] - - defines = [ - "BOARD_ID=${efr32_board}", - "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}", - "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setupDiscriminator}", - ] - - if (chip_enable_pw_rpc) { - defines += [ - "HAL_VCOM_ENABLE=1", - "PW_RPC_ENABLED", - ] - } -} - -efr32_executable("ota_requestor_app") { - output_name = "chip-efr32-ota-requestor-example.out" - include_dirs = [ "include" ] - defines = [] - - sources = [ - "${examples_plat_dir}/LEDWidget.cpp", - "${examples_plat_dir}/heap_4_silabs.c", - "${examples_plat_dir}/init_efrPlatform.cpp", - "src/AppTask.cpp", - "src/LightingManager.cpp", - "src/ZclCallbacks.cpp", - "src/main.cpp", - ] - - if (chip_enable_pw_rpc || chip_build_libshell || enable_openthread_cli) { - sources += [ "${examples_plat_dir}/uart.cpp" ] - } - - deps = [ - ":sdk", - "${chip_root}/examples/ota-requestor-app/ota-requestor-common", - "${chip_root}/src/lib", - "${chip_root}/src/setup_payload", - "${chip_root}/third_party/openthread/platforms:libopenthread-platform", - "${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils", - "${examples_plat_dir}:efr-matter-shell", - ] - - if (chip_openthread_ftd) { - deps += [ - "${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd", - "${chip_root}/third_party/openthread/repo:libopenthread-ftd", - ] - } else { - deps += [ - "${chip_root}/third_party/openthread/repo:libopenthread-cli-mtd", - "${chip_root}/third_party/openthread/repo:libopenthread-mtd", - ] - } - - if (!disable_lcd) { - sources += [ "${examples_plat_dir}/display/lcd.c" ] - defines += [ "DISPLAY_ENABLED" ] - if (show_qr_code) { - defines += [ "QR_CODE_ENABLED" ] - - deps += [ "${chip_root}/examples/common/QRCode" ] - } - } - - if (chip_enable_pw_rpc) { - defines += [ - "PW_RPC_ENABLED", - "PW_RPC_ATTRIBUTE_SERVICE=1", - "PW_RPC_BUTTON_SERVICE=1", - "PW_RPC_DESCRIPTOR_SERVICE=1", - "PW_RPC_DEVICE_SERVICE=1", - "PW_RPC_LIGHTING_SERVICE=1", - ] - - sources += [ - "${chip_root}/examples/common/pigweed/RpcService.cpp", - "${chip_root}/examples/common/pigweed/efr32/PigweedLoggerMutex.cpp", - "${examples_plat_dir}/PigweedLogger.cpp", - "${examples_plat_dir}/Rpc.cpp", - ] - - deps += [ - "$dir_pw_hdlc:rpc_channel_output", - "$dir_pw_stream:sys_io_stream", - "${chip_root}/config/efr32/lib/pw_rpc:pw_rpc", - "${chip_root}/examples/common/pigweed:attributes_service.nanopb_rpc", - "${chip_root}/examples/common/pigweed:button_service.nanopb_rpc", - "${chip_root}/examples/common/pigweed:descriptor_service.nanopb_rpc", - "${chip_root}/examples/common/pigweed:device_service.nanopb_rpc", - "${chip_root}/examples/common/pigweed:lighting_service.nanopb_rpc", - "${examples_plat_dir}/pw_sys_io:pw_sys_io_efr32", - ] - - deps += pw_build_LINK_DEPS - - include_dirs += [ - "${chip_root}/examples/common", - "${chip_root}/examples/common/pigweed/efr32", - ] - } - - if (enable_heap_monitoring) { - sources += [ "${examples_plat_dir}/MemMonitoring.cpp" ] - defines += [ "HEAP_MONITORING" ] - } - - ldscript = "${examples_plat_dir}/ldscripts/${efr32_family}.ld" - - inputs = [ ldscript ] - - ldflags = [ "-T" + rebase_path(ldscript, root_build_dir) ] - - if (chip_print_memory_usage) { - ldflags += [ - "-Wl,--print-memory-usage", - "-fstack-usage", - ] - } - - output_dir = root_out_dir -} - -group("efr32") { - deps = [ ":ota_requestor_app" ] -} - -group("default") { - deps = [ ":efr32" ] -} diff --git a/examples/ota-requestor-app/efr32/README.md b/examples/ota-requestor-app/efr32/README.md deleted file mode 100644 index db7d65e5c66b87..00000000000000 --- a/examples/ota-requestor-app/efr32/README.md +++ /dev/null @@ -1,6 +0,0 @@ -For the description of Software Update process with EFR32 example applications -see -[EFR32 OTA Software Update](../../../docs/guides/silabs_efr32_software_update.md) - -The EFR32 ota-requestor-app example app has been deprecated. The OTA Software -Update functionality can be used in any EFR32 example application. diff --git a/examples/ota-requestor-app/efr32/args.gni b/examples/ota-requestor-app/efr32/args.gni deleted file mode 100644 index 5d3bf441f0fc19..00000000000000 --- a/examples/ota-requestor-app/efr32/args.gni +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2020 Project CHIP Authors -# -# 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. - -import("//build_overrides/chip.gni") -import("//build_overrides/pigweed.gni") -import("${chip_root}/src/platform/EFR32/args.gni") - -efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain") - -pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" -pw_assert_BACKEND = "$dir_pw_assert_log:check_backend" -chip_enable_openthread = true -chip_openthread_ftd = false - -# Disable stack lock tracking -# Example will not be maintained in the long term and will be depraceted now that OTA is beeing intagrated into our examples -chip_stack_lock_tracking = "None" - -chip_enable_ota_requestor = true diff --git a/examples/ota-requestor-app/efr32/build_overrides b/examples/ota-requestor-app/efr32/build_overrides deleted file mode 120000 index e578e73312ebd1..00000000000000 --- a/examples/ota-requestor-app/efr32/build_overrides +++ /dev/null @@ -1 +0,0 @@ -../../build_overrides \ No newline at end of file diff --git a/examples/ota-requestor-app/efr32/include/AppConfig.h b/examples/ota-requestor-app/efr32/include/AppConfig.h deleted file mode 100644 index efe17b3b39288f..00000000000000 --- a/examples/ota-requestor-app/efr32/include/AppConfig.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 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 - -// ---- Lighting Example App Config ---- - -#define APP_TASK_NAME "APP" - -// Time it takes in ms for the simulated actuator to move from one -// state to another. -#define ACTUATOR_MOVEMENT_PERIOS_MS 10 - -// EFR Logging -#ifdef __cplusplus -extern "C" { -#endif - -void efr32LogInit(void); - -void efr32Log(const char * aFormat, ...); -#define EFR32_LOG(...) efr32Log(__VA_ARGS__); -void appError(int err); - -#ifdef __cplusplus -} - -#include -void appError(CHIP_ERROR error); -#endif diff --git a/examples/ota-requestor-app/efr32/include/AppEvent.h b/examples/ota-requestor-app/efr32/include/AppEvent.h deleted file mode 100644 index 7a19b719edad25..00000000000000 --- a/examples/ota-requestor-app/efr32/include/AppEvent.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2018 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_Light, - kEventType_Install, - }; - - uint16_t Type; - - union - { - struct - { - uint8_t Action; - } ButtonEvent; - struct - { - void * Context; - } TimerEvent; - struct - { - uint8_t Action; - int32_t Actor; - } LightEvent; - }; - - EventHandler Handler; -}; diff --git a/examples/ota-requestor-app/efr32/include/AppTask.h b/examples/ota-requestor-app/efr32/include/AppTask.h deleted file mode 100644 index 8dacfd4bd2ca79..00000000000000 --- a/examples/ota-requestor-app/efr32/include/AppTask.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 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 "LightingManager.h" -#include "sl_simple_button_instances.h" - -#include "FreeRTOS.h" -#include "timers.h" // provides FreeRTOS timer support -#include -#include - -// 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 PostLightActionRequest(int32_t aActor, LightingManager::Action_t aAction); - void PostEvent(const AppEvent * event); - - void ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction); - -private: - friend AppTask & GetAppTask(void); - - CHIP_ERROR Init(); - - static void ActionInitiated(LightingManager::Action_t aAction, int32_t aActor); - static void ActionCompleted(LightingManager::Action_t aAction); - - void CancelTimer(void); - - void DispatchEvent(AppEvent * event); - - void InitOTARequestor(); - - static void FunctionTimerEventHandler(AppEvent * aEvent); - static void FunctionHandler(AppEvent * aEvent); - static void LightActionEventHandler(AppEvent * aEvent); - static void TimerEventHandler(TimerHandle_t xTimer); - - static void UpdateClusterState(void); - - void StartTimer(uint32_t aTimeoutMs); - - enum Function_t - { - kFunction_NoneSelected = 0, - kFunction_SoftwareUpdate = 0, - kFunction_StartBleAdv = 1, - kFunction_FactoryReset = 2, - - kFunction_Invalid - } Function; - - Function_t mFunction; - bool mFunctionTimerActive; - bool mSyncClusterToButtonAction; - - static AppTask sAppTask; -}; - -inline AppTask & GetAppTask(void) -{ - return AppTask::sAppTask; -} diff --git a/examples/ota-requestor-app/efr32/include/CHIPProjectConfig.h b/examples/ota-requestor-app/efr32/include/CHIPProjectConfig.h deleted file mode 100644 index 6f790bc204cda8..00000000000000 --- a/examples/ota-requestor-app/efr32/include/CHIPProjectConfig.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 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. - */ - -/** - * @file - * Example project configuration file for CHIP. - * - * This is a place to put application or project-specific overrides - * to the default configuration values for general CHIP features. - * - */ - -#pragma once - -// Use a default pairing code if one hasn't been provisioned in flash. -#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE -#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 -#endif - -#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR -#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -#endif - -// For convenience, Chip Security Test Mode can be enabled and the -// requirement for authentication in various protocols can be disabled. -// -// WARNING: These options make it possible to circumvent basic Chip security functionality, -// including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. -// -#define CHIP_CONFIG_SECURITY_TEST_MODE 0 - -/** - * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID - * - * 0xFFF1: Test vendor. - */ -#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0xFFF1 - -/** - * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID - * - * 0x8008: example ota-requestor - */ -#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x8008 - -/** - * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION - * - * The hardware version number assigned to device or product by the device vendor. This - * number is scoped to the device product id, and typically corresponds to a revision of the - * physical device, a change to its packaging, and/or a change to its marketing presentation. - * This value is generally *not* incremented for device software versions. - */ -#define CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION 1 - -/** - * CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING - * - * A string identifying the software version running on the device. - * CHIP service currently expects the software version to be in the format - * {MAJOR_VERSION}.0d{MINOR_VERSION} - */ -#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING -#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING "0.1ALPHA" -#endif -/** - * CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - * - * Enable support for Chip-over-BLE (CHIPoBLE). - */ -#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 - -/** - * CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC - * - * Enables synchronizing the device's real time clock with a remote Chip Time service - * using the Chip Time Sync protocol. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 0 - -/** - * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER - * - * Enables the use of a hard-coded default serial number if none - * is found in Chip NV storage. - */ -#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" - -/** - * CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS - * - * Enable recording UTC timestamps. - */ -#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 - -/** - * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE - * - * A size, in bytes, of the individual debug event logging buffer. - */ -#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) - -/** - * @def CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL - * - * @brief - * Active retransmit interval, or time to wait before retransmission after - * subsequent failures in milliseconds. - * - * This is the default value, that might be adjusted by end device depending on its - * needs (e.g. sleeping period) using Service Discovery TXT record CRA key. - * - */ -#define CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL (2000_ms32) - -#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 diff --git a/examples/ota-requestor-app/efr32/include/FreeRTOSConfig.h b/examples/ota-requestor-app/efr32/include/FreeRTOSConfig.h deleted file mode 100644 index d53523b8dfd3bd..00000000000000 --- a/examples/ota-requestor-app/efr32/include/FreeRTOSConfig.h +++ /dev/null @@ -1,299 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * 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. - */ - -/*************************************************************************** - * # License - * - * The licensor of this software is Silicon Laboratories Inc. Your use of this - * software is governed by the terms of Silicon Labs Master Software License - * Agreement (MSLA) available at - * www.silabs.com/about-us/legal/master-software-license-agreement. This - * software is Third Party Software licensed by Silicon Labs from a third party - * and is governed by the sections of the MSLA applicable to Third Party - * Software and the additional terms set forth below. - * - ******************************************************************************/ -/* - FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. - All rights reserved - - VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. - - This file is part of the FreeRTOS distribution. - - FreeRTOS is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License (version 2) as published by the - Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. - - *************************************************************************** - >>! NOTE: The modification to the GPL is included to allow you to !<< - >>! distribute a combined work that includes FreeRTOS without being !<< - >>! obliged to provide the source code for proprietary components !<< - >>! outside of the FreeRTOS kernel. !<< - *************************************************************************** - - FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. Full license text is available on the following - link: http://www.freertos.org/a00114.html - - *************************************************************************** - * * - * FreeRTOS provides completely free yet professionally developed, * - * robust, strictly quality controlled, supported, and cross * - * platform software that is more than just the market leader, it * - * is the industry's de facto standard. * - * * - * Help yourself get started quickly while simultaneously helping * - * to support the FreeRTOS project by purchasing a FreeRTOS * - * tutorial book, reference manual, or both: * - * http://www.FreeRTOS.org/Documentation * - * * - *************************************************************************** - - http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading - the FAQ page "My application does not run, what could be wrong?". Have you - defined configASSERT()? - - http://www.FreeRTOS.org/support - In return for receiving this top quality - embedded software for free we request you assist our global community by - participating in the support forum. - - http://www.FreeRTOS.org/training - Investing in training allows your team to - be as productive as possible as early as possible. Now you can receive - FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers - Ltd, and the world's leading authority on the world's leading RTOS. - - http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool, a DOS - compatible FAT file system, and our tiny thread aware UDP/IP stack. - - http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. - Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. - - http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High - Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS - licenses offer ticketed support, indemnification and commercial middleware. - - http://www.SafeRTOS.com - High Integrity Systems also provide a safety - engineered and independently SIL3 certified version for use in safety and - mission critical applications that require provable dependability. - - 1 tab == 4 spaces! -*/ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include "RTE_Components.h" -#include CMSIS_device_header - -#include "em_assert.h" -#include "em_device.h" - -#if defined(SL_COMPONENT_CATALOG_PRESENT) -#include "sl_component_catalog.h" -#endif - -/*----------------------------------------------------------- - * Application specific definitions. - * - * These definitions should be adjusted for your particular hardware and - * application requirements. - * - * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE - * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. - * - * See http://www.freertos.org/a00110.html. - *----------------------------------------------------------*/ - -/* Set configCREATE_LOW_POWER_DEMO as follows: - * - * 0: Build the full test and demo application. - * 1: Build the simple blinky tickless low power demo, generating the tick - * interrupt from the RTCC. EM2 will be entered. The LXFO clock is used. - * See the comments at the top of main.c, main_full.c and main_low_power.c for - * more information. - */ - -#define configCREATE_LOW_POWER_DEMO (0) - -/* Some configuration is dependent on the demo being built. */ -#if (configCREATE_LOW_POWER_DEMO == 0) - -/* Tickless mode is not used. */ - -/* Some of the standard demo test tasks assume a tick rate of 1KHz, even -though that is faster than would normally be warranted by a real -application. */ -#define configTICK_RATE_HZ (1000) - -/* Energy saving modes. */ -#if defined(SL_CATALOG_POWER_MANAGER_PRESENT) -#define configUSE_TICKLESS_IDLE 1 -#else -#define configUSE_TICKLESS_IDLE 0 -#endif - -/* Definition used by Keil to replace default system clock source. */ -#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION 1 - -/* Hook function related definitions. */ -#define configUSE_TICK_HOOK (1) -#define configCHECK_FOR_STACK_OVERFLOW (2) -#define configUSE_MALLOC_FAILED_HOOK (1) -#define configUSE_IDLE_HOOK (1) - -#define configENERGY_MODE (sleepEM1) - -#else - -/* Tickless idle mode, generating RTOS tick interrupts from the RTC, fed -by the LXFO clock. */ - -/* The slow clock used to generate the tick interrupt in the low power demo -runs at 32768/8=4096Hz. Ensure the tick rate is a multiple of the clock. */ -#define configTICK_RATE_HZ (128) - -/* The low power demo uses the tickless idle feature. */ -#define configUSE_TICKLESS_IDLE (1) -#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION (1) - -/* Hook function related definitions. */ -#define configUSE_TICK_HOOK (0) -#define configCHECK_FOR_STACK_OVERFLOW (0) -#define configUSE_MALLOC_FAILED_HOOK (0) -#define configUSE_IDLE_HOOK (1) - -#define configENERGY_MODE (sleepEM3) -#endif - -/* Main functions*/ -/* Run time stats gathering related definitions. */ -#define configGENERATE_RUN_TIME_STATS (0) - -/* Co-routine related definitions. */ -#define configUSE_CO_ROUTINES (0) -#define configMAX_CO_ROUTINE_PRIORITIES (1) - -/* Software timer related definitions. */ -#define configUSE_TIMERS (1) -#define configTIMER_TASK_PRIORITY (40) /* Highest priority */ -#define configTIMER_QUEUE_LENGTH (10) -#define configTIMER_TASK_STACK_DEPTH (1024) - -/* Interrupt priorities used by the kernel port layer itself. These are generic -to all Cortex-M ports, and do not rely on any particular library functions. */ -#define configKERNEL_INTERRUPT_PRIORITY (255) -/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! -See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ -#define configMAX_SYSCALL_INTERRUPT_PRIORITY 48 -#define configENABLE_FPU 0 -#define configENABLE_MPU 0 -/* FreeRTOS Secure Side Only and TrustZone Security Extension */ -#define configRUN_FREERTOS_SECURE_ONLY 1 -#define configENABLE_TRUSTZONE 0 -/* FreeRTOS MPU specific definitions. */ -#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS (0) - -#define configCPU_CLOCK_HZ (SystemCoreClock) -#define configUSE_PREEMPTION (1) -#define configUSE_TIME_SLICING (1) -#define configUSE_PORT_OPTIMISED_TASK_SELECTION (0) -#define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG (1) /* See into vPortSuppressTicksAndSleep source code for explanation */ -#define configMAX_PRIORITIES (56) -#define configMINIMAL_STACK_SIZE (320) /* Number of words to use for Idle and Timer stacks */ -#define configMAX_TASK_NAME_LEN (10) -#define configUSE_16_BIT_TICKS (0) -#define configIDLE_SHOULD_YIELD (1) -#define configUSE_MUTEXES (1) -#define configUSE_RECURSIVE_MUTEXES (1) -#define configUSE_COUNTING_SEMAPHORES (1) -#define configUSE_TASK_NOTIFICATIONS 1 -#define configUSE_TRACE_FACILITY 1 -#define configQUEUE_REGISTRY_SIZE (10) -#define configUSE_QUEUE_SETS (0) -#define configUSE_NEWLIB_REENTRANT (1) -#define configENABLE_BACKWARD_COMPATIBILITY (1) -#define configSUPPORT_STATIC_ALLOCATION (1) -#define configSUPPORT_DYNAMIC_ALLOCATION (1) -#define configTOTAL_HEAP_SIZE ((size_t)(20 * 1024)) - -/* Optional functions - most linkers will remove unused functions anyway. */ -#define INCLUDE_vTaskPrioritySet (1) -#define INCLUDE_uxTaskPriorityGet (1) -#define INCLUDE_vTaskDelete (1) -#define INCLUDE_vTaskSuspend (1) -#define INCLUDE_xResumeFromISR (1) -#define INCLUDE_vTaskDelayUntil (1) -#define INCLUDE_vTaskDelay (1) -#define INCLUDE_xTaskGetSchedulerState (1) -#define INCLUDE_xTaskGetCurrentTaskHandle (1) -#define INCLUDE_uxTaskGetStackHighWaterMark (1) -#define INCLUDE_xTaskGetIdleTaskHandle (1) -#define INCLUDE_xTimerGetTimerDaemonTaskHandle (1) -#define INCLUDE_pcTaskGetTaskName (1) -#define INCLUDE_eTaskGetState (1) -#define INCLUDE_xEventGroupSetBitFromISR (1) -#define INCLUDE_xEventGroupSetBitsFromISR (1) -#define INCLUDE_xSemaphoreGetMutexHolder (1) -#define INCLUDE_xTimerPendFunctionCall (1) -#define INCLUDE_xTaskGetHandle (1) - -/* Stop if an assertion fails. */ -#define configASSERT(x) \ - if ((x) == 0) \ - { \ - taskDISABLE_INTERRUPTS(); \ - printf("\nFREERTOS ASSERT ( %s )\n", #x); \ - for (;;) \ - ; \ - } -#define configASSERTNULL(x) \ - if ((x) == NULL) \ - { \ - taskDISABLE_INTERRUPTS(); \ - for (;;) \ - ; \ - } - -/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS -standard names. */ -#define vPortSVCHandler SVC_Handler -#define xPortPendSVHandler PendSV_Handler -/* Ensure Cortex-M port compatibility. */ -#define SysTick_Handler xPortSysTickHandler - -/* Thread local storage pointers used by the SDK */ -#ifndef configNUM_SDK_THREAD_LOCAL_STORAGE_POINTERS -#define configNUM_SDK_THREAD_LOCAL_STORAGE_POINTERS 0 -#endif - -#if defined(__GNUC__) -/* For the linker. */ -#define fabs __builtin_fabs -#endif - -#ifdef __cplusplus -} -#endif diff --git a/examples/ota-requestor-app/efr32/include/LightingManager.h b/examples/ota-requestor-app/efr32/include/LightingManager.h deleted file mode 100644 index 3aa9871e919074..00000000000000 --- a/examples/ota-requestor-app/efr32/include/LightingManager.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * - * Copyright (c) 2019 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 "FreeRTOS.h" -#include "timers.h" // provides FreeRTOS timer support - -#include - -class LightingManager -{ -public: - enum Action_t - { - ON_ACTION = 0, - OFF_ACTION, - - INVALID_ACTION - } Action; - - enum State_t - { - kState_OffInitiated = 0, - kState_OffCompleted, - kState_OnInitiated, - kState_OnCompleted, - } State; - - CHIP_ERROR Init(); - bool IsLightOn(); - void EnableAutoTurnOff(bool aOn); - void SetAutoTurnOffDuration(uint32_t aDurationInSecs); - bool IsActionInProgress(); - bool InitiateAction(int32_t aActor, Action_t aAction); - - typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor); - typedef void (*Callback_fn_completed)(Action_t); - void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB); - -private: - friend LightingManager & LightMgr(void); - State_t mState; - - Callback_fn_initiated mActionInitiated_CB; - Callback_fn_completed mActionCompleted_CB; - - bool mAutoTurnOff; - uint32_t mAutoTurnOffDuration; - bool mAutoTurnOffTimerArmed; - - void CancelTimer(void); - void StartTimer(uint32_t aTimeoutMs); - - static void TimerEventHandler(TimerHandle_t xTimer); - static void AutoTurnOffTimerEventHandler(AppEvent * aEvent); - static void ActuatorMovementTimerEventHandler(AppEvent * aEvent); - - static LightingManager sLight; -}; - -inline LightingManager & LightMgr(void) -{ - return LightingManager::sLight; -} diff --git a/examples/ota-requestor-app/efr32/src/AppTask.cpp b/examples/ota-requestor-app/efr32/src/AppTask.cpp deleted file mode 100644 index 6562e0bd43f0fe..00000000000000 --- a/examples/ota-requestor-app/efr32/src/AppTask.cpp +++ /dev/null @@ -1,559 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 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 "AppConfig.h" -#include "AppEvent.h" -#include "LEDWidget.h" -#ifdef DISPLAY_ENABLED -#include "lcd.h" -#ifdef QR_CODE_ENABLED -#include "qrcodegen.h" -#endif // QR_CODE_ENABLED -#endif // DISPLAY_ENABLED -#include "sl_simple_led_instances.h" -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include - -#include - -#include - -#include -#if CHIP_ENABLE_OPENTHREAD -#include -#include -#include -#endif - -#define FACTORY_RESET_TRIGGER_TIMEOUT 3000 -#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000 -#define APP_TASK_STACK_SIZE (4096) -#define APP_TASK_PRIORITY 2 -#define APP_EVENT_QUEUE_SIZE 10 -#define EXAMPLE_VENDOR_ID 0xcafe - -#define SYSTEM_STATE_LED &sl_led_led0 -#define LIGHT_LED &sl_led_led1 -#define APP_FUNCTION_BUTTON &sl_button_btn0 -#define APP_LIGHT_SWITCH &sl_button_btn1 - -namespace { -TimerHandle_t sFunctionTimer; // FreeRTOS app sw timer. - -TaskHandle_t sAppTaskHandle; -QueueHandle_t sAppEventQueue; - -LEDWidget sStatusLED; -LEDWidget sLightLED; - -bool sIsThreadProvisioned = false; -bool sIsThreadEnabled = false; -bool sHaveBLEConnections = false; - -// EmberAfIdentifyEffectIdentifier sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT; - -uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(AppEvent)]; -StaticQueue_t sAppEventQueueStruct; - -StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)]; -StaticTask_t appTaskStruct; - -} // namespace - -using namespace chip; -using namespace chip::TLV; -using namespace ::chip::Credentials; -using namespace ::chip::DeviceLayer; - -// Global OTA objects -DefaultOTARequestor gRequestorCore; -DefaultOTARequestorStorage gRequestorStorage; -DeviceLayer::DefaultOTARequestorDriver gRequestorUser; -BDXDownloader gDownloader; -OTAImageProcessorImpl gImageProcessor; - -AppTask AppTask::sAppTask; - -CHIP_ERROR AppTask::StartAppTask() -{ - sAppEventQueue = xQueueCreateStatic(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent), sAppEventQueueBuffer, &sAppEventQueueStruct); - if (sAppEventQueue == NULL) - { - EFR32_LOG("Failed to allocate app event queue"); - appError(APP_ERROR_EVENT_QUEUE_FAILED); - } - - // Start App task. - sAppTaskHandle = xTaskCreateStatic(AppTaskMain, APP_TASK_NAME, ArraySize(appStack), NULL, 1, appStack, &appTaskStruct); - return (sAppTaskHandle == nullptr) ? APP_ERROR_CREATE_TASK_FAILED : CHIP_NO_ERROR; -} - -CHIP_ERROR AppTask::Init() -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - // Init ZCL Data Model - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); - chip::Server::GetInstance().Init(initParams); - - chip::DeviceLayer::PlatformMgr().LockChipStack(); - // Initialize device attestation config - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - - // 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) - { - EFR32_LOG("funct timer create failed"); - appError(APP_ERROR_CREATE_TIMER_FAILED); - } - - EFR32_LOG("Current Software Version: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING); - err = LightMgr().Init(); - if (err != CHIP_NO_ERROR) - { - EFR32_LOG("LightMgr().Init() failed"); - appError(err); - } - - LightMgr().SetCallbacks(ActionInitiated, ActionCompleted); - - // Initialize LEDs - LEDWidget::InitGpio(); - sStatusLED.Init(SYSTEM_STATE_LED); - sLightLED.Init(LIGHT_LED); - sLightLED.Set(LightMgr().IsLightOn()); - UpdateClusterState(); - - ConfigurationMgr().LogDeviceConfig(); - -// Print setup info on LCD if available -#ifdef QR_CODE_ENABLED - // Create buffer for QR code that can fit max size and null terminator. - char qrCodeBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1]; - chip::MutableCharSpan QRCode(qrCodeBuffer); - - if (GetQRCode(QRCode, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)) == CHIP_NO_ERROR) - { - LCDWriteQRCode((uint8_t *) QRCode.data()); - } - else - { - EFR32_LOG("Getting QR code failed!"); - } -#else - PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE)); -#endif // QR_CODE_ENABLED - - // Initialize OTA components - InitOTARequestor(); - - return err; -} - -void AppTask::AppTaskMain(void * pvParameter) -{ - AppEvent event; - - CHIP_ERROR err = sAppTask.Init(); - if (err != CHIP_NO_ERROR) - { - EFR32_LOG("AppTask.Init() failed"); - appError(err); - } - - EFR32_LOG("App Task started"); - - 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(); - } -} - -void AppTask::LightActionEventHandler(AppEvent * aEvent) -{ - bool initiated = false; - LightingManager::Action_t action; - int32_t actor; - CHIP_ERROR err = CHIP_NO_ERROR; - - if (aEvent->Type == AppEvent::kEventType_Light) - { - action = static_cast(aEvent->LightEvent.Action); - actor = aEvent->LightEvent.Actor; - } - else if (aEvent->Type == AppEvent::kEventType_Button) - { - if (LightMgr().IsLightOn()) - { - action = LightingManager::OFF_ACTION; - } - else - { - action = LightingManager::ON_ACTION; - } - actor = AppEvent::kEventType_Button; - } - else - { - err = APP_ERROR_UNHANDLED_EVENT; - } - - if (err == CHIP_NO_ERROR) - { - initiated = LightMgr().InitiateAction(actor, action); - - if (!initiated) - { - EFR32_LOG("Action is already in progress or active."); - } - } -} - -void AppTask::ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction) -{ - if (buttonHandle == NULL) - { - return; - } - - AppEvent button_event = {}; - button_event.Type = AppEvent::kEventType_Button; - button_event.ButtonEvent.Action = btnAction; - - if (buttonHandle == APP_LIGHT_SWITCH && btnAction == SL_SIMPLE_BUTTON_PRESSED) - { - button_event.Handler = LightActionEventHandler; - sAppTask.PostEvent(&button_event); - } - else if (buttonHandle == APP_FUNCTION_BUTTON) - { - button_event.Handler = FunctionHandler; - sAppTask.PostEvent(&button_event); - } -} - -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; - } - - // If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT, - // initiate factory reset - if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartBleAdv) - { - EFR32_LOG("Factory Reset Triggered. Release button within %ums to cancel.", FACTORY_RESET_CANCEL_WINDOW_TIMEOUT); - - // Start timer for FACTORY_RESET_CANCEL_WINDOW_TIMEOUT to allow user to - // cancel, if required. - sAppTask.StartTimer(FACTORY_RESET_CANCEL_WINDOW_TIMEOUT); - - sAppTask.mFunction = kFunction_FactoryReset; - - // Turn off all LEDs before starting blink to make sure blink is - // co-ordinated. - sStatusLED.Set(false); - - sStatusLED.Blink(500); - } - else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset) - { - // Actually trigger Factory Reset - sAppTask.mFunction = kFunction_NoneSelected; - chip::Server::GetInstance().ScheduleFactoryReset(); - } -} - -void AppTask::FunctionHandler(AppEvent * aEvent) -{ - // To trigger software update: press the APP_FUNCTION_BUTTON button briefly (< - // FACTORY_RESET_TRIGGER_TIMEOUT) To initiate factory reset: press the - // APP_FUNCTION_BUTTON for FACTORY_RESET_TRIGGER_TIMEOUT + - // FACTORY_RESET_CANCEL_WINDOW_TIMEOUT All LEDs start blinking after - // FACTORY_RESET_TRIGGER_TIMEOUT to signal factory reset has been initiated. - // To cancel factory reset: release the APP_FUNCTION_BUTTON once all LEDs - // start blinking within the FACTORY_RESET_CANCEL_WINDOW_TIMEOUT - if (aEvent->ButtonEvent.Action == SL_SIMPLE_BUTTON_PRESSED) - { - if (!sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_NoneSelected) - { - sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT); - sAppTask.mFunction = kFunction_StartBleAdv; - } - } - else - { - // If the button was released before factory reset got initiated, start BLE advertissement in fast mode - if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartBleAdv) - { - sAppTask.CancelTimer(); - sAppTask.mFunction = kFunction_NoneSelected; - - if (!ConnectivityMgr().IsThreadProvisioned()) - { - // Enable BLE advertisements - ConnectivityMgr().SetBLEAdvertisingEnabled(true); - ConnectivityMgr().SetBLEAdvertisingMode(ConnectivityMgr().kFastAdvertising); - } - else - { - EFR32_LOG("Network is already provisioned, Ble advertissement not enabled"); - } - } - else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset) - { - sAppTask.CancelTimer(); - - // Change the function to none selected since factory reset has been - // canceled. - sAppTask.mFunction = kFunction_NoneSelected; - - EFR32_LOG("Factory Reset has been Canceled"); - } - } -} - -void AppTask::CancelTimer() -{ - if (xTimerStop(sFunctionTimer, 0) == pdFAIL) - { - EFR32_LOG("app timer stop() failed"); - appError(APP_ERROR_STOP_TIMER_FAILED); - } - - mFunctionTimerActive = false; -} - -void AppTask::StartTimer(uint32_t aTimeoutInMs) -{ - if (xTimerIsTimerActive(sFunctionTimer)) - { - EFR32_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) - { - EFR32_LOG("app timer start() failed"); - appError(APP_ERROR_START_TIMER_FAILED); - } - - mFunctionTimerActive = true; -} - -void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor) -{ - // Action initiated, update the light led - if (aAction == LightingManager::ON_ACTION) - { - EFR32_LOG("Turning light ON") - } - else if (aAction == LightingManager::OFF_ACTION) - { - EFR32_LOG("Turning light OFF") - } - - if (aActor == AppEvent::kEventType_Button) - { - sAppTask.mSyncClusterToButtonAction = true; - } -} - -void AppTask::ActionCompleted(LightingManager::Action_t aAction) -{ - // action has been completed bon the light - if (aAction == LightingManager::ON_ACTION) - { - EFR32_LOG("Light ON") - } - else if (aAction == LightingManager::OFF_ACTION) - { - EFR32_LOG("Light OFF") - } - - if (sAppTask.mSyncClusterToButtonAction) - { - UpdateClusterState(); - sAppTask.mSyncClusterToButtonAction = false; - } -} - -void AppTask::PostLightActionRequest(int32_t aActor, LightingManager::Action_t aAction) -{ - AppEvent event; - event.Type = AppEvent::kEventType_Light; - event.LightEvent.Actor = aActor; - event.LightEvent.Action = aAction; - event.Handler = LightActionEventHandler; - PostEvent(&event); -} - -void AppTask::PostEvent(const AppEvent * aEvent) -{ - if (sAppEventQueue != NULL) - { - BaseType_t status; - if (xPortIsInsideInterrupt()) - { - BaseType_t higherPrioTaskWoken = pdFALSE; - status = xQueueSendFromISR(sAppEventQueue, aEvent, &higherPrioTaskWoken); - -#ifdef portYIELD_FROM_ISR - portYIELD_FROM_ISR(higherPrioTaskWoken); -#elif portEND_SWITCHING_ISR // portYIELD_FROM_ISR or portEND_SWITCHING_ISR - portEND_SWITCHING_ISR(higherPrioTaskWoken); -#else // portYIELD_FROM_ISR or portEND_SWITCHING_ISR -#error "Must have portYIELD_FROM_ISR or portEND_SWITCHING_ISR" -#endif // portYIELD_FROM_ISR or portEND_SWITCHING_ISR - } - else - { - status = xQueueSend(sAppEventQueue, aEvent, 1); - } - - if (!status) - EFR32_LOG("Failed to post event to app task event queue"); - } - else - { - EFR32_LOG("Event Queue is NULL should never happen"); - } -} - -void AppTask::DispatchEvent(AppEvent * aEvent) -{ - if (aEvent->Handler) - { - aEvent->Handler(aEvent); - } - else - { - EFR32_LOG("Event received with no handler. Dropping event."); - } -} - -void AppTask::UpdateClusterState(void) {} - -void AppTask::InitOTARequestor() -{ - - // Initialize and interconnect the Requestor and Image Processor objects -- START - SetRequestorInstance(&gRequestorCore); - - gRequestorStorage.Init(chip::Server::GetInstance().GetPersistentStorage()); - gRequestorCore.Init(chip::Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader); - - gRequestorUser.Init(&gRequestorCore, &gImageProcessor); - - gImageProcessor.SetOTAImageFile("test.txt"); - gImageProcessor.SetOTADownloader(&gDownloader); - - // Connect the Downloader and Image Processor objects - gDownloader.SetImageProcessorDelegate(&gImageProcessor); - // Initialize and interconnect the Requestor and Image Processor objects -- END -} diff --git a/examples/ota-requestor-app/efr32/src/LightingManager.cpp b/examples/ota-requestor-app/efr32/src/LightingManager.cpp deleted file mode 100644 index 7b206fd1ab6f37..00000000000000 --- a/examples/ota-requestor-app/efr32/src/LightingManager.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 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 "LightingManager.h" - -#include "AppConfig.h" -#include "AppTask.h" -#include - -LightingManager LightingManager::sLight; - -TimerHandle_t sLightTimer; - -CHIP_ERROR LightingManager::Init() -{ - // Create FreeRTOS sw timer for light timer. - sLightTimer = xTimerCreate("lightTmr", // 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 = light obj context - TimerEventHandler // timer callback handler - ); - - if (sLightTimer == NULL) - { - EFR32_LOG("sLightTimer timer create failed"); - return APP_ERROR_CREATE_TIMER_FAILED; - } - - mState = kState_OffCompleted; - mAutoTurnOffTimerArmed = false; - mAutoTurnOff = false; - mAutoTurnOffDuration = 0; - - return CHIP_NO_ERROR; -} - -void LightingManager::SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB) -{ - mActionInitiated_CB = aActionInitiated_CB; - mActionCompleted_CB = aActionCompleted_CB; -} - -bool LightingManager::IsActionInProgress() -{ - return (mState == kState_OffInitiated || mState == kState_OnInitiated); -} - -bool LightingManager::IsLightOn() -{ - return (mState == kState_OnCompleted); -} - -void LightingManager::EnableAutoTurnOff(bool aOn) -{ - mAutoTurnOff = aOn; -} - -void LightingManager::SetAutoTurnOffDuration(uint32_t aDurationInSecs) -{ - mAutoTurnOffDuration = aDurationInSecs; -} - -bool LightingManager::InitiateAction(int32_t aActor, Action_t aAction) -{ - bool action_initiated = false; - State_t new_state; - - // Initiate Turn On/Off Action only when the previous one is complete. - if (mState == kState_OffCompleted && aAction == ON_ACTION) - { - action_initiated = true; - - new_state = kState_OnInitiated; - } - else if (mState == kState_OnCompleted && aAction == OFF_ACTION) - { - action_initiated = true; - - new_state = kState_OffInitiated; - } - - if (action_initiated) - { - if (mAutoTurnOffTimerArmed && new_state == kState_OffInitiated) - { - // If auto turn off timer has been armed and someone initiates turning off, - // cancel the timer and continue as normal. - mAutoTurnOffTimerArmed = false; - - CancelTimer(); - } - - StartTimer(ACTUATOR_MOVEMENT_PERIOS_MS); - - // Since the timer started successfully, update the state and trigger callback - mState = new_state; - - if (mActionInitiated_CB) - { - mActionInitiated_CB(aAction, aActor); - } - } - - return action_initiated; -} - -void LightingManager::StartTimer(uint32_t aTimeoutMs) -{ - if (xTimerIsTimerActive(sLightTimer)) - { - EFR32_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(sLightTimer, (aTimeoutMs / portTICK_PERIOD_MS), 100) != pdPASS) - { - EFR32_LOG("sLightTimer timer start() failed"); - appError(APP_ERROR_START_TIMER_FAILED); - } -} - -void LightingManager::CancelTimer(void) -{ - if (xTimerStop(sLightTimer, 0) == pdFAIL) - { - EFR32_LOG("sLightTimer stop() failed"); - appError(APP_ERROR_STOP_TIMER_FAILED); - } -} - -void LightingManager::TimerEventHandler(TimerHandle_t xTimer) -{ - // Get light obj context from timer id. - LightingManager * light = static_cast(pvTimerGetTimerID(xTimer)); - - // The timer event handler will be called in the context of the timer task - // once sLightTimer expires. Post an event to apptask queue with the actual handler - // so that the event can be handled in the context of the apptask. - AppEvent event; - event.Type = AppEvent::kEventType_Timer; - event.TimerEvent.Context = light; - if (light->mAutoTurnOffTimerArmed) - { - event.Handler = AutoTurnOffTimerEventHandler; - } - else - { - event.Handler = ActuatorMovementTimerEventHandler; - } - GetAppTask().PostEvent(&event); -} - -void LightingManager::AutoTurnOffTimerEventHandler(AppEvent * aEvent) -{ - LightingManager * light = static_cast(aEvent->TimerEvent.Context); - int32_t actor = 0; - - // Make sure auto turn off timer is still armed. - if (!light->mAutoTurnOffTimerArmed) - { - return; - } - - light->mAutoTurnOffTimerArmed = false; - - EFR32_LOG("Auto Turn Off has been triggered!"); - - light->InitiateAction(actor, OFF_ACTION); -} - -void LightingManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent) -{ - Action_t actionCompleted = INVALID_ACTION; - - LightingManager * light = static_cast(aEvent->TimerEvent.Context); - - if (light->mState == kState_OffInitiated) - { - light->mState = kState_OffCompleted; - actionCompleted = OFF_ACTION; - } - else if (light->mState == kState_OnInitiated) - { - light->mState = kState_OnCompleted; - actionCompleted = ON_ACTION; - } - - if (actionCompleted != INVALID_ACTION) - { - if (light->mActionCompleted_CB) - { - light->mActionCompleted_CB(actionCompleted); - } - - if (light->mAutoTurnOff && actionCompleted == ON_ACTION) - { - // Start the timer for auto turn off - light->StartTimer(light->mAutoTurnOffDuration * 1000); - - light->mAutoTurnOffTimerArmed = true; - - EFR32_LOG("Auto Turn off enabled. Will be triggered in %u seconds", light->mAutoTurnOffDuration); - } - } -} diff --git a/examples/ota-requestor-app/efr32/src/ZclCallbacks.cpp b/examples/ota-requestor-app/efr32/src/ZclCallbacks.cpp deleted file mode 100644 index cfbcbc8a191411..00000000000000 --- a/examples/ota-requestor-app/efr32/src/ZclCallbacks.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * - * 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. - */ - -/** - * @file - * This file implements the handler for data model messages. - */ - -#include "AppConfig.h" -#include "LightingManager.h" - -#include -#include -#include -#include - -using namespace ::chip; -using namespace ::chip::app::Clusters; - -void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, - uint8_t * value) -{ - ClusterId clusterId = attributePath.mClusterId; - AttributeId attributeId = attributePath.mAttributeId; - ChipLogProgress(Zcl, "Cluster callback: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); - - if (clusterId == OnOff::Id && attributeId == OnOff::Attributes::OnOff::Id) - { - LightMgr().InitiateAction(AppEvent::kEventType_Light, *value ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION); - } - else if (clusterId == LevelControl::Id) - { - ChipLogProgress(Zcl, "Level Control attribute ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u", - ChipLogValueMEI(attributeId), type, *value, size); - - // WIP Apply attribute change to Light - } - else if (clusterId == ColorControl::Id) - { - ChipLogProgress(Zcl, "Color Control attribute ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u", - ChipLogValueMEI(attributeId), type, *value, size); - - // WIP Apply attribute change to Light - } - else if (clusterId == OnOffSwitchConfiguration::Id) - { - ChipLogProgress(Zcl, "OnOff Switch Configuration attribute ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u", - ChipLogValueMEI(attributeId), type, *value, size); - - // WIP Apply attribute change to Light - } - else if (clusterId == Identify::Id) - { - ChipLogProgress(Zcl, "Identify attribute ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u", - ChipLogValueMEI(attributeId), type, *value, size); - } -} - -/** @brief OnOff Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * - * TODO Issue #3841 - * emberAfOnOffClusterInitCallback happens before the stack initialize the cluster - * attributes to the default value. - * The logic here expects something similar to the deprecated Plugins callback - * emberAfPluginOnOffClusterServerPostInitCallback. - * - */ -void emberAfOnOffClusterInitCallback(EndpointId endpoint) -{ - // TODO: implement any additional Cluster Server init actions -} diff --git a/examples/ota-requestor-app/efr32/src/main.cpp b/examples/ota-requestor-app/efr32/src/main.cpp deleted file mode 100644 index b193b31aae3ac1..00000000000000 --- a/examples/ota-requestor-app/efr32/src/main.cpp +++ /dev/null @@ -1,247 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 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 -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -#include - -#include "AppConfig.h" -#include "init_efrPlatform.h" -#include "sl_simple_button_instances.h" -#include "sl_system_kernel.h" -#include - -#ifdef HEAP_MONITORING -#include "MemMonitoring.h" -#endif - -#if DISPLAY_ENABLED -#include "lcd.h" -#endif - -#if CHIP_ENABLE_OPENTHREAD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#endif // CHIP_ENABLE_OPENTHREAD - -#if PW_RPC_ENABLED -#include "Rpc.h" -#endif - -#ifdef ENABLE_CHIP_SHELL -#include "matter_shell.h" -#endif - -using namespace ::chip; -using namespace ::chip::Inet; -using namespace ::chip::DeviceLayer; - -#define UNUSED_PARAMETER(a) (a = a) - -volatile int apperror_cnt; - -#include "platform/bootloader/api/application_properties.h" - -// Header used for building the image GBL file -#define APP_PROPERTIES_VERSION 1 -#define APP_PROPERTIES_ID \ - { \ - 0 \ - } - -__attribute__((used)) ApplicationProperties_t sl_app_properties = { - /// @brief Magic value indicating that this is an ApplicationProperties_t - /// Must equal @ref APPLICATION_PROPERTIES_MAGIC - .magic = APPLICATION_PROPERTIES_MAGIC, - - /// Version number of this struct - .structVersion = APPLICATION_PROPERTIES_VERSION, - - /// Type of signature this application is signed with - .signatureType = APPLICATION_SIGNATURE_NONE, - - /// Location of the signature. Typically a pointer to the end of application - .signatureLocation = 0, - - /// Information about the application - .app = { - - /// Bitfield representing type of application - /// e.g. @ref APPLICATION_TYPE_BLUETOOTH_APP - .type = APPLICATION_TYPE_THREAD, - - /// Version number for this application - .version = APP_PROPERTIES_VERSION, - - /// Capabilities of this application - .capabilities = 0, - - /// Unique ID (e.g. UUID/GUID) for the product this application is built for - .productId = APP_PROPERTIES_ID, - }, -}; - -// ================================================================================ -// App Error -//================================================================================= -void appError(int err) -{ - EFR32_LOG("!!!!!!!!!!!! App Critical Error: %d !!!!!!!!!!!", err); - portDISABLE_INTERRUPTS(); - while (1) - ; -} - -void appError(CHIP_ERROR error) -{ - appError(static_cast(error.AsInteger())); -} - -// ================================================================================ -// FreeRTOS Callbacks -// ================================================================================ -extern "C" void vApplicationIdleHook(void) -{ - // FreeRTOS Idle callback - - // Check CHIP Config nvm3 and repack flash if necessary. - Internal::EFR32Config::RepackNvm3Flash(); -} - -// ================================================================================ -// Main Code -// ================================================================================ -int main(void) -{ - init_efrPlatform(); - mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree); - -#if PW_RPC_ENABLED - chip::rpc::Init(); -#endif - -#ifdef HEAP_MONITORING - MemMonitoring::startHeapMonitoring(); -#endif - - EFR32_LOG("=================================================="); - EFR32_LOG("chip-efr32-ota-requestor-example starting"); - EFR32_LOG("=================================================="); - - EFR32_LOG("Init CHIP Stack"); - // Init Chip memory management before the stack - chip::Platform::MemoryInit(); - - CHIP_ERROR ret = PlatformMgr().InitChipStack(); - if (ret != CHIP_NO_ERROR) - { - EFR32_LOG("PlatformMgr().InitChipStack() failed"); - appError(ret); - } - chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName("EFR32_OTA_REQUESTOR"); -#if CHIP_ENABLE_OPENTHREAD - EFR32_LOG("Initializing OpenThread stack"); - ret = ThreadStackMgr().InitThreadStack(); - if (ret != CHIP_NO_ERROR) - { - EFR32_LOG("ThreadStackMgr().InitThreadStack() failed"); - appError(ret); - } - -#if CHIP_DEVICE_CONFIG_THREAD_FTD - ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router); -#else - ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice); -#endif // CHIP_DEVICE_CONFIG_THREAD_FTD - - if (ret != CHIP_NO_ERROR) - { - EFR32_LOG("ConnectivityMgr().SetThreadDeviceType() failed"); - appError(ret); - } -#endif // CHIP_ENABLE_OPENTHREAD - - EFR32_LOG("Starting Platform Manager Event Loop"); - ret = PlatformMgr().StartEventLoopTask(); - if (ret != CHIP_NO_ERROR) - { - EFR32_LOG("PlatformMgr().StartEventLoopTask() failed"); - appError(ret); - } - -#if CHIP_ENABLE_OPENTHREAD - EFR32_LOG("Starting OpenThread task"); - - // Start OpenThread task - ret = ThreadStackMgrImpl().StartThreadTask(); - if (ret != CHIP_NO_ERROR) - { - EFR32_LOG("ThreadStackMgr().StartThreadTask() failed"); - appError(ret); - } -#endif // CHIP_ENABLE_OPENTHREAD - - EFR32_LOG("Starting App Task"); - ret = GetAppTask().StartAppTask(); - if (ret != CHIP_NO_ERROR) - { - EFR32_LOG("GetAppTask().Init() failed"); - appError(ret); - } - -#ifdef ENABLE_CHIP_SHELL - chip::startShellTask(); -#endif - - EFR32_LOG("Starting FreeRTOS scheduler"); - sl_system_kernel_start(); - - chip::Platform::MemoryShutdown(); - - // Should never get here. - EFR32_LOG("vTaskStartScheduler() failed"); - appError(ret); -} - -void sl_button_on_change(const sl_button_t * handle) -{ - GetAppTask().ButtonEventHandler(handle, sl_button_get_state(handle)); -} diff --git a/examples/ota-requestor-app/efr32/third_party/connectedhomeip b/examples/ota-requestor-app/efr32/third_party/connectedhomeip deleted file mode 120000 index c866b86874994d..00000000000000 --- a/examples/ota-requestor-app/efr32/third_party/connectedhomeip +++ /dev/null @@ -1 +0,0 @@ -../../../.. \ No newline at end of file diff --git a/examples/ota-requestor-app/efr32/with_pw_rpc.gni b/examples/ota-requestor-app/efr32/with_pw_rpc.gni deleted file mode 100644 index d0a8f2c0485f06..00000000000000 --- a/examples/ota-requestor-app/efr32/with_pw_rpc.gni +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2021 Project CHIP Authors -# -# 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. - -# add this gni as import in your build args to use pigweed in the example -# 'import("//with_pw_rpc.gni")' - -import("//build_overrides/chip.gni") -import("${chip_root}/config/efr32/lib/pw_rpc/pw_rpc.gni") -import("${chip_root}/examples/platform/efr32/args.gni") - -efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain") - -chip_enable_pw_rpc = true -chip_enable_openthread = true -chip_openthread_ftd = true - -cpp_standard = "gnu++17" diff --git a/examples/platform/efr32/OTAConfig.h b/examples/platform/efr32/OTAConfig.h index 6e5be37c389fec..afc0f57d702ae4 100644 --- a/examples/platform/efr32/OTAConfig.h +++ b/examples/platform/efr32/OTAConfig.h @@ -30,4 +30,5 @@ class OTAConfig OTAConfig(){}; static void Init(); + static constexpr uint32_t kInitOTARequestorDelaySec = 3; }; diff --git a/examples/platform/efr32/matter_config.cpp b/examples/platform/efr32/matter_config.cpp index b892620acf3b9f..876d0ce58a7959 100644 --- a/examples/platform/efr32/matter_config.cpp +++ b/examples/platform/efr32/matter_config.cpp @@ -95,6 +95,25 @@ CHIP_ERROR EFR32MatterConfig::InitOpenThread(void) } #endif // CHIP_ENABLE_OPENTHREAD +void EFR32MatterConfig::InitOTARequestorHandler(System::Layer * systemLayer, void * appState) +{ + OTAConfig::Init(); +} + +void EFR32MatterConfig::ConnectivityEventCallback(const ChipDeviceEvent * event, intptr_t arg) +{ + // Initialize OTA only when Thread or WiFi connectivity is established + if (((event->Type == DeviceEventType::kThreadConnectivityChange) && + (event->ThreadConnectivityChange.Result == kConnectivity_Established)) || + ((event->Type == DeviceEventType::kInternetConnectivityChange) && + (event->InternetConnectivityChange.IPv6 == kConnectivity_Established))) + { + EFR32_LOG("Scheduling OTA Requestor initialization") + chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(OTAConfig::kInitOTARequestorDelaySec), + InitOTARequestorHandler, nullptr); + } +} + CHIP_ERROR EFR32MatterConfig::InitMatter(const char * appName) { mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree); @@ -139,16 +158,15 @@ CHIP_ERROR EFR32MatterConfig::InitMatter(const char * appName) chip::Server::GetInstance().Init(initParams); chip::DeviceLayer::PlatformMgr().UnlockChipStack(); + // OTA Requestor initialization will be triggered by the connectivity events + PlatformMgr().AddEventHandler(ConnectivityEventCallback, reinterpret_cast(nullptr)); + EFR32_LOG("Starting Platform Manager Event Loop"); ReturnErrorOnFailure(PlatformMgr().StartEventLoopTask()); #ifdef SL_WIFI InitWiFi(); #endif - // Init Matter OTA - chip::DeviceLayer::PlatformMgr().LockChipStack(); - OTAConfig::Init(); - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); #ifdef ENABLE_CHIP_SHELL chip::startShellTask(); diff --git a/examples/platform/efr32/matter_config.h b/examples/platform/efr32/matter_config.h index 067343c1443716..e0af60356becf9 100644 --- a/examples/platform/efr32/matter_config.h +++ b/examples/platform/efr32/matter_config.h @@ -30,4 +30,6 @@ class EFR32MatterConfig private: static CHIP_ERROR InitOpenThread(void); static void InitWiFi(void); + static void ConnectivityEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); + static void InitOTARequestorHandler(chip::System::Layer * systemLayer, void * appState); };