Commit graph

229 commits

Author SHA1 Message Date
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
Marcin Niestroj 0d6fabe6c3 shell: add Ctrl+N and Ctrl+P meta-keys
Ctrl+N - moves in history to next entry
Ctrl+P - moves in history to previous entry

Behavior of those meta-keys is the same as in bash and emacs, which
makes Zephyr shell even more familiar to play with.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2019-06-24 07:17:53 -04:00
Nicolas Pitre 6311766d9a pointer-type args: cast appropriately to be 64-bit compatible
Using void pointers as universal arguments is widely used. However, when
compiling a 64-bit target, the compiler doesn't like when an int is
converted to a pointer and vice versa despite the presence of a cast.
This is due to a width mismatch between ints (32 bits) and pointers
(64 bits). The trick is to cast to a widening integer type such as
intptr_t and then cast to
void*.

When appropriate, the INT_TO_POINTER macro is used instead of this
double cast to make things clearer. The converse with POINTER_TO_INT
is also done which also serves as good code annotations.

While at it, remove unneeded casts to specific pointer types from void*
in the vicinity, and move to typed variable upon function entry to make
the code cleaner.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-12 08:20:52 -07:00
Jakob Olesen 71260d88d5 shell: Initialize va_list variables portably.
The structure of the va_list type is architecture-dependent, and it
doesn't seem possible to initialize va_list variables in a portable way
(except by using va_start()). In particular, the x86_64 ABI defines the
type like this:

    typedef struct {
        unsigned int gp_offset;
        unsigned int fp_offset;
        void *overflow_arg_area;
        void *reg_save_area;
    } va_list[1];

Fortunately, the va_start() macro expects an uninitialized va_list
variable, so we can simply remove the initializers to make the code
portable.

Signed-off-by: Jakob Olesen <jolesen@fb.com>
2019-06-07 12:08:35 +02:00
Anas Nashif 4c32258606 style: add braces around if/while statements
Per guidelines, all statements should have braces around them. We do not
have a CI check for this, so a few went in unnoticed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-06 15:20:21 +02:00
Krzysztof Chruscinski 63e0ae0a9e shell: Fix shell uart not waking up shell on mcumgr data
When mcumgr smp data was received over shell uart transport
it was not waking up shell thread and thus request was not
processed. Shell thread must be waken up on any incoming
data, even data which is only dedicated for mcumgr smp.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-06-04 14:00:17 +02: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
Krzysztof Chruscinski 3b99b20ff0 shell: Move signals initialization from thread to init
By moving signals initialization to shell instance init function,
shell instance is ready to receive RX signals from backend before
thread is ready to handle them.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-05-13 14:05:02 +02:00
Jakub Rzeszutko 0e83ad65b4 shell: prompt configuration during project generation
Adding possibility to modify shell prompt in Kconfig and in prj.config
file.
Fixes #14547.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-04-30 10:40:04 -04:00
Krzysztof Chruscinski ecf2784fe7 shell: Use conditional commands registeration in shell_cmds.c
Modified commands which depends on compile time flags to
use conditional macros.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-04-28 13:31:34 -04: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
Ulf Magnusson 247337a0d1 shell: kconfig: Put 'menuconfig SHELL' in top-level menu
The 'Shell Options' menu contains just the 'menuconfig SHELL' menu in
the menuconfig interface.

Remove the 'Shell Options' menu and put 'menuconfig SHELL' directly in
the top-level menu instead. Also change the prompt from "Enable shell"
to just "Shell", to make it consistent with "Logging".

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-04-18 08:47:42 -04:00
Robert Lubos 9411abbc00 shell: telnet: Fix coverity issues
Fix coverity issue 197618, reporting unhandled return values.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-04-12 08:35:19 -04:00
Jim Paris 38ecf5b41f shell: Consume all input data
A transport may receive multiple bytes of data between shell_thread
wakeups, but state_collect is only called once per wakeup.  So it must
process all data, and only return when all data from the transport has
been consumed.  This is mostly handled correctly, but there were two
places where state_collect would return early instead.

Signed-off-by: Jim Paris <jim@jtan.com>
2019-04-08 19:38:01 -04:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Patrik Flykt 4aa48833d8 subsystems: Rename reserved function names
Rename reserved function names in the subsys/ subdirectory except
for static _mod_pub_set and _mod_unbind functions in bluetooth mesh
cfg_srv.c which clash with the similarly named global functions.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -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
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Jakub Rzeszutko 20e4ca48c7 shell: fix coverity issue in uart backend
Fixed coverity issue CID 196642

