aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/testhal/NRF52/NRF52832/UART/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/testhal/NRF52/NRF52832/UART/main.c')
-rw-r--r--lib/chibios-contrib/testhal/NRF52/NRF52832/UART/main.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/lib/chibios-contrib/testhal/NRF52/NRF52832/UART/main.c b/lib/chibios-contrib/testhal/NRF52/NRF52832/UART/main.c
new file mode 100644
index 000000000..00a00e0fb
--- /dev/null
+++ b/lib/chibios-contrib/testhal/NRF52/NRF52832/UART/main.c
@@ -0,0 +1,144 @@
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
20static virtual_timer_t vt1, vt2;
21
22static void restart(void *p) {
23
24 (void)p;
25
26 chSysLockFromISR();
27 uartStartSendI(&UARTD1, 14, "Hello World!\r\n");
28 chSysUnlockFromISR();
29}
30
31static void ledoff(void *p) {
32
33 (void)p;
34
35 palSetPad(IOPORT1, LED1);
36}
37
38/*
39 * This callback is invoked when a transmission buffer has been completely
40 * read by the driver.
41 */
42static void txend1(UARTDriver *uartp) {
43
44 (void)uartp;
45
46 palClearPad(IOPORT1, LED1);
47}
48
49/*
50 * This callback is invoked when a transmission has physically completed.
51 */
52static void txend2(UARTDriver *uartp) {
53
54 (void)uartp;
55
56 palSetPad(IOPORT1, LED1);
57 chSysLockFromISR();
58 chVTResetI(&vt1);
59 chVTDoSetI(&vt1, TIME_MS2I(5000), restart, NULL);
60 chSysUnlockFromISR();
61}
62
63/*
64 * This callback is invoked on a receive error, the errors mask is passed
65 * as parameter.
66 */
67static void rxerr(UARTDriver *uartp, uartflags_t e) {
68
69 (void)uartp;
70 (void)e;
71}
72
73/*
74 * This callback is invoked when a character is received but the application
75 * was not ready to receive it, the character is passed as parameter.
76 */
77static void rxchar(UARTDriver *uartp, uint16_t c) {
78
79 (void)uartp;
80 (void)c;
81
82 /* Flashing the LED each time a character is received.*/
83 palClearPad(IOPORT1, LED1);
84 chSysLockFromISR();
85 chVTResetI(&vt2);
86 chVTDoSetI(&vt2, TIME_MS2I(200), ledoff, NULL);
87 chSysUnlockFromISR();
88}
89
90/*
91 * This callback is invoked when a receive buffer has been completely written.
92 */
93static void rxend(UARTDriver *uartp) {
94
95 (void)uartp;
96}
97
98/*
99 * UART driver configuration structure.
100 */
101static UARTConfig uart_cfg_1 = {
102 txend1,
103 txend2,
104 rxend,
105 rxchar,
106 rxerr,
107 38400,
108 UART_TX,
109 UART_RX,
110};
111
112/*
113 * Application entry point.
114 */
115int main(void) {
116
117 /*
118 * System initializations.
119 * - HAL initialization, this also initializes the configured device drivers
120 * and performs the board-specific initializations.
121 * - Kernel initialization, the main() function becomes a thread and the
122 * RTOS is active.
123 */
124 halInit();
125 chSysInit();
126
127 /*
128 * Activates the serial driver 2 using the driver default configuration.
129 */
130 uartStart(&UARTD1, &uart_cfg_1);
131
132 /*
133 * Starts the transmission, it will be handled entirely in background.
134 */
135 uartStartSend(&UARTD1, 13, "Starting...\r\n");
136
137 /*
138 * Normal main() thread activity, in this demo it does nothing.
139 */
140 while (true) {
141 chThdSleepMilliseconds(500);
142 }
143 return 0;
144}