Commit graph

44 commits

Author SHA1 Message Date
Fabio Baltieri 48e2f67869 shell: add a callback-filter variant of shell_device_lookup
Add a shell_device_filter variant of the shell device lookup helper that
takes a callback as an argument. This allows more complex filtering on
the device than the existing name prefix.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-04-30 19:30:15 -05:00
Al Semjonovs 0bca04635d shell: Allow extension of shell APIs
Similar to logging module, allow application specific extension of
shell fprintf APIs at a macro level.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2024-04-24 16:04:03 -04:00
Jakub Rzeszutko f8263e8293 shell: Add synchronization for prompt-string access in shell
Resolved a data race in shell.c by copying the user-provided
prompt-string into a private buffer within the shell, ensuring
proper synchronization with the shell-thread.

Fixes: #64972

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2024-04-04 15:18:36 -05:00
Ederson de Souza 28d08ada28 include/zephyr: Add 'version' and 'since' tag to groups
Based on information from doc/develop/api/overview.rst, add current
version for some groups representing APIs, following the following
table:

  - Experimental:   0.1.0
  - Unstable:       0.8.0
  - Stable:         1.0.0

Also based on doc/develop/api/overview.rst, add 'since' tag to the
groups.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-03-19 13:13:45 +01:00
Robert Lubos 5bb97a112d net: telnet: Improve command processing
Current TELNET implementation wrongly assumed that if the command is
present, it will always be included at the beginning of the packet/data
buffer. Such assumptions however are not valid for STREAM sockets,
where the actual stream data could be fragmented in any way.

Therefore, the command parsing needed rework, so that we analyze each
byte received for the command escape code, and once received we enter
"command parsing" mode. Once no more commands are identified in a data
streak, the command bytes are removed from the data buffer before the
buffer is provided to the shell subsystem for processing.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-11 15:09:32 -05:00
Robert Lubos 9e2e234003 net: telnet: Switch TELNET shell backend to use sockets
Rework TELNET shell backend to use socket API for communication and
socket service library for socket monitoring.

Additionally, rework the TX part so that non-blocking TX is used when
sending from the system work queue. In case transfer is not possible at
the moment, the TX work is rescheduled instead of blocking the system
work queue.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-11 15:09:32 -05:00
Pieter De Gendt df7750f63a shell: backends: Add RPMsg shell backend
Introduce a backend for the Shell subsystem using a RPMsg endpoint.

This is useful for tooling & testing a remote processor from linux.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-03-01 14:10:24 +01:00
Jakub Rzeszutko 04de43b1a1 shell: Fix shell init procedure when configured as inactive on startup
The previous behavior of the CONFIG_SHELL_AUTOSTART option, where setting
it to 'n' disabled shell interaction at startup but kept the logger
active as a shell backend, was inconsistent.
Now, when CONFIG_SHELL_AUTOSTART is set to 'n', both the shell and the
logger are inactive at startup. Calling the shell_start function will
activate them and print any pending logs. This change ensures a more
consistent and logical behavior regarding shell and logger activity at
startup.

Additionally, now when the shell_stop function is called, both the shell
and the logger are halted. This enhancement ensures that stopping
the shell also effectively stops the associated logger.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2024-01-21 16:01:36 +01:00
Yong Cong Sin b8008c4727 shell: shell_uart: improve macro compatibility with previous version
The `SHELL_UART_DEFINE` macro was previously
`SHELL_UART_DEFINE(_name, _tx_ringbuf_size, _rx_ringbuf_size)`,
before it got removed in #63967 and then reinstated in #66218 as
`SHELL_UART_DEFINE(_name)`.

However its current form isn't compatible with previous Zephyr
version, and would cause compilation error when an application
migrates from to v3.6, let's modify it to accept variable
arguments for now.

Added documentation for this public API and updated the
migration guide accordingly.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-01-18 10:52:08 +01:00
Yong Cong Sin f61ce34998 shell: shell_uart: reinstate multi-instance macro
Reinstate the `SHELL_UART_DEFINE` macro and moved the struct
declarations to header file, making it possible to create
another UART shell backend instance by doing
`SHELL_UART_DEFINE()` + `SHELL_DEFINE()` + `shell_init()`.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-12-06 11:27:20 -08:00
Yong Cong Sin 72fea5df56 shell: backends: uart: add public function to access smp shell data
`smp_shell_input_timeout_handler`. Create a public function in
the `shell_uart.c` for it to get the pointer to the
`smp_shell_data` and fix the compilation error.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-11-15 16:38:16 +01:00
Krzysztof Chruściński 5e4e944cc0 shell: backends: uart: Rework and add support for async API
Rework UART backend to clearly use single instance approach as
before it was a bit messy with some parts of implementation indicating
multi-instance approach and some single instance. Backend has been
around for years and multi-instance requirement never came.

Added support for UART asynchronous API which is more efficient
in terms of power consumption and performance. Asynchronous API
support is using uart_async_rx helper module for handling data
received asynchronously.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-11-14 09:21:46 +01:00
Witold Lukasik f14c061dd6 shell: fix SHELL_SUBCMD_COND_ADD with NULL as _handler parameter
In dummy_subcmd_##syntax statement, syntax keyword
should be replaced with _syntax, that is the argument name.

In dummy_##syntax##_handler There are two problems:
 - wrong syntax keyword
 - _handler is an argument

So if NULL is passed as an argument to _handler, and the syntax is abcd,
there is: dummy_##abcd##NULL, what causes a build error.

Signed-off-by: Witold Lukasik <witold.lukasik@nordicsemi.no>
2023-10-31 10:24:02 +01:00
Yong Cong Sin a068288091 shell: add new APIs to get the backend instances
Added some new APIs to get the backend instances more easily,
so that dev does not need to rely on `shell_backend_*_get_ptr`,
which looks more like a hack to access a local variable.

These APIs are basically copied from the log backend
implementation.

Added testcase for the APIs.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-10-25 09:57:29 +02:00
Yong Cong Sin dd154406ba shell: make the backend thread name variable generic
Rename the shell backend `thread_name` variable to just `name`,
to be used for other things not specific to thread later.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-10-25 09:57:29 +02:00
Nicolas VINCENT b01739da6f doc: shell: Update docstring regarding dictionnary
The dictionary is a triplet, update generated documentation accordingly.

Signed-off-by: Nicolas VINCENT <nicolas.vincent@vossloh.com>
2023-09-06 15:23:37 +02:00
Georges Oates_Larsen b25ea4742e net: conn_mgr: Rename connectivity monitor
The connectivity monitoring subfeature of conn_mgr is currently also
named conn_mgr, which is confusing.

This commit renames it to conn_mgr_monitor, or conn_mgr_mon for short,
for clarity.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-08-29 16:13:37 +02:00
Benjamin Cabé ea2aac6e51 shell: doc: misc Doxygen fixes
Fixed several incorrect uses of Doxygen, in particular improper use of
/*!< ... */ syntax which is meant to document the *previous* element.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2023-07-16 07:35:25 -04:00
Jasper Jonker e992e5d23f doc: shell: Parse C code sections
Parse the C code sections in the shell documentation.

Signed-off-by: Jasper Jonker <j8tjuh@gmail.com>
2023-07-05 12:33:01 +00:00
Emil Gydesen de3e709b50 Shell: Add shell_strtoull
Add a shell_strtoull function that works similar to
shell_strtoul except that it calls strtoull instead
of strtoul.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 07:05:20 -04:00
Gerard Marull-Paretas 248137169a doc: doxygen: add some subsystems to os_services group
Add the following root Doxygen modules under the umbrella of "OS
Services" Doxygen group:

- Cache
- File system
- IPC
- RTIO
- CRC
- Iterable sections
- ZBus
- Task watchdog
- Shell
- Semihosting
- Logging
- System init

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-31 14:39:29 -04:00
Gerard Marull-Paretas dacb3dbfeb iterable_sections: move to specific header
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-22 10:42:30 +02:00
Georges Oates_Larsen 716c19f7ef net: conn_mgr: Reorganize files
Since conn_mgr is a subsystem rather than a library, relocate it
directly into subsys/net rather than subsys/net/lib/

Rename header files to better match their function.

Remove net_ prefix from conn_mgr types, API, and files, since it is
unnecessary.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Hunter Searle 898a59eb80 Shell: Edit shell to store/retrieve return values
This change to the shell API enables the user to retrieve the
return code of the most recently run shell command. This is
useful both for users wanting specific information beyond the print
statements in a command, but especially for automated users
that prefer a simple return code to parsing human readable text.
This was tested using all default shell commands, as well as
eeprom, flash, and i2c, where specific errors could be forced.
In all cases, the correct return value was returned by the new
retval command.

Signed-off-by: Hunter Searle <hsearle@xes-inc.com>
2023-05-02 16:52:21 +02:00
Kumar Gala 6b5139c4bb shell: Convert to using iterable sections
Convert handling of shell_root_cmds, shell_subcmds, and
shell_dynamic_subcmds to use iterable section macros.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-18 12:48:16 +02:00
Gerard Marull-Paretas 667eeb11fb shell: fix MISRA 5.7 violations on struct shell
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +02:00
Tomasz Moń 59f33a6019 shell: uart: Fix wait for DTR before TX
Fail compilation when incorrect configuration is detected, i.e. when
SHELL_BACKEND_SERIAL_CHECK_DTR is set but UART_LINE_CTRL is not set.