Fixes #14814

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-03-26 21:48:25 +01:00
Krzysztof Chruscinski e2de07b2f1 shell: Fix compile error when shell enabled and log disabled
Shell was selecting logger option which lead to define
CONFIG_LOG_RUNTIME_FILTERING generation even though log
was disabled. That messed up logger and lead to compilation
failure.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-03-25 22:45:08 -04:00
Andrew Boie 2518aaffb5 shell: fix build failure
This didn't compile if CONFIG_SHALL_ECHO_STATUS wasn't
enabled.

Based on a fix by Rodrigo Peixoto.

Fixes: #14546

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-15 06:46:06 -05:00
Ulf Magnusson 53376394b7 kconfig: Remove blank lines at the beginning/end of files
Maybe this is some "just in case" thing that got copied around. There's
no need to have a blank line at the beginning or end of Kconfig files.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-13 07:29:42 -05:00
Jakub Rzeszutko 4fb20c40a1 shell: fix coverity issue
Fixing a case where variable could be used without an initialization.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-03-04 09:41:13 -05:00
Maksim Masalski a4c0810aa0 shell: changed dead code part in function buffer_trim()
According to the Coverity issue 190614 (github issue #12319)
Fix for logically dead code in function buffer_trim
Before while execution cannot reach this statement: buff[0] = '\0';

Tested and noticed that part of code is unnecessary inside of while
For the test, I made the same function in CodeBlocks and send to it
string to detect and delete whitespaces. After deletion of dead code
part, I tested function again, it works.

Function buffer_trim first detects whitespace characters in the end
of the string using first while, then it adds '\0' to the end
of the string to mark that string has new end after all whitespace
characters. Second while finds whitespaces at the beginning
of the string and counts how many whitespaces it found.
In the end using if counted whitespaces are removing from the
string.

Signed-off-by: Maksim Masalski <maxxliferobot@gmail.com>
2019-02-26 02:26:52 +01:00
Krzysztof Chruscinski 3605e48c44 shell: Modify subcommands to use SHELL_STATIC_SUBCMD_SET_CREATE
It is planned to deprecate SHELL_CREATE_STATIC_SUBCMD_SET macro
which is replaced by SHELL_STATIC_SUBCMD_SET_CREATE.

Additionally, removed irrelevant comments about alphabetical
ordering which is no longer needed.

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
Krzysztof Chruscinski 4fac1f4204 shell: Add support to log_panic in RTT backend
Shell RTT backend was using RTT call which was using
lock (mutex). In case of panic, that lead to failure
if panic occured in the interrupt context where mutex
is not permitted.

Implementation changed to use write without log in
blocking mode.

Additionally, added static assert to check if raw RTT
log backend is not enabled on channel 0 which is used
by shell RTT backend.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-13 17:25:59 -05:00
Krzysztof Chruscinski 3a879deecc shell: Fix prompt length not updated in shell_prompt_change
Prompt length is used when printing log messages to erase
prompt. If length is not updated and new prompt is longer
than default one then only part of the prompt is erased
which looks like data corruption.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-11 11:39:57 -06:00
Jakub Rzeszutko 2f040d8188 shell: unify commands execution
This change removes special handling for shell root commands.
Currently there is one loop in execute function that is used
to search commands on each level.

Fixed a bug where command buffer has been processed twice
when it was not needed (wildcards not found).

This change will allow to simplify "select" command
introduction.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-02-08 14:58:44 -05: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
Kumar Gala ff70b3444f dts: Convert CONFIG_ to DT_ symbols for chosen props
Replace generating CONFIG_ symbols with DT_ symbols for chosen
properties like 'zephyr,console' or 'zephyr,bt-mon-uart'.  We now use a
kconfigfunctions (dt_str_val) to extract the info from dts into Kconfig.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 11:41:26 -06:00
Jakub Rzeszutko 870e5cb53e shell: fixed parameter type in exec_cmd function
Last parameter of exec_cmd function has been corrected from
structure type to pointer to structure type.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-02-07 13:58:43 +01: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
Krzysztof Chruscinski 4c2deebcdf shell: Move internal functions from shell.c to shell_ops.c
Move function for printing prompt and command with prompt
to shell_ops.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-05 09:55:39 +01:00
Johan Hedberg 66b9e955b0 shell: remove empty lines at EOF
The c-file one was recently introduced by
commit 5cf7b48eb4

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-31 22:18:06 +02:00
Jakub Rzeszutko 5cf7b48eb4 shell: fix spelling mistake in Kconfig
Fixed spelling mistake in shell's Kconfig file.
Updated description in SHELL_CMD_BUFF_SIZE description.
In shell.c: removed obsolete empty line, added empty line
at the end of file.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-31 19:41:27 +01:00
Jakub Rzeszutko 4c3bcbafef shell: documentation update
Updated documantation in regards to new shell printing strategy.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-30 13:05:56 +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 770261045e shell: added static to char_replace function
Function char_replace is only used in shell_ops.c file.
Added keyword static to function definition and removed
declaration from shell_ops.h

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-29 17:46:47 +01:00
Jakub Rzeszutko e7b55a6eb5 shell: meta-keys handle condition update
Meta keys are active when they are enabled and when shell echo is set
to on.
Updated meta keys description in shell's Kconfig file.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-29 17:46:47 +01:00
Jakub Rzeszutko f2c03280f2 shell: documentation update
1. Update shell documentation according to proposals in
PR #12437 (Extend shell meta keys).
2. Fix lines exceeding 80 characters limit.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-17 15:45:28 -05: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
Jakub Rzeszutko 63696968eb shell: add meta-keys
Added following meta-keys:
Ctrl-B - moves the cursor backward one character
Ctrl-D - deletes the character under the cursor
Ctrl-F - moves the cursor forward one character
Ctrl-K - deletes from the cursor to the end of the line
Alt-F  - moves the cursor forward one word
Alt-B  - moves the cursor backward one word

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-14 16:01:48 -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
Flavio Ceolin 80c03550ba shell: Make shell_strlen return u16_t
Everywhere the return of this function was being assigned to u16_t to
save space on stack. Instead of casting in all these places (and may
end up with overflow), just changing this function's return.

Note that the function itself is not checking for overflow yet since
I'm not sure this can happen and/or is a problem. Though now we have
only one single point to fix this problem.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-28 17:47:46 -05:00
Flavio Ceolin bc4cb76df5 shell: Fix return error in shell_execute_cmd
ENOEXEC should be used for executable file format error.
While is undertandable return it when the command is wrong, this
function is returning it two cases where other errors are more
descriptive. When parameter is NULL, is better return EINVAL.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-28 17:47:46 -05:00
Krzysztof Chruscinski 16e7e82af8 shell: Fix code style errors in shell.c
Fixed errors and warnings reported by checkpatch.pl

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-28 10:42:06 -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 cab9fa35ad shell: fix tab key functionality.
Fixing commit:#7ad59c84c84e8b7ea3c0438ff01c8a6343e65812

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-18 12:42:29 +01:00
Jakub Rzeszutko 956b00388f shell: fix execute command when help not active
When help functionality is not compiled and command is called with
-h or --help option shell will now either pass this option as
an argument or it will print a message that command does not have
a handler.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-17 11:31:22 +01:00
Jakub Rzeszutko f7f4fe33a1 shell: static functions cleanup
Removed shell_ prefix from static functions in .c files.
Added static functions for setting and getting shell
internal flags.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-17 11:31:22 +01:00
Jakub Rzeszutko 4d491b283b shell: remove obsolete \r characters
shell parses output string and it adds \r for each found \n.
It is no longer needed to keep \r for each shell message.

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 f8178dcb05 shell: remove Console dependencies
Removed Console dependencies from shell uart backend.
Generated define: CONFIG_UART_SHELL_ON_DEV_NAME for each board.

Fixes #10191

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-07 12:11:11 +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
Jakub Rzeszutko 3064ca4f2f shell: creating new module for help functionality
1. Created new shell module: shell_help.
2. Simplified command handlers with new shell print macros.
3. Removed help functions from command handlers.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko e0be6a10b3 shell: printing command's help by shell engine
Removed printing command help from help handler. It is now
realized by the shell engine. This change saves a lot of flash
but still allows to print help in command handler with function
shell_help_print.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko 5451ff2848 shell: remove "options" concept
Removing help "options" from shell API.

Currently SHELL_OPT macro is not used by users. What is more
commit: a89690d10f ignores possible options created in
command handler by the user. As a result they are not printed
in help message.

Second, currntly implemented "options" in command handlers options are
implemented without SHELL_OPT macro.

And last but not least this change will allow to implement
help handler in a way that user will not need to think about calling
functions printing help in a command handler.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Pawel Dunaj e344e5752c ext: debug: segger: Fix SEGGER header inclusion
Fix issue caused by 3fc497ac9a

This change removes `rtt` and `systemview` from header includes
as these are already placed in the path.

Also `SEGGER_SYSVIEW_ConfDefaults.h` header included from
`SEGGER_SYSVIEW_Int.h` is placed higher to make sure `INLINE`
definition is properly visible.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2018-12-05 14:35:42 +01:00
Krzysztof Chruscinski 07e01cbb70 shell: Fix thread priority
Removed kconfig option for setting shell thread priority and fix
it to K_LOWEST_APPLICATION_THREAD_PRIO.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-05 10:37:45 +01:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Krzysztof Chruscinski f78067e1f9 shell: Refactor RTT backend
Improved reception in the backend and replaced thread
with periodic timer as thread was used only to
periodically poll RTT data availability and using timer
is more RAM-wise efficient.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-04 16:24:44 -05:00
Jakub Rzeszutko 1a220b4e80 shell: decrease built-in commands flash usage
Rephrase some help messages to decrease flash usage.
Deactivate shell history feature for test test_netusb_rndis

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-04 15:53:02 -05:00
Jakub Rzeszutko 10aeb0e8ab shell: fix resize command
Resize command requires shell to be working on UART interrupt
driven API. This will be now enabled by default when shell serial
backend is selected. Recently this feature was accidentally turned
off in PR #11556.

k_sleep(1) has been replaced with k_busy_wait(1000) to avoid
hanging in command handler.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-04 15:53:02 -05:00
Jakub Rzeszutko 8e1d79a641 shell: improve partial completion
Shell used to require adding commands and subcommands in alphabetical
order to ensure correct autocompletion and printing options with the
<Tab> key.

Commit: bd3a4e5fe5 implemented correct
options printing with the <Tab> key for not sorted commands.
This PR allows to partially autocomplete not sorted commands.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-04 15:52:36 -05:00
Flavio Ceolin 713ec4c71c shell: utils: Remove dead code
Coverity-CID: 188741

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-30 08:06:40 -08:00
Jakub Rzeszutko 9643ed6d27 shell: fix double new line print for RTT backend
In case terminal sends `\r\n` on the Enter button
shell will go to the new line twice and it will print
prompt twice. This patch fixes it.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-11-29 11:54:56 +01:00
Jakub Rzeszutko 6de96b1802 shell: fix make_argv function
Shell will now detect not terminated " or ' character.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-11-27 15:00:19 -06:00
Aurelien Jarno 38efc2d426 shell: add a missing space in the help message
The help message is missing a space between "auto-complete" and "all".
Fix that.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-11-26 01:04:45 -05:00
Krzysztof Chruscinski 96a610b736 shell: Fix log messages queueing for multiple instances
Shell log backend was using k_fifo to enqueue log messages.
It was using field in log message that was used for same
purpose in log_core before passing message to backends.
However, this method supported only single shell as
other shell was corruption the fifo because field was
reused.

Modified shell log backend to use k_msgq for pending
messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-22 13:14:49 -05:00
Krzysztof Chruscinski af973ca1e9 shell: enable UART backend without interrupts
Currently shell UART backend is interrupt driven if UART driver
is interrupt driven. That can be limitation if one instance
wants to use interrupts but shell UART should not.

Added option to shell uart to be able to control use of
interrupts. By default interrupts are enabled if driver
supports it.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-21 22:41:21 -05:00
Krzysztof Chruscinski f214f8b2b2 shell: fix RTT backend not returning TX amount
RTT backend was returning number of transfered data equal
to requested amount because it was not taking into
account value returned by SEGGER_RTT_Write. As the outcome
data could be lost.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-21 12:53:22 +01:00
Jakub Rzeszutko 7d31796416 shell: fix shell thread name
Each shell thread will have unique name.
Previously thread name "shell" has been created for each shell
backend.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-11-19 11:40:05 -05:00
Krzysztof Chruscinski 8421543f1c shell: Add initial log level for rtt and uart backends
RTT and uart shell backends were started with fixed
log limit set to INF. Configuration has been moved
to Kconfig allowing certain level or default LOG_MAX_LEVEL.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-19 12:05:44 +01:00
Krzysztof Chruscinski 5af45bd392 shell: uart: Handle RX ring buffer full case
Scenario where RX ring buffer is full and cannot accept
more data was not handled. In that case byte should be
dropped. Such situation may occur when long command is
pasted (exceeding ring buffer size).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-16 08:31:01 -05:00
qianfan Zhao e3506832a4 subsys: shell: Print help message only if command doesn't available
Fixes: #11250

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-11-11 14:53:34 -05:00
Kumar Gala 896472a13d shell: Fix reference to nonexistent Kconfig symbol
The code referenced CONFIG_SHELL_VT100_COLORS_ENABLED which does not
exist.  Its mostly likely that CONFIG_SHELL_VT100_COLORS was meant
to be tested instead.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-09 11:01:06 -06:00
Luiz Augusto von Dentz a89690d10f shell: Add APIs to set number of arguments
This allows the shell core to perform precheck before calling the
handler which then can assume the number of arguments is correct.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-09 11:19:49 +01:00
Jakub Rzeszutko 59c23b11ff shell: wildcard active by default
Wildcard plugin is active by default.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-11-06 17:12:41 -05:00
Krzysztof Chruscinski 4962618e5f shell: shell_uart: add ring_buffers and interrupt support
Improved RX path to use ring buffer for incoming data instead of single
byte buffer. Improved TX path to use ring buffer. Added support for
asynchronous UART API (interrupts).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-06 17:11:26 -05:00
Flavio Ceolin aecd4ecb8d kernel: Change k_poll_signal api
k_poll_signal was being used by both, struct and function. Besides
this being extremely error prone it is also a MISRA-C violation.
Changing the function to contain a verb, since it performs an action
and the struct will be a noun. This pattern must be formalized and
followed and across the project.

MISRA-C rules 5.7 and 5.9

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-04 11:37:24 -05:00
Christoph Schramm f17a9c93b4 shell: Add a Segger RTT backend
Fixes: #8394

Signed-off-by: Christoph Schramm <schramm@makaio.com>
2018-11-02 12:19:58 -04:00
Krzysztof Chruscinski 39e355eb5b shell: Fix TXDONE signal not being cleared
Fixed the case when TXDONE signal was not cleared. Bug was unnoticed
because UART backend was synchronous.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-02 08:54:49 -04:00
Krzysztof Chruscinski fe9f4900ff shell: Postpone enabling log backend
Shell log backend was enabled too early, before shell thread was
up and running. That could lead to failure if log thread passes
log message to shell log backend.

Additionally, modified algorithm for multiplexing log output with
shell prompt. In case of logs flood prompt was unreadable because
it was deleted immediately after being printed. Added k_sleep
after printing prompt if any character was typed. This ensures that
shell prompt is readable if user uses it.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-02 08:54:49 -04:00
Jakub Rzeszutko 2445ba7a26 shell: fix possible hanging reason when history feature is used
Fixed possible race condition.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-11-01 13:39:20 +01:00
Jakub Rzeszutko 3aaf280108 shell: fix assert in wildcard plugin
Fixing a variable name in assert check in a function subcmd_get.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-29 09:58:08 +00:00
Jakub Rzeszutko 7e3a6e85d3 doc: shell: add information about dummy backend
Shell documentation has been updated with information about new
backend called DUMMY.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-28 11:45:41 -04:00
Jakub Rzeszutko c3bc7180b0 subsys: shell: add dummy backend to simplify commands testing
Added dummy backend which can be enabled with Kconfig. By default it is
disabled because it needs the same amount of memory as other phisical
backends. It shall be use only for commands testing purposes.

Improved shell_execute_cmd function, now it clears command context
before new command will be executed.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-28 11:45:41 -04:00
Jakub Rzeszutko 4c420ff3bf shell: fix history feature
When user was typing a new command and next pressed an up arrow
shell has displayed previously executed command. Next it was not
possible to display back currently edited command using a down arrow.

Fixes #10766.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-24 14:31:25 +01:00
Jakub Rzeszutko a88d5d7e4f shell: commands help unification
1. Changed return value of function: shell_cmd_precheck from bool to
int. Now it returns:
  0       when argument count is correct and help print is not requested
  1       when help was requested and printed
  -EINVAL on wrong arguments count
This change simply shell_cmd_precheck usege in command handlers.

2. Unified all commands in shell_cmd.c file.

3. Fixed a bug where help was not printed on wrong argument count.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-19 13:35:56 +02:00
Anas Nashif 79f434273e shell: kernel: list configured devices
Very simple command to list configured devices and their priorities.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-18 10:15:50 -04:00