Loading...
Searching...
No Matches
shell.h
Go to the documentation of this file.
1
5
6// ALLOW FORMATTING
7#ifndef _SHELL_H
8#define _SHELL_H
9
10#include "FreeRTOS.h"
11#include "stdbool.h"
12#include "stdint.h"
13#include "task.h"
14
15#include "uart.h"
16
17// clang-format off
18
19// Macro for shell program definition boilerplate. The expansion of this will define
20// a static global-scope ShellProgramHandle_t pointer to a compound literal struct.
21#define DEFINE_PROGRAM_HANDLE(progName, execFunction) \
22 static ShellProgramHandle_t __attribute__((section(".shell_" progName), unused)) \
23 *progHandle = &(ShellProgramHandle_t){ \
24 .name = progName, \
25 .exec = execFunction \
26 };
27
28// Max allowable characters for name
29#define SHELL_PROGRAM_NAME_LENGTH 20
30
31// Terminal clear screen control sequence
32#define CMD_CLEAR "\033[3J\033[H\033[2J"
33
34// clang-format on
35
43
48typedef struct Shell {
50 void (*help)(struct Shell *);
51 void (*run)(struct Shell *, uint8_t *);
52 void (*runTask)(struct Shell *, uint8_t *);
53 bool (*clear)(struct Shell *);
54 TaskHandle_t taskHandle;
55} Shell;
56
65typedef struct ShellProgramHandle_t {
66 char name[SHELL_PROGRAM_NAME_LENGTH];
67 void (*exec)(struct Shell *, uint8_t *);
69
74typedef struct ShellTaskParams {
75 Shell *shell;
76 uint8_t *str;
78
79int Shell_init(Shell *);
80void Shell_help(Shell *);
81void Shell_runTask(Shell *, uint8_t *);
82void Shell_run(Shell *, uint8_t *);
83bool Shell_clear(Shell *);
84
86
87#endif
bool(* clear)(struct Shell *)
Definition shell.h:53
void(* run)(struct Shell *, uint8_t *)
Definition shell.h:51
TaskHandle_t taskHandle
Handle of currently active program in shell thread.
Definition shell.h:54
char name[SHELL_PROGRAM_NAME_LENGTH]
Program name as referenced by the shell.
Definition shell.h:66
void(* help)(struct Shell *)
Definition shell.h:50
void(* runTask)(struct Shell *, uint8_t *)
Definition shell.h:52
UART_t usb
UART interface to connect shell I/O.
Definition shell.h:49
void(* exec)(struct Shell *, uint8_t *)
Program entry point function pointer.
Definition shell.h:67
int Shell_init(Shell *)
Initializes the shell, registering programs from shell vector.
Definition shell.c:53
void Shell_help(Shell *)
Displays available shell commands.
Definition shell.c:77
bool Shell_clear(Shell *)
Send clear sequence to host terminal.
Definition shell.c:159
void Shell_runTask(Shell *, uint8_t *)
Creates a task to run a shell program.
Definition shell.c:134
void Shell_run(Shell *, uint8_t *)
Executes a shell program by name.
Definition shell.c:102
Struct definition for shell interface.
Definition shell.h:48
Struct definition for shell program handle.
Definition shell.h:65
Struct definition for parameters passed to shell task.
Definition shell.h:74
Struct definition for UART interface.
Definition uart.h:52