Skip to content

Commit 7e3a6e8

Browse files
Jakub Rzeszutkonashif
authored andcommitted
doc: shell: add information about dummy backend
Shell documentation has been updated with information about new backend called DUMMY. Signed-off-by: Jakub Rzeszutko <[email protected]>
1 parent c3bc718 commit 7e3a6e8

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

doc/subsystems/shell/shell.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ The module can be connected to any transport for command input and output.
3131
At this point, the following transport layers are implemented:
3232

3333
* UART
34+
* DUMMY - not a physical transport layer
3435

3536
See the :ref:`shell_api` documentation for more information.
3637

@@ -168,6 +169,27 @@ that is found deepest in the command tree and further subcommands (without a
168169
handler) are passed as arguments. Characters within parentheses are treated
169170
as one argument. If shell wont find a handler it will display an error message.
170171

172+
Commands can be also executed from a user application using any active backend
173+
and a function :cpp:func:`shell_execute_cmd`, as shown in this example:
174+
175+
.. code-block:: c
176+
177+
void main(void)
178+
{
179+
/* Below code will execute "clear" command on a DUMMY backend */
180+
shell_execute_cmd(NULL, "clear");
181+
182+
/* Below code will execute "shell colors off" command on
183+
* an UART backend
184+
*/
185+
shell_execute_cmd(shell_backend_uart_get_ptr(),
186+
"shell colors off");
187+
}
188+
189+
Enable the DUMMY backend by setting the Kconfig
190+
:option:`CONFIG_SHELL_BACKEND_DUMMY` option.
191+
192+
171193
Command handler
172194
----------------
173195

subsys/shell/Kconfig.backends

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ config SHELL_BACKEND_SERIAL
2323

2424
config SHELL_BACKEND_DUMMY
2525
bool "Enable dummy backend."
26-
select SERIAL
2726
help
28-
Enable dummy backend which can be used to test commands with no need
29-
for physical transport interface.
27+
Enable dummy backend which can be used to execute commands with no
28+
need for physical transport interface.
3029

3130
endif # SHELL_BACKENDS
32-

subsys/shell/shell_dummy.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ static int uninit(const struct shell_transport *transport)
3131
{
3232
struct shell_dummy *sh_dummy = (struct shell_dummy *)transport->ctx;
3333

34-
if (sh_dummy->initialized == false) {
35-
return -EINVAL;
34+
if (!sh_dummy->initialized) {
35+
return -ENODEV;
3636
}
3737

3838
sh_dummy->initialized = false;
@@ -44,8 +44,8 @@ static int enable(const struct shell_transport *transport, bool blocking)
4444
{
4545
struct shell_dummy *sh_dummy = (struct shell_dummy *)transport->ctx;
4646

47-
if (sh_dummy->initialized == false) {
48-
return -EINVAL;
47+
if (!sh_dummy->initialized) {
48+
return -ENODEV;
4949
}
5050

5151
return 0;
@@ -58,7 +58,7 @@ static int write(const struct shell_transport *transport,
5858

5959
if (!sh_dummy->initialized) {
6060
*cnt = 0;
61-
return -EINVAL;
61+
return -ENODEV;
6262
}
6363

6464
*cnt = length;
@@ -70,9 +70,8 @@ static int read(const struct shell_transport *transport,
7070
{
7171
struct shell_dummy *sh_dummy = (struct shell_dummy *)transport->ctx;
7272

73-
74-
if (sh_dummy->initialized) {
75-
return -EINVAL;
73+
if (!sh_dummy->initialized) {
74+
return -ENODEV;
7675
}
7776

7877
*cnt = 0;

0 commit comments

Comments
 (0)