Intel® Quark™ Microcontroller Software Interface 1.4.0 Intel® Quark™ Microcontroller BSP

- Main Page
- Modules
- Data Structures
- Files

Data Structures | Enumerations | Functions
SS SPI

SPI peripheral driver for Sensor Subsystem. More...

## Data Structures
struct | qm_ss_spi_config_t
| SPI configuration type. More...
struct | qm_ss_spi_async_transfer_t
| SPI asynchronous transfer type. More...
struct | qm_ss_spi_transfer_t
| SPI synchronous transfer type. More...

## Enumerations
enum | qm_ss_spi_frame_size_t { QM_SS_SPI_FRAME_SIZE_4_BIT = 3, QM_SS_SPI_FRAME_SIZE_5_BIT, QM_SS_SPI_FRAME_SIZE_6_BIT, QM_SS_SPI_FRAME_SIZE_7_BIT, QM_SS_SPI_FRAME_SIZE_8_BIT, QM_SS_SPI_FRAME_SIZE_9_BIT, QM_SS_SPI_FRAME_SIZE_10_BIT, QM_SS_SPI_FRAME_SIZE_11_BIT, QM_SS_SPI_FRAME_SIZE_12_BIT, QM_SS_SPI_FRAME_SIZE_13_BIT, QM_SS_SPI_FRAME_SIZE_14_BIT, QM_SS_SPI_FRAME_SIZE_15_BIT, QM_SS_SPI_FRAME_SIZE_16_BIT, QM_SS_SPI_FRAME_SIZE_17_BIT, QM_SS_SPI_FRAME_SIZE_18_BIT, QM_SS_SPI_FRAME_SIZE_19_BIT, QM_SS_SPI_FRAME_SIZE_20_BIT, QM_SS_SPI_FRAME_SIZE_21_BIT, QM_SS_SPI_FRAME_SIZE_22_BIT, QM_SS_SPI_FRAME_SIZE_23_BIT, QM_SS_SPI_FRAME_SIZE_24_BIT, QM_SS_SPI_FRAME_SIZE_25_BIT, QM_SS_SPI_FRAME_SIZE_26_BIT, QM_SS_SPI_FRAME_SIZE_27_BIT, QM_SS_SPI_FRAME_SIZE_28_BIT, QM_SS_SPI_FRAME_SIZE_29_BIT, QM_SS_SPI_FRAME_SIZE_30_BIT, QM_SS_SPI_FRAME_SIZE_31_BIT, QM_SS_SPI_FRAME_SIZE_32_BIT }
| QM Sensor SPI frame size type. More...
enum | qm_ss_spi_tmode_t { QM_SS_SPI_TMOD_TX_RX, QM_SS_SPI_TMOD_TX, QM_SS_SPI_TMOD_RX, QM_SS_SPI_TMOD_EEPROM_READ }
| SPI transfer mode type. More...
enum | qm_ss_spi_bmode_t { QM_SS_SPI_BMODE_0 = 0, QM_SS_SPI_BMODE_1, QM_SS_SPI_BMODE_2, QM_SS_SPI_BMODE_3 }
| SPI Bus Mode Type. More...
enum | qm_ss_spi_slave_select_t { QM_SS_SPI_SS_DISABLED = 0, QM_SS_SPI_SS_0 = BIT(0), QM_SS_SPI_SS_1 = BIT(1), QM_SS_SPI_SS_2 = BIT(2), QM_SS_SPI_SS_3 = BIT(3) }
| SPI Slave select type. More...
enum | qm_ss_spi_status_t { QM_SS_SPI_IDLE, QM_SS_SPI_BUSY, QM_SS_SPI_RX_OVERFLOW, QM_SS_SPI_TX_OVERFLOW, QM_SS_SPI_RX_UNDERFLOW }
| SPI status. More...

## Functions
int | qm_ss_spi_set_config (const qm_ss_spi_t spi, const qm_ss_spi_config_t *const cfg)
| Set SPI configuration. More...
int | qm_ss_spi_slave_select (const qm_ss_spi_t spi, const qm_ss_spi_slave_select_t ss)
| Set Slave Select lines. More...
int | qm_ss_spi_get_status (const qm_ss_spi_t spi, qm_ss_spi_status_t *const status)
| Get SPI bus status. More...
int | qm_ss_spi_transfer (const qm_ss_spi_t spi, const qm_ss_spi_transfer_t *const xfer, qm_ss_spi_status_t *const status)
| Perform a blocking SPI transfer. More...
int | qm_ss_spi_irq_transfer (const qm_ss_spi_t spi, const qm_ss_spi_async_transfer_t *const xfer)
| Initiate an interrupt based SPI transfer. More...
int | qm_ss_spi_irq_transfer_terminate (const qm_ss_spi_t spi)
| Terminate SPI IRQ transfer. More...
int | qm_ss_spi_save_context (const qm_ss_spi_t spi, qm_ss_spi_context_t *const ctx)
| Save SS SPI context. More...
int | qm_ss_spi_restore_context (const qm_ss_spi_t spi, const qm_ss_spi_context_t *const ctx)
| Restore SS SPI context. More...

