SPICC32XXDMA.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2018, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!*****************************************************************************
33  * @file SPICC32XXDMA.h
34  *
35  * @brief SPI driver implementation for a CC32XX SPI controller using the
36  * micro DMA controller.
37  *
38  * The SPI header file should be included in an application as follows:
39  * @code
40  * #include <ti/drivers/SPI.h>
41  * #include <ti/drivers/spi/SPICC32XXDMA.h>
42  * @endcode
43  *
44  * Refer to @ref SPI.h for a complete description of APIs & example of use.
45  *
46  * This SPI driver implementation is designed to operate on a CC32XX SPI
47  * controller using a micro DMA controller.
48  *
49  * @warning This driver does not support queueing multiple SPI transactions.
50  *
51  * ## Frame Formats #
52  * This SPI controller supports 4 phase & polarity formats. Refer to the device
53  * specific data sheets & technical reference manuals for specifics on each
54  * format.
55  *
56  * ## SPI Chip Select #
57  * This SPI controller supports a hardware chip select pin. Refer to the
58  * device's user manual on how this hardware chip select pin behaves in regards
59  * to the SPI frame format.
60  *
61  * <table>
62  * <tr>
63  * <th>Chip select type</th>
64  * <th>SPI_MASTER mode</th>
65  * <th>SPI_SLAVE mode</th>
66  * </tr>
67  * <tr>
68  * <td>Hardware chip select</td>
69  * <td>No action is needed by the application to select the peripheral.</td>
70  * <td>See the device documentation on it's chip select requirements.</td>
71  * </tr>
72  * <tr>
73  * <td>Software chip select</td>
74  * <td>The application is responsible to ensure that correct SPI slave is
75  * selected before performing a SPI_transfer().</td>
76  * <td>See the device documentation on it's chip select requirements.</td>
77  * </tr>
78  * </table>
79  *
80  * ## SPI data frames #
81  * SPI data frames can be any size from 4-bits to 32-bits. The SPI data
82  * frame size is set in ::SPI_Params.dataSize passed to SPI_open.
83  * The SPICC32XXDMA driver implementation makes assumptions on the element
84  * size of the ::SPI_Transaction txBuf and rxBuf arrays, based on the data
85  * frame size. If the data frame size is less than or equal to 8 bits,
86  * txBuf and rxBuf are assumed to be arrays of 8-bit uint8_t elements.
87  * If the data frame size is greater than 8 bits, but less than or equal
88  * to 16 bits, txBuf and rxBuf are assumed to be arrays of 16-bit uint16_t
89  * elements. Otherwise, txBuf and rxBuf are assumed to point to 32-bit
90  * uint32_t elements.
91  *
92  * data frame size | buffer element size |
93  * -------------- | ------------------- |
94  * 4-8 bits | uint8_t |
95  * 9-16 bits | uint16_t |
96  * 17-32 bits | uint32_t |
97  *
98  * Data buffers in transactions (rxBuf & txBuf) must be address aligned
99  * according to the data frame size. For example, if data frame is 9-bit
100  * (driver assumes buffers are uint16_t) rxBuf & txBuf must be aligned
101  * on a 16-bit address boundary, if data frame is 20-bit (driver assumes
102  * buffers are uint32_t) rxBuf & txBuf must be aligned on a 32-bit address
103  * boundary.
104  *
105  * ## DMA Interrupts #
106  * This driver is designed to operate with the micro DMA. The micro DMA
107  * generates an interrupt on the perpheral's interrupt vector. This
108  * implementation automatically installs a DMA aware hardware ISR to service
109  * the assigned micro DMA channels.
110  *
111  * ## DMA accessible memory #
112  * As this driver uses uDMA to transfer data/from data buffers, it is the
113  * responsibility of the application to ensure that these buffers reside in
114  * memory that is accessible by the DMA.
115  *
116  * ## Scratch Buffers #
117  * A uint32_t scratch buffer is used to allow SPI_transfers where txBuf or
118  * rxBuf are NULL. Rather than requiring txBuf or rxBuf to have a dummy buffer
119  * of size of the transfer count, a single DMA accessible uint32_t scratch
120  * buffer is used. When rxBuf is NULL, the uDMA will transfer all the SPI data
121  * receives into the scratch buffer as a "bit-bucket". When txBuf is NULL, the
122  * scratch buffer is initialized to defaultTxBufValue so the uDMA will send
123  * some known value. Each SPI driver instance must have its own scratch buffer.
124  *
125  * ## Polling SPI transfers #
126  * When used in blocking mode small SPI transfers are can be done by polling
127  * the peripheral & sending data frame-by-frame. This will not block the task
128  * which requested the transfer, but instead immediately perform the transfer
129  * & return. The minDmaTransferSize field in the hardware attributes is
130  * the threshold; if the transaction count is below the threshold a polling
131  * transfer is performed; otherwise a DMA transfer is done. This is intended
132  * to reduce the overhead of setting up a DMA transfer to only send a few
133  * data frames. Keep in mind that during polling transfers the current task
134  * is still being executed; there is no context switch to another task.
135  *******************************************************************************
136  */
137 
138 #ifndef ti_drivers_spi_SPICC32XXDMA__include
139 #define ti_drivers_spi_SPICC32XXDMA__include
140 
141 #ifdef __cplusplus
142 extern "C" {
143 #endif
144 
145 #include <ti/drivers/dpl/HwiP.h>
146 #include <ti/drivers/dpl/SemaphoreP.h>
147 #include <ti/drivers/Power.h>
148 #include <ti/drivers/SPI.h>
150 
161 /* Add SPICC32XXDMA_STATUS_* macros here */
162 
175 /* Add SPICC32XXDMA_CMD_* macros here */
176 
179 /*
180  * Macros defining possible SPI signal pin mux options
181  *
182  * The lower 8 bits of the macro refer to the pin, offset by 1, to match
183  * driverlib pin defines. For example, SPICC32XXDMA_PIN_05_CLK & 0xff = 4,
184  * which equals PIN_05 in driverlib pin.h. By matching the PIN_xx defines in
185  * driverlib pin.h, we can pass the pin directly to the driverlib functions.
186  * The upper 8 bits of the macro correspond to the pin mux confg mode
187  * value for the pin to operate in the SPI mode.
188  *
189  * PIN_62 is special for the SDSPI driver when using an SD BoosterPack,
190  * as PIN_62 doesn't have an assigned SPI function yet the SD BoosterPack
191  * has it tied to the CS signal.
192  */
193 #define SPICC32XXDMA_PIN_05_CLK 0x0704
194 #define SPICC32XXDMA_PIN_06_MISO 0x0705
195 #define SPICC32XXDMA_PIN_07_MOSI 0x0706
196 #define SPICC32XXDMA_PIN_08_CS 0x0707
197 #define SPICC32XXDMA_PIN_45_CLK 0x072C
198 #define SPICC32XXDMA_PIN_50_CS 0x0931
199 #define SPICC32XXDMA_PIN_52_MOSI 0x0833
200 #define SPICC32XXDMA_PIN_53_MISO 0x0734
205 #define SPICC32XXDMA_PIN_NO_CONFIG 0xFFFF
206 
207 /* SPI function table pointer */
209 
267 typedef struct SPICC32XXDMA_HWAttrsV1 {
269  uint32_t baseAddr;
270 
272  uint32_t intNum;
273 
275  uint32_t intPriority;
276 
278  uint32_t spiPRCM;
279 
281  uint32_t csControl;
282 
283  uint32_t csPolarity;
284 
286  uint32_t pinMode;
287 
289  uint32_t turboMode;
290 
292  uint32_t *scratchBufPtr;
293 
296 
298  uint32_t rxChannelIndex;
299 
301  uint32_t txChannelIndex;
302 
305 
307  uint16_t mosiPin;
308 
310  uint16_t misoPin;
311 
313  uint16_t clkPin;
314 
316  uint16_t csPin;
318 
324 typedef struct SPICC32XXDMA_Object {
325  HwiP_Handle hwiHandle;
327  SemaphoreP_Handle transferComplete;
331 
334  uint32_t bitRate;
335  uint32_t dataSize;
336  uint32_t transferTimeout;
337 
341 
343  bool isOpen;
344  uint8_t rxFifoTrigger;
345  uint8_t txFifoTrigger;
347 
348 #ifdef __cplusplus
349 }
350 #endif
351 
352 #endif /* ti_drivers_spi_SPICC32XXDMA__include */
struct SPICC32XXDMA_Object SPICC32XXDMA_Object
SPICC32XXDMA Object.
size_t amtDataXferred
Definition: SPICC32XXDMA.h:332
SPI driver interface.
void(* SPI_CallbackFxn)(SPI_Handle handle, SPI_Transaction *transaction)
The definition of a callback function used by the SPI driver when used in SPI_MODE_CALLBACK.
Definition: SPI.h:569
enum SPI_Mode_ SPI_Mode
Definitions for various SPI modes of operation.
SPI_FrameFormat frameFormat
Definition: SPICC32XXDMA.h:340
uint16_t csPin
Definition: SPICC32XXDMA.h:316
A SPI_Transaction data structure is used with SPI_transfer(). It indicates how many SPI_FrameFormat f...
Definition: SPI.h:548
uint32_t intPriority
Definition: SPICC32XXDMA.h:275
uint16_t misoPin
Definition: SPICC32XXDMA.h:310
uint32_t * scratchBufPtr
Definition: SPICC32XXDMA.h:292
Power Manager interface.
uint32_t defaultTxBufValue
Definition: SPICC32XXDMA.h:295
Power notify object structure.
Definition: Power.h:121
uint32_t rxChannelIndex
Definition: SPICC32XXDMA.h:298
SPI_Mode spiMode
Definition: SPICC32XXDMA.h:338
uint32_t csPolarity
Definition: SPICC32XXDMA.h:283
uint32_t pinMode
Definition: SPICC32XXDMA.h:286
uDMA driver implementation for CC32XX.
uint32_t turboMode
Definition: SPICC32XXDMA.h:289
SPI_Transaction * transaction
Definition: SPICC32XXDMA.h:329
SPI_TransferMode transferMode
Definition: SPICC32XXDMA.h:339
SemaphoreP_Handle transferComplete
Definition: SPICC32XXDMA.h:327
UDMACC32XX Global configuration.
Definition: UDMACC32XX.h:125
uint32_t transferTimeout
Definition: SPICC32XXDMA.h:336
enum SPI_TransferMode_ SPI_TransferMode
SPI transfer mode determines the whether the SPI controller operates synchronously or asynchronously...
The definition of a SPI function table that contains the required set of functions to control a speci...
Definition: SPI.h:683
SPICC32XXDMA Hardware attributes.
Definition: SPICC32XXDMA.h:267
struct SPICC32XXDMA_Object * SPICC32XXDMA_Handle
uint32_t baseAddr
Definition: SPICC32XXDMA.h:269
uint32_t intNum
Definition: SPICC32XXDMA.h:272
UDMACC32XX_Handle dmaHandle
Definition: SPICC32XXDMA.h:330
uint8_t txFifoTrigger
Definition: SPICC32XXDMA.h:345
SPICC32XXDMA Object.
Definition: SPICC32XXDMA.h:324
uint32_t txChannelIndex
Definition: SPICC32XXDMA.h:301
enum SPI_FrameFormat_ SPI_FrameFormat
Definitions for various SPI data frame formats.
uint32_t dataSize
Definition: SPICC32XXDMA.h:335
Power_NotifyObj notifyObj
Definition: SPICC32XXDMA.h:326
uint32_t csControl
Definition: SPICC32XXDMA.h:281
uint32_t bitRate
Definition: SPICC32XXDMA.h:334
SPI_CallbackFxn transferCallbackFxn
Definition: SPICC32XXDMA.h:328
uint8_t rxFifoTrigger
Definition: SPICC32XXDMA.h:344
size_t currentXferAmt
Definition: SPICC32XXDMA.h:333
uint16_t mosiPin
Definition: SPICC32XXDMA.h:307
struct SPICC32XXDMA_HWAttrsV1 SPICC32XXDMA_HWAttrsV1
SPICC32XXDMA Hardware attributes.
uint16_t clkPin
Definition: SPICC32XXDMA.h:313
uint32_t minDmaTransferSize
Definition: SPICC32XXDMA.h:304
HwiP_Handle hwiHandle
Definition: SPICC32XXDMA.h:325
uint32_t spiPRCM
Definition: SPICC32XXDMA.h:278
bool isOpen
Definition: SPICC32XXDMA.h:343
const SPI_FxnTable SPICC32XXDMA_fxnTable
bool cancelInProgress
Definition: SPICC32XXDMA.h:342
© Copyright 1995-2018, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale