COSA
An Object-Oriented Platform for Arduino Programming
UART Class Reference

#include <UART.hh>

Inheritance diagram for UART:
Inheritance graph
Collaboration diagram for UART:
Collaboration graph

Public Types

enum  {
  DATA5 = 0, DATA6 = _BV(UCSZ00), DATA7 = _BV(UCSZ01), DATA8 = _BV(UCSZ01) | _BV(UCSZ00),
  NO_PARITY = 0, EVEN_PARITY = _BV(UPM01), ODD_PARITY = _BV(UPM01) | _BV(UPM00), STOP1 = 0,
  STOP2 = _BV(USBS0)
}
 

Public Member Functions

 UART (uint8_t port, IOStream::Device *ibuf, IOStream::Device *obuf)
 
virtual int available ()
 
virtual int room ()
 
virtual int putchar (char c)
 
virtual int peekchar ()
 
virtual int peekchar (char c)
 
virtual int getchar ()
 
virtual int flush ()
 
virtual void empty ()
 
virtual bool begin (uint32_t baudrate=DEFAULT_BAUDRATE, uint8_t format=DEFAULT_FORMAT)
 
virtual bool end ()
 
virtual void powerup ()
 
virtual void powerdown ()
 
void non_blocking ()
 
void blocking ()
 
bool is_blocking () const
 
void eol (Mode mode)
 
Mode eol () const
 
virtual int puts (const char *s)
 
virtual int puts (str_P s)
 
virtual int write (const void *buf, size_t size)
 
virtual int write (const iovec_t *vec)
 
virtual int write_P (const void *buf, size_t size)
 
virtual char * gets (char *s, size_t count)
 
virtual int read (void *buf, size_t size)
 
virtual int read (iovec_t *vec)
 

Static Public Attributes

static const uint16_t RX_BUFFER_MAX = COSA_UART_RX_BUFFER_MAX
 
static const uint16_t TX_BUFFER_MAX = COSA_UART_TX_BUFFER_MAX
 
static const uint32_t DEFAULT_BAUDRATE = 9600L
 
static const uint8_t DEFAULT_FORMAT = DATA8 + NO_PARITY + STOP2
 

Protected Member Functions

volatile uint8_t * UCSRnA () const
 
volatile uint8_t * UCSRnB () const
 
volatile uint8_t * UCSRnC () const
 
volatile uint16_t * UBRRn () const
 
volatile uint8_t * UDRn () const
 
virtual void on_udre_interrupt ()
 
virtual void on_rx_interrupt ()
 
virtual void on_tx_interrupt ()
 

Protected Attributes

uint8_t m_port
 UART port index. More...
 
volatile uint8_t *const m_sfr
 Special Function Register Pointer. More...
 
IOStream::Devicem_ibuf
 Input Buffer/Device. More...
 
IOStream::Devicem_obuf
 Output Buffer/Device. More...
 
bool m_idle
 Flag idle mode. More...
 
bool m_blocking
 
Mode m_eol
 

Static Protected Attributes

static UARTuart [Board::UART_MAX] = { NULL }
 

Detailed Description

Basic UART device handler with external buffering. IOStream devices may be piped with the IOBuffer class. The UART class requires an input- and output IOBuffer instance.

Definition at line 59 of file UART.hh.

Member Enumeration Documentation

anonymous enum
inherited

Serial formats; DATA + PARITY + STOP.

Enumerator
DATA5 
DATA6 
DATA7 
DATA8 
NO_PARITY 
EVEN_PARITY 
ODD_PARITY 
STOP1 
STOP2 

Definition at line 46 of file Serial.hh.

Constructor & Destructor Documentation

UART::UART ( uint8_t  port,
IOStream::Device ibuf,
IOStream::Device obuf 
)
inline

Construct serial port handler for given UART.

Parameters
[in]portnumber.
[in]ibufinput stream buffer.
[in]obufoutput stream buffer.

Definition at line 71 of file UART.hh.

Member Function Documentation

virtual int UART::available ( )
inlinevirtual

Number of bytes available in input buffer.

Returns
bytes.

Reimplemented from IOStream::Device.

Definition at line 87 of file UART.hh.

bool UART::begin ( uint32_t  baudrate = DEFAULT_BAUDRATE,
uint8_t  format = DEFAULT_FORMAT 
)
virtual

Powerup and start UART for given baudrate and format. Returns true(1) if successful otherwise false(0).

Parameters
[in]baudrateserial bitrate (default 9600).
[in]formatserial frame format (default async, 8data, 2stop bit)
Returns
true(1) if successful otherwise false(0)

