SPICC26X2DMA.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 /* clang-format off */
33 /*!*****************************************************************************
34  * @file SPICC26X2DMA.h
35  *
36  * @brief SPI driver implementation for a CC26XX SPI controller using
37  * the UDMA controller.
38  *
39  * # Driver include #
40  * The SPI header file should be included in an application as follows:
41  * @code
42  * #include <ti/drivers/SPI.h>
43  * #include <ti/drivers/spi/SPICC26X2DMA.h>
44  * #include <ti/drivers/dma/UDMACC26XX.h>
45  * @endcode
46  *
47  * Refer to @ref SPI.h for a complete description of APIs.
48  *
49  * Note that the user also needs to include the UDMACC26XX.h driver since the
50  * SPI uses uDMA in order to improve throughput.
51  *
52  * # Overview #
53  * The general SPI API should be used in application code, i.e. SPI_open()
54  * should be used instead of SPICC26X2DMA_open(). The board file will define the device
55  * specific config, and casting in the general API will ensure that the correct
56  * device specific functions are called.
57  * This is also reflected in the example code in [Use Cases](@ref USE_CASES_SPI_X2).
58  *
59  * # General Behavior #
60  * Before using SPI on CC26XX:
61  * - The SPI driver is initialized by calling SPI_init().
62  * - The SPI HW is configured and flags system dependencies (e.g. IOs,
63  * power, etc.) by calling SPI_open().
64  * - The SPI driver makes use of DMA in order to optimize throughput.
65  * This is handled directly by the SPI driver, so the application should never
66  * to make any calls directly to the UDMACC26XX.h driver.
67  * - This implementation supports queueing multiple transactions in callback
68  * mode. See the @ref USE_CASE_QUEUE "queueing example."
69  * - When queueing multiple transactions that should transfer one after the
70  * other, it is recommended to use the driver in 'manual start' mode by using
71  * the #SPICC26X2DMA_CMD_SET_MANUAL command. In this mode, the driver will
72  * not start any queued transfers until SPI_control() is called with the
73  * #SPICC26X2DMA_CMD_MANUAL_START command. This mode is off by default and
74  * can be disabled by using command #SPICC26X2DMA_CMD_CLR_MANUAL. See the
75  * @ref USE_CASE_MANUAL_START "Manual Start Example".
76  *
77  * The following is true for peripheral operation:
78  * - RX overrun IRQ, SPI and UDMA modules are enabled by calling SPI_transfer().
79  * - All received bytes are ignored after SPI_open() is called, until
80  * the first SPI_transfer().
81  * - If an RX overrun occur or if SPI_transferCancel() is called, RX overrun IRQ, SPI and UDMA
82  * modules are disabled, TX and RX FIFOs are flushed and all bytes are ignored.
83  * - After a successful transfer, RX overrun IRQ and SPI module remains enabled and UDMA module is disabled.
84  * SPI_transfer() must be called again before RX FIFO goes full in order to
85  * avoid overflow. If the TX buffer is underflowed, zeros will be output.
86  * It is safe to call another SPI_transfer() from the transfer callback,
87  * see [Continuous Peripheral Transfer] (@ref USE_CASE_CST_X2) use case below.
88  * - The SPI driver supports partial return, that can be used if the
89  * transfer size is unknown. If #SPICC26X2DMA_CMD_RETURN_PARTIAL_ENABLE is
90  * passed to SPI_control(), the transfer will end when chip select is
91  * deasserted. The #SPI_Transaction.status and the #SPI_Transaction.count
92  * will be updated to indicate whether the transfer ended due to a chip
93  * select deassertion and how many bytes were transferred. See
94  * [Peripheral Mode With Return Partial] (@ref USE_CASE_RP_X2) use case below.
95  * - When queueing several transactions if the first is a 'short'
96  * transaction (8 or fewer frames), it is required to use
97  * @ref USE_CASE_MANUAL_START "Manual Start mode."
98  *
99  * @warning The SPI modules on the CC13x0, CC26x0, and CC26x0R2 devices have a
100  * bug which may result in TX data being lost when operating in SPI peripheral
101  * mode. Please refer to the device errata sheet for full details. The SPI
102  * protocol should therefore include a data integrity check, such as
103  * appending a CRC to the payload to ensure all the data was transmitted
104  * correctly by the SPI peripheral.
105  *
106  * The following apply for controller operation:
107  * - SPI and UDMA modules are enabled by calling SPI_transfer().
108  * - If the SPI_transfer() succeeds, SPI module is enabled and UDMA module is disabled.
109  * - If SPI_transferCancel() is called, SPI and UDMA modules are disabled and
110  * TX and RX FIFOs are flushed.
111  * .
112  * After SPI operation has ended:
113  * - Release system dependencies for SPI by calling SPI_close().
114  * .
115  * The callback function is always called in a SWI context.
116  *
117  * @warning The application should avoid transmitting data stored in flash via SPI if the application
118  * might switch to the XOSC_HF, the high frequency external oscillator, during this transfer.
119  *
120  * # Error handling #
121  * If an RX overrun occurs during peripheral operation:
122  * - If a transfer is ongoing, all bytes received up until the error occurs will be returned, with the
123  * error signaled in the #SPI_Transaction.status field. RX overrun IRQ, SPI and UDMA modules are then disabled,
124  * TX and RX FIFOs are flushed and all bytes will be ignored until a new transfer is issued.
125  * - If a transfer is not ongoing, RX overrun IRQ, SPI and UDMA modules are disabled,
126  * TX and RX FIFOs are flushed and all bytes will be ignored until a new transfer is issued.
127  *
128  * # Timeout #
129  * Timeout can occur in #SPI_MODE_BLOCKING, there's no timeout in #SPI_MODE_CALLBACK.
130  * When in #SPI_MODE_CALLBACK, the transfer must be cancelled by calling SPI_transferCancel().@n
131  * If a timeout happens in either #SPI_PERIPHERAL or #SPI_CONTROLLER mode,
132  * the receive buffer will contain the bytes received up until the timeout occurred.
133  * The SPI transaction status will be set to #SPI_TRANSFER_FAILED.
134  * The SPI transaction count will be set to the number of bytes sent/received before timeout.
135  * The remaining bytes will be flushed from the TX FIFO so that the subsequent transfer
136  * can be executed correctly. Note that specifying a timeout prevents the
137  * driver from performing a polling transfer when in peripheral mode.
138  *
139  * # Power Management #
140  * The TI-RTOS power management framework will try to put the device into the most
141  * power efficient mode whenever possible. Please see the technical reference
142  * manual for further details on each power mode.
143  *
144  * The SPICC26X2DMA.h driver is setting a power constraint during transfers to keep
145  * the device out of standby. When the transfer has finished, the power
146  * constraint is released.
147  * The following statements are valid:
148  * - After SPI_open(): the device is still allowed to enter standby.
149  * - In peripheral mode:
150  * - During SPI_transfer(): the device cannot enter standby, only idle.
151  * - After an RX overflow: device is allowed to enter standby.
152  * - After a successful SPI_transfer(): the device is allowed
153  * to enter standby, but SPI module remains enabled.
154  * - _Note_: In peripheral mode, the device might enter standby while a byte is being
155  * transferred if SPI_transfer() is not called again after a successful
156  * transfer. This could result in corrupt data being transferred.
157  * - Application thread should typically either issue another transfer after
158  * SPI_transfer() completes successfully, or call
159  * SPI_transferCancel() to disable the SPI module and thus assuring that no data
160  * is received while entering standby.
161  * .
162  * - In controller mode:
163  * - During SPI_transfer(): the device cannot enter standby, only idle.
164  * - After SPI_transfer() succeeds: the device can enter standby.
165  * - If SPI_transferCancel() is called: the device can enter standby.
166  *
167  * @note The external hardware connected to the SPI might have some pull configured on the
168  * SPI lines. When the SPI is inactive, this might cause leakage on the IO and the
169  * current consumption to increase. The application must configure a pull configuration
170  * that aligns with the external hardware.
171  * See [Ensure low power during inactive periods] (@ref USE_CASE_LPWR_X2) for code example.
172  *
173  * # SPI details #
174  * ## Chip Select #
175  * This SPI controller supports a hardware chip select pin. Refer to the
176  * user manual on how this hardware chip select pin behaves in regards
177  * to the SPI frame format.
178  *
179  * <table>
180  * <tr>
181  * <th>Chip select type</th>
182  * <th>SPI_CONTROLLER mode</th>
183  * <th>SPI_PERIPHERAL mode</th>
184  * </tr>
185  * <tr>
186  * <td>Hardware chip select</td>
187  * <td>No action is needed by the application to select the peripheral.</td>
188  * <td>See the device documentation on it's chip select requirements.</td>
189  * </tr>
190  * <tr>
191  * <td>Software chip select</td>
192  * <td>The application is responsible to ensure that correct SPI peripheral is
193  * selected before performing a SPI_transfer().</td>
194  * <td>See the device documentation on it's chip select requirements.</td>
195  * </tr>
196  * </table>
197  *
198  * ### Multiple peripherals when operating in controller mode #
199  * In a scenario where the SPI module is operating in controller mode with multiple
200  * SPI peripherals, the chip select pin can be reallocated at runtime to select the
201  * appropriate peripheral device. See [Controller Mode With Multiple Peripherals](@ref USE_CASE_MMMS_X2) use case below.
202  * This is only relevant when chip select is a hardware chip select. Otherwise the application
203  * can control the chip select pins directly using the GPIO driver.
204  *
205  * ## Data Frames #
206  *
207  * SPI data frames can be any size from 4-bits to 16-bits. If the dataSize in
208  * #SPI_Params is greater that 8-bits, then the SPICC26X2DMA driver
209  * implementation will assume that the #SPI_Transaction txBuf and rxBuf
210  * point to an array of 16-bit uint16_t elements.
211  *
212  * dataSize | buffer element size |
213  * -------- | ------------------- |
214  * 4-8 bits | uint8_t |
215  * 9-16 bits | uint16_t |
216  *
217  * ## Bit Rate ##
218  * When the SPI is configured as SPI peripheral, the maximum bit rate is 4MHz.
219  *
220  * When the SPI is configured as SPI controller, the maximum bit rate is 12MHz.
221  *
222  *
223  * ## UDMA #
224  * ### Interrupts #
225  * The UDMA module generates IRQs on the SPI interrupt vector. This driver automatically
226  * installs a UDMA aware Hwi (interrupt) to service the assigned UDMA channels.
227  *
228  * ### Transfer Size Limit #
229  *
230  * The UDMA controller only supports data transfers of up to 1024 data frames.
231  * A transfer with more than 1024 frames will be transmitted/received in
232  * multiple 1024 sized portions until all data has been transmitted/received.
233  * A data frame can be 4 to 16 bits in length.
234  *
235  * ### Scratch Buffers #
236  * A uint16_t scratch buffer is used to allow SPI_transfers where txBuf or rxBuf
237  * are NULL. Rather than requiring txBuf or rxBuf to have a dummy buffer of size
238  * of the transfer count, a single-word UDMA accessible uint16_t scratch buffer is used.
239  * When rxBuf is NULL, the UDMA will transfer all the received SPI data into the
240  * scratch buffer as a "bit-bucket".
241  * When txBuf is NULL, the scratch buffer is initialized to defaultTxBufValue
242  * so the uDMA will send some known value.
243  * Each SPI driver instance uses its own scratch buffer.
244  *
245  * ### TX and RX buffers #
246  * Before SPI_transfer, txBuf should be filled with the outgoing SPI data. These
247  * data are sent out during the transfer, while the incoming data are received
248  * into rxBuf. To save memory space, txBuf and rxBuf can be assigned to the same
249  * buffer location. At the beginning of the transfer, this buffer holds outgoing
250  * data. At the end of the transfer, the outgoing data are overwritten and
251  * the buffer holds the received SPI data.
252  *
253  * ## Polling SPI transfers #
254  * When used in blocking mode small SPI transfers are can be done by polling
255  * the peripheral & sending data frame-by-frame. A controller device can perform
256  * the transfer immediately and return, but a peripheral will block until it
257  * receives the number of frames specified in the SPI_Transfer() call.
258  * The minDmaTransferSize field in the hardware attributes is
259  * the threshold; if the transaction count is below the threshold a polling
260  * transfer is performed; otherwise a DMA transfer is done. This is intended
261  * to reduce the overhead of setting up a DMA transfer to only send a few
262  * data frames.
263  *
264  * Notes:
265  * - Specifying a timeout prevents peripheral devices from using polling transfers.
266  * - Keep in mind that during polling transfers the current task
267  * is still being executed; there is no context switch to another task.
268  *
269  * # Supported Functions #
270  * Generic API function | API function | Description
271  * ----------------------|------------------------------- |-------------------------------------------------------------
272  * SPI_init() | SPICC26X2DMA_init() | Initialize SPI driver
273  * SPI_open() | SPICC26X2DMA_open() | Initialize SPI HW and set system dependencies
274  * SPI_close() | SPICC26X2DMA_close() | Disable SPI and UDMA HW and release system dependencies
275  * SPI_control() | SPICC26X2DMA_control() | Configure an already opened SPI handle
276  * SPI_transfer() | SPICC26X2DMA_transfer() | Start transfer from SPI
277  * SPI_transferCancel() | SPICC26X2DMA_transferCancel() | Cancel ongoing transfer from SPI
278  *
279  * @note All calls should go through the generic API
280  *
281  * ## Use Cases @anchor USE_CASES_SPI_X2 ##
282  * ### Basic Peripheral Mode #
283  * Receive 100 bytes over SPI in #SPI_MODE_BLOCKING.
284  * @code
285  * SPI_Handle handle;
286  * SPI_Params params;
287  * SPI_Transaction transaction;
288  * uint8_t rxBuf[100]; // Receive buffer
289  *
290  * // Init SPI and specify non-default parameters
291  * SPI_Params_init(&params);
292  * params.bitRate = 1000000;
293  * params.frameFormat = SPI_POL1_PHA1;
294  * params.mode = SPI_PERIPHERAL;
295  *
296  * // Configure the transaction
297  * transaction.count = 100;
298  * transaction.txBuf = NULL;
299  * transaction.rxBuf = rxBuf;
300  *
301  * // Open the SPI and perform the transfer
302  * handle = SPI_open(CONFIG_SPI, &params);
303  * SPI_transfer(handle, &transaction);
304  * @endcode
305  *
306  * ### Peripheral Mode With Return Partial @anchor USE_CASE_RP_X2 #
307  * This use case will perform a transfer in #SPI_MODE_BLOCKING until the wanted
308  * amount of bytes is transferred or until chip select is deasserted by the SPI
309  * controller.
310  * This SPI_transfer() call can be used when unknown amount of bytes shall
311  * be transferred.
312  * <br> Note: Partial return is also possible in #SPI_MODE_CALLBACK mode.
313  * In callback mode, partial transfers can be queued by calling SPI_transfer()
314  * multiple times.
315  * <br> Note: Polling transfers are not available when using return partial mode.
316  * @code
317  * SPI_Handle handle;
318  * SPI_Params params;
319  * SPI_Transaction transaction;
320  * uint8_t rxBuf[100]; // Receive buffer
321  *
322  * // Init SPI and specify non-default parameters
323  * SPI_Params_init(&params);
324  * params.bitRate = 1000000;
325  * params.frameFormat = SPI_POL1_PHA1;
326  * params.mode = SPI_PERIPHERAL;
327  *
328  * // Configure the transaction
329  * transaction.count = 100;
330  * transaction.txBuf = NULL;
331  * transaction.rxBuf = rxBuf;
332  *
333  * // Open the SPI and initiate the partial read
334  * handle = SPI_open(CONFIG_SPI, &params);
335  *
336  * // Enable RETURN_PARTIAL
337  * SPI_control(handle, SPICC26X2DMA_RETURN_PARTIAL_ENABLE, NULL);
338  *
339  * // Begin transfer
340  * SPI_transfer(handle, &transaction);
341  * @endcode
342  *
343  * ### Continuous Peripheral Transfer In #SPI_MODE_CALLBACK @anchor USE_CASE_CST_X2 #
344  * This use case will configure the SPI driver to transfer continuously in
345  * #SPI_MODE_CALLBACK, 16 bytes at the time and echoing received data after every
346  * 16 bytes.
347  * @code
348  * // Callback function
349  * static void transferCallback(SPI_Handle handle, SPI_Transaction *transaction)
350  * {
351  * // Start another transfer
352  * SPI_transfer(handle, transaction);
353  * }
354  *
355  * static void taskFxn(uintptr_t a0, uintptr_t a1)
356  * {
357  * SPI_Handle handle;
358  * SPI_Params params;
359  * SPI_Transaction transaction;
360  * uint8_t buf[16]; // Receive and transmit buffer
361  *
362  * // Init SPI and specify non-default parameters
363  * SPI_Params_init(&params);
364  * params.bitRate = 1000000;
365  * params.frameFormat = SPI_POL1_PHA1;
366  * params.mode = SPI_PERIPHERAL;
367  * params.transferMode = SPI_MODE_CALLBACK;
368  * params.transferCallbackFxn = transferCallback;
369  *
370  * // Configure the transaction
371  * transaction.count = 16;
372  * transaction.txBuf = buf;
373  * transaction.rxBuf = buf;
374  *
375  * // Open the SPI and initiate the first transfer
376  * handle = SPI_open(CONFIG_SPI, &params);
377  * SPI_transfer(handle, &transaction);
378  *
379  * // Wait forever
380  * while(true);
381  * }
382  * @endcode
383  *
384  * ### Basic Controller Mode #
385  * This use case will configure a SPI controller to send the data in txBuf while receiving data to rxBuf in
386  * BLOCKING_MODE.
387  * @code
388  * SPI_Handle handle;
389  * SPI_Params params;
390  * SPI_Transaction transaction;
391  * uint8_t txBuf[] = "Hello World"; // Transmit buffer
392  * uint8_t rxBuf[11]; // Receive buffer
393  *
394  * // Init SPI and specify non-default parameters
395  * SPI_Params_init(&params);
396  * params.bitRate = 1000000;
397  * params.frameFormat = SPI_POL1_PHA1;
398  * params.mode = SPI_CONTROLLER;
399  *
400  * // Configure the transaction
401  * transaction.count = sizeof(txBuf);
402  * transaction.txBuf = txBuf;
403  * transaction.rxBuf = rxBuf;
404  *
405  * // Open the SPI and perform the transfer
406  * handle = SPI_open(CONFIG_SPI, &params);
407  * SPI_transfer(handle, &transaction);
408  * @endcode
409  *
410  * ### Controller Mode With Multiple Peripherals @anchor USE_CASE_MMMS_X2 #
411  * This use case will configure a SPI controller to send data to one peripheral and then to another in
412  * BLOCKING_MODE. It is assumed that the board file is configured so that the two chip select
413  * pins have a default setting of a high output and that the #SPICC26X2DMA_HWAttrs used points
414  * to one of them since the SPI driver will revert to this default setting when switching the
415  * chip select pin.
416  *
417  * @code
418  * // From ti_drivers_config.c
419  * // Use the sysconfig settings to make sure both pins are set to HIGH when not in use
420  * GPIO_PinConfig gpioPinConfigs[31] = {
421  * ...
422  * GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH, // CONFIG_CSN_0
423  * ...
424  * GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH, // CONFIG_CSN_1
425  * }
426  *
427  * const SPICC26X2DMA_HWAttrs SPICC26X2DMAHWAttrs[CC2650_SPICOUNT] = {
428  * { // Use SPI0 module with default chip select on CONFIG_CSN_0
429  * .baseAddr = SSI0_BASE,
430  * .intNum = INT_SSI0,
431  * .intPriority = ~0,
432  * .swiPriority = 0,
433  * .defaultTxBufValue = 0,
434  * .powerMngrId = PERIPH_SSI0,
435  * .rxChannelIndex = UDMA_CHAN_SSI0_RX,
436  * .txChannelIndex = UDMA_CHAN_SSI0_TX,
437  * .picoPin = CONFIG_SPI0_PICO,
438  * .pociPin = CONFIG_SPI0_POCI,
439  * .clkPin = CONFIG_SPI0_CLK,
440  * .csnPin = CONFIG_CSN_0
441  * }
442  *
443  * // From your_application.c
444  * static void taskFxn(uintptr_t a0, uintptr_t a1)
445  * {
446  * SPI_Handle handle;
447  * SPI_Params params;
448  * SPI_Transaction transaction;
449  * uint_least8_t csnPin1 = CONFIG_CSN_1;
450  * uint8_t txBuf[] = "Hello World"; // Transmit buffer
451  *
452  * // Init SPI and specify non-default parameters
453  * SPI_Params_init(&params);
454  * params.bitRate = 1000000;
455  * params.frameFormat = SPI_POL1_PHA1;
456  * params.mode = SPI_CONTROLLER;
457  *
458  * // Configure the transaction
459  * transaction.count = sizeof(txBuf);
460  * transaction.txBuf = txBuf;
461  * transaction.rxBuf = NULL;
462  *
463  * // Open the SPI and perform transfer to the first peripheral
464  * handle = SPI_open(CONFIG_SPI, &params);
465  * SPI_transfer(handle, &transaction);
466  *
467  * // Then switch chip select pin and perform transfer to the second peripheral
468  * SPI_control(handle, SPICC26X2DMA_SET_CSN_PIN, &csnPin1);
469  * SPI_transfer(handle, &transaction);
470  * }
471  * @endcode
472  *
473  * ### Queueing Transactions in Callback Mode #
474  * @anchor USE_CASE_QUEUE
475  * Below is an example of queueing three transactions
476  * @code
477  * // SPI already opened in callback mode
478  * SPI_Transaction t0, t1, t2;
479  *
480  * t0.txBuf = txBuff0;
481  * t0.rxBuf = rxBuff0;
482  * t0.count = 2000;
483  *
484  * t1.txBuf = txBuff1;
485  * t1.rxBuf = rxBuff1;
486  * t1.count = 1000;
487  *
488  * t2.txBuf = txBuff2;
489  * t2.rxBuf = NULL;
490  * t2.count = 1000;
491  *
492  * bool transferOk = false;
493  *
494  * if (SPI_transfer(spiHandle, &t0)) {
495  * if (SPI_transfer(spiHandle, &t1)) {
496  * transferOk = SPI_transfer(spiHandle, &t2);
497  * }
498  * }
499  * }
500  * @endcode
501  *
502  * ### Queueing in Manual Start Mode#
503  * This example shows a peripheral device queueing two transactions that will
504  * complete one after the other. From the controller's perspective there will be
505  * one long transfer.
506  * @note Manual mode also works while the device is in #SPI_CONTROLLER mode. The
507  * control call to MANUAL_START will start the transfers.
508  *
509  * @warning Manual start mode should not be enabled or disabled while a
510  * transaction is in progress.
511  *
512  * @anchor USE_CASE_MANUAL_START
513  * @code
514  * SPI_Handle spi;
515  * SPI_Params params;
516  * SPI_Transaction t0, t1;
517  * uint8_t status = SPI_STATUS_SUCCESS;
518  *
519  * SPI_Params_init(&params);
520  * params.mode = SPI_PERIPHERAL;
521  * spi = SPI_open(CONFIG_SPI, &params);
522  *
523  * if (spi == NULL) {
524  * exit(0);
525  * }
526  *
527  * // Enable manual start mode
528  * SPI_control(spi, SPICC26X2DMA_CMD_SET_MANUAL, NULL);
529  *
530  * // Queue transactions
531  * t0.txBuf = txBuff0;
532  * t0.rxBuf = rxBuff0;
533  * t0.count = 2000;
534  * if (!SPI_transfer(spi, &t0)) {
535  * status = SPI_STATUS_FAIL;
536  * }
537  *
538  * t1.txBuf = txBuff1;
539  * t1.rxBuf = rxBuff1;
540  * t1.count = 1000;
541  * if (!SPI_transfer(spi, &t1)) {
542  * status = SPI_STATUS_FAIL;
543  * }
544  *
545  * // Enable the transfers
546  * if (status == SPI_STATUS_SUCCESS) {
547  * SPI_control(spi, SPICC26X2DMA_CMD_MANUAL_START, NULL);
548  * }
549  * else {
550  * status = SPI_STATUS_FAILURE;
551  * }
552  *
553  * // At this point the peripheral is ready for the controller to start the transfer
554  * // Assume the callback implementation (not shown) posts a semaphore when
555  * // the last transaction completes
556  * sem_wait(&spiSemaphore);
557  *
558  * // Disable manual start mode
559  * SPI_control(spi, SPICC26X2DMA_CMD_CLR_MANUAL, NULL);
560  *
561  * @endcode
562  *
563  * ### Ensure low power during inactive periods @anchor USE_CASE_LPWR_X2 #
564  * External hardware connected on the SPI, i.e. SPI host/peripheral, might have configured
565  * a pull on one or more of the SPI lines. Dependent on the hardware, it might conflict
566  * with the pull used for the CC26XX SPI. To avoid increased leakage and ensure the lowest
567  * possible power consumption when the SPI is inactive, the application must configure a
568  * matching pull on the SPI IOs. An example of how this can be done is shown below.
569  *
570  * @code
571  * SPI_Params params;
572  * SPI_Transaction transaction;
573  * uint8_t txBuf[] = "Heartbeat"; // Transmit buffer
574  * uint8_t rxBuf[9]; // Receive buffer
575  * uint32_t standbyDurationMs = 100;
576  *
577  * // Init SPI and specify non-default parameters
578  * SPI_Params_init(&params);
579  * params.bitRate = 1000000;
580  * params.frameFormat = SPI_POL1_PHA1;
581  * params.mode = SPI_CONTROLLER;
582  *
583  * // Configure the transaction
584  * transaction.count = sizeof(txBuf);
585  * transaction.txBuf = txBuf;
586  * transaction.rxBuf = rxBuf;
587  *
588  * // Open the SPI and perform the transfer
589  * handle = SPI_open(CONFIG_SPI_0, &params);
590  *
591  * // Apply low power sleep pull config for POCI
592  * GPIO_setConfig(CONFIG_GPIO_SPI_0_POCI, GPIO_CFG_IN_PU);
593  *
594  * // Do forever
595  * while(1) {
596  * // Transfer data
597  * SPI_transfer(handle, &transaction);
598  * // Sleep
599  * Task_sleep(standbyDurationMs*100);
600  * }
601  * @endcode
602  *
603  * ### Wake Up On Chip Select Deassertion In Peripheral Mode Using #SPI_MODE_CALLBACK #
604  * This example demonstrates using a GPIO callback on Chip Select to wake up the device
605  * to allow low power modes while waiting for a chip select edge.
606  *
607  * In sysconfig or the board file, the CSN GPIO should be configured
608  * as input/pull up with an interrupt on falling edge. Otherwise, SPI_close()
609  * will reset the pin to the wrong settings and you may see line glitches.
610  *
611  * *Note: The SPI controller must allow enough time between deasserting the chip select and the
612  * start of the transaction for the SPI peripheral to wake up and open up the SPI driver.
613  *
614  * @code
615  * // Global variables
616  * SPI_Handle spiHandle
617  * SPI_Params spiParams;
618  * SPI_Transaction spiTransaction;
619  * const uint8_t transferSize = 8;
620  * uint8_t txBuf[8];
621  *
622  * // Chip select callback
623  * static void chipSelectCallback(uint_least8_t)
624  * {
625  * // Open SPI driver, which will override any previous GPIO configuration
626  * spiHandle = SPI_open(CONFIG_SPI, &spiParams);
627  * // Issue the transfer
628  * SPI_transfer(spiHandle, &spiTransaction);
629  * }
630  *
631  * // SPI transfer callback
632  * static void transferCallback(SPI_Handle handle, SPI_Transaction *transaction)
633  * {
634  * // Close the SPI driver
635  * SPI_close(handle);
636  *
637  * // Note: SPI_close() will reset the pin configuration, so it is important to
638  * // set the default values correctly in sysconfig. We just need to set the
639  * // callback and enable the falling edge interrupt
640  *
641  * GPIO_setCallback(CS_PIN_INDEX, chipSelectCallback);
642  * GPIO_enableInt(CS_PIN_INDEX);
643  * }
644  *
645  * // From your_application.c
646  * static void taskFxn(uintptr_t a0, uintptr_t a1)
647  * {
648  * uint8_t i;
649  *
650  * // Setup SPI params
651  * SPI_Params_init(&spiParams);
652  * spiParams.bitRate = 1000000;
653  * spiParams.frameFormat = SPI_POL1_PHA1;
654  * spiParams.mode = SPI_PERIPHERAL;
655  * spiParams.dataSize = transferSize;
656  * spiParams.transferMode = SPI_MODE_CALLBACK;
657  * spiParams.transferCallbackFxn = transferCallback;
658  *
659  * // Setup SPI transaction
660  * spiTransaction.arg = NULL;
661  * spiTransaction.count = transferSize;
662  * spiTransaction.txBuf = txBuf;
663  * spiTransaction.rxBuf = txBuf;
664  *
665  * // First echo message
666  * for (i = 0; i < transferSize; i++) {
667  * txBuf[i] = i;
668  * }
669  *
670  * // Configure chip select callback
671  * GPIO_setCallback(CS_PIN_INDEX, chipSelectCallback);
672  * GPIO_enableInt(CS_PIN_INDEX);
673  *
674  * // Wait forever
675  * while(true);
676  * }
677  * @endcode
678  *
679  * <hr>
680  */
681 /* clang-format on */
682 #ifndef ti_drivers_spi_SPICC26X2DMA__include
683 #define ti_drivers_spi_SPICC26X2DMA__include
684 
685 #include <stdint.h>
686 #include <ti/drivers/SPI.h>
688 #include <ti/drivers/Power.h>
690 
691 #include <ti/drivers/dpl/HwiP.h>
692 #include <ti/drivers/dpl/SemaphoreP.h>
693 #include <ti/drivers/dpl/SwiP.h>
694 
695 #ifdef __cplusplus
696 extern "C" {
697 #endif
698 
709 /* Add SPICC26X2DMA_STATUS_* macros here */
710 
731 #define SPICC26X2DMA_CMD_RETURN_PARTIAL_ENABLE (SPI_CMD_RESERVED + 0)
732 
740 #define SPICC26X2DMA_CMD_RETURN_PARTIAL_DISABLE (SPI_CMD_RESERVED + 1)
741 
753 #define SPICC26X2DMA_CMD_SET_CSN_PIN (SPI_CMD_RESERVED + 2)
754 
764 #define SPICC26X2DMA_CMD_CLEAR_CSN_PIN (SPI_CMD_RESERVED + 3)
765 
779 #define SPICC26X2DMA_CMD_SET_MANUAL (SPI_CMD_RESERVED + 4)
780 
790 #define SPICC26X2DMA_CMD_CLR_MANUAL (SPI_CMD_RESERVED + 5)
791 
802 #define SPICC26X2DMA_CMD_MANUAL_START (SPI_CMD_RESERVED + 6)
803 
806 /* BACKWARDS COMPATIBILITY */
807 #define SPICC26X2DMA_RETURN_PARTIAL_ENABLE SPICC26X2DMA_CMD_RETURN_PARTIAL_ENABLE
808 #define SPICC26X2DMA_RETURN_PARTIAL_DISABLE SPICC26X2DMA_CMD_RETURN_PARTIAL_DISABLE
809 #define SPICC26X2DMA_SET_CSN_PIN SPICC26X2DMA_CMD_SET_CSN_PIN
810 /* END BACKWARDS COMPATIBILITY */
811 
818 
828 typedef enum
829 {
833 
841 typedef enum
842 {
847 
902 typedef struct
903 {
905  uint32_t baseAddr;
907  uint8_t intNum;
922  uint8_t intPriority;
929  uint32_t swiPriority;
931  PowerCC26XX_Resource powerMngrId;
939  volatile tDMAControlTable *dmaTxTableEntryPri;
941  volatile tDMAControlTable *dmaRxTableEntryPri;
943  volatile tDMAControlTable *dmaTxTableEntryAlt;
945  volatile tDMAControlTable *dmaRxTableEntryAlt;
947  int32_t txPinMux;
949  int32_t rxPinMux;
951  int32_t clkPinMux;
953  int32_t csnPinMux;
955  uint_least8_t picoPin;
957  uint_least8_t pociPin;
959  uint_least8_t clkPin;
961  uint_least8_t csnPin;
962 
966 
972 typedef struct
973 {
974  HwiP_Struct hwi;
976  SwiP_Struct swi;
977  SemaphoreP_Struct transferComplete;
978 
984 
985  size_t framesQueued;
989 
990  uint32_t activeChannel;
991  uint32_t bitRate;
992  uint32_t dataSize;
993  uint32_t transferTimeout;
994  uint32_t busyBit;
995 
996  uint16_t rxScratchBuf;
997  uint16_t txScratchBuf;
998 
1001  uint8_t format;
1002  uint_least8_t csnPin;
1004  bool isOpen;
1007 
1008 #ifdef __cplusplus
1009 }
1010 #endif
1011 
1012 #endif /* ti_drivers_spi_SPICC26X2DMA__include */
Definition: SPICC26X2DMA.h:845
uint_least8_t csnPin
Definition: SPICC26X2DMA.h:1002
uint16_t defaultTxBufValue
Definition: SPICC26X2DMA.h:933
uint32_t minDmaTransferSize
Definition: SPICC26X2DMA.h:964
SPI_Transaction * headPtr
Definition: SPICC26X2DMA.h:980
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
uint32_t txChannelBitMask
Definition: SPICC26X2DMA.h:937
SPI_Transaction * completedTransfers
Definition: SPICC26X2DMA.h:982
uint32_t bitRate
Definition: SPICC26X2DMA.h:991
uint32_t rxChannelBitMask
Definition: SPICC26X2DMA.h:935
SPI_TransferMode
SPI transfer mode determines the whether the SPI controller operates synchronously or asynchronously...
Definition: SPI.h:629
SPI_Transaction * tailPtr
Definition: SPICC26X2DMA.h:981
Power Manager.
uint_least8_t clkPin
Definition: SPICC26X2DMA.h:959
UDMACC26XX Global configuration.
Definition: UDMACC26XX.h:253
Power manager interface for CC26XX/CC13XX.
int32_t rxPinMux
Definition: SPICC26X2DMA.h:949
Power_NotifyObj spiPostObj
Definition: SPICC26X2DMA.h:975
uint16_t rxScratchBuf
Definition: SPICC26X2DMA.h:996
uint32_t transferTimeout
Definition: SPICC26X2DMA.h:993
volatile tDMAControlTable * dmaTxTableEntryAlt
Definition: SPICC26X2DMA.h:943
uint32_t activeChannel
Definition: SPICC26X2DMA.h:990
volatile tDMAControlTable * dmaRxTableEntryAlt
Definition: SPICC26X2DMA.h:945
size_t altTransferSize
Definition: SPICC26X2DMA.h:988
SPI_Mode mode
Definition: SPICC26X2DMA.h:1000
uint8_t intNum
Definition: SPICC26X2DMA.h:907
SPI_TransferMode transferMode
Definition: SPICC26X2DMA.h:999
const SPI_FxnTable SPICC26X2DMA_fxnTable
Definition: SPICC26X2DMA.h:830
The definition of a SPI function table that contains the required set of functions to control a speci...
Definition: SPI.h:718
uint32_t swiPriority
SPI SWI priority. The higher the number, the higher the priority. The minimum is 0 and the maximum is...
Definition: SPICC26X2DMA.h:929
SPICC26X2DMA_ReturnPartial returnPartial
Definition: SPICC26X2DMA.h:1003
size_t framesQueued
Definition: SPICC26X2DMA.h:985
SPICC26X2DMA Hardware attributes.
Definition: SPICC26X2DMA.h:902
uint8_t format
Definition: SPICC26X2DMA.h:1001
SwiP_Struct swi
Definition: SPICC26X2DMA.h:976
volatile tDMAControlTable * dmaRxTableEntryPri
Definition: SPICC26X2DMA.h:941
volatile tDMAControlTable * dmaTxTableEntryPri
Definition: SPICC26X2DMA.h:939
UDMACC26XX driver implementation.
uint32_t busyBit
Definition: SPICC26X2DMA.h:994
A SPI_Transaction data structure is used with SPI_transfer(). It indicates how many SPI_FrameFormat f...
Definition: SPI.h:570
Power notify object structure.
Definition: Power.h:442
Definition: SPICC26X2DMA.h:843
SPI_Mode
Definitions for various SPI modes of operation.
Definition: SPI.h:597
uint_least8_t pociPin
Definition: SPICC26X2DMA.h:957
UDMACC26XX_Handle udmaHandle
Definition: SPICC26X2DMA.h:983
SemaphoreP_Struct transferComplete
Definition: SPICC26X2DMA.h:977
SPICC26X2DMA_ReturnPartial
Definition: SPICC26X2DMA.h:841
int32_t clkPinMux
Definition: SPICC26X2DMA.h:951
uint_least8_t csnPin
Definition: SPICC26X2DMA.h:961
Definition: SPICC26X2DMA.h:831
size_t framesTransferred
Definition: SPICC26X2DMA.h:986
uint16_t txScratchBuf
Definition: SPICC26X2DMA.h:997
uint_least8_t picoPin
Definition: SPICC26X2DMA.h:955
SPICC26X2DMA_FrameSize
Definition: SPICC26X2DMA.h:828
int32_t csnPinMux
Definition: SPICC26X2DMA.h:953
size_t priTransferSize
Definition: SPICC26X2DMA.h:987
int32_t txPinMux
Definition: SPICC26X2DMA.h:947
bool manualStart
Definition: SPICC26X2DMA.h:1005
SPI_CallbackFxn transferCallbackFxn
Definition: SPICC26X2DMA.h:979
bool isOpen
Definition: SPICC26X2DMA.h:1004
PowerCC26XX_Resource powerMngrId
Definition: SPICC26X2DMA.h:931
SPICC26X2DMA Object.
Definition: SPICC26X2DMA.h:972
Definition: SPICC26X2DMA.h:844
HwiP_Struct hwi
Definition: SPICC26X2DMA.h:974
uint32_t dataSize
Definition: SPICC26X2DMA.h:992
uint8_t intPriority
SPI CC26XXDMA Peripheral&#39;s interrupt priority.
Definition: SPICC26X2DMA.h:922
uint32_t baseAddr
SPI Peripheral&#39;s base address.
Definition: SPICC26X2DMA.h:905
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale