PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
|
Receive routines for basic UART communication. More...
#include <PropWare/serial/uart/uartrx.h>
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 |
Receive routines for basic UART communication.
|
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 |
|
stronginherited |
PropWare::UARTRX::UARTRX | ( | const Port::Mask | rx | ) |
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
[in] | string[] | Output buffer which should store the data |
[out] | bufferSize* | Address where the new length of the buffer will be written |
Definition at line 302 of file uartrx.h.
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.
[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] | delimiter | Read from the bus until this character is received. |
uint32_t PropWare::UARTRX::receive | ( | ) | const |
PropWare::ErrorCode PropWare::UARTRX::receive | ( | uint32_t & | data | ) | const |
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.
[out] | data | The byte that was read. |
[in] | timeout | Timeout after which the function will exit without having received a byte. |
Definition at line 146 of file uartrx.h.
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.
[in] | buffer* | Area in memory where received data can be stored |
[in] | length | Number of bytes to read |
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.
[in] | buffer* | Area in memory where received data can be stored |
[in] | length | Number of bytes to read |
[in] | timeout | Amount 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. |