Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
shell_arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) Alexandre Bustico <alexandre.bustico@enac.fr>
3  *
4  * This file is part of paparazzi
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
26 #include "modules/core/shell.h"
28 #include "mcu_periph/uart.h"
29 #include "printf.h"
30 #include "subsystems/abi.h"
31 
32 /*************************
33  * Basic static commands *
34  *************************/
35 
36 static void cmd_mem(BaseSequentialStream *lchp, int argc, const char * const argv[])
37 {
38  (void)argv;
39  if (argc > 0) {
40  chprintf(lchp, "Usage: mem\r\n");
41  return;
42  }
43 
44  chprintf (lchp, "core free memory : %u bytes\r\n", chCoreGetStatusX());
45  //chprintf (lchp, "heap free memory : %u bytes\r\n", getHeapFree());
46 }
47 
48 static void cmd_abi(BaseSequentialStream *lchp, int argc, const char * const argv[])
49 {
50  (void)argv;
51  if (argc > 0) {
52  chprintf(lchp, "Usage: abi\r\n");
53  return;
54  }
55 
56  chprintf(lchp, "ABI message bindings\r\n");
57  for (int i = 0; i < ABI_MESSAGE_NB; i++) {
58  chprintf(lchp, " msg %d: ", i);
59  if (abi_queues[i] == NULL) {
60  chprintf(lchp, "no bindings\r\n");
61  } else {
62  abi_event *e;
63  ABI_FOREACH(abi_queues[i], e) {
64  chprintf(lchp, "(cb 0x%lx, id %d), ", e->cb, e->id);
65  }
66  chprintf(lchp, "\r\n");
67  }
68  }
69 }
70 
71 static const ShellCommand commands[] = {
72  {"mem", cmd_mem},
73  {"abi", cmd_abi},
74  {NULL, NULL}
75 };
76 
78  NULL,
79  commands
80 };
81 
85 void shell_add_entry(char *cmd_name, shell_cmd_t *cmd)
86 {
87  shellAddEntry((ShellCommand) {cmd_name, cmd});
88 }
89 
90 
93 void shell_init_arch(void)
94 {
95  // This should be called after mcu periph init
96  shell_cfg.sc_channel = (BaseSequentialStream *) (SHELL_DEV.reg_addr);
97 
98  shellInit();
99  thread_t * shelltp = shellCreateFromHeap(&shell_cfg, 2048U, NORMALPRIO);
100  if (shelltp == NULL) {
101  chSysHalt("fail starting shell");
102  }
103 }
104 
shellInit
void shellInit(void)
Shell manager initialization.
Definition: microrlShell.c:382
cmd_abi
static void cmd_abi(BaseSequentialStream *lchp, int argc, const char *const argv[])
Definition: shell_arch.c:48
abi.h
chprintf
void chprintf(BaseSequentialStream *lchp, const char *fmt,...)
Definition: printf.c:395
cmd_mem
static void cmd_mem(BaseSequentialStream *lchp, int argc, const char *const argv[])
Definition: shell_arch.c:36
abi_struct
Event structure to store callbacks in a linked list.
Definition: abi_common.h:65
shell_add_entry
void shell_add_entry(char *cmd_name, shell_cmd_t *cmd)
Add dynamic entry.
Definition: shell_arch.c:85
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
shell_cmd_t
void() shell_cmd_t(shell_stream_t *stream, int argc, const char *const argv[])
Command handler.
Definition: shell.h:37
printf.h
Mini printf-like functionality.
ShellCommand
Custom command entry type.
Definition: microrlShell.h:30
abi_struct::id
uint8_t id
Definition: abi_common.h:66
commands
static const ShellCommand commands[]
Definition: shell_arch.c:71
ABI_FOREACH
#define ABI_FOREACH(head, el)
Macros for linked list.
Definition: abi_common.h:73
shell_init_arch
void shell_init_arch(void)
Arch init.
Definition: shell_arch.c:93
abi_struct::cb
abi_callback cb
Definition: abi_common.h:67
microrlShell.h
Simple CLI shell header.
ShellConfig
Shell descriptor type.
Definition: microrlShell.h:38
ShellConfig::sc_channel
BaseSequentialStream * sc_channel
I/O channel associated to the shell.
Definition: microrlShell.h:39
shell.h
shell_cfg
static ShellConfig shell_cfg
Definition: shell_arch.c:77