better uart namespace
authorDan White <dan@whiteaudio.com>
Sat, 20 Apr 2013 05:39:40 +0000 (00:39 -0500)
committerDan White <dan@whiteaudio.com>
Sat, 20 Apr 2013 05:39:40 +0000 (00:39 -0500)
msp4th/main.c
msp4th/ns430-uart.c
ns430-uart.h

index 372816fc1fcf870f892b5a3a83ff67ff5dff3797..cc4bc1a6ca9d0e2bcd0ad819cdd0687acf84943e 100644 (file)
@@ -20,6 +20,7 @@
  *      YE BE WARNED
  */
 void __attribute__ ((naked)) _reset_vector__(void) {
+  __asm__ __volatile__("mov #0xffb0,r1"::);
   __asm__ __volatile__("br #main"::);
 }
 
@@ -54,6 +55,7 @@ static void __inline__ eint(void){
 
 
 
+
 int main(void){
 
     int16_t tmp;
@@ -67,7 +69,7 @@ int main(void){
     PAOUT = 0x0000;
     PAOEN = 0x0010;  // set data direction registers
 
-    UART0_BCR = BCR(DEVBOARD_CLOCK, BAUDRATE);
+    UART0_BCR = UART_BCR(DEVBOARD_CLOCK, BAUDRATE);
     UART0_CR = UARTEn;
 
     // a read clears the register -- ready for TX/RX
@@ -79,8 +81,10 @@ int main(void){
      *
      * word "exit" makes processLoop() return
      */
-    init_msp4th();
-    processLoop();
+    while (1) {
+        init_msp4th();
+        processLoop();
+    }
 
     return 0;
 }
index 5eca285f5ee1e516662320c1578de1f1912024f6..439f135324b4afdce3292a4d9684a4c21a65df1f 100644 (file)
@@ -6,7 +6,7 @@
 
 void uart_putchar(uint8_t c)
 {
-    while ((UART0_SR & (TDRE | TXEMPTY)) == 0) {
+    while ((UART0_SR & (UART_TDRE | UART_TXEMPTY)) == 0) {
         // wait for register to clear
     }
     UART0_TDR = (c & 0xff);
@@ -16,7 +16,7 @@ uint8_t uart_getchar(void)
 {
     uint8_t c;
 
-    while ((UART0_SR & RDRF) == 0) {
+    while ((UART0_SR & UART_RDRF) == 0) {
         // wait for char
     }
     c = (UART0_RDR & 0x00ff);
index fb805c5d71ee6f52bfbe6fd7822b493339afa9a8..1dd5478cea8026eec42f8fa168f21eb3829bfbb1 100644 (file)
@@ -4,16 +4,16 @@
 #include "ns430.h"
 
 /* UARTx_CR bits */
-#define TDRE_IE     (1 << 0)
-#define TXEMPTY_IE  (1 << 1)
-#define RDRF_IE     (1 << 2)
-#define OVER_IE     (1 << 3)
-#define PE_IE       (1 << 4)
-#define FE_IE       (1 << 5)
-#define Parity      (1 << 6)
-#define UARTEn      (1 << 7)
-#define LLEN        (1 << 9)
-#define PAR_En      (1 << 10)
+#define UART_TDRE_IE     (1 << 0)
+#define UART_TXEMPTY_IE  (1 << 1)
+#define UART_RDRF_IE     (1 << 2)
+#define UART_OVER_IE     (1 << 3)
+#define UART_PE_IE       (1 << 4)
+#define UART_FE_IE       (1 << 5)
+#define UART_Parity      (1 << 6)
+#define UARTEn           (1 << 7)
+#define UART_LLEN        (1 << 9)
+#define UART_PAR_En      (1 << 10)
 
 /* UARTx_BCR
  * 11-bit number
  * BCR = (CLK / (16 * Baud)) - 1
  */
 
-#define BCR(c, b) ((c / (16 * b)) - 1)
+#define UART_BCR(c, b) ((c / (16 * b)) - 1)
 
 /* UARTx_SR bits */
-#define TDRE        (1 << 0)
-#define TXEMPTY     (1 << 1)
-#define RDRF        (1 << 2)
-#define OVER        (1 << 3)
-#define PE          (1 << 4)
-#define FE          (1 << 5)
+#define UART_TDRE        (1 << 0)
+#define UART_TXEMPTY     (1 << 1)
+#define UART_RDRF        (1 << 2)
+#define UART_OVER        (1 << 3)
+#define UART_PE          (1 << 4)
+#define UART_FE          (1 << 5)
 
 void uart_putchar(uint8_t c);
 uint8_t uart_getchar(void);