aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/demos/LPC21xx/RT-LPC214x-OLIMEX/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/demos/LPC21xx/RT-LPC214x-OLIMEX/main.c')
-rw-r--r--lib/chibios/demos/LPC21xx/RT-LPC214x-OLIMEX/main.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/lib/chibios/demos/LPC21xx/RT-LPC214x-OLIMEX/main.c b/lib/chibios/demos/LPC21xx/RT-LPC214x-OLIMEX/main.c
new file mode 100644
index 000000000..1915cef0f
--- /dev/null
+++ b/lib/chibios/demos/LPC21xx/RT-LPC214x-OLIMEX/main.c
@@ -0,0 +1,100 @@
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
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
17#include "ch.h"
18#include "hal.h"
19#include "rt_test_root.h"
20#include "oslib_test_root.h"
21
22#define BOTH_BUTTONS (PAL_PORT_BIT(PA_BUTTON1) | PAL_PORT_BIT(PA_BUTTON2))
23
24/*
25 * Red LEDs blinker thread, times are in milliseconds.
26 */
27static THD_WORKING_AREA(waThread1, 128);
28static THD_FUNCTION(Thread1, arg) {
29
30 (void)arg;
31 chRegSetThreadName("blinker1");
32 while (true) {
33 palClearPort(IOPORT1, PAL_PORT_BIT(PA_LED2));
34 chThdSleepMilliseconds(200);
35 palSetPort(IOPORT1, PAL_PORT_BIT(PA_LED1) | PAL_PORT_BIT(PA_LED2));
36 chThdSleepMilliseconds(800);
37 palClearPort(IOPORT1, PAL_PORT_BIT(PA_LED1));
38 chThdSleepMilliseconds(200);
39 palSetPort(IOPORT1, PAL_PORT_BIT(PA_LED1) | PAL_PORT_BIT(PA_LED2));
40 chThdSleepMilliseconds(800);
41 }
42}
43
44/*
45 * Yellow LED blinker thread, times are in milliseconds.
46 */
47static THD_WORKING_AREA(waThread2, 128);
48static THD_FUNCTION(Thread2, arg) {
49
50 (void)arg;
51 chRegSetThreadName("blinker2");
52 while (true) {
53 palClearPad(IOPORT1, PA_LEDUSB);
54 chThdSleepMilliseconds(200);
55 palSetPad(IOPORT1, PA_LEDUSB);
56 chThdSleepMilliseconds(300);
57 }
58}
59
60/*
61 * Application entry point.
62 */
63int main(void) {
64
65 /*
66 * System initializations.
67 * - HAL initialization, this also initializes the configured device drivers
68 * and performs the board-specific initializations.
69 * - Kernel initialization, the main() function becomes a thread and the
70 * RTOS is active.
71 */
72 halInit();
73 chSysInit();
74
75 /*
76 * Activates the serial driver 1 using the driver default configuration.
77 */
78 sdStart(&SD1, NULL);
79
80 /*
81 * Creating blinkers threads.
82 */
83 chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
84 chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL);
85
86 /*
87 * Normal main() thread activity, in this demo it does nothing except
88 * sleeping in a loop and check the buttons state and run test procedure.
89 */
90 while (true) {
91 if (!palReadPad(IOPORT1, PA_BUTTON1))
92 sdWrite(&SD1, (uint8_t *)"Hello World!\r\n", 14);
93 if (!palReadPad(IOPORT1, PA_BUTTON2)) {
94 test_execute((BaseSequentialStream *)&SD1, &rt_test_suite);
95 test_execute((BaseSequentialStream *)&SD1, &oslib_test_suite);
96 }
97 chThdSleepMilliseconds(500);
98 }
99 return 0;
100}