From a927edc984c1a333b91df29c5640eb17b1a6e59c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 1 Aug 2010 08:53:54 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2106 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- testhal/STM32/UART/main.c | 60 +++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 23 deletions(-) (limited to 'testhal/STM32/UART') diff --git a/testhal/STM32/UART/main.c b/testhal/STM32/UART/main.c index 214cf35db..e111935d7 100644 --- a/testhal/STM32/UART/main.c +++ b/testhal/STM32/UART/main.c @@ -20,7 +20,7 @@ #include "ch.h" #include "hal.h" -static VirtualTimer vt; +static VirtualTimer vt1, vt2; static void restart(void *p) { @@ -28,31 +28,66 @@ static void restart(void *p) { uartStartSend(&UARTD2, 14, "Hello World!\r\n"); } +static void ledoff(void *p) { + + (void)p; + palSetPad(IOPORT3, GPIOC_LED); +} + +/* + * This callback is invoked when a transmission buffer has been completely + * read by the driver. + */ static void txend1(void) { + palClearPad(IOPORT3, GPIOC_LED); } +/* + * This callback is invoked when a transmission has phisically completed. + */ static void txend2(void) { + palSetPad(IOPORT3, GPIOC_LED); chSysLockFromIsr(); - chVTSetI(&vt, MS2ST(1000), restart, NULL); + chVTSetI(&vt1, MS2ST(5000), restart, NULL); chSysUnlockFromIsr(); } +/* + * This callback is invoked on a receive error, the errors mask is passed + * as parameter. + */ static void rxerr(uartflags_t e) { (void)e; } +/* + * This callback is invoked when a character is received but the application + * was not ready to receive it, the character is passed as parameter. + */ static void rxchar(uint16_t c) { (void)c; + /* Flashing the LED each time a character is received.*/ + palClearPad(IOPORT3, GPIOC_LED); + chSysLockFromIsr(); + if (!chVTIsArmedI(&vt2)) + chVTSetI(&vt2, MS2ST(200), ledoff, NULL); + chSysUnlockFromIsr(); } +/* + * This callback is invoked when a receive buffer has been completely written. + */ static void rxend(void) { } +/* + * UART driver configuration structure. + */ static UARTConfig uart_cfg_1 = { txend1, txend2, @@ -65,22 +100,6 @@ static UARTConfig uart_cfg_1 = { 0 }; -/* - * Red LEDs blinker thread, times are in milliseconds. - */ -static WORKING_AREA(waThread1, 128); -static msg_t Thread1(void *arg) { - - (void)arg; - while (TRUE) { - palClearPad(IOPORT3, GPIOC_LED); - chThdSleepMilliseconds(500); - palSetPad(IOPORT3, GPIOC_LED); - chThdSleepMilliseconds(500); - } - return 0; -} - /* * Entry point, note, the main() function is already a thread in the system * on entry. @@ -95,11 +114,6 @@ int main(int argc, char **argv) { */ uartStart(&UARTD2, &uart_cfg_1); - /* - * Creates the blinker thread. - */ - chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); - /* * Starts the transmission, it will be handled entirely in background. */ -- cgit v1.2.3