SPICC32XXDMA.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, 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  * ## SPI Chip Select #
50  * This SPI controller supports a hardware chip select pin. Refer to the
51  * device's user manual on how this hardware chip select pin behaves in regards
52  * to the SPI frame format.
53  *
54  * <table>
55  * <tr>
56  * <th>Chip select type</th>
57  * <th>SPI_MASTER mode</th>
58  * <th>SPI_SLAVE mode</th>
59  * </tr>
60  * <tr>
61  * <td>Hardware chip select</td>
62  * <td>No action is needed by the application to select the peripheral.</td>
63  * <td>See the device documentation on it's chip select requirements.</td>
64  * </tr>
65  * <tr>
66  * <td>Software chip select</td>
67  * <td>The application is responsible to ensure that correct SPI slave is
68  * selected before performing a SPI_transfer().</td>
69  * <td>See the device documentation on it's chip select requirements.</td>
70  * </tr>
71  * </table>
72  *
73  * ## DMA Interrupts #
74  * This driver is designed to operate with the micro DMA. The micro DMA
75  * generates an IRQ on the perpheral's interrupt vector. This implementation
76  * automatically installs a DMA aware hardware ISR to service the assigned
77  * micro DMA channels.
78  *
79  * ## SPI data frames #
80  * SPI data frames can be any size from 4-bits to 32-bits. The SPI data
81  * frame size is set in ::SPI_Params.dataSize passed to SPI_open.
82  * The SPICC32XXDMA driver implementation makes assumptions on the element
83  * size of the ::SPI_Transaction txBuf and rxBuf arrays, based on the data
84  * frame size. If the data frame size is less than or equal to 8 bits,
85  * txBuf and rxBuf are assumed to be arrays of 8-bit uint8_t elements.
86  * If the data frame size is greater than 8 bits, but less than or equal
87  * to 16 bits, txBuf and rxBuf are assumed to be arrays of 16-bit uint16_t
88  * elements. Otherwise, txBuf and rxBuf are assumed to point to 32-bit
89  * uint32_t elements.
90  *
91  * data frame size | buffer element size |
92  * -------------- | ------------------- |
93  * 4-8 bits | uint8_t |
94  * 9-16 bits | uint16_t |
95  * 16-32 bits | uint32_t |
96  *
97  * ## DMA transfer size limit #
98  * The micro DMA controller only supports data transfers of up to 1024
99  * data frames. A data frame can be 4 to 32 bits in length.
100  *
101  * ## DMA accessible memory #
102  * As this driver uses uDMA to transfer data/from data buffers, it is the
103  * responsibility of the application to ensure that these buffers reside in
104  * memory that is accessible by the DMA.
105  *
106  *******************************************************************************
107  */
108 
109 #ifndef ti_drivers_spi_SPICC32XXDMA__include
110 #define ti_drivers_spi_SPICC32XXDMA__include
111 
112 #ifdef __cplusplus
113 extern "C" {
114 #endif
115 
116 #include <ti/drivers/dpl/HwiP.h>
117 #include <ti/drivers/dpl/SemaphoreP.h>
118 #include <ti/drivers/Power.h>
119 #include <ti/drivers/SPI.h>
121 
132 /* Add SPICC32XXDMA_STATUS_* macros here */
133 
146 /* Add SPICC32XXDMA_CMD_* macros here */
147 
150 #define SPICC32XXDMA_PIN_05_CLK 0x0704
151 #define SPICC32XXDMA_PIN_06_MISO 0x0705
152 #define SPICC32XXDMA_PIN_07_MOSI 0x0706
153 #define SPICC32XXDMA_PIN_08_CS 0x0707
154 #define SPICC32XXDMA_PIN_45_CLK 0x072C
155 #define SPICC32XXDMA_PIN_50_CS 0x0931
156 #define SPICC32XXDMA_PIN_52_MOSI 0x0833
157 #define SPICC32XXDMA_PIN_53_MISO 0x0734
158 
159 #define SPICC32XXDMA_PIN_NO_CONFIG 0xFFFF
160 
161 
162 typedef unsigned long SPIBaseAddrType;
163 typedef unsigned long SPIDataType;
164 
165 /* SPI function table pointer */
167 
182 
240 typedef struct SPICC32XXDMA_HWAttrsV1 {
242  SPIBaseAddrType baseAddr;
243 
245  uint32_t intNum;
246 
248  uint32_t intPriority;
249 
251  uint32_t spiPRCM;
252 
254  uint32_t csControl;
255 
256  uint32_t csPolarity;
257 
259  uint32_t pinMode;
260 
262  uint32_t turboMode;
263 
265  uint32_t *scratchBufPtr;
266 
268  unsigned long defaultTxBufValue;
269 
271  uint32_t rxChannelIndex;
272 
274  uint32_t txChannelIndex;
275 
278 
280  uint16_t mosiPin;
281 
283  uint16_t misoPin;
284 
286  uint16_t clkPin;
287 
289  uint16_t csPin;
291 
297 typedef struct SPICC32XXDMA_Object {
298  HwiP_Handle hwiHandle;
299  SemaphoreP_Handle transferComplete;
300 
302  unsigned int powerMgrId;
303 
304  uint32_t bitRate;
305  uint32_t dataSize;
308 
309  void (*spiPollingFxn) (uint32_t baseAddr, void *rx,
310  void *tx, uint8_t rxInc, uint8_t txInc,
311  size_t count);
312 
313  uint8_t rxFifoTrigger;
314  uint8_t txFifoTrigger;
319 
320  bool isOpen;
321 
322  /* UDMA */
325 
326 #ifdef __cplusplus
327 }
328 #endif
329 
330 #endif /* ti_drivers_spi_SPICC32XXDMA__include */
struct SPICC32XXDMA_Object SPICC32XXDMA_Object
SPICC32XXDMA Object.
SPIBaseAddrType baseAddr
Definition: SPICC32XXDMA.h:242
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:540
enum SPI_Mode_ SPI_Mode
Definitions for various SPI modes of operation.
SPI_FrameFormat frameFormat
Definition: SPICC32XXDMA.h:317
uint16_t csPin
Definition: SPICC32XXDMA.h:289
A SPI_Transaction data structure is used with SPI_transfer(). It indicates how many SPI_FrameFormat f...
Definition: SPI.h:522
uint32_t intPriority
Definition: SPICC32XXDMA.h:248
uint16_t misoPin
Definition: SPICC32XXDMA.h:283
uint32_t * scratchBufPtr
Definition: SPICC32XXDMA.h:265
unsigned long SPIBaseAddrType
Definition: SPICC32XXDMA.h:162
Power manager interface.
Power notify object structure.
Definition: Power.h:113
uint32_t rxChannelIndex
Definition: SPICC32XXDMA.h:271
SPI_Mode spiMode
Definition: SPICC32XXDMA.h:315
uint32_t csPolarity
Definition: SPICC32XXDMA.h:256
uint32_t pinMode
Definition: SPICC32XXDMA.h:259
uDMA driver implementation for CC32XX.
uint32_t turboMode
Definition: SPICC32XXDMA.h:262
Definition: SPICC32XXDMA.h:180
unsigned int powerMgrId
Definition: SPICC32XXDMA.h:302
SPI_Transaction * transaction
Definition: SPICC32XXDMA.h:307
SPI_TransferMode transferMode
Definition: SPICC32XXDMA.h:316
SemaphoreP_Handle transferComplete
Definition: SPICC32XXDMA.h:299
SPICC32XXDMA_FrameSize frameSize
Definition: SPICC32XXDMA.h:318
UDMACC32XX Global configuration.
Definition: UDMACC32XX.h:135
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:652
SPICC32XXDMA Hardware attributes.
Definition: SPICC32XXDMA.h:240
Definition: SPICC32XXDMA.h:178
struct SPICC32XXDMA_Object * SPICC32XXDMA_Handle
uint32_t intNum
Definition: SPICC32XXDMA.h:245
UDMACC32XX_Handle dmaHandle
Definition: SPICC32XXDMA.h:323
uint8_t txFifoTrigger
Definition: SPICC32XXDMA.h:314
SPICC32XXDMA Object.
Definition: SPICC32XXDMA.h:297
uint32_t txChannelIndex
Definition: SPICC32XXDMA.h:274
enum SPI_FrameFormat_ SPI_FrameFormat
Definitions for various SPI data frame formats.
uint32_t dataSize
Definition: SPICC32XXDMA.h:305
Power_NotifyObj notifyObj
Definition: SPICC32XXDMA.h:301
Definition: SPICC32XXDMA.h:179
uint32_t csControl
Definition: SPICC32XXDMA.h:254
uint32_t bitRate
Definition: SPICC32XXDMA.h:304
SPI_CallbackFxn transferCallbackFxn
Definition: SPICC32XXDMA.h:306
uint8_t rxFifoTrigger
Definition: SPICC32XXDMA.h:313
uint16_t mosiPin
Definition: SPICC32XXDMA.h:280
unsigned long SPIDataType
Definition: SPICC32XXDMA.h:163
struct SPICC32XXDMA_HWAttrsV1 SPICC32XXDMA_HWAttrsV1
SPICC32XXDMA Hardware attributes.
uint16_t clkPin
Definition: SPICC32XXDMA.h:286
unsigned long defaultTxBufValue
Definition: SPICC32XXDMA.h:268
uint32_t minDmaTransferSize
Definition: SPICC32XXDMA.h:277
HwiP_Handle hwiHandle
Definition: SPICC32XXDMA.h:298
uint32_t spiPRCM
Definition: SPICC32XXDMA.h:251
bool isOpen
Definition: SPICC32XXDMA.h:320
SPICC32XXDMA_FrameSize
SPICC32XXDMA data frame size is used to determine how to configure the DMA data transfers. This field is to be only used internally.
Definition: SPICC32XXDMA.h:177
const SPI_FxnTable SPICC32XXDMA_fxnTable
Copyright 2017, Texas Instruments Incorporated