Commit graph

229 commits

Author SHA1 Message Date
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
Jakub Rzeszutko f6197c4f3c shell: create instances automatically basing on enabled backend
If user will enable shell than for each backend shell instance
will be created automatically.

Update all shell examples according to the new initialization
procedure.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-11 12:08:04 +02:00
Jakub Rzeszutko b0571746e2 shell: parsing output LF character
Some terminals literally interprets shell output data. Hence to print
a message in new line shell needs to send `\r\n` each time. To minimize
flash usage user can now send `\n` as a line delimiter and shell will
automatically add missing CR character.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-10 10:45:28 +02:00
Jakub Rzeszutko bc6da1c34a shell: Enable backends via Kconfig file
Added functionality to enable active shell backends via Kconfig
file. When there will be more backends implemented user will
have an option to select only required ones.

It is no longer needed to select SERIAL in prj.conf.

Fixes #10190

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-05 10:04:44 +02:00
Luiz Augusto von Dentz bbaa374afa Shell: Remove reference to alphabetically sorted
It is no longer required to have the command table alphabetically
sorted.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-03 10:51:52 +02:00
Luiz Augusto von Dentz bd3a4e5fe5 shell: Make autocomplete works with non-sorted commands
This allows declaring the commands in any order which sometimes is
convenient when commands are conditional making it undesirable to
sort everything.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-03 10:51:52 +02:00
Jakub Rzeszutko c471614cb6 subsys: shell: fix accept either CR or LF as as line delimiter
1. Shell will accept CR or LF as line delimiter.
2. Macro SHELL_DEFINE simplified - it no longer requires
   new line character.
3. Fixes: #10207.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-02 11:55:47 -07:00
Jakub Rzeszutko 61ca8c17c8 subsys: shell: add handlers diagnostic function
Added function: shell_execute_cmd that can be called
for command diagnostic purposes.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-02 14:44:25 +02:00
Jakub Rzeszutko 0eea1ef212 subsys: shell: add int ret_val to command handlers
1. Command handler can return command exectution status as int.
2. Existing command handlers rework.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-02 14:44:25 +02:00
Jakub Rzeszutko 0ce966bc28 subsys: shell: manual * parsing
This PR fixes: #10195.
Function _vprintk when used cannot parse '*' what
a as result causes dereferencing bad pointer.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-02 11:23:37 +02:00
Mark Ruvald Pedersen d67096da05 portability: Avoid void* arithmetics which is a GNU extension
Under GNU C, sizeof(void) = 1. This commit merely makes it explicit u8.

Pointer arithmetics over void types is:
 * A GNU C extension
 * Not supported by Clang
 * Illegal across all ISO C standards

See also: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-09-28 07:57:28 +05:30
Alberto Escolar Piedras 3e41ac5f04 subsys: shell: Add missing dependency to SERIAL
The shell subsystem, as it is today, depends on having a UART,
therefore let's add the dependency explicitly in its Kconfig

Fixes #10190

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-09-27 17:24:34 +02:00
Alberto Escolar Piedras c09b76abd0 subsys: shell: support posix arch
The posix arch does not compile either of Zephyr's libc,
so _prf() is not avaliable

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-09-27 17:24:34 +02:00
Anas Nashif 6d3fb8b4cf shell: kernel: add more thread data to threads command
Show thread and stack data all under one command and reformat output.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-27 08:58:55 +05:30
Anas Nashif 46f7cd51dd shell: kernel: print thread name
Use new kernel API to display thread name when listing threads.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-27 08:58:55 +05:30
Anas Nashif 57554055d2 kernel: add a new API for setting thread names
Added k_thread_name_set() and enable thread name setting when declaring
static threads. This is enabled only when THREAD_MONITOR is used. System
threads get a name by default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-27 08:58:55 +05:30
Krzysztof Chruscinski 2cc6d0c9c2 logging: Add option to suppress timestamp printing in log_output
Added flag in log_output module to add timestamp when message is
formatted to a string. Updated existing backends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-26 15:01:38 +02:00
Krzysztof Chruscinski 07da32aae5 logging: Add option to suppress level printing in log_output
Added flag in log_output module to add severity level when message is
formatted to a string. Updated existing backends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-26 15:01:38 +02:00
Jakub Rzeszutko 73c2178027 shell : assert standardization
1. All macros assert have been replaced with __ASSERT_NO_MSG.
2. Macro _Static_assert has been replaced with BUILD_ASSERT.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-09-25 10:31:13 +02:00
Jakub Rzeszutko f3db4d7034 subsys: shell: removing troubleshooting assert
Removing assert that was crashing shell in allowed scenario.
For example the Tab button is pressed when command buffer is empty.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-09-25 09:52:07 +02:00
Jakub Rzeszutko e59b8cbef9 subsys : shell : Added API changing prompt
1. Added API to change shell prompt in runtime.
2. Added prompt buffer length configuration in Kconfig.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-09-24 13:17:24 +02:00
Krzysztof Chruscinski 73c01f9e9f shell: modules: Adapt kernel commands to new shell
Kernel commands ported to new shell.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-23 11:43:33 -04:00
Krzysztof Chruscinski 8feab483c9 shell: fix shell_log_backend dependency
Fixed case when shell_log_backend.c was included even though
shell was disabled.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-22 22:28:17 -04:00
Krzysztof Chruscinski 68249ce966 shell: Add wildcard support
Extended shell to support wildcard characters: * and ? and expand
commands accordingly.
Increased default stack size.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Krzysztof Chruscinski c71a5595dc shell: Extend shell as a log backend
Initial logger backend support added to shell.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Krzysztof Chruscinski 989fef9c0e shell: Add built-in shell commands
Added optional shell commands:
- clear - for clearing terminal
- history - commands history
- resize - terminal resize
- shell - controling echo and colors

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Krzysztof Chruscinski 82ca811661 shell: Add shell history feature
Extending shell with terminal-like  history feature.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Krzysztof Chruscinski 6aed72e487 shell: Shell subsystem reimplementation
New shell support features like:
- multi-instance
- command tree
- static and dynamic commands
- multiline
- help print function
- smart tab (autocompletion)
- meta-keys
- history, wildcards etc.
- generic transport (initially, uart present)

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Krzysztof Chruscinski 527256501f shell: Rename shell to legacy_shell
New shell implementation is on the way. For now old one and all
references are kept to be gradually replaced by new shell.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Szymon Janc 9d3237c89e shell: Add support for custom line2argv callback
This allows to define shells which are using different syntax for
commands parsing eg. foocmd=param1,param2.

This is usefull for providing compatibility with existing external
tools while allowing to use Zephyr's shell subsystem.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-18 12:54:44 +02:00
Alberto Escolar Piedras 4486478f53 shell: Add missing header
When compiling with the native_posix console, the prototype
for posix_flush_stdout() was missing => added.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-08-02 19:14:19 +02:00
Ulf Magnusson 1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Remove some 'default ""' properties on string symbols too.

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

This shorthand works for int/hex/string symbols too, not just for bool
symbols.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04:00
Johan Hedberg 5c3d5660ef shell: Fix command completion logic
Similar fix as in commit b26ca13672. Just later in the same
function. This is how the logic used to be before quite heavy redesign
that happened a while ago.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-08 08:04:10 -04:00
Johan Hedberg b26ca13672 shell: Fix command completion logic
The original code (introduced by commit d5db35204a) looked like this
before the last rewrite/cleanup:

       if (default_module != -1) {
               return (str == NULL) ? dest : -1;
       }

However with the cleanup the logic seems to have gotten reversed.

Fixes #8501

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-22 15:09:18 -04:00
Paul Sokolovsky f6d8ab8289 subsys: console: Factor out fifo-based console input abstraction
Console subsystem is intended to be a layer between console drivers
and console clients, like e.g. shell. This change factors out code
from shell which dealed with individial console drivers and moves it
to console subsystem, under the name console_register_line_input().