## Detailed Description

SPI peripheral driver for Sensor Subsystem.

## Enumeration Type Documentation

enum qm_ss_spi_bmode_t

SPI Bus Mode Type.

Enumerator
QM_SS_SPI_BMODE_0 | Clock Polarity = 0, Clock Phase = 0.
QM_SS_SPI_BMODE_1 | Clock Polarity = 0, Clock Phase = 1.
QM_SS_SPI_BMODE_2 | Clock Polarity = 1, Clock Phase = 0.
QM_SS_SPI_BMODE_3 | Clock Polarity = 1, Clock Phase = 1.

Definition at line 95 of file qm_ss_spi.h.

enum qm_ss_spi_frame_size_t

QM Sensor SPI frame size type.

Enumerator
QM_SS_SPI_FRAME_SIZE_4_BIT | 4 bit frame.
QM_SS_SPI_FRAME_SIZE_5_BIT | 5 bit frame.
QM_SS_SPI_FRAME_SIZE_6_BIT | 6 bit frame.
QM_SS_SPI_FRAME_SIZE_7_BIT | 7 bit frame.
QM_SS_SPI_FRAME_SIZE_8_BIT | 8 bit frame.
QM_SS_SPI_FRAME_SIZE_9_BIT | 9 bit frame.
QM_SS_SPI_FRAME_SIZE_10_BIT | 10 bit frame.
QM_SS_SPI_FRAME_SIZE_11_BIT | 11 bit frame.
QM_SS_SPI_FRAME_SIZE_12_BIT | 12 bit frame.
QM_SS_SPI_FRAME_SIZE_13_BIT | 13 bit frame.
QM_SS_SPI_FRAME_SIZE_14_BIT | 14 bit frame.
QM_SS_SPI_FRAME_SIZE_15_BIT | 15 bit frame.
QM_SS_SPI_FRAME_SIZE_16_BIT | 16 bit frame.
QM_SS_SPI_FRAME_SIZE_17_BIT | 17 bit frame.
QM_SS_SPI_FRAME_SIZE_18_BIT | 18 bit frame.
QM_SS_SPI_FRAME_SIZE_19_BIT | 19 bit frame.
QM_SS_SPI_FRAME_SIZE_20_BIT | 20 bit frame.
QM_SS_SPI_FRAME_SIZE_21_BIT | 21 bit frame.
QM_SS_SPI_FRAME_SIZE_22_BIT | 22 bit frame.
QM_SS_SPI_FRAME_SIZE_23_BIT | 23 bit frame.
QM_SS_SPI_FRAME_SIZE_24_BIT | 24 bit frame.
QM_SS_SPI_FRAME_SIZE_25_BIT | 25 bit frame.
QM_SS_SPI_FRAME_SIZE_26_BIT | 26 bit frame.
QM_SS_SPI_FRAME_SIZE_27_BIT | 27 bit frame.
QM_SS_SPI_FRAME_SIZE_28_BIT | 28 bit frame.
QM_SS_SPI_FRAME_SIZE_29_BIT | 29 bit frame.
QM_SS_SPI_FRAME_SIZE_30_BIT | 30 bit frame.
QM_SS_SPI_FRAME_SIZE_31_BIT | 31 bit frame.
QM_SS_SPI_FRAME_SIZE_32_BIT | 32 bit frame.

Definition at line 20 of file qm_ss_spi.h.

enum qm_ss_spi_slave_select_t

SPI Slave select type.

Slave selects can be combined by logical OR.

Enumerator
QM_SS_SPI_SS_DISABLED | Slave select disable.
QM_SS_SPI_SS_0 | Slave select 0.
QM_SS_SPI_SS_1 | Slave select 1.
QM_SS_SPI_SS_2 | Slave select 2.
QM_SS_SPI_SS_3 | Slave select 3.

Definition at line 107 of file qm_ss_spi.h.

