Rev 6 | Rev 8 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 6 | Rev 7 | ||
|---|---|---|---|
| Line 23... | Line 23... | ||
| 23 | a combined work that includes ChibiOS/RT, without being obliged to provide |
23 | a combined work that includes ChibiOS/RT, without being obliged to provide |
| 24 | the source code for any proprietary components. See the file exception.txt |
24 | the source code for any proprietary components. See the file exception.txt |
| 25 | for full details of how and when the exception can be applied. |
25 | for full details of how and when the exception can be applied. |
| 26 | */ |
26 | */ |
| 27 | 27 | ||
| - | 28 | #include <stdio.h> |
|
| 28 | #include <string.h> |
29 | #include <string.h> |
| 29 | 30 | ||
| 30 | #include "ch.h" |
31 | #include "ch.h" |
| 31 | #include "hal.h" |
32 | #include "hal.h" |
| 32 | #include "test.h" |
33 | //#include "test.h" |
| 33 | #include "shell.h" |
34 | #include "shell.h" |
| 34 | #include "evtimer.h" |
35 | #include "evtimer.h" |
| 35 | #include "chprintf.h" |
36 | #include "chprintf.h" |
| 36 | 37 | ||
| - | 38 | #include "usbcfg.h" |
|
| - | 39 | ||
| 37 | 40 | ||
| 38 | #include "ap_math.h" |
41 | #include "ap_math.h" |
| 39 | #include "hardware.h" |
42 | #include "hardware.h" |
| 40 | #include "useAdc.h" |
43 | #include "useAdc.h" |
| 41 | #include "spiInterface.h" |
44 | #include "spiInterface.h" |
| Line 47... | Line 50... | ||
| 47 | 50 | ||
| 48 | /*===========================================================================*/ |
51 | /*===========================================================================*/ |
| 49 | /* Command line related. */ |
52 | /* Command line related. */ |
| 50 | /*===========================================================================*/ |
53 | /*===========================================================================*/ |
| 51 | 54 | ||
| 52 | #define SHELL_WA_SIZE THD_WA_SIZE(2048) |
55 | #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) |
| 53 | #define TEST_WA_SIZE THD_WA_SIZE(256) |
56 | #define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) |
| 54 | 57 | ||
| 55 | static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) { |
58 | static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) { |
| 56 | size_t n, size; |
59 | size_t n, size , largest; |
| 57 | 60 | ||
| 58 | (void) argv; |
61 | (void) argv; |
| 59 | if (argc > 0) { |
62 | if (argc > 0) { |
| 60 | chprintf(chp, "Usage: mem\r\n"); |
63 | chprintf(chp, "Usage: mem\r\n"); |
| 61 | return; |
64 | return; |
| 62 | } |
65 | } |
| 63 | n = chHeapStatus(NULL, &size); |
66 | n = chHeapStatus(NULL, &size, &largest); |
| 64 | chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus()); |
67 | chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus()); |
| 65 | chprintf(chp, "heap fragments : %u\r\n", n); |
68 | chprintf(chp, "heap fragments : %u \r\n",n); |
| - | 69 | chprintf(chp, "largest fragment : %u \r\n",largest); |
|
| 66 | chprintf(chp, "heap free total : %u bytes\r\n", size); |
70 | chprintf(chp, "heap free total : %u bytes\r\n", size); |
| 67 | } |
71 | } |
| 68 | 72 | ||
| 69 | static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) { |
73 | static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { |
| 70 | static const char *states[] = { THD_STATE_NAMES }; |
74 | static const char *states[] = {CH_STATE_NAMES}; |
| 71 | Thread *tp; |
75 | thread_t *tp; |
| 72 | 76 | ||
| 73 | (void) argv; |
77 | (void)argv; |
| 74 | if (argc > 0) { |
78 | if (argc > 0) { |
| 75 | chprintf(chp, "Usage: threads\r\n"); |
79 | shellUsage(chp, "threads"); |
| 76 | return; |
80 | return; |
| - | 81 | } |
|
| - | 82 | chprintf(chp, "stklimit stack addr refs prio state name\r\n" SHELL_NEWLINE_STR); |
|
| - | 83 | tp = chRegFirstThread(); |
|
| - | 84 | do { |
|
| - | 85 | #if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE) |
|
| - | 86 | uint32_t stklimit = (uint32_t)tp->wabase; |
|
| - | 87 | #else |
|
| - | 88 | uint32_t stklimit = 0U; |
|
| - | 89 | #endif |
|
| - | 90 | chprintf(chp, "%08lx %08lx %08lx %4lu %4lu %9s %12s" SHELL_NEWLINE_STR, |
|
| - | 91 | stklimit, (uint32_t)tp->ctx.sp, (uint32_t)tp, |
|
| - | 92 | (uint32_t)tp->refs - 1, (uint32_t)tp->prio, states[tp->state], |
|
| - | 93 | tp->name == NULL ? "" : tp->name); |
|
| - | 94 | tp = chRegNextThread(tp); |
|
| - | 95 | } while (tp != NULL); |
|
| 77 | } |
96 | } |
| 78 | chprintf(chp, " addr stack prio refs state time\r\n"); |
- | |
| 79 | tp = chRegFirstThread(); |
- | |
| 80 | do { |
- | |
| 81 | chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n", (uint32_t) tp, |
- | |
| 82 | (uint32_t) tp->p_ctx.r13, (uint32_t) tp->p_prio, |
- | |
| 83 | (uint32_t)(tp->p_refs - 1), states[tp->p_state], |
- | |
| 84 | (uint32_t) tp->p_time); |
- | |
| 85 | tp = chRegNextThread(tp); |
- | |
| 86 | } while (tp != NULL); |
- | |
| 87 | } |
- | |
| 88 | 97 | ||
| 89 | static void cmd_test(BaseChannel *chp, int argc, char *argv[]) { |
98 | static void cmd_test(BaseChannel *chp, int argc, char *argv[]) { |
| 90 | Thread *tp; |
99 | thread_t *tp; |
| 91 | 100 | ||
| 92 | (void) argv; |
101 | (void) argv; |
| 93 | if (argc > 0) { |
102 | if (argc > 0) { |
| 94 | chprintf(chp, "Usage: test\r\n"); |
103 | chprintf(chp, "Usage: test\r\n"); |
| 95 | return; |
104 | return; |
| 96 | } |
105 | } |
| 97 | tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), TestThread, |
106 | //tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), TestThread, |
| 98 | chp); |
107 | // chp); |
| 99 | if (tp == NULL) { |
108 | if (tp == NULL) { |
| 100 | chprintf(chp, "out of memory\r\n"); |
109 | chprintf(chp, "out of memory\r\n"); |
| 101 | return; |
110 | return; |
| 102 | } |
111 | } |
| 103 | chThdWait(tp); |
112 | chThdWait(tp); |
| 104 | } |
113 | } |
| 105 | 114 | ||
| 106 | static const ShellCommand commands[] = { { "mem", cmd_mem }, { "threads", |
115 | static const ShellCommand commands[] = { { "mem", cmd_mem }, { "threads", |
| 107 | cmd_threads }, { "test", cmd_test }, { NULL, NULL } }; |
116 | cmd_threads }, { "test", cmd_test }, { NULL, NULL } }; |
| 108 | 117 | ||
| 109 | static const ShellConfig shell_cfg1 = { (BaseChannel *) &SD2, commands }; |
118 | static const ShellConfig shell_cfg1 = { (BaseChannel *) &SDU1, commands }; |
| 110 | 119 | ||
| 111 | /* |
120 | /* |
| 112 | * Red LEDs blinker thread, times are in milliseconds. |
121 | * Red LEDs blinker thread, times are in milliseconds. |
| 113 | */ |
122 | */ |
| 114 | uint16_t sampleVal; |
123 | uint16_t sampleVal; |
| 115 | 124 | ||
| 116 | static WORKING_AREA(waThread1, 128); |
125 | static THD_WORKING_AREA(waThread1, 128); |
| 117 | static msg_t Thread1(void *arg) { |
126 | static msg_t Thread1(void *arg) { |
| 118 | 127 | ||
| 119 | (void) arg; |
128 | (void) arg; |
| 120 | chRegSetThreadName("PLL "); |
129 | chRegSetThreadName("PLL "); |
| 121 | while (TRUE) { |
130 | while (TRUE) { |
| Line 125... | Line 134... | ||
| 125 | } |
134 | } |
| 126 | return 0; |
135 | return 0; |
| 127 | } |
136 | } |
| 128 | 137 | ||
| 129 | /* |
138 | /* |
| - | 139 | * USB Bulk thread, times are in milliseconds. |
|
| - | 140 | */ |
|
| - | 141 | static THD_WORKING_AREA(waThread2, 128); |
|
| - | 142 | static msg_t Thread2(void *arg) { |
|
| - | 143 | chThdSleep(TIME_INFINITE); |
|
| - | 144 | ||
| - | 145 | } |
|
| - | 146 | ||
| - | 147 | ||
| - | 148 | ||
| - | 149 | ||
| - | 150 | /* |
|
| 130 | * Application entry point. |
151 | * Application entry point. |
| 131 | */ |
152 | */ |
| 132 | int main(void) { |
153 | int main(void) { |
| 133 | Thread *shelltp = NULL; |
154 | thread_t *shelltp = NULL; |
| 134 | // struct EventListener el0, el1; |
155 | // struct EventListener el0, el1; |
| 135 | 156 | ||
| 136 | /* |
157 | /* |
| 137 | * System initializations. |
158 | * System initializations. |
| 138 | * - HAL initialization, this also initializes the configured device drivers |
159 | * - HAL initialization, this also initializes the configured device drivers |
| Line 141... | Line 162... | ||
| 141 | * RTOS is active. |
162 | * RTOS is active. |
| 142 | */ |
163 | */ |
| 143 | halInit(); |
164 | halInit(); |
| 144 | chSysInit(); |
165 | chSysInit(); |
| 145 | 166 | ||
| - | 167 | /* |
|
| - | 168 | * Initializes a serial-over-USB CDC driver. |
|
| - | 169 | */ |
|
| - | 170 | sduObjectInit(&SDU1); |
|
| - | 171 | sduStart(&SDU1, &serusbcfg); |
|
| - | 172 | ||
| - | 173 | /* |
|
| - | 174 | * Activates the USB driver and then the USB bus pull-up on D+. |
|
| - | 175 | * Note, a delay is inserted in order to not have to disconnect the cable |
|
| - | 176 | * after a reset. |
|
| - | 177 | */ |
|
| - | 178 | usbDisconnectBus(serusbcfg.usbp); |
|
| - | 179 | chThdSleepMilliseconds(1500); |
|
| - | 180 | usbStart(serusbcfg.usbp, &usbcfg); |
|
| - | 181 | usbConnectBus(serusbcfg.usbp); |
|
| 146 | 182 | ||
| - | 183 | // Ignition timing code |
|
| 147 | initTimer2(); |
184 | initTimer2(); |
| 148 | 185 | ||
| 149 | useAdc(); |
186 | useAdc(); |
| 150 | 187 | ||
| 151 | /* |
188 | /* |
| 152 | * Activates the serial driver 2 using the driver default configuration. |
189 | * Activates the serial driver 2 using the driver default configuration. |
| 153 | */ |
190 | */ |
| 154 | sdStart(&SD2, NULL); |
191 | sdStart(&SD2, NULL); |
| Line 198... | Line 235... | ||
| 198 | font_sig_digits(12, 0,1,-1, sampleVal); |
235 | font_sig_digits(12, 0,1,-1, sampleVal); |
| 199 | 236 | ||
| 200 | 237 | ||
| 201 | display(); |
238 | display(); |
| 202 | 239 | ||
| 203 | chMtxUnlock(); |
240 | chMtxUnlock(&mutexDisplay); |
| 204 | // |
241 | // |
| 205 | // invertDisplay(x & 32); |
242 | // invertDisplay(x & 32); |
| 206 | 243 | ||
| 207 | chThdSleep(MS2ST(10)); |
244 | chThdSleep(chTimeMS2I(10)); |
| 208 | 245 | ||
| 209 | } |
246 | } |
| 210 | 247 | ||
| 211 | 248 | ||
| - | 249 | // shell thread code . dead at present |
|
| 212 | /* |
250 | // /* |
| 213 | * Normal main() thread activity, in this demo it does nothing except |
251 | // * Normal main() thread activity, spawning shells. |
| 214 | * sleeping in a loop and listen for events. |
- | |
| 215 | */ |
252 | // */ |
| 216 | while (TRUE) { |
253 | // while (true) { |
| 217 | if (!shelltp) |
254 | // if (SDU1.config->usbp->state == USB_ACTIVE) { |
| 218 | shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); |
255 | // thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, |
| 219 | else if (chThdTerminated(shelltp)) { |
256 | // "shell", NORMALPRIO + 1, |
| 220 | chThdRelease(shelltp); /* Recovers memory of the previous shell. */ |
257 | // shellThread, (void *)&shell_cfg1); |
| 221 | shelltp = NULL; /* Triggers spawning of a new shell. */ |
258 | // chThdWait(shelltp); /* Waiting termination. */ |
| 222 | } |
259 | // } |
| 223 | chThdSleep(MS2ST(100)); |
260 | // chThdSleepMilliseconds(1000); |
| 224 | // chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS)); |
- | |
| 225 | } |
261 | // } |
| 226 | return 0; |
262 | |
| 227 | } |
263 | } |