Extend STM mbed board. Thanks Y.Kuroda-san for creating good function.

Dependencies:   RingBuffer

Dependents:   Frequency_Counter_w_GPS_1PPS FreqCntr_GPS1PPS_F746F4xx_w_recipro

Fork of iSerial by Yoji KURODA

Revision:
4:b38ef9675d39
Parent:
3:d5353b68105f
Child:
5:d83fc550ccbc
diff -r d5353b68105f -r b38ef9675d39 iSerial.cpp
--- a/iSerial.cpp	Sat Sep 01 12:28:28 2012 +0000
+++ b/iSerial.cpp	Mon Sep 03 09:15:34 2012 +0000
@@ -4,11 +4,27 @@
 //  2009.11.13 ... Originally written by Y.Kuroda for Renesas H83664
 //  2012.08.31 ... Code convert for mbed in C++
 //
+#include <stdarg.h>
 #include "mbed.h"
 #include "RingBuffer.h"
 #include "iSerial.h"
 
 
+
+#if defined(TARGET_LPC1768)
+
+//  UART1 = p9, p10
+
+    #define UART_IRQn   UART2_IRQn
+
+#elif defined(TARGET_LPC11U24)
+
+    #define UART_IRQn   UART_IRQn
+
+#endif
+
+
+
 /*
  *    Interrupt Function
  */
@@ -33,19 +49,13 @@
     NVIC_EnableIRQ(UART_IRQn); // UART1_IRQn);
 }
 
-/*
- *  void sci_init(void)
- *
- *@ƒ|[ƒg‰Šú‰»ŠÖ”DDDD‚·‚ׂĂÌI/O‚̐ݒè‚ðs‚Á‚Ä‚¢‚éD
- *
- *@@ˆø”F‚È‚µ
- *@@–ß‚è’lF‚È‚µ
- *
- */
 iSerial::iSerial(PinName _tx, PinName _rx, const char *_name, int _txbufsize, int _rxbufsize)
 :   Serial(_tx, _rx, _name),
-    txbuf(RingBuffer(_txbufsize)),
-    rxbuf(RingBuffer(_rxbufsize))
+    txbufsize(_txbufsize),
+    rxbufsize(_rxbufsize),
+    txbuf(RingBuffer(txbufsize)),
+    rxbuf(RingBuffer(rxbufsize)),
+    str(new char [txbufsize])
 {
     __disable_irq();
 
@@ -59,20 +69,17 @@
     NVIC_EnableIRQ(UART_IRQn); // UART1_IRQn);
 }
 
-/*
- *  ƒVƒŠƒAƒ‹“ü—Í‚É•¶Žš‚ª‚ ‚é‚©‚Ç‚¤‚©ƒ`ƒFƒbƒN
- *  •Ô’lF    ƒoƒbƒtƒ@‚É‚ ‚镶Žš”
- */
+iSerial::~iSerial()
+{
+    delete [] str;
+}
+
 int
 iSerial::readable(void)
 {
     return rxbuf.check();
 }
 
-/*
- *  ƒVƒŠƒAƒ‹‚©‚çˆê•¶Žš“ü—Í
- *    --- •¶Žš“ü—Í‚ð‘Ò‚Â
- */
 int
 iSerial::getc(void)
 {
@@ -84,10 +91,6 @@
     return c;
 }
 
-
-/*
- *@ƒVƒŠƒAƒ‹‚ֈꕶŽšo—Í
- */
 void
 iSerial::putc(short ch)
 {
@@ -101,14 +104,6 @@
     }
 }
 
-/*
- *@ƒVƒŠƒAƒ‹‚Ö•¶Žš—ñ‚ðo—Í
- *@@’Fˆê‰ñ‚̍ő啶Žš”‚ÍLINESIZE
- *@@’F•¶Žš—ñ‚̏I‚í‚è‚ɂ̓kƒ‹•¶Žš‚ª•K—vD
- *
- *@@ˆø”F•¶Žš—ñ‚ւ̃|ƒCƒ“ƒ^
- *@@•Ô’lFo—Í‚µ‚½•¶Žš”
- */
 short int
 iSerial::putstr(const char* s)
 {
@@ -120,13 +115,6 @@
     return i;
 }
 
-/*@short int sci_puts(char* s)
- *@ƒVƒŠƒAƒ‹‚Ö•¶Žš—ñ‚ðˆêso—Í
- *@@’FÅŒã‚ɉüsƒR[ƒh‚𑗂鑼‚Ísci_putstr‚Æ“¯‚¶
- *
- *@@ˆø”F•¶Žš—ñ‚ւ̃|ƒCƒ“ƒ^
- *@@•Ô’lFo—Í‚µ‚½•¶Žš”
- */
 short int
 iSerial::puts(const char* s)
 {
@@ -136,3 +124,17 @@
     return n;
 }
 
+char*
+iSerial::printf(const char* format, ...)
+{
+    va_list arg;
+    va_start(arg,format);
+    vsprintf(str, format, arg);
+    va_end(arg);
+    putstr(str);
+    return str;
+}
+
+
+
+