PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Public Types | Public Member Functions | Static Public Attributes | List of all members
PropWare::UARTRX Class Reference

Receive routines for basic UART communication. More...

#include <PropWare/serial/uart/uartrx.h>

+ Inheritance diagram for PropWare::UARTRX:
+ Collaboration diagram for PropWare::UARTRX:

Public Types

enum  Parity {
  Parity::NO_PARITY,
  Parity::EVEN_PARITY,
  Parity::ODD_PARITY
}
 
enum  ErrorCode {
  NO_ERROR = 0,
  BEG_ERROR = UART_ERRORS_BASE,
  BAUD_TOO_HIGH = BEG_ERROR,
  PARITY_ERROR,
  INVALID_DATA_WIDTH,
  INVALID_STOP_BIT_WIDTH,
  NULL_POINTER,
  TIMEOUT_ERROR,
  END_ERROR = UART::TIMEOUT_ERROR
}
 

Public Member Functions

 UARTRX ()
 
 UARTRX (const Port::Mask rx)
 Initialize a UART receiver. More...
 
void set_rx_mask (const Port::Mask rx)
 
Port::Mask get_rx_mask () const
 
virtual ErrorCode set_data_width (const uint8_t dataWidth)
 
virtual void set_parity (const UART::Parity parity)
 
uint32_t receive () const
 Retrieve a single word from the bus. More...
 
PropWare::ErrorCode receive (uint32_t &data) const
 Receive one byte from the uart. This blocks until the byte is received. More...
 
PropWare::ErrorCode receive (uint32_t &data, const uint32_t timeout) const
 Receive one byte from the uart. This blocks until either the byte was received or the timeout triggered. More...
 
PropWare::ErrorCode get_line (char *buffer, int32_t *length, const char delimiter='\n') const
 Read bytes until the provided delimiter is read or max length is reached. More...
 
PropWare::ErrorCode receive_array (uint8_t *buffer, uint32_t length) const
 Reads multiple bytes into the given buffer. This blocks until requested number of words have been received. More...
 
PropWare::ErrorCode receive_array (uint8_t *buffer, uint32_t length, const uint32_t timeout) const
 Reads multiple bytes into the given buffer. This blocks until either the. More...
 
PropWare::ErrorCode fgets (char string[], int32_t *bufferSize) const
 Read words from the bus until a newline character (\\n) is received or the buffer is filled. More...
 
virtual char get_char ()
 Read and return a single character. Whether the method is blocking or not depends entirely on the implementation.
 
uint8_t get_data_width () const
 
UART::Parity get_parity () const
 
ErrorCode set_stop_bit_width (const uint8_t stopBitWidth)
 
uint8_t get_stop_bit_width () const
 
void set_baud_rate (const int32_t baudRate)
 
int32_t get_baud_rate () const
 

Static Public Attributes

static const uint8_t DEFAULT_DATA_WIDTH = 8
 
static const Parity DEFAULT_PARITY = Parity::NO_PARITY
 
static const uint8_t DEFAULT_STOP_BIT_WIDTH = 1
 
static const int MAX_BAUD = 4413793
 

Detailed Description

Receive routines for basic UART communication.

Examples
BufferedUART_Demo.cpp, and UARTRX_Demo.cpp.

Definition at line 41 of file uartrx.h.

Member Enumeration Documentation

◆ ErrorCode

enum PropWare::UART::ErrorCode
inherited

Error codes - Proceeded by SD, SPI, and HD44780

Enumerator
NO_ERROR 

No errors; Successful completion of the function

BEG_ERROR 

First error code for PropWare::UART

BAUD_TOO_HIGH 

The requested baud rate is too high

PARITY_ERROR 

A parity error has occurred during read

INVALID_DATA_WIDTH 

The requested data width is not between 1 and 16 (inclusive)

INVALID_STOP_BIT_WIDTH 

The requested stop bit width is not between 1 and 14 (inclusive)

NULL_POINTER 

Null pointer was passed as an argument

TIMEOUT_ERROR 

Reading from the serial connection timed out

END_ERROR 

Last error code used by PropWare::UART

Definition at line 102 of file uart.h.

◆ Parity

enum PropWare::UART::Parity
stronginherited
Enumerator
NO_PARITY 

No parity

EVEN_PARITY 

