6.5. shell — Debug shell

The shell is a command line interface where the user can execute various commands to control, debug and monitor its application.

> make -s console
$ kernel/sys/info
app:    shell-master built 2017-03-05 21:26 CET by erik.
board:  Arduino Due
mcu:    Atmel SAM3X8E Cortex-M3 @ 84MHz, 96k sram, 512k flash
OK
$ kernel/thrd/list
            NAME        STATE  PRIO   CPU   SCHEDULED  MAX-STACK-USAGE  LOGMASK
         monitor    suspended   -80    0%          22       176/   518     0x0f
            idle        ready   127   99%         594       276/   390     0x0f
            main      current     0    0%         305       540/ 88898     0x00
OK
$ kernel/thrd/set_log_mask foo 0
ERROR(-3)
$ <Ctrl-D>
>

The shell module has a few configuration variables that can be used to tailor the shell to the application requirements. Most noticeably is the configuration variable CONFIG_SHELL_MINIMAL. If set to 0 all the shell functionality is built; including tab completion, cursor movement, line editing and command history. If set to 1 only the minimal functionality is built; only including tab completion and line editing at the end of the line.

See Configuration for a list of all configuration variables.


Source code: src/oam/shell.h, src/oam/shell.c

Test code: tst/oam/shell/main.c

Test coverage: src/oam/shell.c

Example code: examples/shell/main.c


Functions

int shell_module_init(void)

Initialize the shell module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

Return
zero(0) or negative error code.

int shell_init(struct shell_t *self_p, void *chin_p, void *chout_p, void *arg_p, const char *name_p, const char *username_p, const char *password_p)

Initialize a shell with given parameters.

Parameters
  • chin_p: The shell input channel. The shell waits for commands on this channel.
  • chout_p: The shell output channel. The shell writes responses on this channel.
  • arg_p: User supplied argument passed to all commands.
  • name_p: The shell thread name.
  • username_p: Shell login username, or NULL if no username is required to use the shell.
  • password_p: Shell login password. This field is unused if username_p is NULL.

void *shell_main(void *arg_p)

The shell main function that listens for commands on the input channel and send response on the output channel. All received commands are passed to the debug file system function fs_call() for execution.

Return
Never returns.
Parameters
  • arg_p: Pointer to the shell arguemnt struct struct shell_t. See the struct definition for a description of it’s content.

struct shell_history_elem_t
#include <shell.h>

Public Members

struct shell_history_elem_t *next_p
struct shell_history_elem_t *prev_p
char buf[1]
struct shell_line_t

Public Members

char buf[CONFIG_SHELL_COMMAND_MAX]
int length
int cursor
struct shell_t

Public Members

void *chin_p
void *chout_p
void *arg_p
const char *name_p
const char *username_p
const char *password_p
struct shell_line_t line
struct shell_line_t prev_line
int carriage_return_received
int newline_received
int authorized
struct shell_history_elem_t *head_p
struct shell_history_elem_t *tail_p
struct shell_history_elem_t *current_p
struct shell_line_t pattern
struct shell_line_t match
int line_valid
struct circular_heap_t heap
uint8_t buf[CONFIG_SHELL_HISTORY_SIZE]
struct shell_t::@116::@117 shell_t::heap
struct shell_t::@116 shell_t::history