distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
distortos::chip::ChipUartLowLevel Class Reference

#include "distortos/chip/ChipUartLowLevel.hpp"

Inheritance diagram for distortos::chip::ChipUartLowLevel:
[legend]
Collaboration diagram for distortos::chip::ChipUartLowLevel:
[legend]

Classes

class  Parameters
 parameters for construction of UART low-level drivers More...
 

Public Member Functions

constexpr ChipUartLowLevel (const Parameters &parameters)
 ChipUartLowLevel's constructor. More...
 
 ~ChipUartLowLevel () override
 ChipUartLowLevel's destructor. More...
 
void interruptHandler ()
 Interrupt handler. More...
 
std::pair< int, uint32_t > start (devices::UartBase &uartBase, uint32_t baudRate, uint8_t characterLength, devices::UartParity parity, bool _2StopBits) override
 Starts low-level UART driver. More...
 
int startRead (void *buffer, size_t size) override
 Starts asynchronous read operation. More...
 
int startWrite (const void *buffer, size_t size) override
 Starts asynchronous write operation. More...
 
int stop () override
 Stops low-level UART driver. More...
 
size_t stopRead () override
 Stops asynchronous read operation. More...
 
size_t stopWrite () override
 Stops asynchronous write operation. More...
 
- Public Member Functions inherited from distortos::devices::UartLowLevel
virtual ~UartLowLevel ()=default
 UartLowLevel's destructor. More...
 

Static Public Attributes

static constexpr uint8_t minCharacterLength {7}
 minimum allowed value for UART character length More...
 
static constexpr uint8_t maxCharacterLength {9}
 maximum allowed value for UART character length More...
 

Private Member Functions

bool isStarted () const
 
bool isReadInProgress () const
 
bool isWriteInProgress () const
 

Private Attributes

const Parametersparameters_
 reference to configuration parameters More...
 
devices::UartBaseuartBase_
 pointer to UartBase object associated with this one More...
 
uint8_t *volatile readBuffer_
 buffer to which the data is being written More...
 
volatile size_t readSize_
 size of readBuffer_, bytes More...
 
volatile size_t readPosition_
 current position in readBuffer_ More...
 
const uint8_t *volatile writeBuffer_
 buffer with data that is being transmitted More...
 
volatile size_t writeSize_
 size of writeBuffer_, bytes More...
 
volatile size_t writePosition_
 current position in writeBuffer_ More...
 

Detailed Description

ChipUartLowLevel class is a low-level UART driver for USARTv1 in STM32

Constructor & Destructor Documentation

◆ ChipUartLowLevel()

constexpr distortos::chip::ChipUartLowLevel::ChipUartLowLevel ( const Parameters parameters)
inlineexplicit

ChipUartLowLevel's constructor.

Parameters
[in]parametersis a reference to object with peripheral parameters

◆ ~ChipUartLowLevel()

distortos::chip::ChipUartLowLevel::~ChipUartLowLevel ( )
override

ChipUartLowLevel's destructor.

Does nothing if driver is already stopped. If it's not, performs forced stop of operation.

Here is the call graph for this function:

Member Function Documentation

◆ interruptHandler()

void distortos::chip::ChipUartLowLevel::interruptHandler ( )

Interrupt handler.

Note
this must not be called by user code
Here is the call graph for this function:

◆ isReadInProgress()

bool distortos::chip::ChipUartLowLevel::isReadInProgress ( ) const
inlineprivate
Returns
true if read operation is in progress, false otherwise
Here is the caller graph for this function:

◆ isStarted()

bool distortos::chip::ChipUartLowLevel::isStarted ( ) const
inlineprivate
Returns
true if driver is started, false otherwise
Here is the caller graph for this function:

◆ isWriteInProgress()

bool distortos::chip::ChipUartLowLevel::isWriteInProgress ( ) const
inlineprivate
Returns
true if write operation is in progress, false otherwise
Here is the caller graph for this function:

◆ start()

std::pair< int, uint32_t > distortos::chip::ChipUartLowLevel::start ( devices::UartBase uartBase,
uint32_t  baudRate,
uint8_t  characterLength,
devices::UartParity  parity,
bool  _2StopBits 
)
overridevirtual

Starts low-level UART driver.

Not all combinations of data format are supported. The general rules are:

  • if parity control is disabled, character length must not be 7,
  • if parity control is enabled, character length must not be 9.
