aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/usart.c
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2010-09-01 00:02:36 -0400
committerbnewbold <bnewbold@robocracy.org>2010-09-01 00:02:36 -0400
commitd6a32991684b7bfd8b91e3358dee4ca3fc887021 (patch)
tree535ebe6501bda800363c5f4debccf532d289bc1e /libmaple/usart.c
parent9c9d6c153154981fdedbe3f9ed4a1fb61e2b7776 (diff)
parent0ccec95446d4c7f3ea47a46d267c791fb22bb8d4 (diff)
downloadlibrambutan-d6a32991684b7bfd8b91e3358dee4ca3fc887021.tar.gz
librambutan-d6a32991684b7bfd8b91e3358dee4ca3fc887021.zip
Various fixes, working with Maple
Diffstat (limited to 'libmaple/usart.c')
-rw-r--r--libmaple/usart.c59
1 files changed, 48 insertions, 11 deletions
diff --git a/libmaple/usart.c b/libmaple/usart.c
index 296a1fb..ef54ad0 100644
--- a/libmaple/usart.c
+++ b/libmaple/usart.c
@@ -33,16 +33,18 @@
#include "nvic.h"
#include "usart.h"
-#define USART1_BASE 0x40013800
-#define USART2_BASE 0x40004400
-#define USART3_BASE 0x40004800
-
-#define USART_UE BIT(13)
-#define USART_M BIT(12)
-#define USART_TE BIT(3)
-#define USART_RE BIT(2)
-#define USART_RXNEIE BIT(5) // read data register not empty interrupt enable
-#define USART_TC BIT(6)
+#define USART1_BASE 0x40013800
+#define USART2_BASE 0x40004400
+#define USART3_BASE 0x40004800
+#define UART4_BASE 0x40004C00 // High-density devices only (Maple Native)
+#define UART5_BASE 0x40005000 // High-density devices only (Maple Native)
+
+#define USART_UE BIT(13)
+#define USART_M BIT(12)
+#define USART_TE BIT(3)
+#define USART_RE BIT(2)
+#define USART_RXNEIE BIT(5) // read data register not empty interrupt enable
+#define USART_TC BIT(6)
/* usart descriptor table */
struct usart_dev usart_dev_table[] = {
@@ -61,6 +63,20 @@ struct usart_dev usart_dev_table[] = {
.rcc_dev_num = RCC_USART3,
.nvic_dev_num = NVIC_USART3
},
+ /*
+ #if NR_USART >= 5
+ [UART4] = {
+ .base = (usart_port*)UART4_BASE,
+ .rcc_dev_num = RCC_UART4,
+ .nvic_dev_num = NVIC_UART4
+ },
+ [UART5] = {
+ .base = (usart_port*)UART5_BASE,
+ .rcc_dev_num = RCC_UART5,
+ .nvic_dev_num = NVIC_UART5
+ },
+ #endif
+ */
};
/* usart interrupt handlers */
@@ -75,6 +91,14 @@ void USART2_IRQHandler(void) {
void USART3_IRQHandler(void) {
rb_insert(&usart_dev_table[USART3].rb, (uint8)(((usart_port*)(USART3_BASE))->DR));
}
+#if NR_USART >= 5
+void UART4_IRQHandler(void) {
+ rb_insert(&usart_dev_table[UART4].rb, (uint8)(((usart_port*)(UART4_BASE))->DR));
+}
+void UART5_IRQHandler(void) {
+ rb_insert(&usart_dev_table[UART5].rb, (uint8)(((usart_port*)(UART5_BASE))->DR));
+}
+#endif
/**
* @brief Enable a USART in single buffer transmission mode, multibuffer
@@ -83,6 +107,7 @@ void USART3_IRQHandler(void) {
* @param baud Baud rate to be set at
*/
void usart_init(uint8 usart_num, uint32 baud) {
+ ASSERT(usart_num <= NR_USART);
usart_port *port;
ring_buffer *ring_buf;
@@ -121,6 +146,18 @@ void usart_init(uint8 usart_num, uint32 baud) {
port->CR1 |= USART_UE;
}
+/**
+ * @brief Turn off all USARTs.
+ */
+void usart_disable_all() {
+ usart_disable(USART1);
+ usart_disable(USART2);
+ usart_disable(USART3);
+ #if NR_USART >= 5
+ usart_disable(UART4);
+ usart_disable(UART5);
+ #endif
+}
/**
* @brief Turn off a USART.
@@ -130,7 +167,7 @@ void usart_disable(uint8 usart_num) {
usart_port *port = usart_dev_table[usart_num].base;
/* TC bit must be high before disabling the usart */
- while ((port->SR & USART_TC) == 0)
+ while((port->CR1 & USART_UE) && !(port->SR & USART_TC))
;
/* Disable UE */