34#ifndef _FREERTOS_DRIVERS_TI_TIVASPI_HXX_
35#define _FREERTOS_DRIVERS_TI_TIVASPI_HXX_
39#include "driverlib/ssi.h"
40#include "inc/hw_ssi.h"
41#include "inc/hw_types.h"
42#include "driverlib/udma.h"
62 TivaSPI(
const char *
name,
unsigned long base, uint32_t interrupt,
66 uint32_t dma_channel_index_tx = UDMA_CH11_SSI0TX,
67 uint32_t dma_channel_index_rx = UDMA_CH10_SSI0RX);
101 UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 | UDMA_ARB_1,
102 UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1,
112 UDMA_SIZE_8 | UDMA_SRC_INC_8 | UDMA_DST_INC_NONE | UDMA_ARB_1,
113 UDMA_SIZE_16 | UDMA_SRC_INC_16 | UDMA_DST_INC_NONE | UDMA_ARB_1,
123 UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_NONE | UDMA_ARB_1,
124 UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_NONE | UDMA_ARB_1,
143 __attribute__((optimize(
"-O3")))
144 int
transfer(struct spi_ioc_transfer *msg)
override
168 __attribute__((optimize(
"-O3")))
176 data_put(msg->tx_buf ? *((T*)msg->tx_buf) : 0xFFFFFFFF);
178 T *tx_buf = msg->tx_buf ? ((T*)msg->tx_buf) + 1 : &dummy;
179 T *rx_buf = (T*)msg->rx_buf;
184 uint32_t rx_len = msg->len /
sizeof(T);
185 uint32_t tx_len = rx_len - 1;
192 if (tx_len && ((rx_len - tx_len) < 8))
217 while (tx_len || rx_len);
225 __attribute__((optimize(
"-O3")))
235 return transfer_polled<uint8_t>(msg);
237 return transfer_polled<uint16_t>(msg);
239 DIE(
"32-bit transers are not supported on this MCU.");
246 void config_dma(
struct spi_ioc_transfer *msg);
253 __attribute__((optimize(
"-O3")))
256 if(HWREG(
base_ + SSI_O_SR) & SSI_SR_RNE)
258 *data = HWREG(
base_ + SSI_O_DR);
270 __attribute__((optimize(
"-O3")))
273 if(HWREG(
base_ + SSI_O_SR) & SSI_SR_TNF)
275 HWREG(
base_ + SSI_O_DR) = data;
289 while((HWREG(
base_ + SSI_O_SR) & SSI_SR_TNF) == 0);
290 HWREG(
base_ + SSI_O_DR) = data;
298 HWREG(
base_ + SSI_O_CR1) &= ~SSI_CR1_SSE;
const char * name
device name
OSMutex lock_
protects internal structures.
This class provides a mutex API.
This class provides a counting semaphore API.
Private data for an SPI device.
void bus_lock()
Lock the bus shared by many chip selects.
uint8_t bitsPerWord
number of bits per word transaction
void(* ChipSelectMethod)()
Function point for the chip select assert and deassert methods.
OSSem * sem_
reference to the semaphore belonging to this bus
void disable() override
Function to disable device.
long data_put_non_blocking(uint16_t data)
Transmits a word on the specified port.
static constexpr uint32_t dmaTxConfig_[]
This lookup table is used to configure the DMA channels for the appropriate (8bit or 16bit) transfer ...
OSMutex * get_lock()
This method provides a reference to the Mutex used by this device driver.
static constexpr size_t DEFAULT_DMA_THRESHOLD_BYTES
Transfers longer than this will be with dma by default.
uint32_t dmaChannelIndexRx_
RX DMA channel index.
uint16_t spiCr1_
Configuration register 1 local copy.
uint32_t dmaChannelIndexTx_
TX DMA channel index.
unsigned long base_
base address of this device
uint16_t spiPrescaler_
Prescale register local copy.
int update_configuration() override
Update the configuration of the bus.
size_t dmaThreshold_
threshold in bytes to start using DMA
void interrupt_handler()
Call this from the SPI device's interrupt handler.
int transfer(struct spi_ioc_transfer *msg) override
Method to transmit/receive the data.
static constexpr uint32_t dmaNullConfig_[]
This lookup table is used to configure the DMA channels for the appropriate (8bit or 16bit) transfer ...
void data_put(uint16_t data)
Waits until the word is transmitted on the specified port.
void enable() override
Function to enable device.
long data_get_non_blocking(uint16_t *data)
Receives a word from the specified port.
void config_dma(struct spi_ioc_transfer *msg)
Configure a DMA transaction.
static constexpr uint32_t dmaRxConfig_[]
This lookup table is used to configure the DMA channels for the appropriate (8bit or 16bit) transfer ...
static constexpr size_t MAX_DMA_TRANSFER_AMOUNT
Maximum number of bytes transferred in a single DMA transaction.
unsigned long interrupt_
interrupt of this device
uint16_t spiCr0_
Configuration register 0 local copy.
void set_configuration()
Set the instance local configuration.
int transfer_polled(struct spi_ioc_transfer *msg)
Method to transmit/receive the data.
#define DIE(MSG)
Unconditionally terminates the current process with a message.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.