semf
semf::UartHardware Class Referenceabstract

Class for using UART hardware. More...

#include <uarthardware.h>

Inheritance diagram for semf::UartHardware:
Inheritance graph
Collaboration diagram for semf::UartHardware:
Collaboration graph

Public Types

enum class  ErrorCode : uint8_t {
  Write_IsBusy = 0 , Write_DataIsNullptr , Write_DataSizeIsZero , Read_IsBusy ,
  Read_BufferIsNullptr , Read_BufferSizeIsZero
}
 Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring). More...
 
- Public Types inherited from semf::Uart
enum class  FlowControl : uint8_t { NoFlowControl = 0x00 , RtsFlowControl = 0x01 , CtsFlowControl = 0x10 , RtsAndCtsFlowControl = 0x11 }
 
enum class  Parity : uint8_t { NoParity , OddParity , EvenParity }
 
enum class  StopBits : uint8_t { Stopbits_0_5 , Stopbits_1 , Stopbits_1_5 , Stopbits_2 }
 
enum class  WireMode : uint8_t { ReadWire , WriteWire , ReadAndWriteWires }
 
- Public Types inherited from semf::CommunicationHardware
enum class  Type { SynchronousMaster = 1 , SynchronousSlave , Asynchronous }
 
enum class  Frame : uint8_t { First = 0x01 , Next = 0x08 , Last = 0x10 , FirstAndLast = 0x11 }
 

Public Member Functions

virtual ~UartHardware ()=default
 
void write (const uint8_t data[], size_t dataSize) override
 For writing data, dataWritten signal will be emitted after successful write. More...
 
void read (uint8_t buffer[], size_t bufferSize) override
 For reading data, dataAvailable signal will be emitted after successful read. More...
 
bool isBusyReading () const override
 Communication hardware is busy reading at the moment. More...
 
bool isBusyWriting () const override
 Communication hardware is busy writing at the moment. More...
 
- Public Member Functions inherited from semf::Uart
virtual ~Uart ()=default
 
virtual void setFormat (uint8_t bits, WireMode wire, Parity par, StopBits stop, FlowControl flow)=0
 Sets the format for the spi slave device. More...
 
virtual void setBaud (uint32_t baud)=0
 Sets the baud rate. More...
 
virtual uint32_t baud ()=0
 Returns the currently used baud rate. More...
 
- Public Member Functions inherited from semf::CommunicationHardwareAsynchronous
virtual ~CommunicationHardwareAsynchronous ()=default
 
Type type () const override
 Returns the hardware type. More...
 
void setFrame (Frame frame) final
 Sets the selected usage of start and stop condition. More...
 
- Public Member Functions inherited from semf::CommunicationHardware
virtual ~CommunicationHardware ()=default
 
virtual void init ()=0
 
virtual void deinit ()=0
 
virtual Type type () const =0
 Returns the hardware type. More...
 
virtual void setFrame (Frame frame)=0
 Sets the selected usage of start and stop condition. More...
 
- Public Member Functions inherited from semf::app::Communication
virtual ~Communication ()=default
 
virtual void write (const uint8_t data[], size_t dataSize)=0
 For writing data, dataWritten signal will be emitted after successful write. More...
 
virtual void read (uint8_t buffer[], size_t bufferSize)=0
 For reading data, dataAvailable signal will be emitted after successful read. More...
 
virtual void stopRead ()=0
 
virtual void stopWrite ()=0
 
virtual bool isBusyReading () const =0
 Communication hardware is busy reading at the moment. More...
 
virtual bool isBusyWriting () const =0
 Communication hardware is busy writing at the moment. More...
 

Protected Member Functions

void setBusyReading (bool isBusy)
 Sets the busy flag for reading. More...
 
void setBusyWriting (bool isBusy)
 Sets the busy flag for writing. More...
 
virtual void writeHardware (const uint8_t data[], size_t dataSize)=0
 Hardware will write data in interrupt mode. More...
 
virtual void readHardware (uint8_t buffer[], size_t bufferSize)=0
 Hardware will read data in interrupt mode. More...
 
void onDataWritten ()
 
void onDataAvailable ()
 
void onError (Error thrown)
 Is called if an error occurred by hardware read or write access. Will throw error signal. More...
 

Additional Inherited Members

- Public Attributes inherited from semf::app::Communication
Signal dataWritten
 
Signal dataAvailable
 
Signal writeStopped
 
Signal readStopped
 
Signal< Errorerror
 

Detailed Description

Class for using UART hardware.

Definition at line 21 of file uarthardware.h.

Member Enumeration Documentation

◆ ErrorCode

enum class semf::UartHardware::ErrorCode : uint8_t
strong

Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring).

Enumerator
Write_IsBusy 
Write_DataIsNullptr 
Write_DataSizeIsZero 
Read_IsBusy 
Read_BufferIsNullptr 
Read_BufferSizeIsZero 

Definition at line 27 of file uarthardware.h.

Constructor & Destructor Documentation

◆ ~UartHardware()

virtual semf::UartHardware::~UartHardware ( )
virtualdefault

Member Function Documentation

◆ isBusyReading()

bool semf::UartHardware::isBusyReading ( ) const
overridevirtual

Communication hardware is busy reading at the moment.

Returns
State of the communication hardware.

Implements semf::app::Communication.

Definition at line 68 of file uarthardware.cpp.

◆ isBusyWriting()

bool semf::UartHardware::isBusyWriting ( ) const
overridevirtual

Communication hardware is busy writing at the moment.

Returns
State of the communication hardware.

Implements semf::app::Communication.

Definition at line 73 of file uarthardware.cpp.

◆ onDataAvailable()

void semf::UartHardware::onDataAvailable ( )
protected

Is called after data is available in the hardware. Will emit dataAvailable signal.

Definition at line 95 of file uarthardware.cpp.

Here is the caller graph for this function:

◆ onDataWritten()

void semf::UartHardware::onDataWritten ( )
protected

Is called after data are written by the hardware. Will emit dataWritten signal.

Definition at line 88 of file uarthardware.cpp.

Here is the caller graph for this function:

◆ onError()

void semf::UartHardware::onError ( Error  thrown)
protected

Is called if an error occurred by hardware read or write access. Will throw error signal.

Parameters
thrownA thrown error object.

Definition at line 102 of file uarthardware.cpp.

Here is the caller graph for this function:

◆ read()

void semf::UartHardware::read ( uint8_t  buffer[],
size_t  bufferSize 
)
overridevirtual

For reading data, dataAvailable signal will be emitted after successful read.

Parameters
bufferBuffer to store received bytes in.
bufferSizeSize of receive buffer.
Exceptions
Read_IsBusyIf this is busy.
Read_BufferIsNullptrIf buffer is a nullptr.
Read_BufferSizeIsZeroIf bufferSize is zero.

Implements semf::app::Communication.

Definition at line 42 of file uarthardware.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readHardware()

virtual void semf::UartHardware::readHardware ( uint8_t  buffer[],
size_t  bufferSize 
)
protectedpure virtual

Hardware will read data in interrupt mode.

Parameters
bufferdata array.
bufferSizedata array size.

Implemented in semf::Stm32Uart.

Here is the caller graph for this function:

◆ setBusyReading()

void semf::UartHardware::setBusyReading ( bool  isBusy)
protected

Sets the busy flag for reading.

Note
in the functions write(), read() busy is set to true. In onDataAvailable(), onDataWritten() and onError() is busy reseted to false.
Parameters
isBusytrue for busy, false for idle.

Definition at line 78 of file uarthardware.cpp.

◆ setBusyWriting()

void semf::UartHardware::setBusyWriting ( bool  isBusy)
protected

Sets the busy flag for writing.

Note
in the functions write(), read() busy is set to true. In onDataAvailable(), onDataWritten() and onError() is busy reseted to false.
Parameters
isBusytrue for busy, false for idle.

Definition at line 83 of file uarthardware.cpp.

◆ write()

void semf::UartHardware::write ( const uint8_t  data[],
size_t  dataSize 
)
overridevirtual

For writing data, dataWritten signal will be emitted after successful write.

Parameters
dataArray, containing data to write.
dataSizeSize of write data.
Exceptions
Write_IsBusyIf this is busy.
Write_DataIsNullptrIf data is a nullptr.
Write_DataSizeIsZeroIf dataSize is zero.

Implements semf::app::Communication.

Definition at line 16 of file uarthardware.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeHardware()

virtual void semf::UartHardware::writeHardware ( const uint8_t  data[],
size_t  dataSize 
)
protectedpure virtual

Hardware will write data in interrupt mode.

Parameters
datadata array.
dataSizedata array size.

Implemented in semf::Stm32Uart.

Here is the caller graph for this function: