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