#include "distortos/devices/communication/SpiMaster.hpp"
SpiMaster class is a driver for SPI master
◆ SpiMaster()
◆ ~SpiMaster()
distortos::devices::SpiMaster::~SpiMaster |
( |
| ) |
|
|
override |
SpiMaster's destructor.
- Precondition
- Device is closed.
◆ close()
void distortos::devices::SpiMaster::close |
( |
| ) |
|
|
private |
Closes SPI master.
Does nothing if any user still has this device opened. Otherwise low-level driver is stopped.
- Precondition
- Device is opened.
◆ configure()
void distortos::devices::SpiMaster::configure |
( |
SpiMode |
mode, |
|
|
uint32_t |
clockFrequency, |
|
|
uint8_t |
wordLength, |
|
|
bool |
lsbFirst, |
|
|
uint32_t |
dummyData |
|
) |
| const |
|
private |
Configures parameters of SPI master.
- Precondition
- Device is opened.
-
clockFrequency and wordLength are valid for associated low-level implementation of SpiMasterLowLevel interface.
- Parameters
-
[in] | mode | is the desired SPI mode |
[in] | clockFrequency | is the desired clock frequency, Hz |
[in] | wordLength | selects word length, bits |
[in] | lsbFirst | selects whether MSB (false) or LSB (true) is transmitted first |
[in] | dummyData | is the dummy data that will be sent if write buffer of transfer is nullptr |
◆ executeTransaction()
Executes series of transfers as a single atomic transaction.
The transaction is finished when all transfers are complete or when any error is detected.
- Warning
- This function must not be called from interrupt context!
- Precondition
- Device is opened.
-
transfersRange has at least one transfer.
- Parameters
-
[in] | transfersRange | is the range of transfers that will be executed |
- Returns
- 0 on success, error code otherwise:
- EIO - failure detected by low-level SPI master driver;
◆ lock()
void distortos::devices::SpiMaster::lock |
( |
| ) |
|
|
private |
Locks SPI master for exclusive use by current thread.
- Note
- Locks are recursive.
- Warning
- This function must not be called from interrupt context!
- Precondition
- The number of recursive locks of device is less than 65535.
- Postcondition
- Device is locked.
◆ notifyWaiter()
void distortos::devices::SpiMaster::notifyWaiter |
( |
bool |
success | ) |
|
|
private |
Notifies waiting thread about completion of transaction.
- Parameters
-
[in] | success | tells whether the transaction was successful (true) or not (false) |
◆ open()
int distortos::devices::SpiMaster::open |
( |
| ) |
|
|
private |
Opens SPI master.
Does nothing if any user already has this device opened. Otherwise low-level driver is started.
- Precondition
- The number of times the device is opened is less than 255.
- Returns
- 0 on success, error code otherwise:
◆ transferCompleteEvent()
void distortos::devices::SpiMaster::transferCompleteEvent |
( |
bool |
success | ) |
|
|
overrideprivatevirtual |
"Transfer complete" event
Called by low-level SPI master driver when the transfer is physically finished.
Handles the next transfer from the currently handled transaction. If there are no more transfers, waiting thread is notified about completion of transaction.
- Parameters
-
[in] | success | tells whether the transfer was successful (true) or not (false) |
Implements distortos::devices::SpiMasterBase.
◆ unlock()
void distortos::devices::SpiMaster::unlock |
( |
| ) |
|
|
private |
Unlocks SPI master which was previously locked by current thread.
- Note
- Locks are recursive.
- Warning
- This function must not be called from interrupt context!
- Precondition
- This function is called by the thread that locked the device.
◆ mutex_
Mutex distortos::devices::SpiMaster::mutex_ |
|
private |
mutex used to serialize access to this object
◆ openCount_
uint8_t distortos::devices::SpiMaster::openCount_ |
|
private |
number of times this device was opened but not yet closed
◆ semaphore_
Semaphore* volatile distortos::devices::SpiMaster::semaphore_ |
|
private |
pointer to semaphore used to notify waiting thread about completion of transaction
◆ spiMaster_
◆ success_
volatile bool distortos::devices::SpiMaster::success_ |
|
private |
tells whether the transaction was successful (true) or not (false)
◆ transfersRange_
range of transfers that are part of currently handled transaction
The documentation for this class was generated from the following files: