Minor fork of Yoji KURODA's work to test a fix on a small error.

Dependencies:   RingBuffer

Fork of iSerial by Yoji KURODA

Files at this revision

API Documentation at this revision

Comitter:
ykuroda
Date:
Fri Aug 31 17:32:00 2012 +0000
Parent:
1:28d6ef10e48c
Child:
3:d5353b68105f
Commit message:
Name change

Changed in this revision

SerialIntr.cpp Show diff for this revision Revisions of this file
SerialIntr.h 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
--- a/SerialIntr.cpp	Fri Aug 31 17:21:59 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,150 +0,0 @@
-//
-//  SerialIntr.cpp ... Serial Driver with Interrupt Rec/Send
-//
-//  2009.11.13 ... Originally written by Y.Kuroda for Renesas H83664
-//  2012.08.31 ... Code convert for mbed in C++
-//
-#include "mbed.h"
-#include "RingBuffer.h"
-#include "SerialIntr.h"
-
-
-//DigitalOut led1(LED1);
-//DigitalOut led2(LED2);
-//DigitalOut led3(LED3);
-//DigitalOut led4(LED4);
-
-/*
- *    Interrupt Function
- */
-void
-SerialIntr::rx_handler(void)
-{
-//    led4 = !led4;
-
-    if(Serial::readable()){
-//        led1 = !led1;
-        rxbuf.save(Serial::getc());
-//            led2 = !led2;
-            
-    }
-    
-    NVIC_EnableIRQ(UART_IRQn); // UART1_IRQn);
-}
-
-void
-SerialIntr::tx_handler(void)
-{
-//    led3 = !led3;
-
-    if(writeable()){
-        if(txbuf.check()){
-            Serial::putc( txbuf.read() );
-        }
-    }
-    NVIC_EnableIRQ(UART_IRQn); // UART1_IRQn);
-}
-
-/*
- *  void sci_init(void)
- *
- * ポート初期化関数....すべてのI/Oの設定を行っている.
- *
- *  引数:なし
- *  戻り値:なし
- *
- */
-SerialIntr::SerialIntr(PinName _tx, PinName _rx, const char *_name, int _txbufsize, int _rxbufsize)
-:   Serial(_tx, _rx, _name),
-    txbuf(RingBuffer(_txbufsize)),
-    rxbuf(RingBuffer(_rxbufsize))
-{
-    __disable_irq();
-
-    attach(this, &SerialIntr::tx_handler, Serial::TxIrq);
-    attach(this, &SerialIntr::rx_handler, Serial::RxIrq);
-
-//  format(8,Serial::None,1);   // default
-//  baud(baudrate);
-
-    __enable_irq();
-    NVIC_EnableIRQ(UART_IRQn); // UART1_IRQn);
-}
-
-/*
- *  シリアル入力に文字があるかどうかチェック
- *  返値:    バッファにある文字数
- */
-int
-SerialIntr::readable(void)
-{
-    return rxbuf.check();
-}
-
-/*
- *  シリアルから一文字入力
- *    --- 文字入力を待つ
- */
-int
-SerialIntr::getc(void)
-{
-    unsigned short int c;
-
-    while(!rxbuf.check());
-    c = rxbuf.read();
-
-    return c;
-}
-
-
-/*
- * シリアルへ一文字出力
- */
-void
-SerialIntr::putc(short ch)
-{
-    if(txbuf.check()==0 && Serial::writeable()){
-        Serial::putc(ch);
-        
-    } else {
-        while(txbuf.full());
-        txbuf.save(ch);
-        NVIC_EnableIRQ(UART_IRQn); // UART1_IRQn);
-    }
-}
-
-/*
- * シリアルへ文字列を出力
- *  注:一回の最大文字数はLINESIZE
- *  注:文字列の終わりにはヌル文字が必要.
- *
- *  引数:文字列へのポインタ
- *  返値:出力した文字数
- */
-short int
-SerialIntr::putstr(const char* s)
-{
-    int i=0;
-    for(; ; i++){
-        if(*s==0) break;
-        putc(*s++);
-    }
-    return i;
-}
-
-/* short int sci_puts(char* s)
- * シリアルへ文字列を一行出力
- *  注:最後に改行コードを送る他はsci_putstrと同じ
- *
- *  引数:文字列へのポインタ
- *  返値:出力した文字数
- */
-short int
-SerialIntr::puts(const char* s)
-{
-    short int n = putstr(s);
-    putc(CR);
-    putc(LF);
-    return n;
-}
-
--- a/SerialIntr.h	Fri Aug 31 17:21:59 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-//
-//  SerialIntr.h ... Serial Driver with Interrupt Rec/Send
-//
-//  Copyright 2012  Yoji KURODA
-//
-//  2009.11.13 ... Originally written by Y.Kuroda for Renesas H83664
-//  2012.08.31 ... Code convert for mbed in C++
-//
-#ifndef _SERIALINTR_H
-#define _SERIALINTR_H
-
-#include <string.h>
-#include "RingBuffer.h"
-
-
-class SerialIntr : public Serial {
-  protected:
-
-    RingBuffer txbuf;
-    RingBuffer rxbuf;
-
-    void tx_handler(void);
-    void rx_handler(void);
-
-
-  public:
-
-    enum TERMINL_CODES { CR=0x0D, LF=0x0A };
-
-    /*
-     *  void init_sci(void)
-     *
-     * ポート初期化関数....すべてのI/Oの設定を行っている.
-     *
-     *  引数:なし
-     *  戻り値:なし
-     *
-     */
-    SerialIntr(PinName _tx, PinName _rx, const char *_name=NULL, int _txbufsize=100, int _rxbufsize=100);
-
-    /*
-     *  シリアル入力に文字があるかどうかチェック
-     *  返値:    0  :文字がない
-     *            0以外:文字が来ている
-     */
-    int readable(void);
-    
-    /*
-     *  シリアルから一文字入力
-     */
-    int getc(void);
-    
-    /*
-     * シリアルへ一文字出力
-     */
-    void putc(short ch);
-    
-
-    /*
-     * シリアルへ文字列を出力
-     *  注:一回の最大文字数はLINESIZE
-     *  注:文字列の終わりにはヌル文字が必要.
-     *
-     *  引数:文字列へのポインタ
-     *  返値:出力した文字数
-     */
-    short int putstr(const char* s);
-
-    /* void outs(char* s)
-     * シリアルへ文字列を一行出力
-     *  注:最後に改行コードを送る他はoutstrと同じ
-     *
-     *  引数:文字列へのポインタ
-     *  返値:出力した文字数
-     */
-    short int puts(const char* s);
-};
-
-
-#endif    /* _SCI_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/iSerial.cpp	Fri Aug 31 17:32:00 2012 +0000
@@ -0,0 +1,138 @@
+//
+//  iSerial.cpp ... Serial Driver with Interrupt Rec/Send
+//
+//  2009.11.13 ... Originally written by Y.Kuroda for Renesas H83664
+//  2012.08.31 ... Code convert for mbed in C++
+//
+#include "mbed.h"
+#include "RingBuffer.h"
+#include "iSerial.h"
+
+
+/*
+ *    Interrupt Function
+ */
+void
+ISerial::rx_handler(void)
+{
+    if(Serial::readable()){
+        rxbuf.save(Serial::getc());
+    }
+
+    NVIC_EnableIRQ(UART_IRQn); // UART1_IRQn);
+}
+
+void
+ISerial::tx_handler(void)
+{
+    if(Serial::writeable()){
+        if(txbuf.check()){
+            Serial::putc( txbuf.read() );
+        }
+    }
+    NVIC_EnableIRQ(UART_IRQn); // UART1_IRQn);
+}
+
+/*
+ *  void sci_init(void)
+ *
+ * ポート初期化関数....すべてのI/Oの設定を行っている.
+ *
+ *  引数:なし
+ *  戻り値:なし
+ *
+ */
+ISerial::ISerial(PinName _tx, PinName _rx, const char *_name, int _txbufsize, int _rxbufsize)
+:   Serial(_tx, _rx, _name),
+    txbuf(RingBuffer(_txbufsize)),
+    rxbuf(RingBuffer(_rxbufsize))
+{
+    __disable_irq();
+
+    attach(this, &ISerial::tx_handler, Serial::TxIrq);
+    attach(this, &ISerial::rx_handler, Serial::RxIrq);
+
+//  format(8,Serial::None,1);   // default
+//  baud(baudrate);
+
+    __enable_irq();
+    NVIC_EnableIRQ(UART_IRQn); // UART1_IRQn);
+}
+
+/*
+ *  シリアル入力に文字があるかどうかチェック
+ *  返値:    バッファにある文字数
+ */
+int
+ISerial::readable(void)
+{
+    return rxbuf.check();
+}
+
+/*
+ *  シリアルから一文字入力
+ *    --- 文字入力を待つ
+ */
+int
+ISerial::getc(void)
+{
+    unsigned short int c;
+
+    while(!rxbuf.check());
+    c = rxbuf.read();
+
+    return c;
+}
+
+
+/*
+ * シリアルへ一文字出力
+ */
+void
+ISerial::putc(short ch)
+{
+    if(txbuf.check()==0 && Serial::writeable()){
+        Serial::putc(ch);
+        
+    } else {
+        while(txbuf.full());
+        txbuf.save(ch);
+        NVIC_EnableIRQ(UART_IRQn); // UART1_IRQn);
+    }
+}
+
+/*
+ * シリアルへ文字列を出力
+ *  注:一回の最大文字数はLINESIZE
+ *  注:文字列の終わりにはヌル文字が必要.
+ *
+ *  引数:文字列へのポインタ
+ *  返値:出力した文字数
+ */
+short int
+ISerial::putstr(const char* s)
+{
+    int i=0;
+    for(; ; i++){
+        if(*s==0) break;
+        putc(*s++);
+    }
+    return i;
+}
+
+/* short int sci_puts(char* s)
+ * シリアルへ文字列を一行出力
+ *  注:最後に改行コードを送る他はsci_putstrと同じ
+ *
+ *  引数:文字列へのポインタ
+ *  返値:出力した文字数
+ */
+short int
+ISerial::puts(const char* s)
+{
+    short int n = putstr(s);
+    putc(CR);
+    putc(LF);
+    return n;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/iSerial.h	Fri Aug 31 17:32:00 2012 +0000
@@ -0,0 +1,80 @@
+//
+//  iSerial.h ... Serial Driver with Interrupt Rec/Send
+//
+//  Copyright 2012  Yoji KURODA
+//
+//  2009.11.13 ... Originally written by Y.Kuroda for Renesas H83664
+//  2012.08.31 ... Code convert for mbed in C++
+//
+#ifndef _ISERIAL_H
+#define _ISERIAL_H
+
+#include <string.h>
+#include "RingBuffer.h"
+
+
+class ISerial : public Serial {
+  protected:
+
+    RingBuffer txbuf;
+    RingBuffer rxbuf;
+
+    void tx_handler(void);
+    void rx_handler(void);
+
+
+  public:
+
+    enum TERMINL_CODES { CR=0x0D, LF=0x0A };
+
+    /*
+     *  void init_sci(void)
+     *
+     * ポート初期化関数....すべてのI/Oの設定を行っている.
+     *
+     *  引数:なし
+     *  戻り値:なし
+     *
+     */
+    ISerial(PinName _tx, PinName _rx, const char *_name=NULL, int _txbufsize=100, int _rxbufsize=100);
+
+    /*
+     *  シリアル入力に文字があるかどうかチェック
+     *  返値:    0  :文字がない
+     *            0以外:文字が来ている
+     */
+    int readable(void);
+    
+    /*
+     *  シリアルから一文字入力
+     */
+    int getc(void);
+    
+    /*
+     * シリアルへ一文字出力
+     */
+    void putc(short ch);
+    
+
+    /*
+     * シリアルへ文字列を出力
+     *  注:一回の最大文字数はLINESIZE
+     *  注:文字列の終わりにはヌル文字が必要.
+     *
+     *  引数:文字列へのポインタ
+     *  返値:出力した文字数
+     */
+    short int putstr(const char* s);
+
+    /* void outs(char* s)
+     * シリアルへ文字列を一行出力
+     *  注:最後に改行コードを送る他はoutstrと同じ
+     *
+     *  引数:文字列へのポインタ
+     *  返値:出力した文字数
+     */
+    short int puts(const char* s);
+};
+
+
+#endif    /* _SCI_H */