avr-classes
Public Member Functions | List of all members
BufferedUsart< RXQUEUESIZE, TXQUEUESIZE > Class Template Reference

#include <bufferedusart.h>

Inheritance diagram for BufferedUsart< RXQUEUESIZE, TXQUEUESIZE >:
SimpleUsart Usart::InterruptHandler NotifyingBufferedUsart< RXQUEUESIZE, TXQUEUESIZE >

Public Member Functions

 BufferedUsart (Usart *usart)
 
void enable (bool state)
 
bool read (uint8_t *byte)
 
bool write (uint8_t byte)
 
virtual void onDataRegisterEmpty (void) override
 
virtual void onRxComplete (void) override
 
- Public Member Functions inherited from SimpleUsart
 SimpleUsart (Usart *usart)
 
void enable (bool state)
 
uint8_t read (void)
 
void write (uint8_t byte)
 

Additional Inherited Members

- Protected Attributes inherited from SimpleUsart
Usart *const m_usart
 

Detailed Description

template<uint8_t RXQUEUESIZE, uint8_t TXQUEUESIZE>
class BufferedUsart< RXQUEUESIZE, TXQUEUESIZE >

This template class implements an USART with separate buffers for incoming and outgoing data. The class makes use of the USART's RX Complete and Data Register Empty interrupts.

Parameters
RXQUEUESIZESize of the queue for incoming data in bytes
TXQUEUESIZESize of the queue for outgoing data in bytes

Constructor & Destructor Documentation

◆ BufferedUsart()

template<uint8_t RXQUEUESIZE, uint8_t TXQUEUESIZE>
BufferedUsart< RXQUEUESIZE, TXQUEUESIZE >::BufferedUsart ( Usart usart)
inline

Constructor.

Parameters
usartPointer to USART device to be used.

Member Function Documentation

◆ enable()

template<uint8_t RXQUEUESIZE, uint8_t TXQUEUESIZE>
void BufferedUsart< RXQUEUESIZE, TXQUEUESIZE >::enable ( bool  state)
inline

Enables or disables the USART on hardware level. This also enables or disables the RX Complete Interrupt.

Parameters
stateDesired state of USART, true means enabled, false means disabled.

◆ onDataRegisterEmpty()

template<uint8_t RXQUEUESIZE, uint8_t TXQUEUESIZE>
virtual void BufferedUsart< RXQUEUESIZE, TXQUEUESIZE >::onDataRegisterEmpty ( void  )
inlineoverridevirtual

Handler for Data Register Empty interrupt. Used to put next data byte from outgoing data buffer into data register. When no data is left the Data Register Empty interrupt is disabled.

Note
This method is called from ISR context. Don't perform lengthy operations here.

Reimplemented from Usart::InterruptHandler.

Reimplemented in NotifyingBufferedUsart< RXQUEUESIZE, TXQUEUESIZE >.

◆ onRxComplete()

template<uint8_t RXQUEUESIZE, uint8_t TXQUEUESIZE>
virtual void BufferedUsart< RXQUEUESIZE, TXQUEUESIZE >::onRxComplete ( void  )
inlineoverridevirtual

Handler for RX Complete interrupt. Called in ISR context. Used to get data byte from data register and to store byte in incoming data buffer. If buffer is full the date byte is discarded.

Note
This method is called from ISR context. Don't perform lengthy operations here.

Reimplemented from Usart::InterruptHandler.

Reimplemented in NotifyingBufferedUsart< RXQUEUESIZE, TXQUEUESIZE >.

◆ read()

template<uint8_t RXQUEUESIZE, uint8_t TXQUEUESIZE>
bool BufferedUsart< RXQUEUESIZE, TXQUEUESIZE >::read ( uint8_t *  byte)
inline

Gets a byte from the incoming data buffer, if available.

Parameters
bytePointer to buffer that receives the data byte.
Returns
True if a data byte was read, false otherwise.

◆ write()

template<uint8_t RXQUEUESIZE, uint8_t TXQUEUESIZE>
bool BufferedUsart< RXQUEUESIZE, TXQUEUESIZE >::write ( uint8_t  byte)
inline

Puts a byte in the outgoing data buffer, if possible. This also enables the Data Register Empty interrupt to continue with emptying the buffer.

Parameters
byteData byte to send.
Returns
True if data was enqueued, false otherwise.