SPIMSP432E4DMA.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019, 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 SPIMSP432E4DMA.h
34  *
35  * @brief SPI driver implementation for a MSP432E4 SPI controller using
36  * the 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/SPIMSP432E4DMA.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 MSP432E4 SPI
47  * controller using a micro DMA controller in ping pong mode. This driver
48  * allows for queueing multiple SPI transactions.
49  *
50  * ## Frame Formats #
51  * This SPI controller supports 4 phase & polarity formats as well as
52  * the TI synchronous serial frame format. Refer to the device specific data
53  * sheets & technical reference manuals for specifics on each format.
54  *
55  * ## SPI Chip Select #
56  * This SPI controller supports a hardware chip select pin. Refer to the
57  * device's user manual on how this hardware chip select pin behaves in regards
58  * to the SPI frame format.
59  *
60  * <table>
61  * <tr>
62  * <th>Chip select type</th>
63  * <th>SPI_MASTER mode</th>
64  * <th>SPI_SLAVE mode</th>
65  * </tr>
66  * <tr>
67  * <td>Hardware chip select</td>
68  * <td>No action is needed by the application to select the peripheral.</td>
69  * <td>See the device documentation on it's chip select requirements.</td>
70  * </tr>
71  * <tr>
72  * <td>Software chip select</td>
73  * <td>The application is responsible to ensure that correct SPI slave is
74  * selected before performing a SPI_transfer().</td>
75  * <td>See the device documentation on it's chip select requirements.</td>
76  * </tr>
77  * </table>
78  *
79  * ## SPI data frames #
80  *
81  * SPI data frames can be any size from 4-bits to 16-bits. If the dataSize in
82  * #SPI_Params is greater than 8-bits, then the SPIMSP432E4DMA driver
83  * will assume that the #SPI_Transaction txBuf and rxBuf point to 16-bit
84  * (uint16_t) arrays.
85  *
86  * dataSize | buffer element size |
87  * -------- | ------------------- |
88  * 4-8 bits | uint8_t |
89  * 9-16 bits | uint16_t |
90  *
91  * Data buffers in transactions (rxBuf & txBuf) must be address aligned
92  * according to the data frame size. For example, if data frame is 9-bit or
93  * larger (driver assumes buffers are uint16_t) rxBuf & txBuf must be aligned
94  * on a 16-bit address boundary.
95  *
96  * ## Interrupts #
97  * This driver is designed to make use of the micro DMA for transfers. The
98  * driver implementation automatically installs a hardware interrupt service
99  * routine for the peripheral on which micro DMA generates IRQ once all data
100  * has transfered from memory to the peripheral (TX) or from peripheral to
101  * memory (RX).
102  *
103  * ## DMA and Queueing
104  * This driver utilizes DMA channels in ping pong mode (see device TRM) in
105  * order to overcome the 1024 item DMA channel limit. This means the driver
106  * can execute multi kilo-item transactions without pausing to reconfigure the
107  * DMA and causing gaps in transmission. In addition, the driver also allows
108  * the user to queue up transfers when opened in #SPI_MODE_CALLBACK by calling
109  * SPI_transfer() multiple times. Note that each transaction's
110  * #SPI_Transaction struct must still be persistent and unmodified until that
111  * transaction is complete.
112  *
113  * @anchor ti_drivers_spi_SPIMSP432E4DMA_example_queueing
114  * Below is an example of queueing three transactions
115  * @code
116  * // SPI already opened in callback mode
117  * SPI_Transaction t0, t1, t2;
118  *
119  * t0.txBuf = txBuff0;
120  * t0.rxBuf = rxBuff0;
121  * t0.count = 2000;
122  *
123  * t1.txBuf = txBuff1;
124  * t1.rxBuf = rxBuff1;
125  * t1.count = 1000;
126  *
127  * t2.txBuf = txBuff2;
128  * t2.rxBuf = NULL;
129  * t2.count = 1000;
130  *
131  * bool transferOk = false;
132  *
133  * if (SPI_transfer(spiHandle, &t0)) {
134  * if (SPI_transfer(spiHandle, &t1)) {
135  * transferOk = SPI_transfer(spiHandle, &t2);
136  * }
137  * }
138  * }
139  * @endcode
140  *
141  * ## DMA accessible memory #
142  *
143  * As this driver uses uDMA to transfer data to/from data buffers, it is the
144  * responsibility of the application to ensure that theses buffers reside in
145  * memory that is accessible by the DMA.
146  *
147  * ## NULL Buffers #
148  * When SPI_Transaction.rxBuf is NULL, all frames received will be discarded.
149  * When SPI_Transaction.txBuf is NULL, an internal scratch buffer is
150  * initialized to #SPIMSP432E4DMA_HWAttrs.defaultTxBufValue so the uDMA will
151  * send some known value.
152  *
153  * ## Polling SPI transfers #
154  * When used in blocking mode small SPI transfers are can be done by polling
155  * the peripheral & sending data frame-by-frame. For master devices this will
156  * not block since the transfer can happen immediately. Slaves must exercise
157  * caution since the call will poll on the HW until the transfer is complete.
158  * For this reason slaves with a transfer timeout will not use polling
159  * transfers. The minDmaTransferSize field in the hardware attributes is
160  * the threshold; if the transaction count is below the threshold a polling
161  * transfer is performed; otherwise a DMA transfer is done. This is intended
162  * to reduce the overhead of setting up a DMA transfer to only send a few
163  * data frames.
164  *
165  * Notes:
166  * - Specifying a timeout prevents slave devices from using polling transfers.
167  * - Keep in mind that during polling transfers the current task
168  * is still being executed; there is no context switch to another task.
169  *
170  * <hr>
171  */
172 
173 #ifndef ti_drivers_spi_SPIMSP432E4DMA__include
174 #define ti_drivers_spi_SPIMSP432E4DMA__include
175 
176 #ifdef __cplusplus
177 extern "C" {
178 #endif
179 
180 #include <stdbool.h>
181 #include <stdint.h>
182 
183 #include <ti/devices/msp432e4/inc/msp432.h>
184 
185 #include <ti/devices/msp432e4/driverlib/pin_map.h>
186 
188 #include <ti/drivers/dpl/HwiP.h>
189 #include <ti/drivers/dpl/SemaphoreP.h>
191 #include <ti/drivers/SPI.h>
192 
201 #define SPIMSP432E4_PA2_SSI0CLK GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 2, GPIO_PA2_SSI0CLK)
202 
206 #define SPIMSP432E4_PA3_SSI0FSS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 3, GPIO_PA3_SSI0FSS)
207 
211 #define SPIMSP432E4_PA4_SSI0XDAT0 GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 4, GPIO_PA4_SSI0XDAT0)
212 
216 #define SPIMSP432E4_PA5_SSI0XDAT1 GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 5, GPIO_PA5_SSI0XDAT1)
217 
221 #define SPIMSP432E4_PB5_SSI1CLK GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 5, GPIO_PB5_SSI1CLK)
222 
226 #define SPIMSP432E4_PB4_SSI1FSS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 4, GPIO_PB4_SSI1FSS)
227 
231 #define SPIMSP432E4_PE4_SSI1XDAT0 GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTE, 4, GPIO_PE4_SSI1XDAT0)
232 
236 #define SPIMSP432E4_PE5_SSI1XDAT1 GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTE, 5, GPIO_PE5_SSI1XDAT1)
237 
241 #define SPIMSP432E4_PD3_SSI2CLK GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 3, GPIO_PD3_SSI2CLK)
242 
246 #define SPIMSP432E4_PG7_SSI2CLK GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 7, GPIO_PG7_SSI2CLK)
247 
251 #define SPIMSP432E4_PD2_SSI2FSS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 2, GPIO_PD2_SSI2FSS)
252 
256 #define SPIMSP432E4_PG6_SSI2FSS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 6, GPIO_PG6_SSI2FSS)
257 
261 #define SPIMSP432E4_PD1_SSI2XDAT0 GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 1, GPIO_PD1_SSI2XDAT0)
262 
266 #define SPIMSP432E4_PG5_SSI2XDAT0 GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 5, GPIO_PG5_SSI2XDAT0)
267 
271 #define SPIMSP432E4_PD0_SSI2XDAT1 GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 0, GPIO_PD0_SSI2XDAT1)
272 
276 #define SPIMSP432E4_PG4_SSI2XDAT1 GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 4, GPIO_PG4_SSI2XDAT1)
277 
281 #define SPIMSP432E4_PQ0_SSI3CLK GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTQ, 0, GPIO_PQ0_SSI3CLK)
282 
286 #define SPIMSP432E4_PF3_SSI3CLK GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTF, 3, GPIO_PF3_SSI3CLK)
287 
291 #define SPIMSP432E4_PQ1_SSI3FSS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTQ, 1, GPIO_PQ1_SSI3FSS)
292 
296 #define SPIMSP432E4_PF2_SSI3FSS GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTF, 2, GPIO_PF2_SSI3FSS)
297 
301 #define SPIMSP432E4_PQ2_SSI3XDAT0 GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTQ, 2, GPIO_PQ2_SSI3XDAT0)
302 
306 #define SPIMSP432E4_PF1_SSI3XDAT0 GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTF, 1, GPIO_PF1_SSI3XDAT0)
307 
311 #define SPIMSP432E4_PQ3_SSI3XDAT1 GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTQ, 3, GPIO_PQ3_SSI3XDAT1)
312 
316 #define SPIMSP432E4_PF0_SSI3XDAT1 GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTF, 0, GPIO_PF0_SSI3XDAT1)
317 
347 #define SPIMSP432E4_PIN_NO_CONFIG (0xFFFFFFFF)
348 
359 /* Add SPIMSP432E4DMA_STATUS_* macros here */
360 
373 /* Add SPIMSP432E4DMA_CMD_* macros here */
374 
377 /* SPI function table pointer */
379 
420 typedef struct SPIMSP432E4DMA_HWAttrs {
422  uint32_t baseAddr;
424  uint32_t intNum;
426  uint32_t intPriority;
427 
429  uint16_t *scratchBufPtr;
430 
433 
435  uint32_t rxDmaChannel;
437  uint32_t txDmaChannel;
438 
441 
443  uint32_t clkPinMask;
445  uint32_t fssPinMask;
447  uint32_t xdat0PinMask;
449  uint32_t xdat1PinMask;
451 
458 typedef struct SPIMSP432E4DMA_Object {
459  HwiP_Handle hwiHandle;
460  SemaphoreP_Handle transferComplete;
463 
466 
467  size_t framesQueued;
471 
472  uint32_t bitRate;
473  uint32_t dataSize;
474  uint32_t transferTimeout;
475  uint32_t activeChannel;
476  uint32_t busyBit;
477 
478  uint16_t rxScratchBuf;
479 
482 
483  uint8_t format;
484  bool isOpen;
486 
487 #ifdef __cplusplus
488 }
489 #endif
490 
491 #endif /* ti_drivers_spi_SPIMSP432E4DMA__include */
uint32_t activeChannel
Definition: SPIMSP432E4DMA.h:475
Definition: SPIMSP432E4DMA.h:458
uint32_t intNum
Definition: SPIMSP432E4DMA.h:424
uint32_t txDmaChannel
Definition: SPIMSP432E4DMA.h:437
uint32_t transferTimeout
Definition: SPIMSP432E4DMA.h:474
UDMAMSP432E4 Global configuration.
Definition: UDMAMSP432E4.h:143
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
uint32_t xdat1PinMask
Definition: SPIMSP432E4DMA.h:449
uDMA driver implementation for MSP432E4.
SPI_TransferMode
SPI transfer mode determines the whether the SPI controller operates synchronously or asynchronously...
Definition: SPI.h:620
size_t framesTransferred
Definition: SPIMSP432E4DMA.h:468
uint16_t minDmaTransferSize
Definition: SPIMSP432E4DMA.h:440
SPIMSP432E4DMA Hardware attributes.
Definition: SPIMSP432E4DMA.h:420
uint32_t baseAddr
Definition: SPIMSP432E4DMA.h:422
UDMAMSP432E4_Handle dmaHandle
Definition: SPIMSP432E4DMA.h:462
uint32_t dataSize
Definition: SPIMSP432E4DMA.h:473
uint16_t defaultTxBufValue
Definition: SPIMSP432E4DMA.h:432
SPI_Mode spiMode
Definition: SPIMSP432E4DMA.h:480
size_t framesQueued
Definition: SPIMSP432E4DMA.h:467
size_t altTransferSize
Definition: SPIMSP432E4DMA.h:470
uint32_t intPriority
Definition: SPIMSP432E4DMA.h:426
uint32_t xdat0PinMask
Definition: SPIMSP432E4DMA.h:447
The definition of a SPI function table that contains the required set of functions to control a speci...
Definition: SPI.h:711
uint32_t bitRate
Definition: SPIMSP432E4DMA.h:472
uint16_t rxScratchBuf
Definition: SPIMSP432E4DMA.h:478
uint32_t busyBit
Definition: SPIMSP432E4DMA.h:476
SPI_Transaction * headPtr
Definition: SPIMSP432E4DMA.h:464
struct SPIMSP432E4DMA_Object SPIMSP432E4DMA_Object
SemaphoreP_Handle transferComplete
Definition: SPIMSP432E4DMA.h:460
A SPI_Transaction data structure is used with SPI_transfer(). It indicates how many SPI_FrameFormat f...
Definition: SPI.h:563
SPI_Mode
Definitions for various SPI modes of operation.
Definition: SPI.h:590
uint32_t rxDmaChannel
Definition: SPIMSP432E4DMA.h:435
MSP432E4 GPIO driver.
HwiP_Handle hwiHandle
Definition: SPIMSP432E4DMA.h:459
uint16_t * scratchBufPtr
Definition: SPIMSP432E4DMA.h:429
uint32_t fssPinMask
Definition: SPIMSP432E4DMA.h:445
uint32_t clkPinMask
Definition: SPIMSP432E4DMA.h:443
SPI_CallbackFxn transferCallbackFxn
Definition: SPIMSP432E4DMA.h:461
SPI_Transaction * tailPtr
Definition: SPIMSP432E4DMA.h:465
const SPI_FxnTable SPIMSP432E4DMA_fxnTable
SPI_TransferMode transferMode
Definition: SPIMSP432E4DMA.h:481
bool isOpen
Definition: SPIMSP432E4DMA.h:484
struct SPIMSP432E4DMA_HWAttrs SPIMSP432E4DMA_HWAttrs
SPIMSP432E4DMA Hardware attributes.
size_t priTransferSize
Definition: SPIMSP432E4DMA.h:469
uint8_t format
Definition: SPIMSP432E4DMA.h:483
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale