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.
Fork of BufferedSerial by
Revision 10:9ee15ae3d1a3, committed 2015-01-07
- Comitter:
- ansond
- Date:
- Wed Jan 07 18:37:11 2015 +0000
- Parent:
- 9:2cb30392ade6
- Child:
- 11:779304f9c5d2
- Commit message:
- updates to the constructor to enable expansion of the internal ring buffers and printf() buffer sizes
Changed in this revision
--- a/Buffer.lib Sun Jan 04 23:27:53 2015 +0000 +++ b/Buffer.lib Wed Jan 07 18:37:11 2015 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/users/sam_grove/code/Buffer/#cd0a1f4c623f +https://mbed.org/users/sam_grove/code/Buffer/#7b754354b99c
--- a/BufferedSerial.cpp Sun Jan 04 23:27:53 2015 +0000
+++ b/BufferedSerial.cpp Wed Jan 07 18:37:11 2015 +0000
@@ -23,11 +23,12 @@
#include "BufferedSerial.h"
#include <stdarg.h>
-BufferedSerial::BufferedSerial(PinName tx, PinName rx, const char* name)
- : SERIAL_BASE(tx, rx) , _rxbuf(2*BUFFEREDSERIAL_MAX_BUFFER_SIZE), _txbuf(2*BUFFEREDSERIAL_MAX_BUFFER_SIZE)
+BufferedSerial::BufferedSerial(PinName tx, PinName rx, uint32_t buf_size, uint32_t tx_multiple, const char* name)
+ : SERIAL_BASE(tx, rx) , _rxbuf(buf_size), _txbuf((uint32_t)(tx_multiple*buf_size))
{
SERIAL_BASE::attach(this, &BufferedSerial::rxIrq, Serial::RxIrq);
-
+ this->_buf_size = buf_size;
+ this->_tx_multiple = tx_multiple;
return;
}
@@ -80,20 +81,21 @@
int BufferedSerial::printf(const char* format, ...)
{
- memset(this->_buffer,0,BUFFEREDSERIAL_MAX_BUFFER_SIZE+1);
+ char buffer[this->_buf_size];
+ memset(buffer,0,this->_buf_size);
int r = 0;
va_list arg;
va_start(arg, format);
- r = vsprintf(this->_buffer, format, arg);
+ r = vsprintf(buffer, format, arg);
// this may not hit the heap but should alert the user anyways
- if(r > BUFFEREDSERIAL_MAX_BUFFER_SIZE) {
- error("%s %d buffer overwrite (max_buf_size: %d exceeded: %d)!\r\n", __FILE__, __LINE__,BUFFEREDSERIAL_MAX_BUFFER_SIZE,r);
+ if(r > this->_buf_size) {
+ error("%s %d buffer overwrite (max_buf_size: %d exceeded: %d)!\r\n", __FILE__, __LINE__,this->_buf_size,r);
va_end(arg);
return 0;
}
va_end(arg);
- r = BufferedSerial::write(this->_buffer, r);
+ r = BufferedSerial::write(buffer, r);
return r;
}
--- a/BufferedSerial.h Sun Jan 04 23:27:53 2015 +0000
+++ b/BufferedSerial.h Wed Jan 07 18:37:11 2015 +0000
@@ -30,9 +30,6 @@
// Base Class
#define SERIAL_BASE RawSerial
-// Internal buffer size (Ring buffers will be 2X this value each for RX and TX...)
-#define BUFFEREDSERIAL_MAX_BUFFER_SIZE 512
-
/** A serial port (UART) for communication with other serial devices
*
* Can be used for Full Duplex communication, or Simplex by specifying
@@ -79,7 +76,8 @@
private:
Buffer <char> _rxbuf;
Buffer <char> _txbuf;
- char _buffer[BUFFEREDSERIAL_MAX_BUFFER_SIZE+1];
+ uint32_t _buf_size;
+ uint32_t _tx_multiple;
void rxIrq(void);
void txIrq(void);
@@ -89,10 +87,12 @@
/** Create a BufferedSerial port, connected to the specified transmit and receive pins
* @param tx Transmit pin
* @param rx Receive pin
+ * @param buf_size printf() buffer size
+ * @param tx_multiple amount of max printf() present in the internal ring buffer at one time
* @param name optional name
* @note Either tx or rx may be specified as NC if unused
*/
- BufferedSerial(PinName tx, PinName rx, const char* name=NULL);
+ BufferedSerial(PinName tx, PinName rx, uint32_t buf_size = 256, uint32_t tx_multiple = 4,const char* name=NULL);
/** Destroy a BufferedSerial port
*/
