Paparazzi UAS  v6.2_unstable
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 "modules/core/abi.h"
31 #include "mcu_periph/usb_serial.h"
32 
33 /*************************
34  * Basic static commands *
35  *************************/
36 
37 static void cmd_mem(BaseSequentialStream *lchp, int argc, const char *const argv[])
38 {
39  size_t n, total, largest;
40  memory_area_t area;
41 
42  (void)argv;
43  if (argc > 0) {
44  chprintf(lchp, "Usage: mem\r\n");
45  return;
46  }
47  n = chHeapStatus(NULL, &total, &largest);
48  chCoreGetStatusX(&area);
49  chprintf(lchp, "core free memory : %u bytes\r\n", area.size);
50  chprintf(lchp, "heap fragments : %u\r\n", n);
51  chprintf(lchp, "heap free total : %u bytes\r\n", total);
52  chprintf(lchp, "heap free largest: %u bytes\r\n", largest);
53 }
54 
55 static void cmd_abi(BaseSequentialStream *lchp, int argc, const char *const argv[])
56 {
57  (void)argv;
58  if (argc > 0) {
59  chprintf(lchp, "Usage: abi\r\n");
60  return;
61  }
62 
63  chprintf(lchp, "ABI message bindings\r\n");
64  for (int i = 0; i < ABI_MESSAGE_NB; i++) {
65  chprintf(lchp, " msg %d: ", i);
66  if (abi_queues[i] == NULL) {
67  chprintf(lchp, "no bindings\r\n");
68  } else {
69  abi_event *e;
70  ABI_FOREACH(abi_queues[i], e) {
71  chprintf(lchp, "(cb 0x%lx, id %d), ", e->cb, e->id);
72  }
73  chprintf(lchp, "\r\n");
74  }
75  }
76 }
77 
78 static const ShellCommand commands[] = {
79  {"mem", cmd_mem},
80  {"abi", cmd_abi},
81  {NULL, NULL}
82 };
83 
85  NULL,
86  commands
87 };
88 
92 void shell_add_entry(char *cmd_name, shell_cmd_t *cmd)
93 {
94  shellAddEntry((ShellCommand) {cmd_name, cmd});
95 }
96 
97 
100 void shell_init_arch(void)
101 {
102  // This should be called after mcu periph init
103  shell_cfg.sc_channel = (BaseSequentialStream *)(SHELL_DEV.reg_addr);
104 
105  shellInit();
106  thread_t *shelltp = shellCreateFromHeap(&shell_cfg, 2048U, NORMALPRIO);
107  if (shelltp == NULL) {
108  chSysHalt("fail starting shell");
109  }
110 }
111 
shellInit
void shellInit(void)
Shell manager initialization.
Definition: microrlShell.c:378
cmd_abi
static void cmd_abi(BaseSequentialStream *lchp, int argc, const char *const argv[])
Definition: shell_arch.c:55
usb_serial.h
arch independent USB API
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:37
abi_struct
Event structure to store callbacks in a linked list.
Definition: abi_common.h:66
shell_add_entry
void shell_add_entry(char *cmd_name, shell_cmd_t *cmd)
Add dynamic entry.
Definition: shell_arch.c:92
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:67
commands
static const ShellCommand commands[]
Definition: shell_arch.c:78
ABI_FOREACH
#define ABI_FOREACH(head, el)
Macros for linked list.
Definition: abi_common.h:74
shell_init_arch
void shell_init_arch(void)
Arch init.
Definition: shell_arch.c:100
abi_struct::cb
abi_callback cb
Definition: abi_common.h:68
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:84