aboutsummaryrefslogtreecommitdiffstats
path: root/testhal
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-08-01 08:53:54 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-08-01 08:53:54 +0000
commita927edc984c1a333b91df29c5640eb17b1a6e59c (patch)
tree3c21242715938d11509ae43c8ff2ccdc7edb77db /testhal
parent76d2dd6f453326237db32c06525444a3ba5f40ce (diff)
downloadChibiOS-a927edc984c1a333b91df29c5640eb17b1a6e59c.tar.gz
ChibiOS-a927edc984c1a333b91df29c5640eb17b1a6e59c.tar.bz2
ChibiOS-a927edc984c1a333b91df29c5640eb17b1a6e59c.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2106 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal')
-rw-r--r--testhal/STM32/UART/main.c60
1 files changed, 37 insertions, 23 deletions
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,
@@ -66,22 +101,6 @@ static UARTConfig uart_cfg_1 = {
};
/*
- * 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.
*/
@@ -96,11 +115,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.
*/
uartStartSend(&UARTD2, 13, "Starting...\r\n");