Public Member Functions | Private Member Functions | Private Attributes | List of all members
BufferedSerial Class Reference

Software buffers and interrupt driven tx and rx for Serial. More...

#include <BufferedSerial.h>

Inheritance diagram for BufferedSerial:
Inheritance graph
[legend]

Public Member Functions

 BufferedSerial (PinName tx, PinName rx, uint32_t buf_size=256, uint32_t tx_multiple=4, const char *name=NULL)
 
virtual int getc (void)
 
virtual int printf (const char *format,...)
 
virtual int putc (int c)
 
virtual int puts (const char *s)
 
virtual int readable (void)
 
virtual ssize_t write (const void *s, std::size_t length)
 
virtual int writeable (void)
 
virtual ~BufferedSerial (void)
 

Private Member Functions

void prime (void)
 
void rxIrq (void)
 
void txIrq (void)
 

Private Attributes

uint32_t _buf_size
 
Buffer< char > _rxbuf
 
uint32_t _tx_multiple
 
Buffer< char > _txbuf
 

Detailed Description

Software buffers and interrupt driven tx and rx for Serial.

A serial port (UART) for communication with other serial devices

Can be used for Full Duplex communication, or Simplex by specifying one pin as NC (Not Connected)

Example:

#include "mbed.h"
#include "BufferedSerial.h"
BufferedSerial pc(USBTX, USBRX);
int main()
{
while(1)
{
Timer s;
s.start();
pc.printf("Hello World - buffered\n");
int buffered_time = s.read_us();
wait(0.1f); // give time for the buffer to empty
s.reset();
printf("Hello World - blocking\n");
int polled_time = s.read_us();
s.stop();
wait(0.1f); // give time for the buffer to empty
pc.printf("printf buffered took %d us\n", buffered_time);
pc.printf("printf blocking took %d us\n", polled_time);
wait(0.5f);
}
}

Definition at line 71 of file BufferedSerial.h.

Constructor & Destructor Documentation

BufferedSerial::BufferedSerial ( PinName  tx,
PinName  rx,
uint32_t  buf_size = 256,
uint32_t  tx_multiple = 4,
const char *  name = NULL 
)

Create a BufferedSerial port, connected to the specified transmit and receive pins

Parameters
txTransmit pin
rxReceive pin
buf_sizeprintf() buffer size
tx_multipleamount of max printf() present in the internal ring buffer at one time
nameoptional name
Note
Either tx or rx may be specified as NC if unused

Definition at line 26 of file BufferedSerial.cpp.

BufferedSerial::~BufferedSerial ( void  )
virtual

Destroy a BufferedSerial port

Definition at line 35 of file BufferedSerial.cpp.

Member Function Documentation

int BufferedSerial::getc ( void  )
virtual

Get a single byte from the BufferedSerial Port. Should check readable() before calling this.

Returns
A byte that came in on the Serial Port

Definition at line 53 of file BufferedSerial.cpp.

void BufferedSerial::prime ( void  )
private

Definition at line 146 of file BufferedSerial.cpp.

int BufferedSerial::printf ( const char *  format,
  ... 
)
virtual

Write a formatted string to the BufferedSerial Port.

Parameters
formatThe string + format specifiers to write to the Serial Port
Returns
The number of bytes written to the Serial Port Buffer

Definition at line 82 of file BufferedSerial.cpp.

int BufferedSerial::putc ( int  c)
virtual

Write a single byte to the BufferedSerial Port.

Parameters
cThe byte to write to the Serial Port
Returns
The byte that was written to the Serial Port Buffer

Definition at line 58 of file BufferedSerial.cpp.

int BufferedSerial::puts ( const char *  s)
virtual

Write a string to the BufferedSerial Port. Must be NULL terminated

Parameters
sThe string to write to the Serial Port
Returns
The number of bytes written to the Serial Port Buffer

Definition at line 66 of file BufferedSerial.cpp.

int BufferedSerial::readable ( void  )
virtual

Check on how many bytes are in the rx buffer

Returns
1 if something exists, 0 otherwise

Definition at line 43 of file BufferedSerial.cpp.

void BufferedSerial::rxIrq ( void  )
private

Definition at line 120 of file BufferedSerial.cpp.

void BufferedSerial::txIrq ( void  )
private

Definition at line 130 of file BufferedSerial.cpp.

ssize_t BufferedSerial::write ( const void *  s,
std::size_t  length 
)
virtual

Write data to the Buffered Serial Port

Parameters
sA pointer to data to send
lengthThe amount of data being pointed to
Returns
The number of bytes written to the Serial Port Buffer

Definition at line 103 of file BufferedSerial.cpp.

int BufferedSerial::writeable ( void  )
virtual

Check to see if the tx buffer has room

Returns
1 always has room and can overwrite previous content if too small / slow

Definition at line 48 of file BufferedSerial.cpp.

Member Data Documentation

uint32_t BufferedSerial::_buf_size
private

Definition at line 76 of file BufferedSerial.h.

Buffer<char> BufferedSerial::_rxbuf
private

Definition at line 74 of file BufferedSerial.h.

uint32_t BufferedSerial::_tx_multiple
private

Definition at line 77 of file BufferedSerial.h.

Buffer<char> BufferedSerial::_txbuf
private

Definition at line 75 of file BufferedSerial.h.


The documentation for this class was generated from the following files:


rosserial_mbed
Author(s): Gary Servin
autogenerated on Fri Jun 7 2019 22:02:48