To accommodate for this change, older console subsys Kconfig symbol
is changed from CONFIG_CONSOLE_PULL to CONFIG_CONSOLE_SUBSYS
(CONFIG_CONSOLE is already used by console drivers). This signifies
that console subsystem is intended to deal with all of console
aspects in Zephyr (existing and new), not just provide some "new"
functionality on top of raw console drivers, like it initially
started.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-20 15:59:12 -04:00
Ramakrishna Pallala 62bff616c2 subsys: shell: Remove deprcated k_call_stacks_analyze API
Replace deprecated k_call_stacks_analyze() API with
k_thread_foreach() API.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-05-15 13:43:00 +03:00
Henrik Brix Andersen 83ac3e24d8 shell: kernel: Add reboot command
Add a reboot command for requesting a warm or cold system reboot
through the kernel shell.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2018-04-25 07:18:35 +05:30
Jukka Rissanen ead9cd409c net: websocket: Add console support
Add console driver that allows console session to be transferred
over a websocket connection.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-15 15:17:36 +02:00
Christopher Collins 76bf5646d5 subsys: mgmt: Shell transport for SMP (mcumgr).
Enable the shell to transport mcumgr SMP requests and responses.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-20 22:07:52 +01:00
Alberto Escolar Piedras bfabdf1de5 shell: Added noprompt command
Added noprompt command to shell. It will disable printing
the prompt.
For the native port, when feeding commands from a file or
pipe the prompt reprinting after each command (without echoing)
just confuses the user.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-02-02 07:48:46 -08:00
Alberto Escolar Piedras e3f727cc6e native: added stdin handling for shell
Now the native console driver also handles stdin
so we can drive the shell from the command line,
a pipe or a file

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-02-02 07:48:46 -08:00
Anas Nashif e1d284f648 shell: rename get_mod_cmd
rename function and call out module in the name.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-19 12:01:08 -05:00
Anas Nashif d7777d3bd5 shell: support standalone commands
This will allow us to register commands directly without a need for a
module.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-19 12:01:08 -05:00
Anas Nashif 8d1931504a shell: rename module sections
Prepare for supporting stand-alone commands.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-19 12:01:08 -05:00
Anas Nashif 16424cf0bc shell: kernel: rename tasks -> threads
Rename tasks -> threads, task was the common name for threads before the
unified kernel was introduced.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-19 12:01:08 -05:00
Anas Nashif dd013691b2 shell: add a shell banner
Give details about running version and add a line about usage.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-19 12:01:08 -05:00
Carles Cufi 7d764b35f3 cmake: Use path-corrected version of ZEPHYR_BASE
Instead of accessing the environment variable ZEPHYR_BASE every time we
require accessing the source code root, use an intermediate variable
that has OS path separators correctly set to '/' to avoid issues on
Windows.

Note: This removes the ZEPHYR_SOURCE_DIR CMake variable. External
applications using that will need to change to use the new ZEPHYR_BASE
variable.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-01-11 14:59:03 -05:00
Anas Nashif 429c2a4d9d kconfig: fix help syntax and add spaces
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-13 17:43:28 -06:00
Johan Hedberg 45f258686b shell: Fix looking up help for the current module
The code was not properly handling "help <cmd>" for the currently
selected module.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 7318904ae1 shell: Use struct shell_module instead of integer to refer to modules
It's much more intuitive to read "if (module)" instead of
"if (module != -1)" when checking for a valid module. Update the code
to use struct shell_module pointers instead of integers for tracking
modules.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 22b5ff9b29 shell: Redesign internal command handling
Make the internal commands (exit, select & help) as any other
commands, so that e.g. "help help" works as expected. Also redesign
the way commands are looked up to avoid duplicate lookups.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 329a6628e4 shell: Remove unnecessary function
The print_cmd_unknown() is just a two-liner and only called from a
single place, so just do the printk calls inline.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg f9e30ed582 shell: Fix command lookup for non-default modules
The code was completely broken wrt command lookups when the command is
given in the format "<module> <cmd> <args...>". It would only work if
the default module is not set, which is almost never the case (as most
apps set it explicitly).

Refactor the command handling by moving more logic up to shell_exec(),
so that get_cb() does a lookup for a single module

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg fe20f55d03 shell: Remove redundant checking for argv[0]
The way get_command_and_module() is used it's impossible for it to be
given an argv where argv[0] is NULL.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 74556b7abb shell: Fix unnecessary passing by reference of argc
The get_cb() function does not modify argc, so there's no point in
passing it by reference.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 39a733151d shell: Remove unnecessary first_string variable
This variable adds no value, and is in fact longer to spell out than
simply argv[0].

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 76fb522993 shell: Remove redundant checking for first parameter
The way the command line parsing works, argv[0] is always guaranteed
to be non-NULL as well as a non-empty string, so doing checks for this
in get_cb() is redundant.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 04fbb80adb shell: Remove unnecessary initialization of err
All code paths in shell_exec() are guaranteed to set err before
returning it, so doing this (rather curious) initialization is
completely unnecessary.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 7f6070fb6c shell: Add optional command description
The command name and a shortened form of valid parameters is not
necessarily enough to understand its usage. Add the option of
providing a more lengthy description of the command usage.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 07:51:02 +02:00
Johan Hedberg c87ecf58de shell: Include the command help when listing all commands
Most commands provide a short string to describe the parameters it
takes. Provide this help text as part of the list of supported
commands for each module.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 21:32:20 +02:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Luiz Augusto von Dentz 81cc89189b shell: Adjust arguments when executing a command of different module
The command callback might not recognize commands if the input comes
with the module name as first parameter as both argc and argv will be
off by one.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-09 18:54:27 -04:00
Luiz Augusto von Dentz 417dc03aad shell: Return proper errors if the command fails
If the command cannot be execute code should return a proper since this
may not be a user input.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-09 18:54:27 -04:00
Luiz Augusto von Dentz 1a8cd31d64 shell: Add shell_exec
This adds shell_exec which can be used to execute commands directly
without the use of a console which is useful for both testing as well
as interfacing with applications/upper layer which would like to have
access to shell commands directly.

