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