enum qm_ss_spi_status_t

SPI status.

Enumerator
QM_SS_SPI_IDLE | SPI device is not in use.
QM_SS_SPI_BUSY | SPI device is busy.
QM_SS_SPI_RX_OVERFLOW | RX transfer has overflown.
QM_SS_SPI_TX_OVERFLOW | TX transfer has overflown.
QM_SS_SPI_RX_UNDERFLOW | RX transfer has underflown.

Definition at line 118 of file qm_ss_spi.h.

enum qm_ss_spi_tmode_t

SPI transfer mode type.

Enumerator
QM_SS_SPI_TMOD_TX_RX | Transmit & Receive mode. This mode synchronously receives and transmits data during the transfer. rx_len and tx_len buffer need to be the same length.
QM_SS_SPI_TMOD_TX | Transmit-Only mode. This mode only transmits data. The rx buffer is not accessed and rx_len need to be set to 0.
QM_SS_SPI_TMOD_RX | Receive-Only mode. This mode only receives data. The tx buffer is not accessed and tx_len need to be set to 0.
QM_SS_SPI_TMOD_EEPROM_READ | EEPROM-Read Mode. This mode transmits the data stored in the tx buffer (EEPROM address). After the transmit is completed it populates the rx buffer (EEPROM data) with received data.

Definition at line 57 of file qm_ss_spi.h.

## Function Documentation

int qm_ss_spi_get_status | ( | const qm_ss_spi_t | spi,
|  | qm_ss_spi_status_t *const | status
| ) |  |

Get SPI bus status.

Parameters

  [in] | spi | SPI module identifier.
  [out] | status | Reference to the variable where to store the current SPI bus status (QM_SS_SPI_BUSY if a transfer is in progress or QM_SS_SPI_IDLE if SPI device is IDLE). This must not be NULL.

Returns
  Standard errno return type for QMSI.

Return values

  0 | on success.
  Negative | errno for possible error codes.

Definition at line 111 of file qm_ss_spi.c.

References QM_SS_SPI_BUSY, QM_SS_SPI_IDLE, and QM_SS_SPI_SR.

int qm_ss_spi_irq_transfer | ( | const qm_ss_spi_t | spi,
|  | const qm_ss_spi_async_transfer_t *const | xfer
| ) |  |

Initiate an interrupt based SPI transfer.

Perform an interrupt based SPI transfer. If transfer mode is full duplex (QM_SS_SPI_TMOD_TX_RX), then tx_len and rx_len must be equal. Similarly, for transmit-only transfers (QM_SS_SPI_TMOD_TX) rx_len must be 0, while for receive-only transfers (QM_SS_SPI_TMOD_RX) tx_len must be 0. This function is non blocking.

Parameters

  [in] | spi | SPI module identifier.
  [in] | xfer | Structure containing transfer information. The structure must not be NULL and must be kept valid until the transfer is complete.

Returns
  Standard errno return type for QMSI.

Return values

  0 | on success.
  Negative | errno for possible error codes.

Definition at line 206 of file qm_ss_spi.c.

References QM_SS_SPI_SPIEN, QM_SS_SPI_TMOD_EEPROM_READ, QM_SS_SPI_TMOD_RX, QM_SS_SPI_TMOD_TX_RX, qm_ss_spi_async_transfer_t::rx_len, and qm_ss_spi_async_transfer_t::tx_len.

int qm_ss_spi_irq_transfer_terminate | ( | const qm_ss_spi_t | spi | ) |

Terminate SPI IRQ transfer.

Terminate the current IRQ SPI transfer. This function will trigger complete callbacks even if the transfer is not completed.

Parameters

  [in] | spi | SPI module identifier.

Returns
  Standard errno return type for QMSI.

Return values

  0 | on success.
  Negative | errno for possible error codes.

Definition at line 257 of file qm_ss_spi.c.

References qm_ss_spi_async_transfer_t::callback, qm_ss_spi_async_transfer_t::callback_data, QM_SS_SPI_IDLE, QM_SS_SPI_TMOD_TX, QM_SS_SPI_TMOD_TX_RX, qm_ss_spi_async_transfer_t::rx_len, and qm_ss_spi_async_transfer_t::tx_len.

int qm_ss_spi_restore_context | ( | const qm_ss_spi_t | spi,
|  | const qm_ss_spi_context_t *const | ctx
| ) |  |

Restore SS SPI context.

Restore the configuration of the specified SS SPI peripheral after exiting sleep.

