Amalus / iSerial

Dependencies:   RingBuffer

Fork of iSerial by Yoji KURODA

Files at this revision

API Documentation at this revision

Comitter:
ykuroda
Date:
Mon Sep 03 17:26:38 2012 +0000
Parent:
6:8d4b95b90c3b
Child:
8:20759f992d48
Commit message:
bugfix of tx interrupt

Changed in this revision

iSerial.cpp Show annotated file Show diff for this revision Revisions of this file
iSerial.h Show annotated file Show diff for this revision Revisions of this file
--- a/iSerial.cpp	Mon Sep 03 12:01:55 2012 +0000
+++ b/iSerial.cpp	Mon Sep 03 17:26:38 2012 +0000
@@ -10,7 +10,7 @@
 #include "iSerial.h"
 
 
-//DigitalOut led1(LED1);
+DigitalOut led4(LED4);
 
 
 void
@@ -45,6 +45,37 @@
     }
 }
 
+void
+iSerial::disable_uart_irq(void)
+{
+    switch(tx){
+    case USBTX:
+        #if defined(TARGET_LPC1768)
+            NVIC_DisableIRQ(UART2_IRQn);
+        #elif defined(TARGET_LPC11U24)
+            NVIC_DisableIRQ(UART_IRQn);
+        #endif
+//        led1 = !led1;
+        break;
+        
+    case p9:
+        #if defined(TARGET_LPC1768)
+            NVIC_DisableIRQ(UART1_IRQn);
+        #elif defined(TARGET_LPC11U24)
+            NVIC_DisableIRQ(UART_IRQn);
+        #endif
+        break;
+
+    #if defined(TARGET_LPC1768)
+    case p13:
+        NVIC_DisableIRQ(UART3_IRQn);
+        break;
+    case p28:
+        NVIC_DisableIRQ(UART0_IRQn);
+        break;
+    #endif
+    }
+}
 
 /*
  *    Interrupt Function
@@ -52,21 +83,22 @@
 void
 iSerial::rx_handler(void)
 {
+//    disable_uart_irq();
     if(Serial::readable()){
         rxbuf.save(Serial::getc());
     }
-    enable_uart_irq();
+//    enable_uart_irq();
 }
 
 void
 iSerial::tx_handler(void)
 {
-    if(Serial::writeable()){
-        if(txbuf.check()){
-            Serial::putc( txbuf.read() );
-        }
-    }
-    enable_uart_irq();
+led4 = 1;
+//    disable_uart_irq();
+    while(Serial::writeable() && txbuf.check())
+        Serial::putc( txbuf.read() );
+//    enable_uart_irq();
+led4 = 0;
 }
 
 iSerial::iSerial(PinName _tx, PinName _rx, const char *_name, int _txbufsize, int _rxbufsize)
@@ -107,7 +139,8 @@
 {
     unsigned short int c;
 
-    while(!rxbuf.check());
+    while(!rxbuf.check())   // wait receiving a character
+        enable_uart_irq();
     c = rxbuf.read();
 
     return c;
@@ -120,7 +153,13 @@
         Serial::putc(ch);
         
     } else {
-        while(txbuf.full());
+        while(txbuf.full()){
+            disable_uart_irq();
+            tx_handler();
+            enable_uart_irq();
+        }
+        
+        disable_uart_irq();
         txbuf.save(ch);
         enable_uart_irq();
     }
@@ -161,7 +200,8 @@
 void
 iSerial::flush(void)
 {
-    while(txbuf.check());
+    while(txbuf.check())
+        enable_uart_irq();
 }
 
 
--- a/iSerial.h	Mon Sep 03 12:01:55 2012 +0000
+++ b/iSerial.h	Mon Sep 03 17:26:38 2012 +0000
@@ -27,6 +27,7 @@
     void tx_handler(void);
     void rx_handler(void);
     void enable_uart_irq(void);
+    void disable_uart_irq(void);
 
   public: