Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Frequency_Counter_w_GPS_1PPS FreqCntr_GPS1PPS_F746F4xx_w_recipro
Fork of iSerial by
Revision 4:b38ef9675d39, committed 2012-09-03
- Comitter:
- ykuroda
- Date:
- Mon Sep 03 09:15:34 2012 +0000
- Parent:
- 3:d5353b68105f
- Child:
- 5:d83fc550ccbc
- Commit message:
- printf using interrupt is implemented
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 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ú»ÖDDDD·×ÄÌI/OÌÝèðsÁÄ¢éD
- *
- *@@øFȵ
- *@@ßèlFȵ
- *
- */
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);
}
-/*
- * VAüÍɶª é©Ç¤©`FbN
- * ÔlF obt@É é¶
- */
+iSerial::~iSerial()
+{
+ delete [] str;
+}
+
int
iSerial::readable(void)
{
return rxbuf.check();
}
-/*
- * VA©çê¶üÍ
- * --- ¶üÍðÒÂ
- */
int
iSerial::getc(void)
{
@@ -84,10 +91,6 @@
return c;
}
-
-/*
- *@VAÖê¶oÍ
- */
void
iSerial::putc(short ch)
{
@@ -101,14 +104,6 @@
}
}
-/*
- *@VAÖ¶ñðoÍ
- *@@FêñÌÅå¶ÍLINESIZE
- *@@F¶ñÌIíèÉÍk¶ªKvD
- *
- *@@øF¶ñÖÌ|C^
- *@@ÔlFo͵½¶
- */
short int
iSerial::putstr(const char* s)
{
@@ -120,13 +115,6 @@
return i;
}
-/*@short int sci_puts(char* s)
- *@VAÖ¶ñðêsoÍ
- *@@FÅãÉüsR[hðé¼Ísci_putstrƯ¶
- *
- *@@øF¶ñÖÌ|C^
- *@@ÔlFo͵½¶
- */
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;
+}
+
+
+
+
--- a/iSerial.h Sat Sep 01 12:28:28 2012 +0000
+++ b/iSerial.h Mon Sep 03 09:15:34 2012 +0000
@@ -16,64 +16,30 @@
class iSerial : public Serial {
protected:
+ const int txbufsize;
+ const int rxbufsize;
RingBuffer txbuf;
RingBuffer rxbuf;
+ char* str;
void tx_handler(void);
void rx_handler(void);
-
public:
enum TERMINL_CODES { CR=0x0D, LF=0x0A };
- /*
- * void init_sci(void)
- *
- *@|[gú»ÖDDDD·×ÄÌI/OÌÝèðsÁÄ¢éD
- *
- *@@øFȵ
- *@@ßèlFȵ
- *
- */
iSerial(PinName _tx, PinName _rx, const char *_name=NULL, int _txbufsize=100, int _rxbufsize=100);
-
- /*
- * VAüÍɶª é©Ç¤©`FbN
- * ÔlF O@@F¶ªÈ¢
- * OÈOF¶ªÄ¢é
- */
- int readable(void);
+ virtual ~iSerial();
- /*
- * VA©çê¶üÍ
- */
- int getc(void);
-
- /*
- *@VAÖê¶oÍ
- */
- void putc(short ch);
-
-
- /*
- *@VAÖ¶ñðoÍ
- *@@FêñÌÅå¶ÍLINESIZE
- *@@F¶ñÌIíèÉÍk¶ªKvD
- *
- *@@øF¶ñÖÌ|C^
- *@@ÔlFo͵½¶
- */
short int putstr(const char* s);
- /*@void outs(char* s)
- *@VAÖ¶ñðêsoÍ
- *@@FÅãÉüsR[hðé¼ÍoutstrƯ¶
- *
- *@@øF¶ñÖÌ|C^
- *@@ÔlFo͵½¶
- */
+ int readable(void);
+ int getc(void);
+ void putc(short ch);
short int puts(const char* s);
+ //void printf();
+ char* printf(const char* format, ...);
};
