Rev 16 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 16 | mjames | 1 | /* |
| 2 | * shellCmds.c |
||
| 3 | * |
||
| 4 | * Created on: 1 Oct 2019 |
||
| 5 | * Author: Mike |
||
| 6 | */ |
||
| 7 | |||
| 8 | |||
| 9 | #include <stdio.h> |
||
| 10 | #include <string.h> |
||
| 11 | |||
| 12 | #include "ch.h" |
||
| 13 | #include "hal.h" |
||
| 14 | //#include "test.h" |
||
| 15 | #include "shell.h" |
||
| 16 | #include "evtimer.h" |
||
| 17 | #include "chprintf.h" |
||
| 18 | |||
| 19 | #include "shellCmds.h" |
||
| 17 | mjames | 20 | #include "timer2.h" |
| 16 | mjames | 21 | |
| 22 | |||
| 23 | static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) { |
||
| 24 | size_t n, size , largest; |
||
| 25 | |||
| 26 | (void) argv; |
||
| 27 | if (argc > 0) { |
||
| 28 | chprintf(chp, "Usage: mem\r\n"); |
||
| 29 | return; |
||
| 30 | } |
||
| 31 | n = chHeapStatus(NULL, &size, &largest); |
||
| 32 | chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX()); |
||
| 33 | chprintf(chp, "heap fragments : %u \r\n",n); |
||
| 34 | chprintf(chp, "largest fragment : %u \r\n",largest); |
||
| 35 | chprintf(chp, "heap free total : %u bytes\r\n", size); |
||
| 36 | } |
||
| 37 | |||
| 38 | static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { |
||
| 39 | static const char *states[] = {CH_STATE_NAMES}; |
||
| 40 | thread_t *tp; |
||
| 41 | |||
| 42 | (void)argv; |
||
| 43 | if (argc > 0) { |
||
| 44 | shellUsage(chp, "threads"); |
||
| 45 | return; |
||
| 46 | } |
||
| 47 | chprintf(chp, "stklimit stack addr refs prio state name\r\n" SHELL_NEWLINE_STR); |
||
| 48 | tp = chRegFirstThread(); |
||
| 49 | do { |
||
| 50 | #if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE) |
||
| 51 | uint32_t stklimit = (uint32_t)tp->wabase; |
||
| 52 | #else |
||
| 53 | uint32_t stklimit = 0U; |
||
| 54 | #endif |
||
| 55 | chprintf(chp, "%08lx %08lx %08lx %4lu %4lu %9s %12s" SHELL_NEWLINE_STR, |
||
| 56 | stklimit, (uint32_t)tp->ctx.sp, (uint32_t)tp, |
||
| 57 | (uint32_t)tp->refs - 1, (uint32_t)tp->prio, states[tp->state], |
||
| 58 | tp->name == NULL ? "" : tp->name); |
||
| 59 | tp = chRegNextThread(tp); |
||
| 60 | } while (tp != NULL); |
||
| 61 | } |
||
| 62 | |||
| 63 | |||
| 64 | static void cmd_pll (BaseChannel *chp, int argc, char *argv[]) |
||
| 65 | { |
||
| 66 | |||
| 17 | mjames | 67 | chprintf(chp,"pll "); |
| 16 | mjames | 68 | |
| 17 | mjames | 69 | if(argc >= 2) |
| 70 | { |
||
| 71 | if(strncmp(argv[0],"gain",4)==0) |
||
| 72 | { |
||
| 73 | int v = atoi(argv[0]); |
||
| 74 | v=v==0?1:v; |
||
| 75 | setGain(v); |
||
| 76 | chprintf(chp,"setGain(%d)\r\n",v); |
||
| 77 | } |
||
| 16 | mjames | 78 | |
| 17 | mjames | 79 | |
| 80 | } |
||
| 81 | else |
||
| 82 | { |
||
| 83 | chprintf(chp,"no args\r\n"); |
||
| 84 | } |
||
| 85 | |||
| 86 | |||
| 16 | mjames | 87 | } |
| 88 | |||
| 89 | |||
| 90 | |||
| 91 | |||
| 92 | |||
| 93 | |||
| 94 | const ShellCommand shellCommands[] = { { "mem", cmd_mem }, { "threads", |
||
| 95 | cmd_threads }, { "pll", cmd_pll }, { NULL, NULL } }; |
||
| 96 | |||
| 97 |