Parameters
[in]uartBaseis a reference to UartBase object that will be associated with this one
[in]baudRateis the desired baud rate, bps
[in]characterLengthselects character length, bits, [7; 9] or [minCharacterLength; maxCharacterLength]
[in]parityselects parity
[in]_2StopBitsselects whether 1 (false) or 2 (true) stop bits are used
Returns
pair with return code (0 on success, error code otherwise) and real baud rate; error codes:
  • EBADF - the driver is not stopped;
  • EINVAL - selected baud rate and/or format are invalid;

Implements distortos::devices::UartLowLevel.

Here is the call graph for this function:

◆ startRead()

int distortos::chip::ChipUartLowLevel::startRead ( void *  buffer,
size_t  size 
)
overridevirtual

Starts asynchronous read operation.

This function returns immediately. When the operation is finished (expected number of bytes were read), UartBase::readCompleteEvent() will be executed. For any detected error during reception, UartBase::receiveErrorEvent() will be executed. Note that overrun error may be reported even if it happened when no read operation was in progress.

Parameters
[out]bufferis the buffer to which the data will be written
[in]sizeis the size of buffer, bytes, must be even if selected character length is greater than 8 bits
Returns
0 on success, error code otherwise:
  • EBADF - the driver is not started;
  • EBUSY - read is in progress;
  • EINVAL - buffer and/or size are invalid;

Implements distortos::devices::UartLowLevel.

Here is the call graph for this function:

◆ startWrite()

int distortos::chip::ChipUartLowLevel::startWrite ( const void *  buffer,
size_t  size 
)
overridevirtual

Starts asynchronous write operation.

This function returns immediately. If no transmission is active, UartBase::transmitStartEvent() will be executed. When the operation is finished (expected number of bytes were written), UartBase::writeCompleteEvent() will be executed. When the transmission physically ends, UartBase::transmitCompleteEvent() will be executed.

Parameters
[in]bufferis the buffer with data that will be transmitted
[in]sizeis the size of buffer, bytes, must be even if selected character length is greater than 8 bits
Returns
0 on success, error code otherwise:
  • EBADF - the driver is not started;
  • EBUSY - write is in progress;
  • EINVAL - buffer and/or size are invalid;

Implements distortos::devices::UartLowLevel.

Here is the call graph for this function:

◆ stop()

int distortos::chip::ChipUartLowLevel::stop ( )
overridevirtual

Stops low-level UART driver.

Returns
0 on success, error code otherwise:
  • EBADF - the driver is not started;
  • EBUSY - read and/or write are in progress;

Implements distortos::devices::UartLowLevel.

Here is the call graph for this function:

◆ stopRead()

size_t distortos::chip::ChipUartLowLevel::stopRead ( )
overridevirtual

Stops asynchronous read operation.

This function returns immediately. After this call UartBase::readCompleteEvent() will not be executed.

Returns
number of bytes already read by low-level UART driver (and written to read buffer)

Implements distortos::devices::UartLowLevel.

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

◆ stopWrite()

size_t distortos::chip::ChipUartLowLevel::stopWrite ( )
overridevirtual

Stops asynchronous write operation.

This function returns immediately. After this call UartBase::writeCompleteEvent() will not be executed. UartBase::transmitCompleteEvent() will not be suppressed.

Returns
number of bytes already written by low-level UART driver (and read from write buffer)

Implements distortos::devices::UartLowLevel.

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

Member Data Documentation

◆ maxCharacterLength

constexpr uint8_t distortos::chip::ChipUartLowLevel::maxCharacterLength {9}
static

maximum allowed value for UART character length

◆ minCharacterLength

constexpr uint8_t distortos::chip::ChipUartLowLevel::minCharacterLength {7}
static

minimum allowed value for UART character length

◆ parameters_

const Parameters& distortos::chip::ChipUartLowLevel::parameters_
private

reference to configuration parameters

◆ readBuffer_

uint8_t* volatile distortos::chip::ChipUartLowLevel::readBuffer_
private

buffer to which the data is being written

◆ readPosition_

volatile size_t distortos::chip::ChipUartLowLevel::readPosition_
private

current position in readBuffer_

◆ readSize_

volatile size_t distortos::chip::ChipUartLowLevel::readSize_
private

size of readBuffer_, bytes

◆ uartBase_

devices::UartBase* distortos::chip::ChipUartLowLevel::uartBase_
private

pointer to UartBase object associated with this one

◆ writeBuffer_

const uint8_t* volatile distortos::chip::ChipUartLowLevel::writeBuffer_
private

buffer with data that is being transmitted

◆ writePosition_

volatile size_t distortos::chip::ChipUartLowLevel::writePosition_
private

current position in writeBuffer_

◆ writeSize_

volatile size_t distortos::chip::ChipUartLowLevel::writeSize_
private

size of writeBuffer_, bytes


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