Skip to content

Commit

Permalink
[EFR32] Cleanup EFR32 Examples (#18054)
Browse files Browse the repository at this point in the history
* Cleanup EFR32 Examples
  • Loading branch information
jepenven-silabs authored and pull[bot] committed Sep 12, 2023
1 parent a2eb38c commit 3546123
Show file tree
Hide file tree
Showing 27 changed files with 361 additions and 1,594 deletions.
4 changes: 3 additions & 1 deletion examples/light-switch-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ if (chip_enable_wifi) {
efr32_sdk("sdk") {
sources = [
"${efr32_project_dir}/include/CHIPProjectConfig.h",
"${efr32_project_dir}/include/FreeRTOSConfig.h",
"${examples_plat_dir}/FreeRTOSConfig.h",
]

include_dirs = [
Expand Down Expand Up @@ -161,8 +161,10 @@ efr32_executable("light_switch_app") {

sources = [
"${examples_plat_dir}/LEDWidget.cpp",
"${examples_plat_dir}/efr32_utils.cpp",
"${examples_plat_dir}/heap_4_silabs.c",
"${examples_plat_dir}/init_efrPlatform.cpp",
"${examples_plat_dir}/matter_config.cpp",
"src/AppTask.cpp",
"src/LightingManager.cpp",
"src/ZclCallbacks.cpp",
Expand Down
2 changes: 2 additions & 0 deletions examples/light-switch-app/efr32/build_for_wifi_args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain")
chip_enable_openthread = false
import("${chip_root}/src/platform/EFR32/wifi_args.gni")

chip_enable_ota_requestor = true

pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip"
pw_assert_BACKEND = "$dir_pw_assert_log"
209 changes: 7 additions & 202 deletions examples/light-switch-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,13 @@
* limitations under the License.
*/

#include <stdio.h>
#include <stdlib.h>

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>

#include <FreeRTOS.h>
#include <mbedtls/threading.h>

#include <lib/support/CHIPMem.h>
#include <lib/support/CHIPPlatformMemory.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/KeyValueStoreManager.h>

#include <AppTask.h>

#include "AppConfig.h"
#include "init_efrPlatform.h"
#include "sl_simple_button_instances.h"
#include "sl_system_kernel.h"
#include <app/server/Server.h>

#ifdef HEAP_MONITORING
#include "MemMonitoring.h"
#endif

#if DISPLAY_ENABLED
#include "lcd.h"
#endif

#include <mbedtls/platform.h>
#if CHIP_ENABLE_OPENTHREAD
#include <inet/EndPointStateOpenThread.h>
#include <openthread/cli.h>
#include <openthread/dataset.h>
#include <openthread/error.h>
#include <openthread/heap.h>
#include <openthread/icmp6.h>
#include <openthread/instance.h>
#include <openthread/link.h>
#include <openthread/platform/openthread-system.h>
#include <openthread/tasklet.h>
#include <openthread/thread.h>
#endif // CHIP_ENABLE_OPENTHREAD

#if defined(RS911X_WIFI) || defined(WF200_WIFI)
#include "wfx_host_events.h"
#endif /* RS911X_WIFI */

#if PW_RPC_ENABLED
#include "Rpc.h"
#endif

#ifdef ENABLE_CHIP_SHELL
#include "matter_shell.h"
#endif
#include <matter_config.h>

#define BLE_DEV_NAME "SiLabs-Light-Switch"
using namespace ::chip;
Expand All @@ -84,170 +34,25 @@ using namespace ::chip::DeviceLayer;

volatile int apperror_cnt;
// ================================================================================
// 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<int>(error.AsInteger()));
}

// ================================================================================
// FreeRTOS Callbacks
// ================================================================================
extern "C" void vApplicationIdleHook(void)
{
// FreeRTOS Idle callback

// Check CHIP Config nvm3 and repack flash if necessary.
Internal::EFR32Config::RepackNvm3Flash();
}
#if CHIP_ENABLE_OPENTHREAD
// ================================================================================
// Matter Networking Callbacks
// ================================================================================
void LockOpenThreadTask(void)
{
chip::DeviceLayer::ThreadStackMgr().LockThreadStack();
}

void UnlockOpenThreadTask(void)
{
chip::DeviceLayer::ThreadStackMgr().UnlockThreadStack();
}
#endif
// ================================================================================
// 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-light-switch-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(BLE_DEV_NAME);
#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 // CHIP_DEVICE_CONFIG_THREAD_FTD
#if CHIP_DEVICE_CONFIG_ENABLE_SED
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice);
#else // CHIP_DEVICE_CONFIG_ENABLE_SED
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
#endif // CHIP_DEVICE_CONFIG_THREAD_FTD
if (ret != CHIP_NO_ERROR)
{
EFR32_LOG("ConnectivityMgr().SetThreadDeviceType() failed");
appError(ret);
}
#endif // CHIP_ENABLE_OPENTHREAD

chip::DeviceLayer::PlatformMgr().LockChipStack();
// Init ZCL Data Model
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
#if CHIP_ENABLE_OPENTHREAD
chip::Inet::EndPointStateOpenThread::OpenThreadEndpointInitParam nativeParams;
nativeParams.lockCb = LockOpenThreadTask;
nativeParams.unlockCb = UnlockOpenThreadTask;
nativeParams.openThreadInstancePtr = chip::DeviceLayer::ThreadStackMgrImpl().OTInstance();
initParams.endpointNativeParams = static_cast<void *>(&nativeParams);
#endif
chip::Server::GetInstance().Init(initParams);
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

EFR32_LOG("Starting Platform Manager Event Loop");
ret = PlatformMgr().StartEventLoopTask();
if (ret != CHIP_NO_ERROR)
{
EFR32_LOG("PlatformMgr().StartEventLoopTask() failed");
appError(ret);
}

#ifdef WF200_WIFI
// Start wfx bus communication task.
wfx_bus_start();
#ifdef SL_WFX_USE_SECURE_LINK
wfx_securelink_task_start(); // start securelink key renegotiation task
#endif // SL_WFX_USE_SECURE_LINK
#endif /* WF200_WIFI */

#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
#ifdef RS911X_WIFI
/*
* Start up any RSI interface stuff
* (Not required) - Note that wfx_wifi_start will deal with
* starting up a rsi task - which will initialize the SPI interface.
*/
#endif
if (EFR32MatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR)
appError(CHIP_ERROR_INTERNAL);

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
if (GetAppTask().StartAppTask() != CHIP_NO_ERROR)
appError(CHIP_ERROR_INTERNAL);

EFR32_LOG("Starting FreeRTOS scheduler");
sl_system_kernel_start();

chip::Platform::MemoryShutdown();

// Should never get here.
chip::Platform::MemoryShutdown();
EFR32_LOG("vTaskStartScheduler() failed");
appError(ret);
appError(CHIP_ERROR_INTERNAL);
}

void sl_button_on_change(const sl_button_t * handle)
Expand Down
4 changes: 3 additions & 1 deletion examples/lighting-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ if (chip_enable_wifi) {
efr32_sdk("sdk") {
sources = [
"${efr32_project_dir}/include/CHIPProjectConfig.h",
"${efr32_project_dir}/include/FreeRTOSConfig.h",
"${examples_plat_dir}/FreeRTOSConfig.h",
]

include_dirs = [
Expand Down Expand Up @@ -161,8 +161,10 @@ efr32_executable("lighting_app") {

sources = [
"${examples_plat_dir}/LEDWidget.cpp",
"${examples_plat_dir}/efr32_utils.cpp",
"${examples_plat_dir}/heap_4_silabs.c",
"${examples_plat_dir}/init_efrPlatform.cpp",
"${examples_plat_dir}/matter_config.cpp",
"src/AppTask.cpp",
"src/LightingManager.cpp",
"src/ZclCallbacks.cpp",
Expand Down
2 changes: 2 additions & 0 deletions examples/lighting-app/efr32/build_for_wifi_args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain")
chip_enable_openthread = false
import("${chip_root}/src/platform/EFR32/wifi_args.gni")

chip_enable_ota_requestor = true

pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip"
pw_assert_BACKEND = "$dir_pw_assert_log"
20 changes: 2 additions & 18 deletions examples/lighting-app/efr32/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,12 @@

#pragma once

#include "efr32_utils.h"

// ---- Lighting Example App Config ----

#define APP_TASK_NAME "Lit"

// 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 <lib/core/CHIPError.h>
void appError(CHIP_ERROR error);
#endif
Loading

0 comments on commit 3546123

Please sign in to comment.