Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /* |
2 | ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, |
||
3 | 2011,2012 Giovanni Di Sirio. |
||
4 | |||
5 | This file is part of ChibiOS/RT. |
||
6 | |||
7 | ChibiOS/RT is free software; you can redistribute it and/or modify |
||
8 | it under the terms of the GNU General Public License as published by |
||
9 | the Free Software Foundation; either version 3 of the License, or |
||
10 | (at your option) any later version. |
||
11 | |||
12 | ChibiOS/RT is distributed in the hope that it will be useful, |
||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
15 | GNU General Public License for more details. |
||
16 | |||
17 | You should have received a copy of the GNU General Public License |
||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
19 | |||
20 | --- |
||
21 | |||
22 | A special exception to the GPL can be applied should you wish to distribute |
||
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 |
||
25 | for full details of how and when the exception can be applied. |
||
26 | */ |
||
27 | |||
28 | #include <string.h> |
||
29 | |||
30 | #include "ch.h" |
||
31 | #include "hal.h" |
||
32 | #include "test.h" |
||
33 | #include "shell.h" |
||
34 | #include "evtimer.h" |
||
35 | #include "chprintf.h" |
||
36 | |||
37 | |||
38 | #include "hardware.h" |
||
39 | |||
40 | |||
41 | /*===========================================================================*/ |
||
42 | /* Command line related. */ |
||
43 | /*===========================================================================*/ |
||
44 | |||
45 | #define SHELL_WA_SIZE THD_WA_SIZE(2048) |
||
46 | #define TEST_WA_SIZE THD_WA_SIZE(256) |
||
47 | |||
48 | static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) { |
||
49 | size_t n, size; |
||
50 | |||
51 | (void) argv; |
||
52 | if (argc > 0) { |
||
53 | chprintf(chp, "Usage: mem\r\n"); |
||
54 | return; |
||
55 | } |
||
56 | n = chHeapStatus(NULL, &size); |
||
57 | chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus()); |
||
58 | chprintf(chp, "heap fragments : %u\r\n", n); |
||
59 | chprintf(chp, "heap free total : %u bytes\r\n", size); |
||
60 | } |
||
61 | |||
62 | static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) { |
||
63 | static const char *states[] = { THD_STATE_NAMES }; |
||
64 | Thread *tp; |
||
65 | |||
66 | (void) argv; |
||
67 | if (argc > 0) { |
||
68 | chprintf(chp, "Usage: threads\r\n"); |
||
69 | return; |
||
70 | } |
||
71 | chprintf(chp, " addr stack prio refs state time\r\n"); |
||
72 | tp = chRegFirstThread(); |
||
73 | do { |
||
74 | chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n", (uint32_t) tp, |
||
75 | (uint32_t) tp->p_ctx.r13, (uint32_t) tp->p_prio, |
||
76 | (uint32_t)(tp->p_refs - 1), states[tp->p_state], |
||
77 | (uint32_t) tp->p_time); |
||
78 | tp = chRegNextThread(tp); |
||
79 | } while (tp != NULL); |
||
80 | } |
||
81 | |||
82 | static void cmd_test(BaseChannel *chp, int argc, char *argv[]) { |
||
83 | Thread *tp; |
||
84 | |||
85 | (void) argv; |
||
86 | if (argc > 0) { |
||
87 | chprintf(chp, "Usage: test\r\n"); |
||
88 | return; |
||
89 | } |
||
90 | tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), TestThread, |
||
91 | chp); |
||
92 | if (tp == NULL) { |
||
93 | chprintf(chp, "out of memory\r\n"); |
||
94 | return; |
||
95 | } |
||
96 | chThdWait(tp); |
||
97 | } |
||
98 | |||
99 | static const ShellCommand commands[] = { { "mem", cmd_mem }, { "threads", |
||
100 | cmd_threads }, { "test", cmd_test }, { NULL, NULL } }; |
||
101 | |||
102 | static const ShellConfig shell_cfg1 = { (BaseChannel *) &SD2, commands }; |
||
103 | |||
104 | /* |
||
105 | * Red LEDs blinker thread, times are in milliseconds. |
||
106 | */ |
||
107 | static WORKING_AREA(waThread1, 128); |
||
108 | static msg_t Thread1(void *arg) { |
||
109 | |||
110 | (void) arg; |
||
111 | chRegSetThreadName("blinker"); |
||
112 | while (TRUE) { |
||
113 | palTogglePad(GPIOC, GPIOC_LED); |
||
114 | chThdSleepMilliseconds(500); |
||
115 | } |
||
116 | return 0; |
||
117 | } |
||
118 | |||
119 | /* |
||
120 | * Application entry point. |
||
121 | */ |
||
122 | int main(void) { |
||
123 | Thread *shelltp = NULL; |
||
124 | // struct EventListener el0, el1; |
||
125 | |||
126 | /* |
||
127 | * System initializations. |
||
128 | * - HAL initialization, this also initializes the configured device drivers |
||
129 | * and performs the board-specific initializations. |
||
130 | * - Kernel initialization, the main() function becomes a thread and the |
||
131 | * RTOS is active. |
||
132 | */ |
||
133 | halInit(); |
||
134 | chSysInit(); |
||
135 | |||
136 | /* |
||
137 | * Activates the serial driver 2 using the driver default configuration. |
||
138 | */ |
||
139 | sdStart(&SD2, NULL); |
||
140 | |||
141 | /* |
||
142 | * Shell manager initialization. |
||
143 | */ |
||
144 | shellInit(); |
||
145 | |||
146 | /* |
||
147 | * Creates the blinker thread. |
||
148 | */ |
||
149 | chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); |
||
150 | |||
151 | /* |
||
152 | * Normal main() thread activity, in this demo it does nothing except |
||
153 | * sleeping in a loop and listen for events. |
||
154 | */ |
||
155 | while (TRUE) { |
||
156 | if (!shelltp) |
||
157 | shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); |
||
158 | else if (chThdTerminated(shelltp)) { |
||
159 | chThdRelease(shelltp); /* Recovers memory of the previous shell. */ |
||
160 | shelltp = NULL; /* Triggers spawning of a new shell. */ |
||
161 | } |
||
162 | chThdSleep(MS2ST(100)); |
||
163 | // chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS)); |
||
164 | } |
||
165 | return 0; |
||
166 | } |