Implements Serial.

Definition at line 45 of file UART.cpp.

void IOStream::Device::blocking ( )
inlineinherited

Set blocking mode.

Definition at line 85 of file IOStream.hh.

virtual void UART::empty ( )
inlinevirtual

Empty output device buffers.

Reimplemented from IOStream::Device.

Definition at line 156 of file UART.hh.

bool UART::end ( )
virtual

Stop and powerdown UART device driver. Returns true(1) if successful otherwise false(0).

Returns
true(1) if successful otherwise false(0)

Reimplemented from Serial.

Definition at line 69 of file UART.cpp.

void IOStream::Device::eol ( Mode  mode)
inlineinherited

Set end of line mode.

Parameters
[in]modefor end of line.

Definition at line 103 of file IOStream.hh.

Mode IOStream::Device::eol ( ) const
inlineinherited

Get end of line mode.

Returns
mode.

Definition at line 112 of file IOStream.hh.

int UART::flush ( )
virtual

Flush device output buffer and wait for device to become idle and all character transmitted.

Returns
zero(0) or negative error code.

Reimplemented from IOStream::Device.

Definition at line 130 of file UART.cpp.

virtual int UART::getchar ( )
inlinevirtual

Read character from serial port input buffer. Returns character if successful otherwise a negative error code (EOF(-1)).

Returns
character or EOF(-1).

Reimplemented from IOStream::Device.

Definition at line 139 of file UART.hh.

char * IOStream::Device::gets ( char *  s,
size_t  count 
)
virtualinherited

Read string terminated by new-line or until size into given string buffer. Returns pointer to string or NULL if empty line.

Parameters
[in]sstring buffer to read into.
[in]countmax number of bytes to read.
Returns
string pointer or NULL.

Definition at line 118 of file IOStream_Device.cpp.

bool IOStream::Device::is_blocking ( ) const
inlineinherited

Is blocking mode?

Returns
bool.

Definition at line 94 of file IOStream.hh.

void IOStream::Device::non_blocking ( )
inlineinherited

Set non-blocking mode.

Definition at line 77 of file IOStream.hh.

void UART::on_rx_interrupt ( )
protectedvirtual

Common UART receive interrupt handler.

Definition at line 221 of file UART.cpp.

virtual void UART::on_tx_interrupt ( )
inlineprotectedvirtual

Common UART transmit completed interrupt handler.

Reimplemented in RS485.

Definition at line 266 of file UART.hh.

void UART::on_udre_interrupt ( )
protectedvirtual

Common UART data register empty (transmit) interrupt handler.

Reimplemented in RS485.

Definition at line 208 of file UART.cpp.

virtual int UART::peekchar ( )
inlinevirtual

Peek at next character from serial port input buffer. Returns character if successful otherwise a negative error code (EOF(-1)).

Returns
character or EOF(-1).

Reimplemented from IOStream::Device.

Definition at line 117 of file UART.hh.

virtual int UART::peekchar ( char  c)
inlinevirtual

Peek for given character from serial port input buffer.

Parameters
[in]ccharacter to peek for.
Returns
available or EOF(-1).

Reimplemented from IOStream::Device.

Definition at line 128 of file UART.hh.

void UART::powerdown ( )
virtual

Powerdown UART.

Reimplemented from Serial.

Definition at line 179 of file UART.cpp.

void UART::powerup ( )
virtual

Powerup UART.

Reimplemented from Serial.

Definition at line 150 of file UART.cpp.

int UART::putchar ( char  c)
virtual

Write character to serial port output buffer. Returns character if successful otherwise a negative error code (EOF(-1)).

Parameters
[in]ccharacter to write.
Returns
character written or EOF(-1).

Reimplemented from IOStream::Device.

Reimplemented in RS485.

Definition at line 95 of file UART.cpp.

int IOStream::Device::puts ( const char *  s)
virtualinherited

Write null terminated string to device. Terminating null is not written.

Parameters
[in]sstring to write.
Returns
zero(0) or negative error code.

Definition at line 43 of file IOStream_Device.cpp.

int IOStream::Device::puts ( str_P  s)
virtualinherited

Write null terminated string from program memory to device. Terminating null is not written.

Parameters
[in]sstring in program memory to write.
Returns
zero(0) or negative error code.

Definition at line 54 of file IOStream_Device.cpp.

int IOStream::Device::read ( void *  buf,
size_t  size 
)
virtualinherited

Read data to given buffer with given size from device.

Parameters
[in]bufbuffer to read into.
[in]sizenumber of bytes to read.
Returns
number of bytes read or EOF(-1).

