aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2010-07-15 23:34:23 -0400
committerbnewbold <bnewbold@robocracy.org>2010-07-19 00:38:00 -0400
commit432cf91f7d61b3d0642609a33c683388de626e32 (patch)
treef2e496e82d57a9f5fc3323386910f1942e0e5f4e /libmaple
parenta852f8d6a62d5e94afd7092c64c242ab4d5a1c60 (diff)
downloadlibrambutan-432cf91f7d61b3d0642609a33c683388de626e32.tar.gz
librambutan-432cf91f7d61b3d0642609a33c683388de626e32.zip
added Serial.flush()
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/usart.c23
-rw-r--r--libmaple/usart.h1
2 files changed, 24 insertions, 0 deletions
diff --git a/libmaple/usart.c b/libmaple/usart.c
index 717a9d8..282fc5d 100644
--- a/libmaple/usart.c
+++ b/libmaple/usart.c
@@ -209,6 +209,9 @@ void usart_disable(uint8 usart_num) {
/* Disable UE */
port->CR1 = 0;
+
+ /* Clean up buffer */
+ usart_clear_buffer(usart_num);
}
@@ -308,6 +311,26 @@ uint32 usart_data_available(uint8 usart_num) {
return rb->tail - rb->head;
}
+void usart_clear_buffer(uint8 usart_num) {
+ usart_ring_buf *rb;
+
+ switch (usart_num) {
+ case 1:
+ rb = &ring_buf1;
+ break;
+ case 2:
+ rb = &ring_buf2;
+ break;
+ case 3:
+ rb = &ring_buf3;
+ break;
+ default:
+ ASSERT(0);
+ }
+
+ rb->tail = rb->head;
+}
+
/**
diff --git a/libmaple/usart.h b/libmaple/usart.h
index e2c2328..02fb6e0 100644
--- a/libmaple/usart.h
+++ b/libmaple/usart.h
@@ -48,6 +48,7 @@ void usart_putc(uint8 usart_num, uint8 ch);
uint32 usart_data_available(uint8 usart_num);
uint8 usart_getc(uint8 usart_num);
+void usart_clear_buffer(uint8 usart_num);
#ifdef __cplusplus
} // extern "C"