In addition to that this may be more trivial to interface with instead
of using fifos like uart_register_input and telnet_register_input do.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-09 18:54:27 -04:00
Andrew Boie 567c6c7683 misc: use K_THREAD_STACK_DEFINE macros
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-06-09 18:53:28 -04:00
Siddharth Chandrasekaran faaf859a46 shell: Add 'exit' command to leave a module
In console shell, add explicit, 'exit' command to leave the current
module. Currently this is being achieved by overloading select command
(without an argument).

Signed-off-by: Siddharth Chandrasekaran <siddharth@embedjournal.com>
2017-05-30 20:45:55 -04:00
Luiz Augusto von Dentz 6213730154 Shell: Add SHELL_REGISTER_WITH_PROMPT
This enables modules to define its own prompt handler instead of always
using the default_module_prompt.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-29 10:42:21 +03:00
Andrew Boie 77d1f1d232 shell: use k_thread_create()
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-11 20:24:22 -04:00
Kumar Gala 6da829690f subsys: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: Icbf9e542b23208890a3a32358447d44cdc274ef1
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 09:36:22 -05:00
Tomasz Bursztyka f7b0e35c5f shell: If enabled, let's register telnet console as an input
Change-Id: I476ca0f7914b02d2523a341560023c7e334d8b1b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:53 +02:00
Tomasz Bursztyka 587335c6cf shell: Make the command queue size configurable via Kconfig
Change-Id: I80551c76903118bfe831776c87135e89d32552da
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:53 +02:00
Tomasz Bursztyka 2f1af492ee console/shell: Switch to generic console input
Let's use the generic console input type now. This will be useful for
other console input drivers such as telnet.

Change-Id: I787a1e9d86481d5f8c4803453726d9042a89dea4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:53 +02:00
Tomasz Bursztyka 1a52e6e91a shell: Fix tiny style issues
- identation alignment
- 80 chars length limit

Change-Id: Ieae83e0daa2c7ee7aff32a053db5692094488df7
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:53 +02:00
Benjamin Walsh ed240f2796 kernel/arch: streamline thread user options
The K_<thread option> flags/options avaialble to users were hidden in
the kernel private header files: move them to include/kernel.h to
publicize them.

Also, to avoid any future confusion, rename the k_thread.execution_flags
field to user_options.

Change-Id: I65a6fd5e9e78d4ccf783f3304b607a1e6956aeac
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-01-24 13:34:50 +00:00
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Anas Nashif f1d0c2b0ad shell: add stacks command
Change-Id: Ibefface37c38749043602bce29317a315d0b53fd
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-11 20:47:10 +00:00
Anas Nashif 36c5167b72 shell: add tasks command to kernel module
Change-Id: I67c497c04e3c92a7f55cc5d95d7d3cfea414b4d8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-11 20:47:09 +00:00
Anas Nashif 502f0c893c shell: rename command 'set_module' to 'select'
select is more intuitive and easy to remember, and it is shorter too :)

Change-Id: Icc79e5cb88163344c1e2fcf65e313c33c4afa2cc
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-11 19:20:57 +00:00
Anas Nashif 7297f5db88 shell: move shell to its own subsystem
This moves the shell component into its own subsys and groups all
related files and options into a single place.

Additionally, one Kconfig option will now be required to enable the
shell:

 CONFIG_CONSOLE_SHELL=y

The header files was also moved to include/shell/shell.h and can be now
referenced with

 #include <shell/shell.h>

instead of

 #include <misc/shell.h>

Updated documentation as well.

Change-Id: Iffbba4acfa05408055e9fd28dffa213451351f94
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-25 19:35:11 +00:00