Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for matter cli in EFR32 example apps #12749

Merged
merged 4 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Support matter shell in all efr32 example apps
  • Loading branch information
jmartinez-silabs committed Dec 8, 2021
commit 8d27b7261fe30b14ed8eca2b1887822a34336ce1
12 changes: 11 additions & 1 deletion examples/lighting-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import("//build_overrides/efr32_sdk.gni")
import("//build_overrides/pigweed.gni")

import("${build_root}/config/defaults.gni")
import("${chip_root}/src/lib/lib.gni")
import("${efr32_sdk_build_root}/efr32_executable.gni")
import("${efr32_sdk_build_root}/efr32_sdk.gni")

Expand Down Expand Up @@ -69,6 +70,14 @@ efr32_sdk("sdk") {
"CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setupDiscriminator}",
]

if (chip_build_libshell)
{
defines += [
"ENABLE_CHIP_SHELL",
"OPENTHREAD_CONFIG_CLI_TRANSPORT=OT_CLI_TRANSPORT_CONSOLE",
]
}

if (chip_enable_pw_rpc) {
defines += [
"HAL_VCOM_ENABLE=1",
Expand All @@ -84,7 +93,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 @@ -97,6 +106,7 @@ efr32_executable("lighting_app") {
"${chip_root}/examples/lighting-app/lighting-common",
"${chip_root}/src/lib",
"${chip_root}/src/setup_payload",
"${examples_plat_dir}:efr-matter-shell",
"${chip_root}/third_party/openthread/platforms:libopenthread-platform",
"${chip_root}/third_party/openthread/platforms:libopenthread-platform-utils",
"${chip_root}/third_party/openthread/repo:libopenthread-cli-ftd",
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

//#if defined(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);
}

//#if defined(ENABLE_CHIP_SHELL)
chip::startShellTask();
//#endif

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

Expand Down
2 changes: 1 addition & 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 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
18 changes: 17 additions & 1 deletion examples/platform/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

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

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

config("chip_examples_project_config") {
include_dirs = [ "project_include" ]
Expand Down Expand Up @@ -49,3 +49,19 @@ 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 = [ "${chip_root}/examples/platform/efr32" ]

public_deps = [
"${chip_root}/src/lib/shell:shell",
"${chip_root}/src/lib/shell:shell_core",
#"${chip_root}/examples/shell/shell_common:shell_common",
]
}
}
91 changes: 91 additions & 0 deletions examples/platform/efr32/matter_shell.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
*
* 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 <FreeRTOS.h>
#include <task.h>
//#include <ChipShellCollection.h>
#include <lib/shell/Engine.h>
#include <lib/core/CHIPCore.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);

#ifdef SHELL_APP
cmd_misc_init();
cmd_otcli_init();
cmd_ping_init();
cmd_send_init();
#endif

shellTaskHandle = xTaskCreateStatic(MatterShellTask, "matter_cli", ArraySize(shellStack), NULL, SHELL_TASK_PRIORITY, shellStack, &shellTaskStruct);
// if (!shellTaskHandle)
// {
// EFR32_LOG("Shell task creation error");
// }
}

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

//#define CHIP_SHELL_PROMPT "matter >"

namespace chip {

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

} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <stddef.h>
#include <string.h>

#include "matter_shell.h"

#if !defined(MIN)
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#endif
Expand Down Expand Up @@ -176,7 +178,7 @@ static uint8_t RetrieveFromFifo(Fifo_t * fifo, uint8_t * pData, uint16_t SizeToR
*/
void uartConsoleInit(void)
{
sl_board_enable_vcom();
//sl_board_enable_vcom();
// Init a fifo for the data received on the uart
InitFifo(&sReceiveFifo, sRxFifoBuffer, MAX_BUFFER_SIZE);

Expand All @@ -192,6 +194,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 +217,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
3 changes: 2 additions & 1 deletion examples/shell/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ efr32_sdk("sdk") {
"BOARD_ID=${efr32_board}",
"OPENTHREAD_CONFIG_CLI_TRANSPORT=OT_CLI_TRANSPORT_CONSOLE",
"ENABLE_CHIP_SHELL",
"SHELL_APP",
]
}

Expand All @@ -58,7 +59,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 Down
34 changes: 1 addition & 33 deletions examples/shell/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,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 +80,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 +88,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 +155,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();
}
2 changes: 1 addition & 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 Down
2 changes: 1 addition & 1 deletion src/lib/lib.gni
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

declare_args() {
# Enable libshell support.
chip_build_libshell = false
chip_build_libshell = true
}
2 changes: 1 addition & 1 deletion src/lib/shell/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static_library("shell") {
]
} else if (chip_device_platform == "efr32") {
sources += [
"MainLoopDefault.cpp",
"MainLoopEFR32.cpp",
"streamer_efr32.cpp",
]
} else if (chip_device_platform == "k32w0") {
Expand Down
Loading