Parameters

  [in] | spi | SPI controller identifier.
  [in] | ctx | SPI context structure. This must not be NULL.

Returns
  Standard errno return type for QMSI.

Return values

  0 | on success.
  Negative | errno for possible error codes.

Definition at line 478 of file qm_ss_spi.c.

References QM_SS_SPI_CTRL, QM_SS_SPI_SPIEN, QM_SS_SPI_TIMING, qm_ss_spi_context_t::spi_ctrl, qm_ss_spi_context_t::spi_spien, and qm_ss_spi_context_t::spi_timing.

int qm_ss_spi_save_context | ( | const qm_ss_spi_t | spi,
|  | qm_ss_spi_context_t *const | ctx
| ) |  |

Save SS SPI context.

Saves the configuration of the specified SS SPI peripheral before entering sleep.

Parameters

  [in] | spi | SPI controller identifier.
  [out] | ctx | SPI context structure. This must not be NULL.

Returns
  Standard errno return type for QMSI.

Return values

  0 | on success.
  Negative | errno for possible error codes.

Definition at line 469 of file qm_ss_spi.c.

References QM_SS_SPI_CTRL, QM_SS_SPI_SPIEN, QM_SS_SPI_TIMING, qm_ss_spi_context_t::spi_ctrl, qm_ss_spi_context_t::spi_spien, and qm_ss_spi_context_t::spi_timing.

int qm_ss_spi_set_config | ( | const qm_ss_spi_t | spi,
|  | const qm_ss_spi_config_t *const | cfg
| ) |  |

Set SPI configuration.

Change the configuration of a SPI module. This includes transfer mode, bus mode, clock divider and data frame size.

This operation is permitted only when the SPI module is disabled.

Parameters

  [in] | spi | SPI module identifier.
  [in] | cfg | New configuration for SPI. This must not be NULL.

Returns
  Standard errno return type for QMSI.

Return values

  0 | on success.
  Negative | errno for possible error codes.

Definition at line 65 of file qm_ss_spi.c.

References qm_ss_spi_config_t::bus_mode, qm_ss_spi_config_t::clk_divider, qm_ss_spi_config_t::frame_size, QM_SS_SPI_SPIEN, and qm_ss_spi_config_t::transfer_mode.

int qm_ss_spi_slave_select | ( | const qm_ss_spi_t | spi,
|  | const qm_ss_spi_slave_select_t | ss
| ) |  |

Set Slave Select lines.

Select which slaves to perform SPI transmissions on. Select lines can be combined using the | operator. It is only suggested to use this functionality in TX only mode. This operation is permitted only when a SPI transfer is not already in progress; the caller should check that by retrieving the device status.

Parameters

  [in] | spi | SPI module identifier.
  [in] | ss | Select lines to enable when performing transfers.

Returns
  Standard errno return type for QMSI.

Return values

  0 | on success.
  Negative | errno for possible error codes.

Definition at line 96 of file qm_ss_spi.c.

References QM_SS_SPI_SR.

int qm_ss_spi_transfer | ( | const qm_ss_spi_t | spi,
|  | const qm_ss_spi_transfer_t *const | xfer,
|  | qm_ss_spi_status_t *const | status
| ) |  |

Perform a blocking SPI transfer.

This is a blocking synchronous call. If transfer mode is full duplex (QM_SS_SPI_TMOD_TX_RX) tx_len and rx_len must be equal. Similarly, for transmit-only transfers (QM_SS_SPI_TMOD_TX) rx_len must be 0, while for receive-only transfers (QM_SS_SPI_TMOD_RX) tx_len must be 0.

Parameters

  [in] | spi | SPI module identifier.
  [in] | xfer | Structure containing transfer information. This must not be NULL.
  [out] | status | Reference to the variable where to store the SPI status at the end of the transfer.

Returns
  Standard errno return type for QMSI.

Return values

  0 | on success.
  Negative | errno for possible error codes.

Definition at line 126 of file qm_ss_spi.c.

References QM_SS_SPI_RX_OVERFLOW, QM_SS_SPI_SPIEN, QM_SS_SPI_SR, QM_SS_SPI_TMOD_EEPROM_READ, QM_SS_SPI_TMOD_RX, QM_SS_SPI_TMOD_TX, QM_SS_SPI_TMOD_TX_RX, qm_ss_spi_transfer_t::rx, qm_ss_spi_transfer_t::rx_len, qm_ss_spi_transfer_t::tx, and qm_ss_spi_transfer_t::tx_len.