diff options
Diffstat (limited to 'lib/chibios-contrib/testhal/KINETIS/TEENSY3_x/SERIAL/main.c')
-rw-r--r-- | lib/chibios-contrib/testhal/KINETIS/TEENSY3_x/SERIAL/main.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/lib/chibios-contrib/testhal/KINETIS/TEENSY3_x/SERIAL/main.c b/lib/chibios-contrib/testhal/KINETIS/TEENSY3_x/SERIAL/main.c new file mode 100644 index 000000000..174774eaa --- /dev/null +++ b/lib/chibios-contrib/testhal/KINETIS/TEENSY3_x/SERIAL/main.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2015 RedoX https://github.com/RedoXyde | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | #include "hal.h" | ||
17 | |||
18 | static THD_WORKING_AREA(waSerEcho, 128); | ||
19 | static THD_FUNCTION(thSerEcho, arg) | ||
20 | { | ||
21 | (void)arg; | ||
22 | chRegSetThreadName("SerEcho"); | ||
23 | event_listener_t elSerData; | ||
24 | eventflags_t flags; | ||
25 | chEvtRegisterMask((event_source_t *)chnGetEventSource(&SD1), &elSerData, EVENT_MASK(1)); | ||
26 | |||
27 | while (!chThdShouldTerminateX()) | ||
28 | { | ||
29 | chEvtWaitOneTimeout(EVENT_MASK(1), TIME_MS2I(10)); | ||
30 | flags = chEvtGetAndClearFlags(&elSerData); | ||
31 | if (flags & CHN_INPUT_AVAILABLE) | ||
32 | { | ||
33 | msg_t charbuf; | ||
34 | do | ||
35 | { | ||
36 | charbuf = chnGetTimeout(&SD1, TIME_IMMEDIATE); | ||
37 | if ( charbuf != Q_TIMEOUT ) | ||
38 | { | ||
39 | streamPut(&SD1, charbuf); | ||
40 | } | ||
41 | } | ||
42 | while (charbuf != Q_TIMEOUT); | ||
43 | } | ||
44 | } | ||
45 | } | ||
46 | |||
47 | SerialConfig s0cfg = | ||
48 | { | ||
49 | 19200 | ||
50 | }; | ||
51 | |||
52 | /* | ||
53 | * Application entry point. | ||
54 | */ | ||
55 | int main(void) { | ||
56 | |||
57 | /* | ||
58 | * System initializations. | ||
59 | * - HAL initialization, this also initializes the configured device drivers | ||
60 | * and performs the board-specific initializations. | ||
61 | * - Kernel initialization, the main() function becomes a thread and the | ||
62 | * RTOS is active. | ||
63 | */ | ||
64 | halInit(); | ||
65 | chSysInit(); | ||
66 | |||
67 | /* | ||
68 | * Activates serial 1 (UART0) using the driver default configuration. | ||
69 | */ | ||
70 | sdStart(&SD1, &s0cfg); | ||
71 | |||
72 | chThdCreateStatic(waSerEcho, sizeof(waSerEcho), NORMALPRIO, thSerEcho, NULL); | ||
73 | |||
74 | while (!chThdShouldTerminateX()) { | ||
75 | chThdSleepMilliseconds(1000); | ||
76 | palTogglePad(TEENSY_PIN13_IOPORT, TEENSY_PIN13); | ||
77 | sdPut(&SD1,'B'); | ||
78 | } | ||
79 | |||
80 | return 0; | ||
81 | } | ||