aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/demos/SPC5/RT-SPC56EC-EVB/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/demos/SPC5/RT-SPC56EC-EVB/main.c')
-rw-r--r--lib/chibios/demos/SPC5/RT-SPC56EC-EVB/main.c142
1 files changed, 142 insertions, 0 deletions
diff --git a/lib/chibios/demos/SPC5/RT-SPC56EC-EVB/main.c b/lib/chibios/demos/SPC5/RT-SPC56EC-EVB/main.c
new file mode 100644
index 000000000..86d191b89
--- /dev/null
+++ b/lib/chibios/demos/SPC5/RT-SPC56EC-EVB/main.c
@@ -0,0 +1,142 @@
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 "shell.h"
20#include "chprintf.h"
21
22#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024)
23
24static const ShellCommand commands[] = {
25 {NULL, NULL}
26};
27
28static const ShellConfig shell_cfg1 = {
29 (BaseSequentialStream *)&SD1,
30 commands
31};
32
33/*
34 * LEDs blinker thread, times are in milliseconds.
35 */
36static THD_WORKING_AREA(waThread1, 128);
37static THD_FUNCTION(Thread1, arg) {
38
39 (void)arg;
40 chRegSetThreadName("blinker");
41
42 while (true) {
43 unsigned i;
44
45 for (i = 0; i < 4; i++) {
46 palClearPad(PORT_E, PE_LED1);
47 chThdSleepMilliseconds(100);
48 palClearPad(PORT_E, PE_LED2);
49 chThdSleepMilliseconds(100);
50 palClearPad(PORT_E, PE_LED3);
51 chThdSleepMilliseconds(100);
52 palClearPad(PORT_E, PE_LED4);
53 chThdSleepMilliseconds(100);
54 palSetPad(PORT_E, PE_LED1);
55 chThdSleepMilliseconds(100);
56 palSetPad(PORT_E, PE_LED2);
57 chThdSleepMilliseconds(100);
58 palSetPad(PORT_E, PE_LED3);
59 chThdSleepMilliseconds(100);
60 palSetPad(PORT_E, PE_LED4);
61 chThdSleepMilliseconds(300);
62 }
63
64 for (i = 0; i < 4; i++) {
65 palTogglePort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) |
66 PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4));
67 chThdSleepMilliseconds(500);
68 palTogglePort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) |
69 PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4));
70 chThdSleepMilliseconds(500);
71 }
72
73 for (i = 0; i < 4; i++) {
74 palTogglePad(PORT_E, PE_LED1);
75 chThdSleepMilliseconds(250);
76 palTogglePad(PORT_E, PE_LED1);
77 palTogglePad(PORT_E, PE_LED2);
78 chThdSleepMilliseconds(250);
79 palTogglePad(PORT_E, PE_LED2);
80 palTogglePad(PORT_E, PE_LED3);
81 chThdSleepMilliseconds(250);
82 palTogglePad(PORT_E, PE_LED3);
83 palTogglePad(PORT_E, PE_LED4);
84 chThdSleepMilliseconds(250);
85 palTogglePad(PORT_E, PE_LED4);
86 }
87
88 for (i = 0; i < 4; i++) {
89 palClearPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED3));
90 palSetPort(PORT_E, PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED4));
91 chThdSleepMilliseconds(500);
92 palClearPort(PORT_E, PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED4));
93 palSetPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED3));
94 chThdSleepMilliseconds(500);
95 }
96
97 palSetPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) |
98 PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4));
99 }
100}
101
102/*
103 * Application entry point.
104 */
105int main(void) {
106
107 /*
108 * System initializations.
109 * - HAL initialization, this also initializes the configured device drivers
110 * and performs the board-specific initializations.
111 * - Kernel initialization, the main() function becomes a thread and the
112 * RTOS is active.
113 */
114 halInit();
115 chSysInit();
116
117 /*
118 * Shell manager initialization.
119 */
120 shellInit();
121
122 /*
123 * Activates the serial driver 1 using the driver default configuration.
124 */
125 sdStart(&SD1, NULL);
126
127 /*
128 * Creates the blinker thread.
129 */
130 chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
131
132 /*
133 * Normal main() thread activity, spawning shells.
134 */
135 while (true) {
136 thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
137 "shell", NORMALPRIO + 1,
138 shellThread, (void *)&shell_cfg1);
139 chThdWait(shelltp); /* Waiting termination. */
140 chThdSleepMilliseconds(1000);
141 }
142}