Rev 15 | Rev 18 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 15 | Rev 16 | ||
|---|---|---|---|
| Line 33... | Line 33... | ||
| 33 | //#include "test.h" |
33 | //#include "test.h" |
| 34 | #include "shell.h" |
34 | #include "shell.h" |
| 35 | #include "evtimer.h" |
35 | #include "evtimer.h" |
| 36 | #include "chprintf.h" |
36 | #include "chprintf.h" |
| 37 | 37 | ||
| - | 38 | ||
| - | 39 | ||
| 38 | #if (HAL_USE_SERIAL_USB == TRUE) |
40 | #if (HAL_USE_SERIAL_USB == TRUE) |
| 39 | #include "usbcfg.h" |
41 | #include "usbcfg.h" |
| 40 | #endif |
42 | #endif |
| 41 | 43 | ||
| 42 | 44 | ||
| 43 | #include "ap_math.h" |
45 | #include "ap_math.h" |
| 44 | #include "hardware.h" |
46 | #include "hardware.h" |
| 45 | #include "useAdc.h" |
47 | #include "useAdc.h" |
| 46 | #include "spiInterface.h" |
48 | #include "spiInterface.h" |
| 47 | #include "SSD1306.h" |
49 | #include "SSD1306.h" |
| - | 50 | #include "font.h" |
|
| 48 | 51 | ||
| 49 | #include "timer2.h" |
52 | #include "timer2.h" |
| 50 | 53 | ||
| 51 | 54 | ||
| - | 55 | #include "shellCmds.h" |
|
| 52 | 56 | ||
| 53 | 57 | ||
| 54 | static MUTEX_DECL(mutexDisplay); |
58 | static MUTEX_DECL(mutexDisplay); |
| 55 | 59 | ||
| 56 | /*===========================================================================*/ |
60 | /*===========================================================================*/ |
| Line 58... | Line 62... | ||
| 58 | /*===========================================================================*/ |
62 | /*===========================================================================*/ |
| 59 | 63 | ||
| 60 | #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) |
64 | #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) |
| 61 | #define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) |
65 | #define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) |
| 62 | 66 | ||
| 63 | static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) { |
- | |
| 64 | size_t n, size , largest; |
- | |
| 65 | - | ||
| 66 | (void) argv; |
- | |
| 67 | if (argc > 0) { |
- | |
| 68 | chprintf(chp, "Usage: mem\r\n"); |
- | |
| 69 | return; |
- | |
| 70 | } |
- | |
| 71 | n = chHeapStatus(NULL, &size, &largest); |
- | |
| 72 | chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX()); |
- | |
| 73 | chprintf(chp, "heap fragments : %u \r\n",n); |
- | |
| 74 | chprintf(chp, "largest fragment : %u \r\n",largest); |
- | |
| 75 | chprintf(chp, "heap free total : %u bytes\r\n", size); |
- | |
| 76 | } |
- | |
| 77 | - | ||
| 78 | static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { |
- | |
| 79 | static const char *states[] = {CH_STATE_NAMES}; |
- | |
| 80 | thread_t *tp; |
- | |
| 81 | - | ||
| 82 | (void)argv; |
- | |
| 83 | if (argc > 0) { |
- | |
| 84 | shellUsage(chp, "threads"); |
- | |
| 85 | return; |
- | |
| 86 | } |
- | |
| 87 | chprintf(chp, "stklimit stack addr refs prio state name\r\n" SHELL_NEWLINE_STR); |
- | |
| 88 | tp = chRegFirstThread(); |
- | |
| 89 | do { |
- | |
| 90 | #if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE) |
- | |
| 91 | uint32_t stklimit = (uint32_t)tp->wabase; |
- | |
| 92 | #else |
- | |
| 93 | uint32_t stklimit = 0U; |
- | |
| 94 | #endif |
- | |
| 95 | chprintf(chp, "%08lx %08lx %08lx %4lu %4lu %9s %12s" SHELL_NEWLINE_STR, |
- | |
| 96 | stklimit, (uint32_t)tp->ctx.sp, (uint32_t)tp, |
- | |
| 97 | (uint32_t)tp->refs - 1, (uint32_t)tp->prio, states[tp->state], |
- | |
| 98 | tp->name == NULL ? "" : tp->name); |
- | |
| 99 | tp = chRegNextThread(tp); |
- | |
| 100 | } while (tp != NULL); |
- | |
| 101 | } |
- | |
| 102 | - | ||
| 103 | static void cmd_test(BaseChannel *chp, int argc, char *argv[]) { |
- | |
| 104 | thread_t *tp; |
- | |
| 105 | - | ||
| 106 | (void) argv; |
- | |
| 107 | if (argc > 0) { |
- | |
| 108 | chprintf(chp, "Usage: test\r\n"); |
- | |
| 109 | return; |
- | |
| 110 | } |
- | |
| 111 | //tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), TestThread, |
- | |
| 112 | // chp); |
- | |
| 113 | if (tp == NULL) { |
- | |
| 114 | chprintf(chp, "out of memory\r\n"); |
- | |
| 115 | return; |
- | |
| 116 | } |
- | |
| 117 | chThdWait(tp); |
- | |
| 118 | } |
- | |
| 119 | - | ||
| 120 | static const ShellCommand commands[] = { { "mem", cmd_mem }, { "threads", |
- | |
| 121 | cmd_threads }, { "test", cmd_test }, { NULL, NULL } }; |
- | |
| 122 | - | ||
| 123 | - | ||
| 124 | - | ||
| 125 | - | ||
| 126 | 67 | ||
| 127 | 68 | ||
| 128 | static const ShellConfig shell_cfg1 = { |
69 | static const ShellConfig shell_cfg1 = { |
| 129 | #if (HAL_USE_SERIAL_USB == TRUE) |
70 | #if (HAL_USE_SERIAL_USB == TRUE) |
| 130 | (BaseSequentialStream *)&SDU1, |
71 | (BaseSequentialStream *)&SDU1, |
| 131 | #else |
72 | #else |
| 132 | (BaseSequentialStream *)&SD1, |
73 | (BaseSequentialStream *)&SD1, |
| 133 | #endif |
74 | #endif |
| 134 | commands |
75 | shellCommands |
| 135 | }; |
76 | }; |
| 136 | //////// |
77 | //////// |
| 137 | // end of shell stuff |
78 | // end of shell stuff |
| 138 | 79 | ||
| 139 | uint16_t sampIndex; |
80 | uint16_t sampIndex; |
| Line 156... | Line 97... | ||
| 156 | * Command Shell Thread |
97 | * Command Shell Thread |
| 157 | */ |
98 | */ |
| 158 | static THD_WORKING_AREA(waThread2, 512); |
99 | static THD_WORKING_AREA(waThread2, 512); |
| 159 | static msg_t Thread2(void *arg) { |
100 | static msg_t Thread2(void *arg) { |
| 160 | thread_t *shelltp = NULL; |
101 | thread_t *shelltp = NULL; |
| - | 102 | ||
| - | 103 | chRegSetThreadName("Shell "); |
|
| 161 | /* |
104 | /* |
| 162 | * Normal main() thread activity, in this demo it just performs |
105 | * in this demo it just performs |
| 163 | * a shell respawn upon its termination. |
106 | * a shell respawn upon its termination. |
| 164 | */ |
107 | */ |
| 165 | while (true) { |
108 | while (true) { |
| 166 | if (!shelltp) { |
109 | if (!shelltp) { |
| 167 | #if (HAL_USE_SERIAL_USB == TRUE) |
110 | #if (HAL_USE_SERIAL_USB == TRUE) |