Kenji Arai / iSerial

Dependencies:   RingBuffer

Dependents:   Frequency_Counter_w_GPS_1PPS FreqCntr_GPS1PPS_F746F4xx_w_recipro

Fork of iSerial by Yoji KURODA

Files at this revision

API Documentation at this revision

Comitter:
kenjiArai
Date:
Fri Jan 02 10:35:19 2015 +0000
Parent:
8:20759f992d48
Child:
10:04095c7f816a
Commit message:
Extend mbed NucleoL152RE, NucleoF401RE and NucleoF411RE. Thanks Y.Kuroda-san to create base function.

Changed in this revision

Device.lib Show annotated file Show diff for this revision Revisions of this file
RingBuffer.lib Show annotated file Show diff for this revision Revisions of this file
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Device.lib	Fri Jan 02 10:35:19 2015 +0000
@@ -0,0 +1,1 @@
+Device#885438211555
--- a/RingBuffer.lib	Mon Sep 03 17:59:00 2012 +0000
+++ b/RingBuffer.lib	Fri Jan 02 10:35:19 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/ykuroda/code/RingBuffer/#1c3a10f2eb04
+http://mbed.org/users/ykuroda/code/RingBuffer/#ea6d02ba96ae
--- a/iSerial.cpp	Mon Sep 03 17:59:00 2012 +0000
+++ b/iSerial.cpp	Fri Jan 02 10:35:19 2015 +0000
@@ -3,79 +3,18 @@
 //
 //  2009.11.13 ... Originally written by Y.Kuroda for Renesas H83664
 //  2012.08.31 ... Code convert for mbed in C++
+//  2015.01.02 ... Added other mbed code by JH1PJL
 //
+
 #include <stdarg.h>
 #include "mbed.h"
 #include "RingBuffer.h"
 #include "iSerial.h"
-
-//DigitalOut led3(LED3);
-//DigitalOut led4(LED4);
-
-
-void
-iSerial::enable_uart_irq(void)
-{
-    switch(tx){
-    case USBTX:
-        #if defined(TARGET_LPC1768)
-            NVIC_EnableIRQ(UART2_IRQn);
-        #elif defined(TARGET_LPC11U24)
-            NVIC_EnableIRQ(UART_IRQn);
-        #endif
-//        led1 = !led1;
-        break;
-        
-    case p9:
-        #if defined(TARGET_LPC1768)
-            NVIC_EnableIRQ(UART1_IRQn);
-        #elif defined(TARGET_LPC11U24)
-            NVIC_EnableIRQ(UART_IRQn);
-        #endif
-        break;
-
-    #if defined(TARGET_LPC1768)
-    case p13:
-        NVIC_EnableIRQ(UART3_IRQn);
-        break;
-    case p28:
-        NVIC_EnableIRQ(UART0_IRQn);
-        break;
-    #endif
-    }
-}
-
-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
-    }
-}
+// Device header files
+#include "iSerial_LPC1768.h"
+#include "iSerial_LPC11U24.h"
+#include "iSerial_NucleoF4xx.h"
+#include "iSerial_NucleoL152.h"
 
 /*
  *    Interrupt Function
@@ -83,30 +22,26 @@
 void
 iSerial::rx_handler(void)
 {
-//  led3 = 1;
     while(Serial::readable())
         rxbuf.save(Serial::getc());
-//  led3 = 0;
 }
 
 void
 iSerial::tx_handler(void)
 {
-//  led4 = 1;
     while(Serial::writeable() && txbuf.check())
         Serial::putc( txbuf.read() );
-//  led4 = 0;
 }
 
-iSerial::iSerial(PinName _tx, PinName _rx, const char *_name, int _txbufsize, int _rxbufsize)
-:   Serial(_tx, _rx, _name),
-    tx(_tx),
-    rx(_rx),
-    txbufsize(_txbufsize),
-    rxbufsize(_rxbufsize),
-    txbuf(RingBuffer(txbufsize)),
-    rxbuf(RingBuffer(rxbufsize)),
-    str(new char [txbufsize])    
+iSerial::iSerial(PinName _tx, PinName _rx, int _txbufsize, int _rxbufsize)
+    :   Serial(_tx, _rx),
+        tx(_tx),
+        rx(_rx),
+        txbufsize(_txbufsize),
+        rxbufsize(_rxbufsize),
+        txbuf(RingBuffer(txbufsize)),
+        rxbuf(RingBuffer(rxbufsize)),
+        str(new char [txbufsize])
 {
     __disable_irq();
 
@@ -117,7 +52,7 @@
 //  baud(baudrate);
 
     __enable_irq();
-    enable_uart_irq();    
+    enable_uart_irq();
 }
 
 iSerial::~iSerial()
@@ -147,16 +82,16 @@
 void
 iSerial::putc(short ch)
 {
-    if(txbuf.check()==0 && Serial::writeable()){
+    if(txbuf.check()==0 && Serial::writeable()) {
         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();
@@ -167,7 +102,7 @@
 iSerial::putstr(const char* s)
 {
     int i=0;
-    for(; ; i++){
+    for(; ; i++) {
         if(*s==0) break;
         putc(*s++);
     }
@@ -194,12 +129,9 @@
     return str;
 }
 
-
 void
 iSerial::flush(void)
 {
     while(txbuf.check())
         enable_uart_irq();
 }
-
-
--- a/iSerial.h	Mon Sep 03 17:59:00 2012 +0000
+++ b/iSerial.h	Fri Jan 02 10:35:19 2015 +0000
@@ -5,6 +5,7 @@
 //
 //  2009.11.13 ... Originally written by Y.Kuroda for Renesas H83664
 //  2012.08.31 ... Code convert for mbed in C++
+//  2015.01.02 ... Added other mbed code by JH1PJL
 //
 #ifndef _ISERIAL_H
 #define _ISERIAL_H
@@ -12,6 +13,24 @@
 #include <string.h>
 #include "RingBuffer.h"
 
+/** iSerial class
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "iSerial.h"
+ *
+ * iSerial     pc(USBTX, USBRX, 1024, 32);
+ * 
+ * int main() {
+ * uint32_t n = 0;
+ *    
+ *     while(true){
+ *          pc.printf("count n=%d", ++n);
+ *          wait(1.0);
+ *     } 
+ * }
+ *  @endcode
+ */
 
 class iSerial : public Serial {
   protected:
@@ -33,11 +52,14 @@
 
     enum TERMINL_CODES { CR=0x0D, LF=0x0A };
 
-    iSerial(PinName _tx, PinName _rx, const char *_name=NULL, int _txbufsize=100, int _rxbufsize=100);
+    /** Configure pin and buffer size
+      * @param pin assign TX, RX the buffer size for TX, RX
+      */
+    iSerial(PinName _tx, PinName _rx, int _txbufsize=100, int _rxbufsize=100);
+    
     virtual ~iSerial();
     
     short int putstr(const char* s);
-
     int readable(void);
     int getc(void);
     void putc(short ch);
@@ -48,5 +70,4 @@
     void flush(void);
 };
 
-
 #endif    /* _SCI_H */