ChibiOS/RT Logo ChibiOS/RT

Architecture - Reference Manual - Guides

Modules | Defines | Enumerations | Functions

SPI Driver
[HAL]

Generic SPI Driver. More...

Collaboration diagram for SPI Driver:


Description

Generic SPI Driver.

This module implements a generic SPI driver. The driver implements a state machine internally:

inline_dotgraph_15.dot

The driver is not thread safe for performance reasons, if you need to access the SPI bus from multiple thread then use the spiAcquireBus() and spiReleaseBus() APIs in order to gain exclusive access.

Modules

 SPI Low Level Driver
 

SPI Driver low level driver template.


Defines

#define SPI_USE_MUTUAL_EXCLUSION   TRUE
 Enables the mutual exclusion APIs on the SPI bus.

Enumerations

enum  spistate_t { SPI_UNINIT = 0, SPI_STOP = 1, SPI_READY = 2, SPI_ACTIVE = 3 }
 

Driver state machine possible states.

More...

Functions

void spiInit (void)
 SPI Driver initialization.
void spiObjectInit (SPIDriver *spip)
 Initializes the standard part of a SPIDriver structure.
void spiStart (SPIDriver *spip, const SPIConfig *config)
 Configures and activates the SPI peripheral.
void spiStop (SPIDriver *spip)
 Deactivates the SPI peripheral.
void spiSelect (SPIDriver *spip)
 Asserts the slave select signal and prepares for transfers.
void spiUnselect (SPIDriver *spip)
 Deasserts the slave select signal.
void spiIgnore (SPIDriver *spip, size_t n)
 Ignores data on the SPI bus.
void spiExchange (SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf)
 Exchanges data on the SPI bus.
void spiSend (SPIDriver *spip, size_t n, const void *txbuf)
 Sends data over the SPI bus.
void spiReceive (SPIDriver *spip, size_t n, void *rxbuf)
 Receives data from the SPI bus.
void spiAcquireBus (SPIDriver *spip)
 Gains exclusive access to the SPI bus.
void spiReleaseBus (SPIDriver *spip)
 Releases exclusive access to the SPI bus.

Define Documentation

#define SPI_USE_MUTUAL_EXCLUSION   TRUE

Enables the mutual exclusion APIs on the SPI bus.

Definition at line 52 of file spi.h.


Enumeration Type Documentation

enum spistate_t

Driver state machine possible states.

Enumerator:
SPI_UNINIT 

Not initialized.

SPI_STOP 

Stopped.

SPI_READY 

Ready.

SPI_ACTIVE 

Slave selected.

Definition at line 70 of file spi.h.


Function Documentation

void spiInit ( void   ) 

SPI Driver initialization.

Definition at line 59 of file spi.c.

References spi_lld_init().

Referenced by halInit().

Here is the call graph for this function:

void spiObjectInit ( SPIDriver spip  ) 

Initializes the standard part of a SPIDriver structure.

Parameters:
[in] spip pointer to the SPIDriver object

Definition at line 69 of file spi.c.

References chMtxInit(), chSemInit(), SPIDriver::spd_config, SPIDriver::spd_mutex, and SPIDriver::spd_state.

Here is the call graph for this function:

void spiStart ( SPIDriver spip,
const SPIConfig config 
)

Configures and activates the SPI peripheral.

Parameters:
[in] spip pointer to the SPIDriver object
[in] config pointer to the SPIConfig object

Definition at line 88 of file spi.c.

References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, SPIDriver::spd_config, SPIDriver::spd_state, spi_lld_start(), SPI_READY, and SPI_STOP.

Referenced by mmcConnect(), mmcStartSequentialRead(), and mmcStartSequentialWrite().

Here is the call graph for this function:

void spiStop ( SPIDriver spip  ) 

Deactivates the SPI peripheral.

Parameters:
[in] spip pointer to the SPIDriver object

Definition at line 107 of file spi.c.

References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, SPIDriver::spd_state, spi_lld_stop(), SPI_READY, and SPI_STOP.

Referenced by mmcDisconnect(), and mmcStop().

Here is the call graph for this function:

void spiSelect ( SPIDriver spip  ) 

Asserts the slave select signal and prepares for transfers.

Parameters:
[in] spip pointer to the SPIDriver object

Definition at line 125 of file spi.c.

References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, SPIDriver::spd_state, SPI_ACTIVE, spi_lld_select(), and SPI_READY.

Referenced by mmcStartSequentialRead(), and mmcStartSequentialWrite().

Here is the call graph for this function:

void spiUnselect ( SPIDriver spip  ) 

Deasserts the slave select signal.

The previously selected peripheral is unselected.

Parameters:
[in] spip pointer to the SPIDriver object

Definition at line 145 of file spi.c.

References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, SPIDriver::spd_state, SPI_ACTIVE, spi_lld_unselect(), and SPI_READY.

Referenced by mmcSequentialRead(), mmcSequentialWrite(), mmcStartSequentialRead(), mmcStartSequentialWrite(), mmcStopSequentialRead(), and mmcStopSequentialWrite().

Here is the call graph for this function:

void spiIgnore ( SPIDriver spip,
size_t  n 
)

Ignores data on the SPI bus.

This function transmits a series of idle words on the SPI bus and ignores the received data. This function can be invoked even when a slave select signal has not been yet asserted.

Parameters:
[in] spip pointer to the SPIDriver object
[in] n number of words to be ignored

Definition at line 168 of file spi.c.

References chDbgAssert, chDbgCheck, SPIDriver::spd_state, SPI_ACTIVE, spi_lld_ignore(), and SPI_READY.

Referenced by mmcConnect(), mmcSequentialRead(), and mmcSequentialWrite().

Here is the call graph for this function:

void spiExchange ( SPIDriver spip,
size_t  n,
const void *  txbuf,
void *  rxbuf 
)

Exchanges data on the SPI bus.

This function performs a simultaneous transmit/receive operation.

Note:
The buffers are organized as uint8_t arrays for data sizes below or equal to 8 bits else it is organized as uint16_t arrays.
Parameters:
[in] spip pointer to the SPIDriver object
[in] n number of words to be exchanged
[in] txbuf the pointer to the transmit buffer
[out] rxbuf the pointer to the receive buffer

Definition at line 189 of file spi.c.

References chDbgAssert, chDbgCheck, SPIDriver::spd_state, SPI_ACTIVE, and spi_lld_exchange().

Here is the call graph for this function:

void spiSend ( SPIDriver spip,
size_t  n,
const void *  txbuf 
)

Sends data over the SPI bus.

Note:
The buffers are organized as uint8_t arrays for data sizes below or equal to 8 bits else it is organized as uint16_t arrays.
Parameters:
[in] spip pointer to the SPIDriver object
[in] n number of words to send
[in] txbuf the pointer to the transmit buffer

Definition at line 209 of file spi.c.

References chDbgAssert, chDbgCheck, SPIDriver::spd_state, SPI_ACTIVE, and spi_lld_send().

Referenced by mmcSequentialWrite(), mmcStopSequentialRead(), and mmcStopSequentialWrite().

Here is the call graph for this function:

void spiReceive ( SPIDriver spip,
size_t  n,
void *  rxbuf 
)

Receives data from the SPI bus.

Note:
The buffers are organized as uint8_t arrays for data sizes below or equal to 8 bits else it is organized as uint16_t arrays.
Parameters:
[in] spip pointer to the SPIDriver object
[in] n number of words to receive
[out] rxbuf the pointer to the receive buffer

Definition at line 229 of file spi.c.

References chDbgAssert, chDbgCheck, SPIDriver::spd_state, SPI_ACTIVE, and spi_lld_receive().

Referenced by mmcSequentialRead(), and mmcSequentialWrite().

Here is the call graph for this function:

void spiAcquireBus ( SPIDriver spip  ) 

Gains exclusive access to the SPI bus.

This function tries to gain ownership to the SPI bus, if the bus is already being used then the invoking thread is queued.

Note:
This function is only available when the SPI_USE_MUTUAL_EXCLUSION option is set to TRUE.
Parameters:
[in] spip pointer to the SPIDriver object

Definition at line 251 of file spi.c.

References chDbgCheck, chMtxLock(), chSemWait(), and SPIDriver::spd_mutex.

Here is the call graph for this function:

void spiReleaseBus ( SPIDriver spip  ) 

Releases exclusive access to the SPI bus.

Note:
This function is only available when the SPI_USE_MUTUAL_EXCLUSION option is set to TRUE.
Parameters:
[in] spip pointer to the SPIDriver object

Definition at line 269 of file spi.c.

References chDbgCheck, chMtxUnlock(), and chSemSignal().

Here is the call graph for this function:


Generated on Sun Oct 24 2010 09:40:47 for ChibiOS/RT by doxygen 1.7.1