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

#include "distortos/chip/SpiMasterLowLevelDmaBased.hpp"

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

Classes

class  RxDmaChannelFunctor
 RxDmaChannelFunctor class is a DmaChannelFunctor for DMA channel used for reception. More...
 
class  TxDmaChannelFunctor
 TxDmaChannelFunctor class is a DmaChannelFunctorCommon for DMA channel used for transmission. More...
 

Public Member Functions

constexpr SpiMasterLowLevelDmaBased (const SpiPeripheral &spiPeripheral, DmaChannel &rxDmaChannel, const uint8_t rxDmaRequest, DmaChannel &txDmaChannel, const uint8_t txDmaRequest)
 SpiMasterLowLevelDmaBased's constructor. More...
 
 ~SpiMasterLowLevelDmaBased () override
 SpiMasterLowLevelDmaBased's destructor. More...
 
void configure (devices::SpiMode mode, uint32_t clockFrequency, uint8_t wordLength, bool lsbFirst, uint32_t dummyData) override
 Configures parameters of low-level SPI master driver. More...
 
int start () override
 Starts low-level SPI master driver. More...
 
void startTransfer (devices::SpiMasterBase &spiMasterBase, const void *writeBuffer, void *readBuffer, size_t size) override
 Starts asynchronous transfer. More...
 
void stop () override
 Stops low-level SPI master driver. More...
 
- Public Member Functions inherited from distortos::devices::SpiMasterLowLevel
virtual ~SpiMasterLowLevel ()=default
 SpiMasterLowLevel's destructor. More...
 

Private Member Functions

void eventHandler (bool success)
 "Transfer complete" and "transfer error" event handler More...
 
bool isStarted () const
 
bool isTransferInProgress () const
 

Private Attributes

const SpiPeripheralspiPeripheral_
 reference to raw SPI peripheral More...
 
DmaChannelrxDmaChannel_
 reference to DMA channel used for reception More...
 
DmaChanneltxDmaChannel_
 reference to DMA channel used for transmission More...
 
DmaChannelHandle rxDmaChannelHandle_
 handle of DMA channel used for reception More...
 
DmaChannelHandle txDmaChannelHandle_
 handle of DMA channel used for transmission More...
 
RxDmaChannelFunctor rxDmaChannelFunctor_
 functor for DMA channel used for reception More...
 
TxDmaChannelFunctor txDmaChannelFunctor_
 functor for DMA channel used for transmission More...
 
devices::SpiMasterBase *volatile spiMasterBase_
 pointer to SpiMasterBase object associated with this one More...
 
uint16_t rxDummyData_
 object used as reception DMA target if read buffer of transfer is nullptr More...
 
uint16_t txDummyData_
 dummy data that will be sent if write buffer of transfer is nullptr More...
 
uint8_t rxDmaRequest_
 request identifier for DMA channel used for reception More...
 
uint8_t txDmaRequest_
 request identifier for DMA channel used for transmission More...
 
bool started_
 true if driver is started, false otherwise More...
 
uint8_t wordLength_
 selected word length, bits, [4; 16] or [minSpiWordLength; maxSpiWordLength] More...
 

Detailed Description

SpiMasterLowLevelDmaBased class is a low-level SPI master driver for SPIv1 in STM32.

This driver uses DMA for data transfers.

Constructor & Destructor Documentation

◆ SpiMasterLowLevelDmaBased()

constexpr distortos::chip::SpiMasterLowLevelDmaBased::SpiMasterLowLevelDmaBased ( const SpiPeripheral spiPeripheral,
DmaChannel rxDmaChannel,
const uint8_t  rxDmaRequest,
DmaChannel txDmaChannel,
const uint8_t  txDmaRequest 
)
inline

SpiMasterLowLevelDmaBased's constructor.

Parameters
[in]spiPeripheralis a reference to raw SPI peripheral
[in]rxDmaChannelis a reference to DMA channel used for reception
[in]rxDmaRequestis the request identifier for DMA channel used for reception
[in]txDmaChannelis a reference to DMA channel used for transmission
[in]txDmaRequestis the request identifier for DMA channel used for transmission

◆ ~SpiMasterLowLevelDmaBased()

distortos::chip::SpiMasterLowLevelDmaBased::~SpiMasterLowLevelDmaBased ( )
override

SpiMasterLowLevelDmaBased's destructor.

Precondition
Driver is stopped.
Here is the call graph for this function:

Member Function Documentation

◆ configure()

void distortos::chip::SpiMasterLowLevelDmaBased::configure ( devices::SpiMode  mode,
uint32_t  clockFrequency,
uint8_t  wordLength,
bool  lsbFirst,
uint32_t  dummyData 
)
overridevirtual

Configures parameters of low-level SPI master driver.

Precondition
Driver is started.
No transfer is in progress.
clockFrequency is greater than or equal to spiPeripheral_.getPeripheralFrequency() / 256.
wordLength is valid.
Parameters
[in]modeis the desired SPI mode
[in]clockFrequencyis the desired clock frequency, Hz
[in]wordLengthselects word length, bits, [4; 16] or [minSpiWordLength; maxSpiWordLength]
[in]lsbFirstselects whether MSB (false) or LSB (true) is transmitted first
[in]dummyDatais the dummy data that will be sent if write buffer of transfer is nullptr

Implements distortos::devices::SpiMasterLowLevel.

Here is the call graph for this function:

◆ eventHandler()

void distortos::chip::SpiMasterLowLevelDmaBased::eventHandler ( bool  success)
private

"Transfer complete" and "transfer error" event handler

Parameters
[in]successtells whether the transfer was successful (true) or not (false)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isStarted()

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

◆ isTransferInProgress()

bool distortos::chip::SpiMasterLowLevelDmaBased::isTransferInProgress ( ) const
inlineprivate
Returns
true if transfer is in progress, false otherwise
Here is the caller graph for this function:

◆ start()

int distortos::chip::SpiMasterLowLevelDmaBased::start ( )
overridevirtual

Starts low-level SPI master driver.

Precondition
Driver is stopped.
Returns
0 on success, error code otherwise:

Implements distortos::devices::SpiMasterLowLevel.

Here is the call graph for this function:

◆ startTransfer()

void distortos::chip::SpiMasterLowLevelDmaBased::startTransfer ( devices::SpiMasterBase spiMasterBase,
const void *  writeBuffer,
void *  readBuffer,
size_t  size 
)
overridevirtual

Starts asynchronous transfer.

This function returns immediately. When the transfer is physically finished (either expected number of bytes were written and read or an error was detected), SpiMasterBase::transferCompleteEvent() will be executed.

Precondition
Driver is started.
No transfer is in progress.
size is valid.
Postcondition
Transfer is in progress.
Parameters
[in]spiMasterBaseis a reference to SpiMasterBase object that will be notified about completed transfer
[in]writeBufferis the buffer with data that will be written, nullptr to send dummy data
[out]readBufferis the buffer with data that will be read, nullptr to ignore received data
[in]sizeis the size of transfer (size of writeBuffer and/or readBuffer), bytes, most not be zero, must be even if number of data bits is in range (8; 16], divisible by 3 if number of data bits is in range (16; 24] or divisible by 4 if number of data bits is in range (24; 32]

Implements distortos::devices::SpiMasterLowLevel.

Here is the call graph for this function:

◆ stop()

void distortos::chip::SpiMasterLowLevelDmaBased::stop ( )
overridevirtual

Stops low-level SPI master driver.

Precondition
Driver is started.
No transfer is in progress.
Postcondition
Driver is stopped.

Implements distortos::devices::SpiMasterLowLevel.

Here is the call graph for this function:

Member Data Documentation

◆ rxDmaChannel_

DmaChannel& distortos::chip::SpiMasterLowLevelDmaBased::rxDmaChannel_
private

reference to DMA channel used for reception

◆ rxDmaChannelFunctor_

RxDmaChannelFunctor distortos::chip::SpiMasterLowLevelDmaBased::rxDmaChannelFunctor_
private

functor for DMA channel used for reception

◆ rxDmaChannelHandle_

DmaChannelHandle distortos::chip::SpiMasterLowLevelDmaBased::rxDmaChannelHandle_
private

handle of DMA channel used for reception

◆ rxDmaRequest_

uint8_t distortos::chip::SpiMasterLowLevelDmaBased::rxDmaRequest_
private

request identifier for DMA channel used for reception

◆ rxDummyData_

uint16_t distortos::chip::SpiMasterLowLevelDmaBased::rxDummyData_
private

object used as reception DMA target if read buffer of transfer is nullptr

◆ spiMasterBase_

devices::SpiMasterBase* volatile distortos::chip::SpiMasterLowLevelDmaBased::spiMasterBase_
private

pointer to SpiMasterBase object associated with this one

◆ spiPeripheral_

const SpiPeripheral& distortos::chip::SpiMasterLowLevelDmaBased::spiPeripheral_
private

reference to raw SPI peripheral

◆ started_

bool distortos::chip::SpiMasterLowLevelDmaBased::started_
private

true if driver is started, false otherwise

◆ txDmaChannel_

DmaChannel& distortos::chip::SpiMasterLowLevelDmaBased::txDmaChannel_
private

reference to DMA channel used for transmission

◆ txDmaChannelFunctor_

TxDmaChannelFunctor distortos::chip::SpiMasterLowLevelDmaBased::txDmaChannelFunctor_
private

functor for DMA channel used for transmission

◆ txDmaChannelHandle_

DmaChannelHandle distortos::chip::SpiMasterLowLevelDmaBased::txDmaChannelHandle_
private

handle of DMA channel used for transmission

◆ txDmaRequest_

uint8_t distortos::chip::SpiMasterLowLevelDmaBased::txDmaRequest_
private

request identifier for DMA channel used for transmission

◆ txDummyData_

uint16_t distortos::chip::SpiMasterLowLevelDmaBased::txDummyData_
private

dummy data that will be sent if write buffer of transfer is nullptr

◆ wordLength_

uint8_t distortos::chip::SpiMasterLowLevelDmaBased::wordLength_
private

selected word length, bits, [4; 16] or [minSpiWordLength; maxSpiWordLength]


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