ClearCore Library
|
ClearCore ARM Serial Port base class.
This class is used to create a buffered serial port.
ClearCore ARM Serial Port base class. More...
#include <SerialBase.h>
Classes | |
union | SerialErrorStatusRegister |
Public Types | |
enum | DataOrders { COM_MSB_FIRST = 0 , COM_LSB_FIRST = 1 } |
enum | PortModes { UART , SPI } |
enum | SpiClockPolarities { SCK_LOW = 0 , SCK_HIGH } |
enum | SpiClockPhases { LEAD_SAMPLE = 0 , LEAD_CHANGE } |
enum | CtrlLineModes { LINE_OFF , LINE_ON , LINE_HW } |
Public Types inherited from ClearCore::ISerial | |
enum | _Parities { PARITY_E = 0 , PARITY_O , PARITY_N } |
typedef enum ClearCore::ISerial::_Parities | Parities |
Public Member Functions | |
bool | PortMode (PortModes newMode) |
Setup the port mode. | |
void | Flush () override |
void | FlushInput () override |
virtual void | PortOpen () override |
virtual void | PortClose () override |
virtual bool | Speed (uint32_t bitsPerSecond) override |
Change the baud rate for the port. | |
virtual uint32_t | Speed () override |
Gets the baud rate of the port. | |
int16_t | CharGet () override |
Attempt to read the next character from serial channel. | |
int16_t | CharPeek () override |
Attempt to get the next character from the serial channel without pulling the character out of the buffer. | |
bool | SendChar (uint8_t charToSend) override |
Send an ascii character on the serial channel. | |
int32_t | AvailableForRead () override |
int32_t | AvailableForWrite () override |
Determines the number of characters available in the transmit buffer. | |
void | WaitForTransmitIdle () override |
bool | PortIsOpen () override |
Return whether or not the port is open. | |
void | FlowControl (bool useFlowControl) |
Set UART CTS/RTS flow control. | |
bool | FlowControl () |
Return whether UART CTS/RTS flow control is enabled. | |
bool | RtsMode (CtrlLineModes mode) |
Change the serial RTS mode. | |
bool | CtsState () |
Read the serial CTS state. | |
void | SerialBreak (bool enable) |
Initiate a Serial Break. | |
bool | Parity (Parities newParity) override |
Set UART transmission parity format. | |
Parities | Parity () override |
Return current port UART transmission format. | |
bool | StopBits (uint8_t bits) override |
bool | CharSize (uint8_t size) override |
Change the number of bits in a character. | |
void | SpiClock (SpiClockPolarities polarity, SpiClockPhases phase) |
Change the polarity and phase for the SPI clock. | |
bool | SpiSsMode (CtrlLineModes mode) |
Change the SPI Slave Select mode. | |
uint8_t | SpiTransferData (uint8_t data) |
int32_t | SpiTransferData (uint8_t const *writeBuf, uint8_t *readBuf, int32_t len) |
SPI's multi-byte transmit and receive function. | |
bool | SpiTransferDataAsync (uint8_t const *writeBuf, uint8_t *readBuf, int32_t len) |
SPI's asynchronous multi-byte transmit and receive function. | |
bool | SpiAsyncWaitComplete () |
Block until asynchronous transfers are completed. | |
void | DataOrder (DataOrders newOrder) |
Change the data order for the port. | |
void | HandleFrameError () |
void | HandleParityError () |
void | HandleOverflow () |
SerialErrorStatusRegister | ErrorStatusAccum (SerialErrorStatusRegister mask=UINT32_MAX) |
Accumulating clear on read accessor for any error status bits that were asserted sometime since the previous invocation of this function. | |
Public Member Functions inherited from ClearCore::ISerial | |
bool | SendLine () |
Send carriage return and newline characters. | |
bool | Send (const char *buffer, size_t bufferSize) |
Send the array of characters out the port. | |
bool | SendLine (const char *buffer, size_t bufferSize) |
Send the array of characters out the port. Terminate the line with carriage return and newline characters. | |
bool | Send (const char *nullTermStr) |
Send a string of characters out the port. | |
bool | SendLine (const char *nullTermStr) |
Send a string of characters out the port. Terminate the line with carriage return and newline characters. | |
bool | Send (char theChar) |
Send a character to be printed to the serial port. | |
bool | SendLine (char theChar) |
Send a character to be printed to the serial port. Terminate the line with carriage return and newline characters. | |
bool | Send (double number, uint8_t precision=2) |
Send a floating point number to the serial port. | |
bool | SendLine (double number, uint8_t precision=2) |
Send a floating point number to the serial port. Terminate the line with carriage return and newline characters. | |
bool | Send (int8_t number, uint8_t radix=10) |
Send an 8-bit signed number to be printed to the serial port. | |
bool | SendLine (int8_t number, uint8_t radix=10) |
Send an 8-bit signed number to be printed to the serial port. Terminate the line with carriage return and newline characters. | |
bool | Send (uint8_t number, uint8_t radix=10) |
Send an 8-bit unsigned number to be printed to the serial port. | |
bool | SendLine (uint8_t number, uint8_t radix=10) |
Send an 8-bit unsigned number to be printed to the serial port. Terminate the line with carriage return and newline characters. | |
bool | Send (int16_t number, uint8_t radix=10) |
Send a 16-bit signed number to be printed to the serial port. | |
bool | SendLine (int16_t number, uint8_t radix=10) |
Send a 16-bit signed number to be printed to the serial port. Terminate the line with carriage return and newline characters. | |
bool | Send (uint16_t number, uint8_t radix=10) |
Send a 16-bit unsigned number to be printed to the serial port. | |
bool | SendLine (uint16_t number, uint8_t radix=10) |
Send a 16-bit unsigned number to be printed to the serial port. Terminate the line with carriage return and newline characters. | |
bool | Send (int32_t number, uint8_t radix=10) |
Send a 32-bit signed number to be printed to the serial port. | |
bool | SendLine (int32_t number, uint8_t radix=10) |
Send a 32-bit signed number to be printed to the serial port. Terminate the line with carriage return and newline characters. | |
bool | Send (uint32_t number, uint8_t radix=10) |
Send a 32-bit unsigned number to be printed to the serial port. | |
bool | SendLine (uint32_t number, uint8_t radix=10) |
Send a 32-bit unsigned number to be printed to the serial port. Terminate the line with carriage return and newline characters. | |
bool | Send (int number, uint8_t radix=10) |
Send an integer to be printed to the serial port. | |
bool | SendLine (int number, uint8_t radix=10) |
Send an integer to be printed to the serial port. | |
virtual | operator bool ()=0 |
Static Public Attributes | |
static const int16_t | BREAK_DETECTED = int16_t(0xBDBD) |
static const int16_t | EOB = -1 |
|
overridevirtual |
Returns number of characters waiting in the receive buffer.
Implements ClearCore::ISerial.
|
overridevirtual |
Determines the number of characters available in the transmit buffer.
Implements ClearCore::ISerial.
|
overridevirtual |
Attempt to read the next character from serial channel.
Implements ClearCore::ISerial.
|
overridevirtual |
Attempt to get the next character from the serial channel without pulling the character out of the buffer.
Implements ClearCore::ISerial.
|
overridevirtual |
Change the number of bits in a character.
For UART mode valid settings are: 5, 6, 7, 8, or 9. For SPI mode valid settings are: 8 or 9.
Implements ClearCore::ISerial.
bool ClearCore::SerialBase::CtsState | ( | ) |
Read the serial CTS state.
void ClearCore::SerialBase::DataOrder | ( | DataOrders | newOrder | ) |
Change the data order for the port.
For UART, this should most likely be set to COM_LSB_FIRST.
SerialErrorStatusRegister ClearCore::SerialBase::ErrorStatusAccum | ( | SerialErrorStatusRegister | mask = UINT32_MAX | ) |
Accumulating clear on read accessor for any error status bits that were asserted sometime since the previous invocation of this function.
[in] | mask | (optional) A SerialErrorStatusRegister whose asserted bits indicate which of the error status bits to check for an asserted state. If one of the bit members of this mask are deasserted, that bit will be ignored when checking for asserted status bits. If no mask is provided, it's equivalent to passing a SerialErrorStatusRegister with all bits asserted, in which case this function would report any accumulated asserted error status bits. |
|
inline |
Return whether UART CTS/RTS flow control is enabled.
void ClearCore::SerialBase::FlowControl | ( | bool | useFlowControl | ) |
Set UART CTS/RTS flow control.
[in] | useFlowControl | The new flow control setting. |
|
overridevirtual |
Flush the serial port's transmit buffer
Implements ClearCore::ISerial.
|
overridevirtual |
Flush the serial port's receive buffer
Implements ClearCore::ISerial.
void ClearCore::SerialBase::HandleFrameError | ( | ) |
Handles frame errors by clearing the error flag and raising an internal warning flag.
void ClearCore::SerialBase::HandleOverflow | ( | ) |
Handles overflow errors by clearing the error flag and raising an internal warning flag.
void ClearCore::SerialBase::HandleParityError | ( | ) |
Handles parity errors by clearing the error flag and raising an internal warning flag.
|
inlineoverridevirtual |
Return current port UART transmission format.
Implements ClearCore::ISerial.
|
overridevirtual |
Set UART transmission parity format.
Implements ClearCore::ISerial.
|
overridevirtual |
Shut down the port
Implements ClearCore::ISerial.
Reimplemented in ClearCore::SerialDriver.
|
overridevirtual |
Return whether or not the port is open.
Implements ClearCore::ISerial.
bool ClearCore::SerialBase::PortMode | ( | PortModes | newMode | ) |
Setup the port mode.
Puts the port into SPI or UART mode for subsequent transfers.
[in] | newMode | The requested serial mode. |
|
overridevirtual |
Set up the port to allow operations
Implements ClearCore::ISerial.
Reimplemented in ClearCore::SerialDriver.
bool ClearCore::SerialBase::RtsMode | ( | CtrlLineModes | mode | ) |
Change the serial RTS mode.
[in] | mode | The desired RTS pin mode. |
|
overridevirtual |
Send an ascii character on the serial channel.
[in] | charToSend | The character to be sent |
Implements ClearCore::ISerial.
void ClearCore::SerialBase::SerialBreak | ( | bool | enable | ) |
Initiate a Serial Break.
[in] | enable | true enables a serial break, false disables a serial break |
|
inlineoverridevirtual |
Gets the baud rate of the port.
Implements ClearCore::ISerial.
|
overridevirtual |
Change the baud rate for the port.
[in] | bitsPerSecond | The new speed setting |
Implements ClearCore::ISerial.
Reimplemented in ClearCore::SerialDriver.
bool ClearCore::SerialBase::SpiAsyncWaitComplete | ( | ) |
Block until asynchronous transfers are completed.
void ClearCore::SerialBase::SpiClock | ( | SpiClockPolarities | polarity, |
SpiClockPhases | phase | ||
) |
Change the polarity and phase for the SPI clock.
bool ClearCore::SerialBase::SpiSsMode | ( | CtrlLineModes | mode | ) |
Change the SPI Slave Select mode.
[in] | mode | The desired SS pin mode. |
int32_t ClearCore::SerialBase::SpiTransferData | ( | uint8_t const * | writeBuf, |
uint8_t * | readBuf, | ||
int32_t | len | ||
) |
SPI's multi-byte transmit and receive function.
This can be used to send/receive a buffer's worth of data. The SPI channel will be commanded to transfer a byte at a time for the given len of bytes. The data transferred out will come from the writeBuf or a dummy value, and the data received in will be written to the readBuf or a dummy value.
[in] | writeBuf | A pointer to the beginning of the data to write |
[in] | readBuf | A pointer to the beginning of a read destination for the data in the serial port |
[in] | len | The maximum number of bytes to read and write |
uint8_t ClearCore::SerialBase::SpiTransferData | ( | uint8_t | data | ) |
SPI's transmit and receive function
bool ClearCore::SerialBase::SpiTransferDataAsync | ( | uint8_t const * | writeBuf, |
uint8_t * | readBuf, | ||
int32_t | len | ||
) |
SPI's asynchronous multi-byte transmit and receive function.
This can be used to send/receive a buffer's worth of data. The SPI channel will be commanded to transfer len of bytes asynchronously via the Direct Memory Access Controller. The data transferred out will come from the writeBuf or a dummy value, and the data received in will be written to the readBuf or a dummy value.
[in] | writeBuf | A pointer to the beginning of the data to write |
[in] | readBuf | A pointer to the beginning of a read destination for the data in the serial port |
[in] | len | The maximum number of bytes to read and write |
|
overridevirtual |
Change the number of stop bits used in UART communication.
Implements ClearCore::ISerial.
|
overridevirtual |
Wait for transmission idle.
Implements ClearCore::ISerial.
|
static |
Break detected 'character' placed in the character stream when the break condition has been detected.
|
static |
No character available indicator.