aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/demos/SPC5/NIL-SPC560D-EVB/main.c
diff options
context:
space:
mode:
authorAkshay <[email protected]>2022-04-10 12:13:40 +0100
committerAkshay <[email protected]>2022-04-10 12:13:40 +0100
commitdc90387ce7d8ba7b607d9c48540bf6d8b560f14d (patch)
tree4ccb8fa5886b66fa9d480edef74236c27f035e16 /lib/chibios/demos/SPC5/NIL-SPC560D-EVB/main.c
Diffstat (limited to 'lib/chibios/demos/SPC5/NIL-SPC560D-EVB/main.c')
-rw-r--r--lib/chibios/demos/SPC5/NIL-SPC560D-EVB/main.c150
1 files changed, 150 insertions, 0 deletions
diff --git a/lib/chibios/demos/SPC5/NIL-SPC560D-EVB/main.c b/lib/chibios/demos/SPC5/NIL-SPC560D-EVB/main.c
new file mode 100644
index 000000000..8ba866780
--- /dev/null
+++ b/lib/chibios/demos/SPC5/NIL-SPC560D-EVB/main.c
@@ -0,0 +1,150 @@
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 "nil_test_root.h"
20#include "oslib_test_root.h"
21
22/*
23 * LEDs blinker thread, times are in milliseconds.
24 */
25static THD_WORKING_AREA(waThread1, 128);
26static THD_FUNCTION(Thread1, arg) {
27
28 (void)arg;
29
30 /*
31 * Activates the serial driver 1 using the driver default configuration.
32 */
33 sdStart(&SD1, NULL);
34
35 while (true) {
36 unsigned i;
37
38 for (i = 0; i < 4; i++) {
39 palClearPad(PORT_E, PE_LED1);
40 chThdSleepMilliseconds(100);
41 palClearPad(PORT_E, PE_LED2);
42 chThdSleepMilliseconds(100);
43 palClearPad(PORT_E, PE_LED3);
44 chThdSleepMilliseconds(100);
45 palClearPad(PORT_E, PE_LED4);
46 chThdSleepMilliseconds(100);
47 palSetPad(PORT_E, PE_LED1);
48 chThdSleepMilliseconds(100);
49 palSetPad(PORT_E, PE_LED2);
50 chThdSleepMilliseconds(100);
51 palSetPad(PORT_E, PE_LED3);
52 chThdSleepMilliseconds(100);
53 palSetPad(PORT_E, PE_LED4);
54 chThdSleepMilliseconds(300);
55 }
56
57 for (i = 0; i < 4; i++) {
58 palTogglePort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) |
59 PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4));
60 chThdSleepMilliseconds(500);
61 palTogglePort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) |
62 PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4));
63 chThdSleepMilliseconds(500);
64 }
65
66 for (i = 0; i < 4; i++) {
67 palTogglePad(PORT_E, PE_LED1);
68 chThdSleepMilliseconds(250);
69 palTogglePad(PORT_E, PE_LED1);
70 palTogglePad(PORT_E, PE_LED2);
71 chThdSleepMilliseconds(250);
72 palTogglePad(PORT_E, PE_LED2);
73 palTogglePad(PORT_E, PE_LED3);
74 chThdSleepMilliseconds(250);
75 palTogglePad(PORT_E, PE_LED3);
76 palTogglePad(PORT_E, PE_LED4);
77 chThdSleepMilliseconds(250);
78 palTogglePad(PORT_E, PE_LED4);
79 }
80
81 for (i = 0; i < 4; i++) {
82 palClearPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED3));
83 palSetPort(PORT_E, PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED4));
84 chThdSleepMilliseconds(500);
85 palClearPort(PORT_E, PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED4));
86 palSetPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED3));
87 chThdSleepMilliseconds(500);
88 }
89
90 palSetPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) |
91 PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4));
92 }
93}
94
95/*
96 * Tester thread.
97 */
98THD_WORKING_AREA(waThread2, 128);
99THD_FUNCTION(Thread2, arg) {
100
101 (void)arg;
102
103 /*
104 * Activates the serial driver 1 using the driver default configuration.
105 */
106 sdStart(&SD1, NULL);
107
108 /* Welcome message.*/
109 chnWriteTimeout(&SD1, (uint8_t *)"Hello World!\r\n", 14, TIME_INFINITE);
110
111 /* Waiting for button push and activation of the test suite.*/
112 while (true) {
113 if (palReadPad(PORT_E, PE_BUTTON1)) {
114 test_execute((BaseSequentialStream *)&SD1, &nil_test_suite);
115 test_execute((BaseSequentialStream *)&SD1, &oslib_test_suite);
116 }
117 chThdSleepMilliseconds(500);
118 }
119}
120
121/*
122 * Threads creation table, one entry per thread.
123 */
124THD_TABLE_BEGIN
125 THD_TABLE_THREAD(0, "blinker", waThread1, Thread1, NULL)
126 THD_TABLE_THREAD(4, "tester", waThread2, Thread2, NULL)
127THD_TABLE_END
128
129/*
130 * Application entry point.
131 */
132int main(void) {
133
134 /*
135 * System initializations.
136 * - HAL initialization, this also initializes the configured device drivers
137 * and performs the board-specific initializations.
138 * - Kernel initialization, the main() function becomes a thread and the
139 * RTOS is active.
140 */
141 halInit();
142 chSysInit();
143
144 /* This is now the idle thread loop, you may perform here a low priority
145 task but you must never try to sleep or wait in this loop. Note that
146 this tasks runs at the lowest priority level so any instruction added
147 here will be executed after all other tasks have been started.*/
148 while (true) {
149 }
150}