SPICC32XXDMA.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2021, 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 peripheral's interrupt vector. This
108  * implementation automatically installs a DMA aware hardware ISR to service
109  * the assigned micro DMA channels.
110  *
111  * ## DMA and Queueing
112  * This driver utilizes DMA channels in ping pong mode (see device TRM) in
113  * order to overcome the 1024 item DMA channel limit. This means the driver
114  * can execute multi kilo-item transactions without pausing to reconfigure the
115  * DMA and causing gaps in transmission. In addition, the driver also allows
116  * the user to queue up transfers when opened in #SPI_MODE_CALLBACK by calling
117  * SPI_transfer() multiple times. Note that each transaction's
118  * #SPI_Transaction struct must still be persistent and unmodified until that
119  * transaction is complete.
120  *
121  * @anchor ti_drivers_spi_SPICC32XXDMA_example_queueing
122  * Below is an example of queueing three transactions
123  * @code
124  * // SPI already opened in callback mode
125  * SPI_Transaction t0, t1, t2;
126  *
127  * t0.txBuf = txBuff0;
128  * t0.rxBuf = rxBuff0;
129  * t0.count = 2000;
130  *
131  * t1.txBuf = txBuff1;
132  * t1.rxBuf = rxBuff1;
133  * t1.count = 1000;
134  *
135  * t2.txBuf = txBuff2;
136  * t2.rxBuf = NULL;
137  * t2.count = 1000;
138  *
139  * bool transferOk = false;
140  *
141  * if (SPI_transfer(spiHandle, &t0)) {
142  * if (SPI_transfer(spiHandle, &t1)) {
143  * transferOk = SPI_transfer(spiHandle, &t2);
144  * }
145  * }
146  * }
147  * @endcode
148  *
149  * ## DMA accessible memory #
150  * As this driver uses uDMA to transfer data/from data buffers, it is the
151  * responsibility of the application to ensure that these buffers reside in
152  * memory that is accessible by the DMA.
153  *
154  * ## Scratch Buffers #
155  * A uint32_t scratch buffer is used to allow SPI_transfers where txBuf or
156  * rxBuf are NULL. Rather than requiring txBuf or rxBuf to have a dummy buffer
157  * of size of the transfer count, a single DMA accessible uint32_t scratch
158  * buffer is used. When rxBuf is NULL, the uDMA will transfer all the SPI data
159  * receives into the scratch buffer as a "bit-bucket". When txBuf is NULL, the
160  * scratch buffer is initialized to defaultTxBufValue so the uDMA will send
161  * some known value. Each SPI driver instance must have its own scratch buffer.
162  *
163  * ## Polling SPI transfers #
164  * When used in blocking mode small SPI transfers are can be done by polling
165  * the peripheral & sending data frame-by-frame. This will not block the task
166  * which requested the transfer, but instead immediately perform the transfer
167  * & return. The minDmaTransferSize field in the hardware attributes is
168  * the threshold; if the transaction count is below the threshold a polling
169  * transfer is performed; otherwise a DMA transfer is done. This is intended
170  * to reduce the overhead of setting up a DMA transfer to only send a few
171  * data frames. Keep in mind that during polling transfers the current task
172  * is still being executed; there is no context switch to another task.
173  *******************************************************************************
174  */
175 
176 #ifndef ti_drivers_spi_SPICC32XXDMA__include
177 #define ti_drivers_spi_SPICC32XXDMA__include
178 
179 #include <ti/drivers/dpl/HwiP.h>
180 #include <ti/drivers/dpl/SemaphoreP.h>
181 #include <ti/drivers/Power.h>
182 #include <ti/drivers/SPI.h>
184 
185 #ifdef __cplusplus
186 extern "C" {
187 #endif
188 
199 /* Add SPICC32XXDMA_STATUS_* macros here */
200 
213 /* Add SPICC32XXDMA_CMD_* macros here */
214 
215 
218 /*
219  * Macros defining possible SPI signal pin mux options
220  *
221  * The lower 8 bits of the macro refer to the pin, offset by 1, to match
222  * driverlib pin defines. For example, SPICC32XXDMA_PIN_05_CLK & 0xff = 4,
223  * which equals PIN_05 in driverlib pin.h. By matching the PIN_xx defines in
224  * driverlib pin.h, we can pass the pin directly to the driverlib functions.
225  * The upper 8 bits of the macro correspond to the pin mux confg mode
226  * value for the pin to operate in the SPI mode.
227  *
228  * PIN_62 is special for the SDSPI driver when using an SD BoosterPack,
229  * as PIN_62 doesn't have an assigned SPI function yet the SD BoosterPack
230  * has it tied to the CS signal.
231  */
233 #define SPICC32XXDMA_PIN_05_CLK 0x0704
234 #define SPICC32XXDMA_PIN_06_MISO 0x0705
235 #define SPICC32XXDMA_PIN_07_MOSI 0x0706
236 #define SPICC32XXDMA_PIN_08_CS 0x0707
237 #define SPICC32XXDMA_PIN_45_CLK 0x072C
238 #define SPICC32XXDMA_PIN_50_CS 0x0931
239 #define SPICC32XXDMA_PIN_52_MOSI 0x0833
240 #define SPICC32XXDMA_PIN_53_MISO 0x0734
247 #define SPICC32XXDMA_PIN_NO_CONFIG 0xFFFF
248 
249 /* SPI function table pointer */
251 
309 typedef struct {
311  uint32_t baseAddr;
312 
313 
315  uint32_t intNum;
316 
318  uint32_t intPriority;
319 
321  uint32_t spiPRCM;
322 
324  uint32_t csControl;
325 
326  uint32_t csPolarity;
327 
329  uint32_t pinMode;
330 
332  uint32_t turboMode;
333 
335  uint32_t *scratchBufPtr;
336 
339 
341  uint32_t rxChannelIndex;
342 
344  uint32_t txChannelIndex;
345 
348 
350  uint16_t mosiPin;
351 
353  uint16_t misoPin;
354 
356  uint16_t clkPin;
357 
359  uint16_t csPin;
361 
367 typedef struct {
368  HwiP_Handle hwiHandle;
370  SemaphoreP_Handle transferComplete;
374 
377  uint32_t bitRate;
378  uint32_t dataSize;
379  uint32_t transferTimeout;
380 
384 
386  bool isOpen;
387  uint8_t rxFifoTrigger;
388  uint8_t txFifoTrigger;
390 
391 #ifdef __cplusplus
392 }
393 #endif
394 
395 #endif /* ti_drivers_spi_SPICC32XXDMA__include */
size_t amtDataXferred
Definition: SPICC32XXDMA.h:375
Serial Peripheral Interface (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:584
SPI_FrameFormat frameFormat
Definition: SPICC32XXDMA.h:383
uint16_t csPin
Definition: SPICC32XXDMA.h:359
uint32_t intPriority
Definition: SPICC32XXDMA.h:318
uint16_t misoPin
Definition: SPICC32XXDMA.h:353
SPI_TransferMode
SPI transfer mode determines the whether the SPI controller operates synchronously or asynchronously...
Definition: SPI.h:620
uint32_t * scratchBufPtr
Definition: SPICC32XXDMA.h:335
Power Manager.
uint32_t defaultTxBufValue
Definition: SPICC32XXDMA.h:338
uint32_t rxChannelIndex
Definition: SPICC32XXDMA.h:341
SPI_Mode spiMode
Definition: SPICC32XXDMA.h:381
uint32_t csPolarity
Definition: SPICC32XXDMA.h:326
uint32_t pinMode
Definition: SPICC32XXDMA.h:329
uDMA driver implementation for CC32XX.
uint32_t turboMode
Definition: SPICC32XXDMA.h:332
SPI_Transaction * transaction
Definition: SPICC32XXDMA.h:372
SPI_TransferMode transferMode
Definition: SPICC32XXDMA.h:382
SemaphoreP_Handle transferComplete
Definition: SPICC32XXDMA.h:370
The definition of a SPI function table that contains the required set of functions to control a speci...
Definition: SPI.h:709
UDMACC32XX Global configuration.
Definition: UDMACC32XX.h:125
uint32_t transferTimeout
Definition: SPICC32XXDMA.h:379
SPICC32XXDMA Hardware attributes.
Definition: SPICC32XXDMA.h:309
uint32_t baseAddr
Definition: SPICC32XXDMA.h:311
A SPI_Transaction data structure is used with SPI_transfer(). It indicates how many SPI_FrameFormat f...
Definition: SPI.h:563
uint32_t intNum
Definition: SPICC32XXDMA.h:315
Power notify object structure.
Definition: Power.h:443
SPI_Mode
Definitions for various SPI modes of operation.
Definition: SPI.h:590
UDMACC32XX_Handle dmaHandle
Definition: SPICC32XXDMA.h:373
uint8_t txFifoTrigger
Definition: SPICC32XXDMA.h:388
SPICC32XXDMA Object.
Definition: SPICC32XXDMA.h:367
uint32_t txChannelIndex
Definition: SPICC32XXDMA.h:344
uint32_t dataSize
Definition: SPICC32XXDMA.h:378
Power_NotifyObj notifyObj
Definition: SPICC32XXDMA.h:369
uint32_t csControl
Definition: SPICC32XXDMA.h:324
uint32_t bitRate
Definition: SPICC32XXDMA.h:377
struct SPICC32XXDMA_Object * SPICC32XXDMA_Handle
SPI_CallbackFxn transferCallbackFxn
Definition: SPICC32XXDMA.h:371
uint8_t rxFifoTrigger
Definition: SPICC32XXDMA.h:387
size_t currentXferAmt
Definition: SPICC32XXDMA.h:376
uint16_t mosiPin
Definition: SPICC32XXDMA.h:350
uint16_t clkPin
Definition: SPICC32XXDMA.h:356
uint32_t minDmaTransferSize
Definition: SPICC32XXDMA.h:347
HwiP_Handle hwiHandle
Definition: SPICC32XXDMA.h:368
uint32_t spiPRCM
Definition: SPICC32XXDMA.h:321
bool isOpen
Definition: SPICC32XXDMA.h:386
const SPI_FxnTable SPICC32XXDMA_fxnTable
SPI_FrameFormat
Definitions for various SPI data frame formats.
Definition: SPI.h:599
bool cancelInProgress
Definition: SPICC32XXDMA.h:385
© Copyright 1995-2021, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale