From 70a2d4de7efaf5e5c886deb50680b1470fa8915a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 10 Mar 2013 10:22:17 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5399 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- testhal/STM32F4xx/UART/main.c | 57 +++++++++++++++++++++++------------ 1 file 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]; + +static void led3off(void *p) { (void)p; - - chSysLockFromIsr(); - uartStartSendI(&UARTD2, 14, "Hello World!\r\n"); - chSysUnlockFromIsr(); + 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); } }