diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-03-10 10:22:17 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-03-10 10:22:17 +0000 |
commit | 70a2d4de7efaf5e5c886deb50680b1470fa8915a (patch) | |
tree | dc700deb563f91c6c72f40fbbd4013e376153482 /testhal/STM32F4xx/UART/main.c | |
parent | 178aeec4b7e7c341acbfc1a3aafa77f27555a8af (diff) | |
download | ChibiOS-70a2d4de7efaf5e5c886deb50680b1470fa8915a.tar.gz ChibiOS-70a2d4de7efaf5e5c886deb50680b1470fa8915a.tar.bz2 ChibiOS-70a2d4de7efaf5e5c886deb50680b1470fa8915a.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5399 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal/STM32F4xx/UART/main.c')
-rw-r--r-- | testhal/STM32F4xx/UART/main.c | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/testhal/STM32F4xx/UART/main.c b/testhal/STM32F4xx/UART/main.c index d51d6beb6..99237e8ae 100644 --- a/testhal/STM32F4xx/UART/main.c +++ b/testhal/STM32F4xx/UART/main.c @@ -21,23 +21,29 @@ #include "ch.h"
#include "hal.h"
-static VirtualTimer vt1, vt2;
+static VirtualTimer vt3, vt4, vt5;
-static void restart(void *p) {
+static const uint8_t message[] = "0123456789ABCDEF";
+static uint8_t buffer[16];
- (void)p;
+static void led3off(void *p) {
- chSysLockFromIsr();
- uartStartSendI(&UARTD2, 14, "Hello World!\r\n");
- chSysUnlockFromIsr();
+ (void)p;
+ palClearPad(GPIOD, GPIOD_LED3);
}
-static void ledoff(void *p) {
+static void led4off(void *p) {
(void)p;
palClearPad(GPIOD, GPIOD_LED4);
}
+static void led5off(void *p) {
+
+ (void)p;
+ palClearPad(GPIOD, GPIOD_LED5);
+}
+
/*
* This callback is invoked when a transmission buffer has been completely
* read by the driver.
@@ -45,7 +51,6 @@ static void ledoff(void *p) { static void txend1(UARTDriver *uartp) {
(void)uartp;
- palSetPad(GPIOD, GPIOD_LED4);
}
/*
@@ -54,11 +59,11 @@ static void txend1(UARTDriver *uartp) { static void txend2(UARTDriver *uartp) {
(void)uartp;
- palClearPad(GPIOD, GPIOD_LED4);
+ palSetPad(GPIOD, GPIOD_LED5);
chSysLockFromIsr();
- if (chVTIsArmedI(&vt1))
- chVTResetI(&vt1);
- chVTSetI(&vt1, MS2ST(5000), restart, NULL);
+ if (chVTIsArmedI(&vt5))
+ chVTResetI(&vt5);
+ chVTSetI(&vt5, MS2ST(200), led5off, NULL);
chSysUnlockFromIsr();
}
@@ -83,9 +88,9 @@ static void rxchar(UARTDriver *uartp, uint16_t c) { /* Flashing the LED each time a character is received.*/
palSetPad(GPIOD, GPIOD_LED4);
chSysLockFromIsr();
- if (chVTIsArmedI(&vt2))
- chVTResetI(&vt2);
- chVTSetI(&vt2, MS2ST(200), ledoff, NULL);
+ if (chVTIsArmedI(&vt4))
+ chVTResetI(&vt4);
+ chVTSetI(&vt4, MS2ST(200), led4off, NULL);
chSysUnlockFromIsr();
}
@@ -95,6 +100,14 @@ static void rxchar(UARTDriver *uartp, uint16_t c) { static void rxend(UARTDriver *uartp) {
(void)uartp;
+
+ /* Flashing the LED each time a character is received.*/
+ palSetPad(GPIOD, GPIOD_LED3);
+ chSysLockFromIsr();
+ if (chVTIsArmedI(&vt3))
+ chVTResetI(&vt3);
+ chVTSetI(&vt3, MS2ST(200), led3off, NULL);
+ chSysUnlockFromIsr();
}
/*
@@ -134,15 +147,21 @@ int main(void) { palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
- /*
- * Starts the transmission, it will be handled entirely in background.
- */
- uartStartSend(&UARTD2, 13, "Starting...\r\n");
/*
* Normal main() thread activity, in this demo it does nothing.
*/
while (TRUE) {
+ if (palReadPad(GPIOA, GPIOA_BUTTON)) {
+ /*
+ * Starts both a transmission and a receive operations, both will be
+ * handled entirely in background.
+ */
+ uartStopReceive(&UARTD2);
+ uartStopSend(&UARTD2);
+ uartStartReceive(&UARTD2, 16, buffer);
+ uartStartSend(&UARTD2, 16, message);
+ }
chThdSleepMilliseconds(500);
}
}
|