Rev 14 | Rev 16 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 14 | Rev 15 | ||
|---|---|---|---|
| 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 | #if (HAL_USE_SERIAL_USB == TRUE) |
|
| 38 | #include "usbcfg.h" |
39 | #include "usbcfg.h" |
| - | 40 | #endif |
|
| 39 | 41 | ||
| 40 | 42 | ||
| 41 | #include "ap_math.h" |
43 | #include "ap_math.h" |
| 42 | #include "hardware.h" |
44 | #include "hardware.h" |
| 43 | #include "useAdc.h" |
45 | #include "useAdc.h" |
| 44 | #include "spiInterface.h" |
46 | #include "spiInterface.h" |
| 45 | #include "SSD1306.h" |
47 | #include "SSD1306.h" |
| 46 | 48 | ||
| 47 | #include "timer2.h" |
49 | #include "timer2.h" |
| 48 | 50 | ||
| - | 51 | ||
| - | 52 | ||
| - | 53 | ||
| 49 | static MUTEX_DECL(mutexDisplay); |
54 | static MUTEX_DECL(mutexDisplay); |
| 50 | 55 | ||
| 51 | /*===========================================================================*/ |
56 | /*===========================================================================*/ |
| 52 | /* Command line related. */ |
57 | /* Command line related. */ |
| 53 | /*===========================================================================*/ |
58 | /*===========================================================================*/ |
| Line 62... | Line 67... | ||
| 62 | if (argc > 0) { |
67 | if (argc > 0) { |
| 63 | chprintf(chp, "Usage: mem\r\n"); |
68 | chprintf(chp, "Usage: mem\r\n"); |
| 64 | return; |
69 | return; |
| 65 | } |
70 | } |
| 66 | n = chHeapStatus(NULL, &size, &largest); |
71 | n = chHeapStatus(NULL, &size, &largest); |
| 67 | chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus()); |
72 | chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX()); |
| 68 | chprintf(chp, "heap fragments : %u \r\n",n); |
73 | chprintf(chp, "heap fragments : %u \r\n",n); |
| 69 | chprintf(chp, "largest fragment : %u \r\n",largest); |
74 | chprintf(chp, "largest fragment : %u \r\n",largest); |
| 70 | chprintf(chp, "heap free total : %u bytes\r\n", size); |
75 | chprintf(chp, "heap free total : %u bytes\r\n", size); |
| 71 | } |
76 | } |
| 72 | 77 | ||
| Line 113... | Line 118... | ||
| 113 | } |
118 | } |
| 114 | 119 | ||
| 115 | static const ShellCommand commands[] = { { "mem", cmd_mem }, { "threads", |
120 | static const ShellCommand commands[] = { { "mem", cmd_mem }, { "threads", |
| 116 | cmd_threads }, { "test", cmd_test }, { NULL, NULL } }; |
121 | cmd_threads }, { "test", cmd_test }, { NULL, NULL } }; |
| 117 | 122 | ||
| - | 123 | ||
| - | 124 | ||
| - | 125 | ||
| - | 126 | ||
| - | 127 | ||
| 118 | static const ShellConfig shell_cfg1 = { (BaseChannel *) &SDU1, commands }; |
128 | static const ShellConfig shell_cfg1 = { |
| - | 129 | #if (HAL_USE_SERIAL_USB == TRUE) |
|
| - | 130 | (BaseSequentialStream *)&SDU1, |
|
| - | 131 | #else |
|
| - | 132 | (BaseSequentialStream *)&SD1, |
|
| - | 133 | #endif |
|
| - | 134 | commands |
|
| - | 135 | }; |
|
| - | 136 | //////// |
|
| - | 137 | // end of shell stuff |
|
| 119 | 138 | ||
| 120 | uint16_t sampIndex; |
139 | uint16_t sampIndex; |
| 121 | 140 | ||
| 122 | static THD_WORKING_AREA(waThread1, 512); |
141 | static THD_WORKING_AREA(waThread1, 512); |
| 123 | static msg_t Thread1(void *arg) { |
142 | static msg_t Thread1(void *arg) { |
| Line 132... | Line 151... | ||
| 132 | } |
151 | } |
| 133 | return 0; |
152 | return 0; |
| 134 | } |
153 | } |
| 135 | 154 | ||
| 136 | /* |
155 | /* |
| 137 | * USB Bulk thread, times are in milliseconds. |
156 | * Command Shell Thread |
| 138 | */ |
157 | */ |
| 139 | static THD_WORKING_AREA(waThread2, 512); |
158 | static THD_WORKING_AREA(waThread2, 512); |
| 140 | static msg_t Thread2(void *arg) { |
159 | static msg_t Thread2(void *arg) { |
| - | 160 | thread_t *shelltp = NULL; |
|
| - | 161 | /* |
|
| - | 162 | * Normal main() thread activity, in this demo it just performs |
|
| - | 163 | * a shell respawn upon its termination. |
|
| - | 164 | */ |
|
| - | 165 | while (true) { |
|
| - | 166 | if (!shelltp) { |
|
| - | 167 | #if (HAL_USE_SERIAL_USB == TRUE) |
|
| - | 168 | if (SDU1.config->usbp->state == USB_ACTIVE) { |
|
| - | 169 | /* Spawns a new shell.*/ |
|
| - | 170 | shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, "shell", NORMALPRIO, shellThread, (void *) &shell_cfg1); |
|
| - | 171 | } |
|
| - | 172 | #else |
|
| - | 173 | shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, "shell", NORMALPRIO, shellThread, (void *) &shell_cfg1); |
|
| - | 174 | #endif |
|
| - | 175 | } |
|
| - | 176 | else { |
|
| - | 177 | /* If the previous shell exited.*/ |
|
| - | 178 | if (chThdTerminatedX(shelltp)) { |
|
| - | 179 | /* Recovers memory of the previous shell.*/ |
|
| - | 180 | chThdRelease(shelltp); |
|
| - | 181 | shelltp = NULL; |
|
| - | 182 | } |
|
| - | 183 | } |
|
| 141 | chThdSleep(TIME_INFINITE); |
184 | chThdSleepMilliseconds(500); |
| - | 185 | } |
|
| 142 | 186 | ||
| - | 187 | return MSG_OK; |
|
| 143 | } |
188 | } |
| 144 | 189 | ||
| 145 | 190 | ||
| 146 | 191 | ||
| 147 | 192 | ||
| 148 | /* |
193 | /* |
| 149 | * Application entry point. |
194 | * Application entry point. |
| 150 | */ |
195 | */ |
| 151 | int main(void) { |
196 | int main(void) { |
| 152 | thread_t *shelltp = NULL; |
- | |
| 153 | // struct EventListener el0, el1; |
197 | // struct EventListener el0, el1; |
| 154 | 198 | ||
| 155 | /* |
199 | /* |
| 156 | * System initializations. |
200 | * System initializations. |
| 157 | * - HAL initialization, this also initializes the configured device drivers |
201 | * - HAL initialization, this also initializes the configured device drivers |
| Line 160... | Line 204... | ||
| 160 | * RTOS is active. |
204 | * RTOS is active. |
| 161 | */ |
205 | */ |
| 162 | halInit(); |
206 | halInit(); |
| 163 | chSysInit(); |
207 | chSysInit(); |
| 164 | 208 | ||
| 165 | /* |
- | |
| 166 | * Initializes a serial-over-USB CDC driver. |
- | |
| 167 | */ |
- | |
| 168 | // sduObjectInit(&SDU1); |
- | |
| 169 | // sduStart(&SDU1, &serusbcfg); |
- | |
| 170 | 209 | ||
| - | 210 | ||
| - | 211 | #if (HAL_USE_SERIAL_USB == TRUE) |
|
| 171 | /* |
212 | /* |
| - | 213 | * Initializes a serial-over-USB CDC driver. |
|
| - | 214 | */ |
|
| - | 215 | sduObjectInit(&SDU1); |
|
| - | 216 | sduStart(&SDU1, &serusbcfg); |
|
| - | 217 | ||
| - | 218 | /* |
|
| 172 | * Activates the USB driver and then the USB bus pull-up on D+. |
219 | * Activates the USB driver and then the USB bus pull-up on D+. |
| 173 | * Note, a delay is inserted in order to not have to disconnect the cable |
220 | * Note, a delay is inserted in order to not have to disconnect the cable |
| 174 | * after a reset. |
221 | * after a reset. |
| 175 | */ |
222 | */ |
| 176 | // usbDisconnectBus(serusbcfg.usbp); |
223 | usbDisconnectBus(serusbcfg.usbp); |
| 177 | // chThdSleepMilliseconds(1500); |
224 | chThdSleepMilliseconds(1000); |
| 178 | // usbStart(serusbcfg.usbp, &usbcfg); |
225 | usbStart(serusbcfg.usbp, &usbcfg); |
| 179 | // usbConnectBus(serusbcfg.usbp); |
226 | usbConnectBus(serusbcfg.usbp); |
| - | 227 | #else |
|
| - | 228 | /* |
|
| - | 229 | * Initializes serial port. |
|
| - | 230 | */ |
|
| - | 231 | sdStart(&SD2, NULL); |
|
| - | 232 | #endif /* HAL_USE_SERIAL_USB */ |
|
| 180 | 233 | ||
| 181 | // Ignition timing code |
234 | // Ignition timing code |
| 182 | initTimer2(); |
235 | initTimer2(); |
| 183 | 236 | ||
| 184 | useAdc(); |
237 | useAdc(); |
| Line 199... | Line 252... | ||
| 199 | /* |
252 | /* |
| 200 | * Creates the PLL thread |
253 | * Creates the PLL thread |
| 201 | */ |
254 | */ |
| 202 | chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); |
255 | chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); |
| 203 | 256 | ||
| - | 257 | ||
| - | 258 | ||
| - | 259 | chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL); |
|
| - | 260 | ||
| 204 | /* start the SPI hardware for display */ |
261 | /* start the SPI hardware for display */ |
| 205 | ssd1306spiInit(); |
262 | ssd1306spiInit(); |
| 206 | 263 | ||
| 207 | ssd1306_begin( SSD1306_SWITCHCAPVCC, 0) ; |
264 | ssd1306_begin( SSD1306_SWITCHCAPVCC, 0) ; |
| 208 | int spd = 800; |
265 | int spd = 800; |