Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
microrlShell.c
Go to the documentation of this file.
1
9#include <string.h>
11#include "microrl/microrl.h"
12#include "printf.h"
13//#include "stdutil.h"
15
16
17#define printScreen(...) {chprintf (chpg, __VA_ARGS__); chprintf (chpg, "\r\n");}
18
19typedef struct {
20 void (*altFunc) (uint8_t c, uint32_t mode);
23
24static void cmd_info(BaseSequentialStream *lchp, int argc,
25 const char * const argv[]);
26
27
32
37static const char * complWorlds[64];
41#if SHELL_DYNAMIC_ENTRIES_NUMBER // compatibility with legacy static only behavior
43#else
44static const ShellCommand localCommands[] = {
45#endif
46 {"info", cmd_info},
47 {NULL, NULL}
48};
49
50static AltCbParam altCbParam = {.altFunc = NULL, .param = 0};
51
52void microrlPrint (const char * str)
53{
54 int i = 0;
55
56 while (str[i] != 0) {
57 streamPut(chpg, str[i++]);
58 }
59}
60
61void microrlExecute (int argc, const char * const *argv)
62{
64 const char *name = argv[0];
65
66 chMtxLock(&mut);
67
68 while (scp->sc_name != NULL) {
69 if (strcasecmp(scp->sc_name, name) == 0) {
70 scp->sc_function(chpg, argc-1, &argv[1]);
71 goto exit;
72 }
73 scp++;
74 }
75
77 while (scp->sc_name != NULL) {
78 if (strcasecmp(scp->sc_name, name) == 0) {
79 scp->sc_function(chpg, argc-1, &argv[1]);
80 goto exit;
81 }
82 scp++;
83 }
84
85 exit:
87}
88
89const char ** microrlComplet (int argc, const char * const * argv)
90{
91 uint32_t j = 0;
92
93 complWorlds [0] = NULL;
94 chMtxLock(&mut);
95
96 // if there is token in cmdline
97 if (argc == 1) {
98 // get last entered token
99 const char *bit = argv[argc-1];
100 // iterate through our available token and match it
101 for (const ShellCommand *scp = localCommands;
102 scp->sc_name != NULL; scp++) {
103 // if token is matched (text is part of our token starting from 0 char)
104 if (strstr(scp->sc_name, bit) == scp->sc_name) {
105 // add it to completion set
106 complWorlds[j++] = scp->sc_name;
107 }
108 }
109 for (const ShellCommand *scp = staticCommands;
110 scp->sc_name != NULL; scp++) {
111 // if token is matched (text is part of our token starting from 0 char)
112 if (strstr(scp->sc_name, bit) == scp->sc_name) {
113 // add it to completion set
114 complWorlds[j++] = scp->sc_name;
115 }
116 }
117 } else { // if there is no token in cmdline, just print all available token
118 for (const ShellCommand *scp = localCommands; scp->sc_name != NULL; scp++)
119 complWorlds[j++] = scp->sc_name;
120 for (const ShellCommand *scp = staticCommands; scp->sc_name != NULL; scp++)
121 complWorlds[j++] = scp->sc_name;
122 }
123
124 // note! last ptr in array always must be NULL!!!
125 complWorlds[j] = NULL;
127 // return set of variants
128 return complWorlds;
129}
130
131
132void microrlSigint (void)
133{
134 chprintf (chpg, "^C catched!\n\r");
135}
136
137
138static void usage(BaseSequentialStream *lchp, char *p) {
139
140 chprintf(lchp, "Usage: %s\r\n", p);
141}
142
143
144
145static void cmd_info(BaseSequentialStream *lchp, int argc, const char * const argv[]) {
146
147 (void)argv;
148 if (argc > 0) {
149 usage(lchp, "info");
150 return;
151 }
152
153 /*
154 Bits 31:16 REV_ID[15:0] Revision identifier
155 This field indicates the revision of the device.
156 STM32F405xx/07xx and STM32F415xx/17xx devices:
157 0x1000 = Revision A
158 0x1001 = Revision Z
159 0x1003 = Revision 1
160 0x1007 = Revision 2
161 0x100F= Revision Y
162 STM32F42xxx and STM32F43xxx devices:
163 0x1000 = Revision A
164 0x1003 = Revision Y
165 0x1007 = Revision 1
166 0x2001= Revision 3
167 Bits 15:12 Reserved, must be kept at reset value.
168 Bits 11:0 DEV_ID[11:0]: Device identifier (STM32F405xx/07xx and STM32F415xx/17xx)
169 The device ID is 0x413.
170 Bits 11:0 DEV_ID[11:0]: Device identifier (STM32F42xxx and STM32F43xxx)
171 The device ID is 0x419
172
173
174 F7
175 Bits 31:16 REV_ID[15:0] Revision identifier
176 This field indicates the revision of the device:
177 0x1000 = Revision A
178 0x1001 = Revision Z
179 Bits 15:12 Reserved, must be kept at reset value.
180 Bits 11:0 DEV_ID[11:0]: Device identifier
181 The device ID is 0x449.
182
183
184 L47x 49x
185 Bits 31:16 REV_ID[15:0] Revision identifier
186 This field indicates the revision of the device.
187 For STM32L475xx/476xx/486xx devices
188 0x1000: Rev 1
189 0x1001: Rev 2
190 0x1003: Rev 3
191 0x1007: Rev 4
192 For STM32L496xx/4A6xx devices
193 0x1000: Rev A
194 0x2000: Rev B
195
196 Bits 11:0 DEV_ID[11:0]: Device identifier
197 The device ID is:
198 0x461 for STM32L496xx/4A6xx devices
199 0x415 for STM32L475xx/476xx/486xx devices.
200 */
201
202
203 const uint16_t mcu_revid = (DBGMCU->IDCODE & DBGMCU_IDCODE_REV_ID) >> 16;
205 char *mcu_devid_str ="not known, please fix microrlShell.c";
206 char mcu_revid_chr = '?';
207
208 switch (mcu_devid) {
209 case 0x415 : mcu_devid_str = "STM32L475xx/476xx/486xx devices";
210 switch (mcu_revid) {
211 case 0x1000 : mcu_revid_chr = '1'; break;
212 case 0x1001 : mcu_revid_chr = '2'; break;
213 case 0x1003 : mcu_revid_chr = '3'; break;
214 case 0x1007 : mcu_revid_chr = '4'; break;
215 }
216 break;
217 case 0x461 : mcu_devid_str = "STM32L496xx/4A6xx devices";
218 switch (mcu_revid) {
219 case 0x1000 : mcu_revid_chr = 'A'; break;
220 case 0x2000 : mcu_revid_chr = 'B'; break;
221 }
222 break;
223 case 0x411 : mcu_devid_str = "STM32F2xx and *EARLY* STM32F40x and 41x";
224 switch (mcu_revid) {
225 case 0x1000 : mcu_revid_chr = 'A'; break;
226 case 0x1001 : mcu_revid_chr = 'Z'; break;
227 case 0x2000 : mcu_revid_chr = 'B'; break;
228 case 0x2001 : mcu_revid_chr = 'Y'; break;
229 case 0x2003 : mcu_revid_chr = 'X'; break;
230 }
231 break;
232 case 0x413 : mcu_devid_str = "STM32F40x and 41x";
233 switch (mcu_revid) {
234 case 0x1000 : mcu_revid_chr = 'A'; break;
235 case 0x1001 : mcu_revid_chr = 'Z'; break;
236 case 0x1003 : mcu_revid_chr = '1'; break;
237 case 0x1007 : mcu_revid_chr = '2'; break;
238 case 0x100F : mcu_revid_chr = 'Y'; break;
239 }
240 break;
241 case 0x419 : mcu_devid_str = "STM32F42x and F43x";
242 switch (mcu_revid) {
243 case 0x1000 : mcu_revid_chr = 'A'; break;
244 case 0x1003 : mcu_revid_chr = 'Y'; break;
245 case 0x1007 : mcu_revid_chr = '1'; break;
246 case 0x2001 : mcu_revid_chr = '3'; break;
247 }
248 break;
249 case 0x449 : mcu_devid_str = "STM32F74x and STM32F75x";
250 switch (mcu_revid) {
251 case 0x1000 : mcu_revid_chr = 'A'; break;
252 case 0x1001 : mcu_revid_chr = 'Z'; break;
253 }
254 break;
255 case 0x451 : mcu_devid_str = "STM32F76x and STM32F77x";
256 switch (mcu_revid) {
257 case 0x1000 : mcu_revid_chr = 'A'; break;
258 case 0x1001 : mcu_revid_chr = 'Z'; break;
259 }
260 break;
261 case 0x435 : mcu_devid_str = "STM32L43x";
262 switch (mcu_revid) {
263 case 0x1000 : mcu_revid_chr = 'A'; break;
264 case 0x1001 : mcu_revid_chr = 'Z'; break;
265 }
266 break;
267 case 0x446 : mcu_devid_str = "STM32F303xD/E and STM32F398xE";
268 switch (mcu_revid) {
269 case 0x1001 : mcu_revid_chr = 'Z'; break;
270 case 0x1003 : mcu_revid_chr = 'Y'; break;
271 }
272 break;
273 }
274
275 chprintf(lchp, "Kernel: %s\r\n", CH_KERNEL_VERSION);
276#ifdef HAL_VERSION
277 chprintf(lchp, "Hal: %s\r\n", HAL_VERSION);
278#endif
279
280#ifdef CH_COMPILER_NAME
281 chprintf(lchp, "Compiler: %s\r\n", CH_COMPILER_NAME);
282#endif
283#ifdef PORT_COMPILER_NAME
284 chprintf(lchp, "Compiler: %s\r\n", PORT_COMPILER_NAME);
285#endif
286
287#ifdef CH_ARCHITECTURE_NAME
288 chprintf(lchp, "Architecture: %s\r\n", CH_ARCHITECTURE_NAME);
289#endif
290#ifdef PORT_ARCHITECTURE_NAME
291 chprintf(lchp, "Architecture: %s\r\n", PORT_ARCHITECTURE_NAME);
292#endif
293
294
295#ifdef CH_CORE_VARIANT_NAME
296 chprintf(lchp, "Core Variant: %s\r\n", CH_CORE_VARIANT_NAME);
297#endif
298#ifdef PORT_CORE_VARIANT_NAME
299 chprintf(lchp, "Core Variant: %s\r\n", PORT_CORE_VARIANT_NAME);
300#endif
301#ifdef STM32_SYSCLK
302#pragma GCC diagnostic push
303#pragma GCC diagnostic ignored "-Wdouble-promotion"
304 chprintf(lchp, "Main STM32_SYSCLK frequency %.2f Mhz\r\n", STM32_SYSCLK/1e6f);
305#pragma GCC diagnostic pop
306#endif
307
308#ifdef CH_PORT_INFO
309 chprintf(lchp, "Port Info: %s\r\n", CH_PORT_INFO);
310#endif
311#ifdef PORT_INFO
312 chprintf(lchp, "Port Info: %s\r\n", PORT_INFO);
313#endif
314
315#ifdef PLATFORM_NAME
316 chprintf(lchp, "Platform: %s\r\n", PLATFORM_NAME);
317#endif
318
319#ifdef BOARD_NAME
320 chprintf(lchp, "Board: %s\r\n", BOARD_NAME);
321#endif
322
323 chprintf(lchp, "Chip Revision: %s REV '%c' (0x%x:0x%x)\r\n", mcu_devid_str, mcu_revid_chr, mcu_devid, mcu_revid);
324
325#if (!defined STM32_USE_REVISION_A_FIX) || (STM32_USE_REVISION_A_FIX == 0)
326 if ((mcu_devid == 0x413) && (mcu_revid_chr == 'A')) {
327 chprintf(lchp, "Chip Revision: %s REV '%c' PLEASE define STM32_USE_REVISION_A_FIX in mcuconf.h !!\r\n",
329 }
330#endif
331
332#ifdef __DATE__
333#ifdef __TIME__
334 chprintf(lchp, "Build time: %s%s%s\r\n", __DATE__, " - ", __TIME__);
335#endif
336#endif
337
338 chprintf(lchp, "systime= %lu\r\n", (unsigned long)chVTGetSystemTimeX());
339}
340
341
352 msg_t msg = MSG_OK;
353 chpg = ((ShellConfig *)p)->sc_channel;
354 staticCommands = ((ShellConfig *)p)->sc_commands;
355
356 chRegSetThreadName("Enhanced_shell");
357 printScreen ("ChibiOS/RT Enhanced Shell");
358 while (!chThdShouldTerminateX()) {
359 uint8_t c;
360 if (streamRead(chpg, &c, 1) > 0) {
361 if (altCbParam.altFunc == NULL) {
363 } else {
365 }
366 }
367 }
368 /* Atomically broadcasting the event source and terminating the thread,
369 there is not a chSysUnlock() because the thread terminates upon return.*/
370 printScreen ("exit");
371 chSysLock();
374}
375
386
397#if CH_CFG_USE_HEAP && CH_CFG_USE_DYNAMIC
399 return chThdCreateFromHeap(NULL, size, "shell", prio, shell_thread, (void *)scp);
400}
401#endif
402
403
414 size_t size, tprio_t prio) {
415 return chThdCreateStatic(wsp, size, prio, shell_thread, (void *)scp);
416}
417
418#if SHELL_DYNAMIC_ENTRIES_NUMBER
428bool shellAddEntry(const ShellCommand sc)
429{
431 static const int len = (sizeof(localCommands) / sizeof(localCommands[0]))
432 -1U;
433 chMtxLock(&mut);
434 while ((lcp->sc_function != NULL) &&
435 (strcmp(lcp->sc_name, sc.sc_name) != 0) &&
436 ((lcp - localCommands) < len))
437 lcp++;
438
439 if ((lcp - localCommands) == len) {
441 return false;
442 }
443 lcp->sc_function = sc.sc_function;
444 lcp->sc_name = sc.sc_function == NULL ? NULL : sc.sc_name;
445 *(++lcp) = (ShellCommand){NULL, NULL};
446
448 return true;
449}
450#endif
451
459
460void modeShell(void)
461{
462 chMtxLock(&mut);
465 printScreen ("retour au shell");
466}
467
468
469
#define BOARD_NAME
Definition board.h:37
static pthread_mutex_t mut
Definition catia.c:23
shellcmd_f * sc_function
Command function.
const char * sc_name
Command name.
static AltCbParam altCbParam
#define printScreen(...)
void shellInit(void)
Shell manager initialization.
uint32_t param
event_source_t shell_terminated
Shell termination event source.
static microrl_t rl
static const ShellCommand localCommands[]
Array of the default and dynamic commands.
void microrlExecute(int argc, const char *const *argv)
const char ** microrlComplet(int argc, const char *const *argv)
void modeShell(void)
static THD_FUNCTION(shell_thread, p)
Shell thread function.
void microrlSigint(void)
static void cmd_info(BaseSequentialStream *lchp, int argc, const char *const argv[])
#define SHELL_DYNAMIC_ENTRIES_NUMBER
static MUTEX_DECL(mut)
static BaseSequentialStream * chpg
void microrlPrint(const char *str)
static void usage(BaseSequentialStream *lchp, char *p)
void modeAlternate(void(*funcp)(uint8_t c, uint32_t mode), uint32_t mode)
void(* altFunc)(uint8_t c, uint32_t mode)
thread_t * shellCreateStatic(const ShellConfig *scp, void *wsp, size_t size, tprio_t prio)
Spawns a new shell.
static const char * complWorlds[64]
static const ShellCommand * staticCommands
Custom command entry type.
Shell descriptor type.
void chprintf(BaseSequentialStream *lchp, const char *fmt,...)
Definition printf.c:395
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
static float p[2][2]
uint16_t foo
Definition main_demo5.c:58
Simple CLI shell header.
void microrl_set_complete_callback(microrl_t *pThis, const char **(*get_completion)(int, const char *const *))
Definition microrl.c:353
void microrl_init(microrl_t *pThis, void(*print)(const char *))
Definition microrl.c:329
void microrl_insert_char(microrl_t *pThis, int ch)
Definition microrl.c:576
void microrl_set_sigint_callback(microrl_t *pThis, void(*sigintf)(void))
Definition microrl.c:366
void microrl_set_execute_callback(microrl_t *pThis, void(*execute)(int, const char *const *))
Definition microrl.c:360
Mini printf-like functionality.
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
Definition sonar_bebop.c:65
Implementation of system time functions for ChibiOS arch.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.