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

#include "distortos/chip/SpiMasterLowLevelInterruptBased.hpp"

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

Public Member Functions

constexpr SpiMasterLowLevelInterruptBased (const SpiPeripheral &spiPeripheral)
 SpiMasterLowLevelInterruptBased's constructor. More...
 
 ~SpiMasterLowLevelInterruptBased () override
 SpiMasterLowLevelInterruptBased'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...
 
void interruptHandler ()
 Interrupt handler. 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

bool isStarted () const
 
bool isTransferInProgress () const
 
void writeNextItem ()
 Writes next item to SPI peripheral. More...
 

Private Attributes

const SpiPeripheralspiPeripheral_
 reference to raw SPI peripheral More...
 
devices::SpiMasterBase *volatile spiMasterBase_
 pointer to SpiMasterBase object associated with this one More...
 
uint8_t *volatile readBuffer_
 buffer to which the data is being written, nullptr to ignore received data More...
 
const uint8_t *volatile writeBuffer_
 buffer with data that is being transmitted, nullptr to send dummy data More...
 
volatile size_t size_
 size of transfer (size of readBuffer_ and/or writeBuffer_), bytes More...
 
volatile size_t readPosition_
 current position in readBuffer_ More...
 
volatile size_t writePosition_
 current position in writeBuffer_ More...
 
uint16_t dummyData_
 dummy data that will be sent if write buffer of transfer is nullptr More...
 
bool started_
 true if driver is started, false otherwise More...
 
uint8_t wordLength_
 selected word length, bits, {8, 16} More...
 

Detailed Description

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

This driver uses interrupts for data transfers.

Constructor & Destructor Documentation

◆ SpiMasterLowLevelInterruptBased()

constexpr distortos::chip::SpiMasterLowLevelInterruptBased::SpiMasterLowLevelInterruptBased ( const SpiPeripheral spiPeripheral)
inlineexplicit

SpiMasterLowLevelInterruptBased's constructor.

Parameters
[in]spiPeripheralis a reference to raw SPI peripheral

◆ ~SpiMasterLowLevelInterruptBased()

distortos::chip::SpiMasterLowLevelInterruptBased::~SpiMasterLowLevelInterruptBased ( )
override

SpiMasterLowLevelInterruptBased's destructor.

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

Member Function Documentation

◆ configure()

void distortos::chip::SpiMasterLowLevelInterruptBased::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, {8, 16}
[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:

◆ interruptHandler()

void distortos::chip::SpiMasterLowLevelInterruptBased::interruptHandler ( )

Interrupt handler.

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

◆ isStarted()

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

◆ isTransferInProgress()

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

◆ start()

int distortos::chip::SpiMasterLowLevelInterruptBased::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::SpiMasterLowLevelInterruptBased::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::SpiMasterLowLevelInterruptBased::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:

◆ writeNextItem()

void distortos::chip::SpiMasterLowLevelInterruptBased::writeNextItem ( )
private

Writes next item to SPI peripheral.

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

Member Data Documentation

◆ dummyData_

uint16_t distortos::chip::SpiMasterLowLevelInterruptBased::dummyData_
private

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

◆ readBuffer_

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

buffer to which the data is being written, nullptr to ignore received data

◆ readPosition_

volatile size_t distortos::chip::SpiMasterLowLevelInterruptBased::readPosition_
private

current position in readBuffer_

◆ size_

volatile size_t distortos::chip::SpiMasterLowLevelInterruptBased::size_
private

size of transfer (size of readBuffer_ and/or writeBuffer_), bytes

◆ spiMasterBase_

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

pointer to SpiMasterBase object associated with this one

◆ spiPeripheral_

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

reference to raw SPI peripheral

◆ started_

bool distortos::chip::SpiMasterLowLevelInterruptBased::started_
private

true if driver is started, false otherwise

◆ wordLength_

uint8_t distortos::chip::SpiMasterLowLevelInterruptBased::wordLength_
private

selected word length, bits, {8, 16}

◆ writeBuffer_

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

buffer with data that is being transmitted, nullptr to send dummy data

◆ writePosition_

volatile size_t distortos::chip::SpiMasterLowLevelInterruptBased::writePosition_
private

current position in writeBuffer_


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