Even parity

ODD_PARITY 

Odd parity

Definition at line 88 of file uart.h.

Constructor & Destructor Documentation

◆ UARTRX() [1/2]

PropWare::UARTRX::UARTRX ( )
See also
PropWare::UART::UART()

Definition at line 50 of file uartrx.h.

◆ UARTRX() [2/2]

PropWare::UARTRX::UARTRX ( const Port::Mask  rx)

Initialize a UART receiver.

Parameters
[in]rxPin mask for RX (receive) pin

Definition at line 64 of file uartrx.h.

Member Function Documentation

◆ fgets()

PropWare::ErrorCode PropWare::UARTRX::fgets ( char  string[],
int32_t *  bufferSize 
) const

Read words from the bus until a newline character (\\n) is received or the buffer is filled.

If found, the newline character will be replaced with a null-terminator. If the buffer is filled before a newline is found, no null-terminator will be inserted

Parameters
[in]string[]Output buffer which should store the data
[out]bufferSize*Address where the new length of the buffer will be written
Returns
Zero upon success, error code otherwise

Definition at line 302 of file uartrx.h.

+ Here is the caller graph for this function:

◆ get_line()

PropWare::ErrorCode PropWare::UARTRX::get_line ( char buffer,
int32_t *  length,
const char  delimiter = '\n' 
) const

Read bytes until the provided delimiter is read or max length is reached.

If the delimiter is read before hitting the max length, then the delimiter will be inserted into the buffer and the function will return. At the point that the max length is hit, the function will immediately return.

Postcondition
The input buffer will contain data read in and the length parameter will contain the number of characters received.
Parameters
[out]buffer*Area in memory will data can be stored
[in]length*Maximum number of characters to read from the bus. Upon returning, the number of characters actually received will be stored here.
[in]delimiterRead from the bus until this character is received.
Returns
0 upon success, error code otherwise.

Definition at line 175 of file uartrx.h.

◆ receive() [1/3]

uint32_t PropWare::UARTRX::receive ( ) const

Retrieve a single word from the bus.

Returns
Either the word is returned from the bus, or -1 if a parity error occurs.

Definition at line 104 of file uartrx.h.

+ Here is the caller graph for this function:

◆ receive() [2/3]

PropWare::ErrorCode PropWare::UARTRX::receive ( uint32_t &  data) const

Receive one byte from the uart. This blocks until the byte is received.

Parameters
[out]dataThe byte that was read.
Returns
An ErrorCode that specifies if something went wrong, and what.

Definition at line 121 of file uartrx.h.

◆ receive() [3/3]

PropWare::ErrorCode PropWare::UARTRX::receive ( uint32_t &  data,
const uint32_t  timeout 
) const

Receive one byte from the uart. This blocks until either the byte was received or the timeout triggered.

Parameters
[out]dataThe byte that was read.
[in]timeoutTimeout after which the function will exit without having received a byte.
Returns
An ErrorCode that specifies if something went wrong, and what.
Warning
If this method is used for multiple consecutive bytes, the baud rate should be no greater than
  1. If this method is used only for the first byte of a multi-byte transmission, then the standard maximum baud rate is acceptable.

Definition at line 146 of file uartrx.h.

+ Here is the call graph for this function:

◆ receive_array() [1/2]

PropWare::ErrorCode PropWare::UARTRX::receive_array ( uint8_t *  buffer,
uint32_t  length 
) const

Reads multiple bytes into the given buffer. This blocks until requested number of words have been received.

Parameters
[in]buffer*Area in memory where received data can be stored
[in]lengthNumber of bytes to read
Returns
An ErrorCode that specifies if something went wrong, and what.

Definition at line 225 of file uartrx.h.

◆ receive_array() [2/2]

PropWare::ErrorCode PropWare::UARTRX::receive_array ( uint8_t *  buffer,
uint32_t  length,
const uint32_t  timeout 
) const

Reads multiple bytes into the given buffer. This blocks until either the.

Parameters
[in]buffer*Area in memory where received data can be stored
[in]lengthNumber of bytes to read
[in]timeoutAmount of clock cycles after which the function will stop waiting for a new byte to start. This timeout is not for all bytes read here.
Returns
An ErrorCode that specifies if something went wrong, and what.

Definition at line 264 of file uartrx.h.


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