Commit graph

92 commits

Author SHA1 Message Date
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Krzysztof Chruscinski 512de5ecac shell: Refactor command execution to enable raw arguments
Added special flag that can be used to indicate that optional
arguments are passed without any parsing (e.g. quotation marks
removal). Modified execute command to parse command line buffer
argument by argument.

After this change it is possible to forward whole command to
command handler (using select).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-05-07 23:47:39 -05:00
Simon Glass fc0e10d064 shell: Support output using a va_list
At present it is not possible to write a printf()-like function in
board code which outputs to the shell. Add shell_vfprintf() to permit
this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-07 10:04:28 +02:00
Simon Glass 2a8463e2b8 shell: Extend dummy backend to record for testing
It is useful to run tests which generate shell output and check that it
is correct. Update the existing 'dummy' backend to support this.

It works by retaining the output in a small buffer so that it can be
read and checked by the test.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-07 10:04:28 +02:00
Krzysztof Chruscinski 450c6b44f9 shell: Add shell_set_root_cmd function
New function allows to set from the code the root command. It is
an equivalent of calling 'select <rootcmd>' except it sets command
for all shell instances.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-04-17 11:34:01 +02:00
Krzysztof Chruscinski 8a63c9c8c8 shell: Add dedicated section for shell instances
Addded dedicated section for shell instances.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-04-17 11:34:01 +02:00
Oleg Zhurakivskyy b1e1f64d14 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-31 07:18:06 +02:00
Krzysztof Chruscinski f0548f100e shell: Replace __attribute__((unused)) with __unused
Replaced gcc specific with generic.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-03-25 09:34:21 -04:00
Carles Cufi 4b37a8f3a4 Revert "global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()"
This reverts commit 8739517107.

Pull Request #23437 was merged by mistake with an invalid manifest.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-03-19 18:45:13 +01:00
Oleg Zhurakivskyy 8739517107 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-19 15:47:53 +01:00
Andrew Boie 831f6d5051 shell: use correct data type for atomic variables
The variable needs to be an atomic_t, and in one case it was
being incremented outside of an atomic_inc/atomic_add.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 10:18:16 -04:00
Robert Lubos 4f9b9a4500 shell: telnet: Replace timer with a delayed work
A `k_timer` callback is called from the ISR context on certain devices
(nRF), which resulted in an assert in the kernel, as `telnet_send`, and
thus `net_context_send` used a mutex.

Fix the issue by replacing a timer used by the `shell_telnet` module
with a delayed work, which will execute it's callback in a system
workqueue context.

Fixes #22697

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-02-12 10:22:49 +02:00
Krzysztof Chruscinski 279e5b45b8 shell: Fix SHELL_COND_CMD_ARG_REGISTER macro with NULL handler
Macro was failing when handler was NULL and else case was
hit because of attempt to concatenate with handler which was
set to NULL (which is ((void *)0)).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-02-01 08:10:06 -05:00
Carles Cufi beedf19ca4 shell: Remove deprecated macros
Remove deprecated macros and add a note to the release notes to this
effect.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-01-09 14:38:49 -05:00
Ulf Magnusson 984bfae831 global: Remove leading/trailing blank lines in files
Remove leading/trailing blank lines in .c, .h, .py, .rst, .yml, and
.yaml files.

Will avoid failures with the new CI test in
https://github.com/zephyrproject-rtos/ci-tools/pull/112, though it only
checks changed files.

Move the 'target-notes' target in boards/xtensa/odroid_go/doc/index.rst
to get rid of the trailing blank line there. It was probably misplaced.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-11 19:17:27 +01:00
David B. Kinder 73896c0bf0 doc: fix misspelling in API doxygen comments
Fix misspellings in API doxygen comments missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-10-29 06:00:14 +01:00
Andrew Boie a7787c8519 shell: fix configuration issue
These checks should be against CONFIG_SHELL_LOG_BACKEND,
and not against CONFIG_LOG, since it's possible to enable
logging without building this particular backend.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-01 09:24:02 -04:00
Nicolas Pitre 91d057f146 shell_history: align buffer to pointer size
The code in shell_history_put() adds padding to new entries so they
are pointer aligned. The whole buffer has to be so aligned too.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-04 09:28:47 +02:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif ee9dd1a54a cleanup: include/: move misc/dlist.h to sys/dlist.h
move misc/dlist.h to sys/dlist.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 7435e5e089 cleanup: include/: move ring_buffer.h to sys/ring_buffer.h
move ring_buffer.h to sys/ring_buffer.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif e1e05a2eac cleanup: include/: move atomic.h to sys/atomic.h
move atomic.h to sys/atomic.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
David B. Kinder 8de9cc7079 doc: use @rst/@endrst for ReST in headers
Folks found the use of @rststar/@endrststar non-intuitive (wanted to use
@rststart).  The "star" was there indicating the doxygen comment lines
had a leading asterisk that needed to be stripped, but since our
commenting convention is to use the leading asterisk on continuation
lines, the leading asterisk is always there.  So, change the doxygen
alias to the more expected @rst/@endrst.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-06-25 23:33:55 -04:00
David B. Kinder 00c41ea893 doc: fix doxygen comments with embedded reST
Doxygen comments can include doxygen-specific markup tags.  If other
markup tags are used (e.g., restructuredText) we need to indicate that
in the doxygen comments (via @rststar/@endrststar tags).

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-06-10 18:16:12 -04:00
Krzysztof Chruscinski c2cb60f613 shell: Refactor shell_history to use less RW memory
Shell history module reworked to use ring buffer for storing
commands. Dedicated buffer is used to story all command lineary.
History capacity is in bytes not in number of entries, e.g.
many short commands can be stored or few long (depending on
CONFIG_SHELL_HISTORY_BUFFER).

Removed implicit command null termination from shell_history and
added it to shell after fetching command line from the history.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-05-30 09:44:03 -04:00
Jakub Rzeszutko b633e431a4 shell: add select command
The "select" command has been implemented, which allows user to
narrow down the command tree.

This implementation differs from the "select" command available
in the legacy shell. In a new implementation, if the selected
command has a handler and if the user has not entered the
registered subcommand, the shell will call the handler of selected
command and pass the text as arguments.

This may be useful, for example, if someone wants to use the
shell as an interface to a modem that supports AT commands.
Instead of each time you write e.g:
	at at+command1
	at at+command2
	at at+command3
user can execute following commands:
	select at
	at+command1
	at+command2
	at+command3

where:
at - root command for passing at commands to the modem
at+commandX - at command passed to the modem.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-05-24 11:04:42 +02:00
Bradley Bolen 3c0c1bfa8d shell: Fix checks of Kconfig options
The compiler was generating errors of the form
error: "CONFIG_LOG" is not defined, evaluates to 0 [-Werror=undef]
when -Wundef is used and the config option was turned off.  Change
several #if checks to #ifdef.

Signed-off-by: Bradley Bolen <bbolen@lexmark.com>
2019-05-17 15:46:18 -07:00
Krzysztof Chruscinski 7e26f53470 shell: Add macros for creating conditional commands
Added macros which can be used to create a command which depends
on compilation flag. Macros are a cleaner alternative to #ifdefs
around command registration and command handler.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-04-28 13:31:34 -04:00
Luiz Augusto von Dentz 65e350e6af Shell: Introduce shell_hexdump
This introduces shell_hexdump API which can be used to print an array
such as a network buffer.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-18 17:50:16 -04:00
Robert Lubos 658a08a4cb shell: Add TELNET backend
Add TELNET backed for shell module. The TELNET implementation is based
on the telnet_console driver.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-04-01 10:26:13 -04:00
Krzysztof Chruscinski c35bb26ebd shell: Making root command a global variable
By making it global we ensure that there will not be the
same root commands.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-20 07:31:35 -05:00
Krzysztof Chruscinski a64b0fe1e3 shell: Deprecate macros for subcommands creation
Macros are replaced by C++ friendly versions:
- SHELL_CREATE_STATIC_SUBCMD_SET by SHELL_STATIC_SUBCMD_SET_CREATE
- SHELL_CREATE_DYNAMIC_CMD by SHELL_DYNAMIC_CMD_CREATE

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-20 07:31:35 -05:00
Krzysztof Chruscinski a5efcc2c53 shell: Add cpp-friendly shell macro for subcommands creation
Add macro for creating subcommand set in a way that is
accepted by C++ (SHELL_STATIC_SUBCMD_SET_CREATE). Currently,
it exists along with SHELL_CREATE_STATIC_SUBCMD_SET which is
used in the tree but it is not liked by cpp.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-20 07:31:35 -05:00
Krzysztof Chruscinski 349dd964e0 shell: Refactor shell argument count validation
Shell arguments structure was stored as a pointer in shell structure
and NULL pointer indicated that argument count checking is skipped.
It has been reworked to hold the structure (2 bytes) in the shell
structure with mandatory=0 skipping the check. This approach is cpp
friendly, contrary to the legacy one.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-20 07:31:35 -05:00
Jakub Rzeszutko 46a02322ec shell: allow commands to suspend shell thread
It was possible to deadlock the shell when command
suspended shell's thread and next another thread wanted
to print something on the shell.

To avoid that shell releases mutex before entering command
handler. Due to this change some  adapations to shell
internal print functions have been applied.