Reimplemented in FAT16::File, W5200::Driver, W5500::Driver, W5100::Driver, CFFS::File, Socket, and CC3000::Driver.

Definition at line 144 of file IOStream_Device.cpp.

int IOStream::Device::read ( iovec_t vec)
virtualinherited

Read data to given buffers in null terminated io vector.

Parameters
[in]vecio vector with buffers to read into.
Returns
number of bytes read or EOF(-1).

Definition at line 157 of file IOStream_Device.cpp.

virtual int UART::room ( )
inlinevirtual

Number of bytes room in output buffer.

Returns
bytes.

Reimplemented from IOStream::Device.

Definition at line 97 of file UART.hh.

volatile uint16_t* UART::UBRRn ( ) const
inlineprotected

Return pointer to UART Baud Rate Register (UBRRn).

Returns
UBRRn register pointer.

Definition at line 236 of file UART.hh.

volatile uint8_t* UART::UCSRnA ( ) const
inlineprotected

Return pointer to UART Control and Status Register A (UCSRnA).

Returns
UCSRAn register pointer.

Definition at line 209 of file UART.hh.

volatile uint8_t* UART::UCSRnB ( ) const
inlineprotected

Return pointer to UART Control and Status Register B (UCSRnB).

Returns
UCSRnB register pointer.

Definition at line 218 of file UART.hh.

volatile uint8_t* UART::UCSRnC ( ) const
inlineprotected

Return pointer to UART Control and Status Register C (UCSRnC).

Returns
UCSRnC register pointer.

Definition at line 227 of file UART.hh.

volatile uint8_t* UART::UDRn ( ) const
inlineprotected

Return pointer to UART I/O Data Register (UDRn).

Returns
UDRn register pointer.

Definition at line 245 of file UART.hh.

int IOStream::Device::write ( const void *  buf,
size_t  size 
)
virtualinherited

Write data from buffer with given size to device.

Parameters
[in]bufbuffer to write.
[in]sizenumber of bytes to write.
Returns
number of bytes written or EOF(-1).

Reimplemented in FAT16::File, HD44780, CFFS::File, VLCD, Socket, and CC3000::Driver.

Definition at line 65 of file IOStream_Device.cpp.

int IOStream::Device::write ( const iovec_t vec)
virtualinherited

Write data from buffers in null terminated io vector.

Parameters
[in]vecio vector with buffers to write.
Returns
number of bytes written or EOF(-1).

Definition at line 87 of file IOStream_Device.cpp.

int IOStream::Device::write_P ( const void *  buf,
size_t  size 
)
virtualinherited

Write data from buffer in program memory with given size to device.

Parameters
[in]bufbuffer to write.
[in]sizenumber of bytes to write.
Returns
number of bytes written or EOF(-1).

Reimplemented in CFFS::File, Socket, and CC3000::Driver.

Definition at line 76 of file IOStream_Device.cpp.

Member Data Documentation

const uint32_t Serial::DEFAULT_BAUDRATE = 9600L
staticinherited

Default baudrate.

Definition at line 43 of file Serial.hh.

const uint8_t Serial::DEFAULT_FORMAT = DATA8 + NO_PARITY + STOP2
staticinherited

Default serial format.

Definition at line 59 of file Serial.hh.

bool IOStream::Device::m_blocking
protectedinherited

Blocking state

Definition at line 248 of file IOStream.hh.

Mode IOStream::Device::m_eol
protectedinherited

End of line mode

Definition at line 251 of file IOStream.hh.

IOStream::Device* UART::m_ibuf
protected

Input Buffer/Device.

Definition at line 195 of file UART.hh.

bool UART::m_idle
protected

Flag idle mode.

Definition at line 197 of file UART.hh.

IOStream::Device* UART::m_obuf
protected

Output Buffer/Device.

Definition at line 196 of file UART.hh.

uint8_t UART::m_port
protected

UART port index.

Definition at line 193 of file UART.hh.

volatile uint8_t* const UART::m_sfr
protected

Special Function Register Pointer.

Definition at line 194 of file UART.hh.

const uint16_t UART::RX_BUFFER_MAX = COSA_UART_RX_BUFFER_MAX
static

Default buffer size for standard UART0 (at 9600 baud).

Definition at line 62 of file UART.hh.

const uint16_t UART::TX_BUFFER_MAX = COSA_UART_TX_BUFFER_MAX
static

Definition at line 63 of file UART.hh.

UART * UART::uart = { NULL }
staticprotected

Serial port references. Only uart0 is predefined (reference to global uart). Others as installed by constructor when created in application.

Definition at line 203 of file UART.hh.


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