34#ifndef _FREERTOS_DRIVERS_TI_CC32XXSPI_HXX_
35#define _FREERTOS_DRIVERS_TI_CC32XXSPI_HXX_
45#include "inc/hw_mcspi.h"
46#include "inc/hw_types.h"
47#include "driverlib/udma.h"
49#include <ti/drivers/dma/UDMACC32XX.h>
71 CC32xxSPI(
const char *
name,
unsigned long base, uint32_t interrupt,
74 size_t dma_threshold = DEFAULT_DMA_THRESHOLD_BYTES,
75 uint32_t dma_channel_index_tx = UDMA_CH7_GSPI_TX,
76 uint32_t dma_channel_index_rx = UDMA_CH6_GSPI_RX);
101 static constexpr size_t DEFAULT_DMA_THRESHOLD_BYTES = 64;
113 UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 | UDMA_ARB_1,
114 UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1,
115 UDMA_SIZE_32 | UDMA_SRC_INC_NONE | UDMA_DST_INC_32 | UDMA_ARB_1
125 UDMA_SIZE_8 | UDMA_SRC_INC_8 | UDMA_DST_INC_NONE | UDMA_ARB_1,
126 UDMA_SIZE_16 | UDMA_SRC_INC_16 | UDMA_DST_INC_NONE | UDMA_ARB_1,
127 UDMA_SIZE_32 | UDMA_SRC_INC_32 | UDMA_DST_INC_NONE | UDMA_ARB_1
137 UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_NONE | UDMA_ARB_1,
138 UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_NONE | UDMA_ARB_1,
139 UDMA_SIZE_32 | UDMA_SRC_INC_NONE | UDMA_DST_INC_NONE | UDMA_ARB_1
164 __attribute__((optimize(
"-O3")))
165 int
transfer(struct spi_ioc_transfer *msg)
override
185 __attribute__((optimize(
"-O3")))
193 data_put(msg->tx_buf ? *((T*)msg->tx_buf) : 0xFFFFFFFF);
195 T *tx_buf = msg->tx_buf ? ((T*)msg->tx_buf) + 1 : &dummy;
196 T *rx_buf = (T*)msg->rx_buf;
201 uint32_t rx_len = msg->len /
sizeof(T);
202 uint32_t tx_len = rx_len - 1;
209 if (tx_len && ((rx_len - tx_len) < (32 /
sizeof(T))))
234 while (tx_len || rx_len);
242 __attribute__((optimize(
"-O3")))
252 return transfer_polled<uint8_t>(msg);
254 return transfer_polled<uint16_t>(msg);
256 return transfer_polled<uint32_t>(msg);
263 void config_dma(
struct spi_ioc_transfer *msg);
270 __attribute__((optimize(
"-O3")))
273 if(HWREG(
base_ + MCSPI_O_CH0STAT) & MCSPI_CH0STAT_RXS)
275 *data = HWREG(
base_ + MCSPI_O_RX0);
287 __attribute__((optimize(
"-O3")))
290 if(HWREG(
base_ + MCSPI_O_CH0STAT) & MCSPI_CH0STAT_TXS)
292 HWREG(
base_ + MCSPI_O_TX0) = data;
306 while(UNLIKELY(!(HWREG(
base_ + MCSPI_O_CH0STAT)&MCSPI_CH0STAT_TXS)));
308 HWREG(
base_ + MCSPI_O_TX0) = data;
Lightweight locking class for protecting small critical sections.
Specialization of Serial SPI driver for CC32xx devices.
int transfer(struct spi_ioc_transfer *msg) override
Method to transmit/receive the data.
long data_get_non_blocking(unsigned long *data)
Receives a word from the specified port.
static constexpr uint32_t dmaRxConfig_[]
This lookup table is used to configure the DMA channels for the appropriate (8bit,...
int transfer_polled(struct spi_ioc_transfer *msg)
Method to transmit/receive the data.
static constexpr uint32_t dmaTxConfig_[]
This lookup table is used to configure the DMA channels for the appropriate (8bit,...
static constexpr uint32_t dmaNullConfig_[]
This lookup table is used to configure the DMA channels for the appropriate (8bit,...
unsigned long clock_
clock rate supplied to the module
uint32_t dmaChannelIndexRx_
RX DMA channel index.
CC32xxSPI()
Default constructor.
void data_put(unsigned long data)
Waits until the word is transmitted on the specified port.
void set_configuration()
Set the instance local configuration.
long data_put_non_blocking(unsigned long data)
Transmits a word on the specified port.
void disable() override
Function to disable device.
size_t dmaThreshold_
threshold in bytes to start using DMA
uint32_t spiChctrl_
instance local copy of configuration
static constexpr size_t MAX_DMA_TRANSFER_AMOUNT
Maximum number of bytes transferred in a single DMA transaction.
uint32_t dmaChannelIndexTx_
TX DMA channel index.
OSMutex * get_lock()
This method provides a reference to the Mutex used by this device driver.
UDMACC32XX_Handle dmaHandle_
handle to DMA reference
void interrupt_handler()
handle an interrupt.
OSSem * sem_
reference to the semaphore belonging to this bus
uint32_t spiXferlevel_
instance local copy of configuration
uint32_t spiChconf_
instance local copy of configuration
unsigned long interrupt_
interrupt of this device
void config_dma(struct spi_ioc_transfer *msg)
Configure a DMA transaction.
int update_configuration() override
Update the configuration of the bus.
void enable() override
Function to enable device.
unsigned long base_
base address of this device
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.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.