![]() |
![]() |
TI-RTOS Drivers
tidrivers_full_2_20_01_10
|
SPI driver implementation for a TivaSPIcontroller using the micro DMA controller.
============================================================================
The SPI header file should be included in an application as follows:
Refer to SPI.h for a complete description of APIs & example of use.
This SPI driver implementation is designed to operate on a Tiva SPI controller using a micro DMA controller.
This SPI controller supports a hardware chip select pin. Refer to the device's user manual on how this hardware chip select pin behaves in regards to the SPI frame format.
Chip select type | SPI_MASTER mode | SPI_SLAVE mode |
---|---|---|
Hardware chip select | No action is needed by the application to select the peripheral. | See the device documentation on it's chip select requirements. |
Software chip select | The application is responsible to ensure that correct SPI slave is selected before performing a SPI_transfer(). | See the device documentation on it's chip select requirements. |
This driver is designed to operation on a micro DMA. The micro DMA generates IRQ on the perpheral's interrupt vector. This implementation automatically installs a DMA aware Hwi (interrupt) to service the assigned micro DMA channels.
A uint32_t scratch buffer is used to allow SPI_transfers where txBuf or rxBuf are NULL. Rather than requiring txBuf or rxBuf to have a dummy buffer of size of the transfer count, a single DMA accessible uint32_t scratch buffer is used. When rxBuf is NULL, the uDMA will transfer all the SPI data receives into the scratch buffer as a "bit-bucket". When rxBuf is NULL, the scratch buffer is initialized to defaultTxBufValue so the uDMA will send some known value. Each SPI driver instance should uses its own scratch buffer.
SPI data frames can be any size from 4-bits to 16-bits. If the dataSize in SPI_Params is greater that 8-bits, then the SPITivaDMA driver implementation will assume that the SPI_Transaction txBuf and rxBuf point to an array of 16-bit uint16_t elements.
dataSize | buffer element size |
---|---|
4-8 bits | uint8_t |
9-16 bits | uint16_t |
The Tiva micro DMA contoller only supports data transfers of upto 1024 data frames. A data frame can be 4 to 16 bits in length.
As this driver uses uDMA to transfer data/from data buffers, it is the responsibility of the application to ensure that theses buffers reside in memory that is accessible by the DMA.
For example, on Concerto devices local SRAM C0 and C1 are NOT accessible the DMA.
#include <stdint.h>
#include <ti/drivers/SPI.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
Go to the source code of this file.
Data Structures | |
struct | SPITivaDMA_HWAttrs |
SPITivaDMA Hardware attributes. More... | |
struct | SPITivaDMA_Object |
SPITivaDMA Object. More... | |
Macros | |
#define | ti_sysbios_family_arm_m3_Hwi__nolocalnames |
Typedefs | |
typedef unsigned long | SPIBaseAddrType |
typedef unsigned long | SPIDataType |
typedef enum SPITivaDMA_FrameSize | SPITivaDMA_FrameSize |
SPITivaDMA data frame size is used to determine how to configure the DMA data transfers. This field is to be only used internally. More... | |
typedef struct SPITivaDMA_HWAttrs | SPITivaDMA_HWAttrs |
SPITivaDMA Hardware attributes. More... | |
typedef struct SPITivaDMA_Object | SPITivaDMA_Object |
SPITivaDMA Object. More... | |
typedef struct SPITivaDMA_Object * | SPITivaDMA_Handle |
Enumerations | |
enum | SPITivaDMA_FrameSize { SPITivaDMA_8bit = 0, SPITivaDMA_16bit = 1 } |
SPITivaDMA data frame size is used to determine how to configure the DMA data transfers. This field is to be only used internally. More... | |
Variables | |
const SPI_FxnTable | SPITivaDMA_fxnTable |
#define ti_sysbios_family_arm_m3_Hwi__nolocalnames |
typedef unsigned long SPIBaseAddrType |
typedef unsigned long SPIDataType |
typedef enum SPITivaDMA_FrameSize SPITivaDMA_FrameSize |
SPITivaDMA data frame size is used to determine how to configure the DMA data transfers. This field is to be only used internally.
SPITivaDMA_8bit: txBuf and rxBuf are arrays of uint8_t elements SPITivaDMA_16bit: txBuf and rxBuf are arrays of uint16_t elements
typedef struct SPITivaDMA_HWAttrs SPITivaDMA_HWAttrs |
SPITivaDMA Hardware attributes.
These fields, with the exception of intPriority, are used by driverlib APIs and therefore must be populated by driverlib macro definitions. For TivaWare these definitions are found in:
intPriority is the SPI peripheral's interrupt priority, as defined by the underlying OS. It is passed unmodified to the underlying OS's interrupt handler creation code, so you need to refer to the OS documentation for usage. For example, for SYS/BIOS applications, refer to the ti.sysbios.family.arm.m3.Hwi documentation for SYS/BIOS usage of interrupt priorities. If the driver uses the ti.drivers.ports interface instead of making OS calls directly, then the HwiP port handles the interrupt priority in an OS specific way. In the case of the SYS/BIOS port, intPriority is passed unmodified to Hwi_create().
A sample structure is shown below:
typedef struct SPITivaDMA_Object SPITivaDMA_Object |
SPITivaDMA Object.
The application must not access any member variables of this structure!
typedef struct SPITivaDMA_Object * SPITivaDMA_Handle |
enum SPITivaDMA_FrameSize |
SPITivaDMA data frame size is used to determine how to configure the DMA data transfers. This field is to be only used internally.
SPITivaDMA_8bit: txBuf and rxBuf are arrays of uint8_t elements SPITivaDMA_16bit: txBuf and rxBuf are arrays of uint16_t elements
Enumerator | |
---|---|
SPITivaDMA_8bit | |
SPITivaDMA_16bit |
const SPI_FxnTable SPITivaDMA_fxnTable |