This change addresses following usecase:
1. A command handler needs to call a (system) function which
communicate results via a callback, and this callback is expected
to print these results. The callback is called by the system from
another thread.
2. To achieve that, the handler needs to pass `struct shell *`
to callbacks, but also some other data specific to callback.
Thus, handles allocates some structure will those fields on
the stack.
3. The handler schedules this callback to be called.
4. As a reference to stack structure is passed to the callback,
the handler can't return immediately (or stack data will go out
of scope and will be overwritten).
5. So, the handler blocks waiting for callback to finish.

Previously, this scenario led to deadlock when the callback
trying or print to shell. With these changes, it just works,
as long as main handler and callback serialize there access
to the shell structure (i.e. when callback prints, the main
handler is blocked waiting for its completion).

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-02-14 13:40:28 +01:00
Jakub Rzeszutko 090ef041e8 shell: improved shell_prompt_change function
Shell will store only pointer to the prompt string instead of
copying it to the RAM buffer. It will save RAM memory and
it will simplify implementation of a  new feature: "select"
command. When a command will be selected than shell will
display command syntax as a prompt.

Removed obsolete ASSERT check in a static function.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-02-08 14:51:52 -05:00
Andy Gross 1e968a1976 shell: Allocate proper amount of history slab memory
This patch increases the amount of slab memory per item for the shell
history to match the maximum command input buffer size plus the
accounting information for the dnode list item.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2019-02-06 07:16:08 -05:00
Krzysztof Chruscinski 2e6892c9b0 shell: Add handling of CONFIG_LOG_INPLACE_PROCESS option
Extended shell to be able to process logs in place
(in the context of a log call). In order to achieve that,
shell was extended to  support for TX blocking operations. If
CONFIG_LOG_INPLACE_PROCESS is enabled then shell instance
attempts to be initialized in blocking TX mode. If fails to
do so, shell log backend is disabled. If successfully enabled
logs are processed and printed in the context of the call.

Due to that change, user may expirience interleaved output as
shell has no means to multiplex shell output with logger output.
In extreme, huge amount of log messages may prevent shell thread
execution and shell may become unresponsive.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-05 09:55:39 +01:00
Jakub Rzeszutko ce6be8600b shell: safe print from different threads
Added display text management to shell_fprintf function.
Now it can be used from diffrent threads with not risk that
displayed lines will overlay.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2019-01-30 13:05:56 +01:00
Jakub Rzeszutko 75ad61f7ef shell: removed foreground command functionality
Removed foreground command functionality from shell source files.
Removed associated example.
Removed enter/exit command functions from the Bluetooth example
Updated project config files.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-30 13:05:56 +01:00
Krzysztof Chruscinski be4b2cd62d shell: Add support for notifying about dropped logs
Extended shell log backend to print warning message on dropped
log messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 18:31:16 +01:00
Jakub Rzeszutko fd0b7f7767 shell: removing legacy shell
Legacy shell removed in order to avoid maintaining two shells
systems.

All examples and tests have been migrated to the new shell.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-16 21:35:36 -05:00
Mieszko Mierunski 8587bb19a7 smp: shell: Add support for SMP in new shell.
Added smp support for new shell.

Signed-off-by: Mieszko Mierunski <mieszko.mierunski@nordicsemi.no>
2019-01-15 17:19:20 -05:00
Flavio Ceolin 6bed8fc241 shell: Changing shell_history_get signature
Change arg_len to be u16_t in shell_history_get since it is returning
a value that can be hold by u16_t.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-28 17:47:46 -05:00
Krzysztof Chruscinski d653a5182c shell: Allow calling shell_fprintf from various contexts
Extended shell to allow command to indicate that shell should
halt not accepting any input until termination sequence is
received (CTRL+C) or shell_command_exit() is called. While shell
is in that state it is allowed to print to shell from any thread
context.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-28 10:42:06 -05:00
Krzysztof Chruscinski b467de5849 shell: Add dropping of expired messages
Log message get timestamp when being added to shell log message queue.
When adding to log message queue timeouts then all messages added
before timeout are dropped.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-19 14:37:00 +01:00
Krzysztof Chruscinski 08f0d93cbb shell: Improve handling of log messages
If burst of log messages was passed to the shell log
backend, it was likely that messages were lost because
shell had no means to control arrivals of log messages.

Added log message enqueueing timeout to the shell instance
to allow blocking logger thread if short-term arrival rate
exceeded shell capabilities.

Added kconfig option for setting log message queue size
and timeout in RTT and UART instances. Added section in
shell documentation which explains interaction between
the logger and shell instance acting as a logger backend.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-19 14:37:00 +01:00
Jakub Rzeszutko 0c678fac9d shell: header file update
Minor formatting corrections in shell.h file.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-17 11:31:22 +01:00
Jakub Rzeszutko 7ad59c84c8 shell: minor shell source cleanup
Cleanup in shell.c file.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-17 11:31:22 +01:00
Jakub Rzeszutko b928b71756 shell: rename shell_help_print function
Function printing help has been renamed to shell_help.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00