#include <uart_dev.hpp>

Inheritance diagram for UartDev:
Collaboration diagram for UartDev:

Public Member Functions

void setBaudRate (unsigned int baudRate)
 Reset the baud-rate after UART has been initialized. More...
 
bool getChar (char *pInputChar, unsigned int timeout=portMAX_DELAY)
 
bool putChar (char out, unsigned int timeout=portMAX_DELAY)
 
bool flush (void)
 Flushed all pending transmission of the uart queue. More...
 
void handleInterrupt ()
 
unsigned int getRxQueueSize () const
 
unsigned int getTxQueueSize () const
 
unsigned int getRxQueueWatermark () const
 
unsigned int getTxQueueWatermark () const
 
bool recentlyActive (unsigned int ms=3000) const
 
TickType_t getLastActivityTime (void) const
 
void resetActivity (void)
 
- Public Member Functions inherited from CharDev
bool gets (char *pBuff, int maxLen, unsigned int timeout=0xffffffff)
 
int printf (const char *format,...)
 
int scanf (const char *format,...)
 
uint16_t getPrintfMemSize (void) const
 
bool put (const char *pString, unsigned int timeout=0xffffffff)
 
void putline (const char *pBuff, unsigned int timeout=0xffffffff)
 
bool isReady (void)
 
void setReady (bool r)
 

Protected Member Functions

bool init (unsigned int pclk, unsigned int baudRate, int rxQSize=32, int txQSize=32)
 
 UartDev (unsigned int *pUARTBaseAddr)
 
 ~UartDev ()
 
- Protected Member Functions inherited from CharDev
 CharDev ()
 
virtual ~CharDev ()
 

Detailed Description

UART Base class that can be used to write drivers for all UART peripherals. Steps needed to write a UART driver:

  • Inherit this class
  • Call init() and configure PINSEL to select your UART pins
  • When your UART(#) hardware interrupt occurs, call handleInterrupt()

To connect UART Interrupt with your UART, reference this example:

extern "C"
{
{
UART0::getInstance().handleInterrupt();
}
}
Warning
This class hasn't been tested for UART1 due to different memory map.

Constructor & Destructor Documentation

UartDev::UartDev ( unsigned int *  pUARTBaseAddr)
protected

Protected constructor that requires parent class to provide UART's base register address for which to operate this UART driver

UartDev::~UartDev ( )
inlineprotected

Member Function Documentation

bool UartDev::flush ( void  )
virtual

Flushed all pending transmission of the uart queue.

Reimplemented from CharDev.

bool UartDev::getChar ( char *  pInputChar,
unsigned int  timeout = portMAX_DELAY 
)
virtual
Returns
a character from the UART input
Parameters
pInputCharThe pointer to input char to store received character
timeoutOptional parameter which defaults to maximum value that will allow you to wait forever for a character to be received
Returns
true if a character was obtained within the given timeout

Implements CharDev.

TickType_t UartDev::getLastActivityTime ( void  ) const
inline
unsigned int UartDev::getRxQueueSize ( ) const
inline

Get the Rx and Tx queue information Watermarks provide the queue's usage to access the capacity usage

unsigned int UartDev::getRxQueueWatermark ( ) const
inline
unsigned int UartDev::getTxQueueSize ( ) const
inline
unsigned int UartDev::getTxQueueWatermark ( ) const
inline
void UartDev::handleInterrupt ( )

When the UART interrupt occurs, this function should be called to handle future action to take due to the interrupt cause.

Bit Masks of IIR register Bits 3:1 that contain interrupt reason. Bits are shifted left because reasonForInterrupt contains Bits 3:0

If multiple sources of interrupt arise, let this interrupt exit, and re-enter for the new source of interrupt.

When THRE (Transmit Holding Register Empty) interrupt occurs, we can send as many bytes as the hardware FIFO supports (16)

While receive Hardware FIFO not empty, keep queuing the data. Even if xQueueSendFromISR() Fails (Queue is full), we still need to read RBR register otherwise interrupt will not clear

bool UartDev::init ( unsigned int  pclk,
unsigned int  baudRate,
int  rxQSize = 32,
int  txQSize = 32 
)
protected

Initializes the UART register including Queues, baudrate and hardware. Parent class should call this method before initializing Pin-Connect-Block

Parameters
pclkThe system peripheral clock for this UART
baudRateThe baud rate to set
rxQSizeThe receive queue size
txQSizeThe transmit queue size
Postcondition
Sets 8-bit mode, no parity, no flow control.
Warning
This will not initialize the PINS, so user needs to do pin selection because LPC's same UART hardware, such as UART2 is available on multiple pins.
Note
If the txQSize is too small, functions performing printf will start to block.
bool UartDev::putChar ( char  out,
unsigned int  timeout = portMAX_DELAY 
)
virtual

Outputs a char given by

Parameters
out
timeoutOptional parameter which defaults to maximum value that will allow you to wait forever for a character to be sent
Returns
true if the output char was successfully written to Queue, or false if the output queue was full within the given timeout

Implements CharDev.

bool UartDev::recentlyActive ( unsigned int  ms = 3000) const

Recent activity api Check to see if this UART received any Rx/Tx activity within the last #X OS ticks.

Parameters
msOptional Parameter: Defaults to 3000 milliseconds
void UartDev::resetActivity ( void  )
inline
void UartDev::setBaudRate ( unsigned int  baudRate)

Reset the baud-rate after UART has been initialized.


The documentation for this class was generated from the following files:
  • /var/www/html/SJSU-DEV-Linux/firmware/default/lib/L2_Drivers/base/uart_dev.hpp
  • /var/www/html/SJSU-DEV-Linux/firmware/default/lib/L2_Drivers/base/uart_dev.cpp