Skip to content

Commit

Permalink
Add support for matter cli in EFR32 example apps (#12749)
Browse files Browse the repository at this point in the history
* Support matter shell in all efr32 example apps

* add source set and start task for other examples

* add shell_common example cmds

* restyle
  • Loading branch information
jmartinez-silabs authored Dec 9, 2021
1 parent bba082b commit a583812
Show file tree
Hide file tree
Showing 17 changed files with 397 additions and 42 deletions.
3 changes: 2 additions & 1 deletion examples/lighting-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ efr32_executable("lighting_app") {
"${examples_plat_dir}/LEDWidget.cpp",
"${examples_plat_dir}/heap_4_silabs.c",
"${examples_plat_dir}/init_efrPlatform.cpp",
"${examples_plat_dir}/uart.c",
"${examples_plat_dir}/uart.cpp",
"src/AppTask.cpp",
"src/LightingManager.cpp",
"src/ZclCallbacks.cpp",
Expand All @@ -101,6 +101,7 @@ efr32_executable("lighting_app") {
"${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils",
"${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd",
"${chip_root}/third_party/openthread/repo:libopenthread-ftd",
"${examples_plat_dir}:efr-matter-shell",
]

include_dirs = [ "include" ]
Expand Down
8 changes: 8 additions & 0 deletions examples/lighting-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
#include "Rpc.h"
#endif

#ifdef ENABLE_CHIP_SHELL
#include "matter_shell.h"
#endif

using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::DeviceLayer;
Expand Down Expand Up @@ -177,6 +181,10 @@ int main(void)
appError(ret);
}

#ifdef ENABLE_CHIP_SHELL
chip::startShellTask();
#endif

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

Expand Down
3 changes: 2 additions & 1 deletion examples/lock-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ efr32_executable("lock_app") {
"${examples_plat_dir}/LEDWidget.cpp",
"${examples_plat_dir}/heap_4_silabs.c",
"${examples_plat_dir}/init_efrPlatform.cpp",
"${examples_plat_dir}/uart.c",
"${examples_plat_dir}/uart.cpp",
"src/AppTask.cpp",
"src/BoltLockManager.cpp",
"src/ZclCallbacks.cpp",
Expand All @@ -98,6 +98,7 @@ efr32_executable("lock_app") {
"${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils",
"${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd",
"${chip_root}/third_party/openthread/repo:libopenthread-ftd",
"${examples_plat_dir}:efr-matter-shell",
]

include_dirs = [ "include" ]
Expand Down
8 changes: 8 additions & 0 deletions examples/lock-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
#include "Rpc.h"
#endif

#ifdef ENABLE_CHIP_SHELL
#include "matter_shell.h"
#endif

#if CHIP_ENABLE_OPENTHREAD
#include <mbedtls/platform.h>
#include <openthread/cli.h>
Expand Down Expand Up @@ -174,6 +178,10 @@ int main(void)
appError(ret);
}

#ifdef ENABLE_CHIP_SHELL
chip::startShellTask();
#endif

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

Expand Down
2 changes: 1 addition & 1 deletion examples/pigweed-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ efr32_executable("pigweed_app") {
"${examples_plat_dir}/PigweedLogger.cpp",
"${examples_plat_dir}/heap_4_silabs.c",
"${examples_plat_dir}/init_efrPlatform.cpp",
"${examples_plat_dir}/uart.c",
"${examples_plat_dir}/uart.cpp",
"src/main.cpp",
]

Expand Down
17 changes: 16 additions & 1 deletion examples/platform/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import("//build_overrides/chip.gni")
import("//build_overrides/efr32_sdk.gni")

import("${chip_root}/src/lib/lib.gni")
import("${efr32_sdk_build_root}/efr32_sdk.gni")

config("chip_examples_project_config") {
Expand Down Expand Up @@ -49,3 +49,18 @@ source_set("openthread_core_config_efr32_chip_examples") {

public_configs = [ ":chip_examples_project_config" ]
}

source_set("efr-matter-shell") {
if (chip_build_libshell) {
defines = [ "ENABLE_CHIP_SHELL" ]

sources = [ "matter_shell.cpp" ]
include_dirs = [ "." ]

public_deps = [
"${chip_root}/examples/shell/shell_common:shell_common",
"${chip_root}/src/lib/shell:shell",
"${chip_root}/src/lib/shell:shell_core",
]
}
}
88 changes: 88 additions & 0 deletions examples/platform/efr32/matter_shell.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
*
* 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.
*/

#include "matter_shell.h"
#include <ChipShellCollection.h>
#include <FreeRTOS.h>
#include <lib/core/CHIPCore.h>
#include <lib/shell/Engine.h>
#include <task.h>

using namespace ::chip;
using chip::Shell::Engine;

namespace {

#define SHELL_TASK_STACK_SIZE 2048
#define SHELL_TASK_PRIORITY 5
TaskHandle_t shellTaskHandle;
StackType_t shellStack[SHELL_TASK_STACK_SIZE / sizeof(StackType_t)];
StaticTask_t shellTaskStruct;

void MatterShellTask(void * args)
{
chip::Shell::Engine::Root().RunMainLoop();
}

} // namespace

extern "C" unsigned int sleep(unsigned int seconds)
{
const TickType_t xDelay = 1000 * seconds / portTICK_PERIOD_MS;
vTaskDelay(xDelay);
return 0;
}

namespace chip {

void NotifyShellProcess()
{
xTaskNotifyGive(shellTaskHandle);
}

void NotifyShellProcessFromISR()
{
BaseType_t yieldRequired = pdFALSE;
if (shellTaskHandle != NULL)
{
vTaskNotifyGiveFromISR(shellTaskHandle, &yieldRequired);
}
portYIELD_FROM_ISR(yieldRequired);
}

void WaitForShellActivity()
{
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
}

void startShellTask()
{
int status = chip::Shell::streamer_init(chip::Shell::streamer_get());
assert(status == 0);

// For now also register commands from shell_common (shell app).
// TODO move at least OTCLI to default commands in lib/shell/commands
cmd_misc_init();
cmd_otcli_init();
cmd_ping_init();
cmd_send_init();

shellTaskHandle = xTaskCreateStatic(MatterShellTask, "matter_cli", ArraySize(shellStack), NULL, SHELL_TASK_PRIORITY, shellStack,
&shellTaskStruct);
}

} // namespace chip
27 changes: 27 additions & 0 deletions examples/platform/efr32/matter_shell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* 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.
*/

#pragma once

namespace chip {

void NotifyShellProcess();
void NotifyShellProcessFromISR();
void WaitForShellActivity();
void startShellTask();

} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "uart.h"
#include "AppConfig.h"
#include "matter_shell.h"

#ifdef __cplusplus
extern "C" {
#endif
#include "assert.h"
#include "em_core.h"
#include "em_usart.h"
#include "sl_board_control.h"
#include "sl_uartdrv_instances.h"
#include "sl_uartdrv_usart_vcom_config.h"
#include "uart.h"
#include "uartdrv.h"
#include <stddef.h>
#include <string.h>
Expand Down Expand Up @@ -192,6 +197,9 @@ void uartConsoleInit(void)

void USART_IRQHandler(void)
{
#ifdef ENABLE_CHIP_SHELL
chip::NotifyShellProcessFromISR();
#endif
#ifndef PW_RPC_ENABLED
otSysEventSignalPending();
#endif
Expand All @@ -212,6 +220,10 @@ static void UART_rx_callback(UARTDRV_Handle_t handle, Ecode_t transferStatus, ui
}

UARTDRV_Receive(sl_uartdrv_usart_vcom_handle, data, transferCount, UART_rx_callback);

#ifdef ENABLE_CHIP_SHELL
chip::NotifyShellProcessFromISR();
#endif
#ifndef PW_RPC_ENABLED
otSysEventSignalPending();
#endif
Expand Down Expand Up @@ -267,3 +279,7 @@ int16_t uartConsoleRead(char * Buf, uint16_t NbBytesToRead)

return (int16_t) RetrieveFromFifo(&sReceiveFifo, (uint8_t *) Buf, NbBytesToRead);
}

#ifdef __cplusplus
}
#endif
3 changes: 2 additions & 1 deletion examples/shell/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ efr32_executable("shell_app") {
sources = [
"${examples_plat_dir}/heap_4_silabs.c",
"${examples_plat_dir}/init_efrPlatform.cpp",
"${examples_plat_dir}/uart.c",
"${examples_plat_dir}/uart.cpp",
"src/main.cpp",
]

Expand All @@ -70,6 +70,7 @@ efr32_executable("shell_app") {
"${chip_root}/third_party/openthread/platforms:libopenthread-platform",
"${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils",
"${chip_root}/third_party/openthread/repo:libopenthread-ftd",
"${examples_plat_dir}:efr-matter-shell",
]

include_dirs = [ "include" ]
Expand Down
35 changes: 2 additions & 33 deletions examples/shell/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <platform/CHIPDeviceLayer.h>
#include <platform/KeyValueStoreManager.h>

#include "matter_shell.h"
#include <AppConfig.h>
#include <app/server/Server.h>
#include <init_efrPlatform.h>
Expand Down Expand Up @@ -63,13 +64,6 @@ using namespace ::chip;
using namespace ::chip::DeviceLayer;
using chip::Shell::Engine;

#define SHELL_TASK_STACK_SIZE 8192
#define SHELL_TASK_PRIORITY 3
static TaskHandle_t sShellTaskHandle;
#define APP_TASK_STACK_SIZE (1536)
static StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
static StaticTask_t appTaskStruct;

// ================================================================================
// Supporting functions
// ================================================================================
Expand All @@ -87,13 +81,6 @@ void appError(CHIP_ERROR error)
appError(static_cast<int>(error.AsInteger()));
}

extern "C" unsigned int sleep(unsigned int seconds)
{
const TickType_t xDelay = 1000 * seconds / portTICK_PERIOD_MS;
vTaskDelay(xDelay);
return 0;
}

extern "C" void vApplicationIdleHook(void)
{
// FreeRTOS Idle callback
Expand All @@ -102,11 +89,6 @@ extern "C" void vApplicationIdleHook(void)
Internal::EFR32Config::RepackNvm3Flash();
}

static void shell_task(void * args)
{
Engine::Root().RunMainLoop();
}

// ================================================================================
// Main Code
// ================================================================================
Expand Down Expand Up @@ -174,19 +156,6 @@ int main(void)
}
#endif // CHIP_ENABLE_OPENTHREAD

int status = chip::Shell::streamer_init(chip::Shell::streamer_get());
assert(status == 0);

cmd_misc_init();
cmd_otcli_init();
cmd_ping_init();
cmd_send_init();

sShellTaskHandle = xTaskCreateStatic(shell_task, APP_TASK_NAME, ArraySize(appStack), NULL, 1, appStack, &appTaskStruct);
if (!sShellTaskHandle)
{
EFR32_LOG("MEMORY ERROR!!!");
}

chip::startShellTask();
sl_system_kernel_start();
}
3 changes: 2 additions & 1 deletion examples/window-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ efr32_executable("window_app") {
"${examples_plat_dir}/LEDWidget.cpp",
"${examples_plat_dir}/heap_4_silabs.c",
"${examples_plat_dir}/init_efrPlatform.cpp",
"${examples_plat_dir}/uart.c",
"${examples_plat_dir}/uart.cpp",
"${project_dir}/common/src/WindowApp.cpp",
"${project_dir}/common/src/ZclCallbacks.cpp",
"src/WindowAppImpl.cpp",
Expand All @@ -88,6 +88,7 @@ efr32_executable("window_app") {
"${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils",
"${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd",
"${chip_root}/third_party/openthread/repo:libopenthread-ftd",
"${examples_plat_dir}:efr-matter-shell",
]

include_dirs = [
Expand Down
Loading

0 comments on commit a583812

Please sign in to comment.