Skip to content

Commit a0c4d57

Browse files
Add silabs specific CLI (#32733)
1 parent cb07513 commit a0c4d57

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

examples/platform/silabs/matter_shell.cpp

+57
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@
1616
*/
1717

1818
#include "matter_shell.h"
19+
#include "sl_component_catalog.h"
1920
#include <ChipShellCollection.h>
2021
#include <cmsis_os2.h>
2122
#include <lib/core/CHIPCore.h>
2223
#include <lib/shell/Engine.h>
2324
#include <sl_cmsis_os2_common.h>
25+
#ifdef SL_CATALOG_CLI_PRESENT
26+
#include "sl_cli.h"
27+
#include "sl_cli_config.h"
28+
#include "sli_cli_io.h"
29+
#endif
2430

2531
using namespace ::chip;
2632
using chip::Shell::Engine;
@@ -60,6 +66,51 @@ void WaitForShellActivity()
6066
osThreadFlagsWait(kShellProcessFlag, osFlagsWaitAny, osWaitForever);
6167
}
6268

69+
#ifdef SL_CATALOG_CLI_PRESENT
70+
71+
CHIP_ERROR CmdSilabsDispatch(int argc, char ** argv)
72+
{
73+
CHIP_ERROR error = CHIP_NO_ERROR;
74+
75+
char buff[SL_CLI_INPUT_BUFFER_SIZE] = { 0 };
76+
char * buff_ptr = buff;
77+
int i = 0;
78+
79+
VerifyOrExit(argc > 0, error = CHIP_ERROR_INVALID_ARGUMENT);
80+
81+
for (i = 0; i < argc; i++)
82+
{
83+
size_t arg_len = strlen(argv[i]);
84+
85+
/* Make sure that the next argument won't overflow the buffer */
86+
VerifyOrExit(buff_ptr + arg_len < buff + kMaxLineLength, error = CHIP_ERROR_BUFFER_TOO_SMALL);
87+
88+
strncpy(buff_ptr, argv[i], arg_len);
89+
buff_ptr += arg_len;
90+
91+
/* Make sure that there is enough buffer for a space char */
92+
if (buff_ptr + sizeof(char) < buff + kMaxLineLength)
93+
{
94+
strncpy(buff_ptr, " ", sizeof(char));
95+
buff_ptr++;
96+
}
97+
}
98+
buff_ptr = 0;
99+
sl_cli_handle_input(sl_cli_default_handle, buff);
100+
exit:
101+
return error;
102+
}
103+
104+
static const Shell::shell_command_t cmds_silabs_root = { &CmdSilabsDispatch, "silabs", "Dispatch Silicon Labs CLI command" };
105+
106+
void cmdSilabsInit()
107+
{
108+
// Register the root otcli command with the top-level shell.
109+
Engine::Root().RegisterCommands(&cmds_silabs_root, 1);
110+
}
111+
112+
#endif // SL_CATALOG_CLI_PRESENT
113+
63114
void startShellTask()
64115
{
65116
int status = chip::Shell::Engine::Root().Init();
@@ -68,7 +119,13 @@ void startShellTask()
68119
// For now also register commands from shell_common (shell app).
69120
// TODO move at least OTCLI to default commands in lib/shell/commands
70121
cmd_misc_init();
122+
#ifndef SL_WIFI
71123
cmd_otcli_init();
124+
#endif
125+
126+
#ifdef SL_CATALOG_CLI_PRESENT
127+
cmdSilabsInit();
128+
#endif
72129

73130
shellTaskHandle = osThreadNew(MatterShellTask, nullptr, &kShellTaskAttr);
74131
VerifyOrDie(shellTaskHandle);

src/platform/silabs/platformAbstraction/GsdkSpam.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ extern "C" {
4545
#include "sl_component_catalog.h"
4646
#include "sl_mbedtls.h"
4747
#if SILABS_LOG_OUT_UART || ENABLE_CHIP_SHELL || CHIP_DEVICE_CONFIG_THREAD_ENABLE_CLI
48+
#ifdef SL_CATALOG_CLI_PRESENT
49+
#include "sl_iostream.h"
50+
#include "sl_iostream_stdio.h"
51+
#endif //
4852
#include "uart.h"
4953
#endif
5054

@@ -71,6 +75,10 @@ CHIP_ERROR SilabsPlatform::Init(void)
7175
// Clear register so it does accumualate the causes of each reset
7276
RMU_ResetCauseClear();
7377

78+
#if SILABS_LOG_OUT_UART && defined(SL_CATALOG_CLI_PRESENT)
79+
sl_iostream_set_default(sl_iostream_stdio_handle);
80+
#endif
81+
7482
#if CHIP_ENABLE_OPENTHREAD
7583
sl_ot_sys_init();
7684
#endif

0 commit comments

Comments
 (0)