Use periodic timer to wait for DTR instead of waiting in uart callback
to prevent blocking caller workqueue and/or sleeping in ISR.

DTR check was only ever supported with interrupt driven backend so add
appropriate depends on to Kconfig.

Fixes: e9f238889b ("shell: uart: Add waiting on DTR signal before
sending data")
Fixes: #47120
Fixes: #54705

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2023-04-06 14:21:57 +02:00
Aleksander Wasaznik cc1c3ac58e Shell: Add missing include
`include/zephyr/shell/shell_string_conv.h` uses `bool` from `stdbool.h`,
but the include was missing.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-03-20 09:51:24 +01:00
Krzysztof Chruscinski 24ad096232 logging: Renamed internal defines to get rid of 2 suffix
Some internal macros were still using 2 suffix which comes from
time when there was v1 and v2. Cleaning up by removing the suffix.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2023-03-09 15:10:06 -08:00
Wojciech Slenska 6272ba2d5c shell: added function shell_use_vt100_set
Added function to enable/disable vt100 commands.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2023-03-04 18:36:39 +01:00
Dominik Ermel db34adf9c3 mgmt/mcumgr: Standardise MCUmgr Kconfig names
Standardise Kconfig options for MCUmgr.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-12-22 12:36:34 +01:00
Xinyang Tan 535f5a6c04 shell: support setting help string for each entry in a dictionary command
Add support for setting the help description for each entry in a dictionary
command. Currently the syntax string alone may not provide sufficient
description of its entry. This commit also helps keep the help messages
consistent with existing style.

Signed-off-by: Xinyang Tan <xinyang.tan@delve.com>
2022-12-05 18:40:46 +01:00
Wojciech Slenska 188d2dfcca shell: shell_log_backend: take buffer size from config
Use LOG_MESSAGE_QUEUE_SIZE config instead of hardcoded value.
LOG_MESSAGE_QUEUE_SIZE default value has been changed to 512, so
it is now matching to the hardcoded value.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2022-11-22 13:05:29 +09:00
Dominik Ermel 7c2924f4bc mgmt/mcumgr: Move transport headers to transport subdir
The MCUmgr transport headers have been moved to
zephyr/mgmt/mcumgr/transport/

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-11-17 15:31:17 +01:00
Jakub Rzeszutko 66d4471d48 shell: add function checking shell readiness.
Tests with shell commands will fail if they are started
before the shell backend is initialized or started.
Adding API function: shell_ready indicating shell readiness.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2022-09-06 12:36:01 +02:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Frank Li f18f94ee18 shell: fix shell start obscure invaild.
When CONFIG_SHELL_START_OBSCURED is enabled, obscure should be
set by default to ensure that shell input is hidden by default
when the system starts.

Signed-off-by: Frank Li <lgl88911@163.com>
2022-07-11 10:20:35 +02:00
Krzysztof Chruscinski 9833ca61c9 logging: Removing v2 suffix from logging names
Renaming objects which had 2 in the name to indicate that
it is v2 specific. Once logging v1 has been removed such
suffixes are redundant.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-23 15:46:37 -04:00
Krzysztof Chruscinski 747d6ffdb0 shell: Remove support for logging v1
Remove support for logging v1 from shell log backend.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-15 10:55:26 -04:00
Georgij Cernysiov 3d035a71fe includes: shell: uart: fix legacy includes
Adds `zephyr/...` prefix to `smp_shell.h` include.

Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
2022-05-25 14:19:28 +02:00
Gerard Marull-Paretas fb9b3bcd93 include: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all includes within
include directory to the new prefix <zephyr/...>. Note that the
conversion has been scripted, refer to zephyrproject-rtos#45388 for more
details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 20:03:00 +02:00
Krzysztof Chruscinski 3ee5c57934 shell: Add new way of adding subcommands
Added macro SHELL_SUBCMD_SET_CREATE which creates a set of subcommands.
SHELL_SUBCMD_ADD and SHELL_SUBCMD_COND_ADD can be used from any file to
add command to the set. This approach allows to have subcommands added
from multiple files.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-04-29 14:54:08 +02:00
Yuval Peress bf6ca7f2e2 include: Update zephyr.h includes to use zephyr/ prefix
Issue #41543

Signed-off-by: Yuval Peress <peress@google.com>
2022-04-21 07:40:54 -05:00
Yuval Peress 53ef68d459 include: Prefix includes to use a scope
Move include paths and add new target_include_directories to support
backwards compatibility:
* /include -> /include/zephyr
  example: <irq.h> -> <zephyr/irq.h>

Issue #41543

Signed-off-by: Yuval Peress <peress@google.com>
2022-04-08 19:03:32 +02:00