SPICC26X2DMA.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2022, 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() |
272  * Initialize SPI driver | | SPI_open() | SPICC26X2DMA_open() |
273  * Initialize SPI HW and set system dependencies | | SPI_close() | SPICC26X2DMA_close() |
274  * Disable SPI and UDMA HW and release system dependencies | | SPI_control() | SPICC26X2DMA_control() |
275  * Configure an already opened SPI handle | | SPI_transfer() | SPICC26X2DMA_transfer() |
276  * Start transfer from SPI | | SPI_transferCancel() | SPICC26X2DMA_transferCancel()
277  * | 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 Slave 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_SLAVE;
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  * ### Slave Mode With Return Partial @anchor USE_CASE_RP_X2 #
307  * This use case will perform a transfer in #SPI_MODE_BLOCKING until the wanted amount of bytes is
308  * transferred or until chip select is deasserted by the SPI master.
309  * This SPI_transfer() call can be used when unknown amount of bytes shall
310  * be transferred.
311  * Note: The partial return is also possible in #SPI_MODE_CALLBACK mode.
312  * Note: Polling transfers are not available when using return partial mode.
313  * @code
314  * SPI_Handle handle;
315  * SPI_Params params;
316  * SPI_Transaction transaction;
317  * uint8_t rxBuf[100]; // Receive buffer
318  *
319  * // Init SPI and specify non-default parameters
320  * SPI_Params_init(&params);
321  * params.bitRate = 1000000;
322  * params.frameFormat = SPI_POL1_PHA1;
323  * params.mode = SPI_SLAVE;
324  *
325  * // Configure the transaction
326  * transaction.count = 100;
327  * transaction.txBuf = NULL;
328  * transaction.rxBuf = rxBuf;
329  *
330  * // Open the SPI and initiate the partial read
331  * handle = SPI_open(CONFIG_SPI, &params);
332  *
333  * // Enable RETURN_PARTIAL
334  * SPI_control(handle, SPICC26X2DMA_RETURN_PARTIAL_ENABLE, NULL);
335  *
336  * // Begin transfer
337  * SPI_transfer(handle, &transaction);
338  * @endcode
339  *
340  * ### Continuous Slave Transfer In #SPI_MODE_CALLBACK @anchor USE_CASE_CST_X2 #
341  * This use case will configure the SPI driver to transfer continuously in
342  * #SPI_MODE_CALLBACK, 16 bytes at the time and echoing received data after every
343  * 16 bytes.
344  * @code
345  * // Callback function
346  * static void transferCallback(SPI_Handle handle, SPI_Transaction *transaction)
347  * {
348  * // Start another transfer
349  * SPI_transfer(handle, transaction);
350  * }
351  *
352  * static void taskFxn(uintptr_t a0, uintptr_t a1)
353  * {
354  * SPI_Handle handle;
355  * SPI_Params params;
356  * SPI_Transaction transaction;
357  * uint8_t buf[16]; // Receive and transmit buffer
358  *
359  * // Init SPI and specify non-default parameters
360  * SPI_Params_init(&params);
361  * params.bitRate = 1000000;
362  * params.frameFormat = SPI_POL1_PHA1;
363  * params.mode = SPI_SLAVE;
364  * params.transferMode = SPI_MODE_CALLBACK;
365  * params.transferCallbackFxn = transferCallback;
366  *
367  * // Configure the transaction
368  * transaction.count = 16;
369  * transaction.txBuf = buf;
370  * transaction.rxBuf = buf;
371  *
372  * // Open the SPI and initiate the first transfer
373  * handle = SPI_open(CONFIG_SPI, &params);
374  * SPI_transfer(handle, &transaction);
375  *
376  * // Wait forever
377  * while(true);
378  * }
379  * @endcode
380  *
381  * ### Basic Master Mode #
382  * This use case will configure a SPI master to send the data in txBuf while receiving data to rxBuf in
383  * BLOCKING_MODE.
384  * @code
385  * SPI_Handle handle;
386  * SPI_Params params;
387  * SPI_Transaction transaction;
388  * uint8_t txBuf[] = "Hello World"; // Transmit buffer
389  * uint8_t rxBuf[11]; // Receive buffer
390  *
391  * // Init SPI and specify non-default parameters
392  * SPI_Params_init(&params);
393  * params.bitRate = 1000000;
394  * params.frameFormat = SPI_POL1_PHA1;
395  * params.mode = SPI_MASTER;
396  *
397  * // Configure the transaction
398  * transaction.count = sizeof(txBuf);
399  * transaction.txBuf = txBuf;
400  * transaction.rxBuf = rxBuf;
401  *
402  * // Open the SPI and perform the transfer
403  * handle = SPI_open(CONFIG_SPI, &params);
404  * SPI_transfer(handle, &transaction);
405  * @endcode
406  *
407  * ### Master Mode With Multiple Slaves @anchor USE_CASE_MMMS_X2 #
408  * This use case will configure a SPI master to send data to one slave and then to another in
409  * BLOCKING_MODE. It is assumed that the board file is configured so that the two chip select
410  * pins have a default setting of a high output and that the #SPICC26X2DMA_HWAttrs used points
411  * to one of them since the SPI driver will revert to this default setting when switching the
412  * chip select pin.
413  *
414  * @code
415  * // From ti_drivers_config.c
416  * // Use the sysconfig settings to make sure both pins are set to HIGH when not in use
417  * GPIO_PinConfig gpioPinConfigs[31] = {
418  * ...
419  * GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH, // CONFIG_CSN_0
420  * ...
421  * GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH, // CONFIG_CSN_1
422  * }
423  *
424  * const SPICC26X2DMA_HWAttrs SPICC26X2DMAHWAttrs[CC2650_SPICOUNT] = {
425  * { // Use SPI0 module with default chip select on CONFIG_CSN_0
426  * .baseAddr = SSI0_BASE,
427  * .intNum = INT_SSI0,
428  * .intPriority = ~0,
429  * .swiPriority = 0,
430  * .defaultTxBufValue = 0,
431  * .powerMngrId = PERIPH_SSI0,
432  * .rxChannelIndex = UDMA_CHAN_SSI0_RX,
433  * .txChannelIndex = UDMA_CHAN_SSI0_TX,
434  * .mosiPin = CONFIG_SPI0_MOSI,
435  * .misoPin = CONFIG_SPI0_MISO,
436  * .clkPin = CONFIG_SPI0_CLK,
437  * .csnPin = CONFIG_CSN_0
438  * }
439  *
440  * // From your_application.c
441  * static void taskFxn(uintptr_t a0, uintptr_t a1)
442  * {
443  * SPI_Handle handle;
444  * SPI_Params params;
445  * SPI_Transaction transaction;
446  * uint_least8_t csnPin1 = CONFIG_CSN_1;
447  * uint8_t txBuf[] = "Hello World"; // Transmit buffer
448  *
449  * // Init SPI and specify non-default parameters
450  * SPI_Params_init(&params);
451  * params.bitRate = 1000000;
452  * params.frameFormat = SPI_POL1_PHA1;
453  * params.mode = SPI_MASTER;
454  *
455  * // Configure the transaction
456  * transaction.count = sizeof(txBuf);
457  * transaction.txBuf = txBuf;
458  * transaction.rxBuf = NULL;
459  *
460  * // Open the SPI and perform transfer to the first slave
461  * handle = SPI_open(CONFIG_SPI, &params);
462  * SPI_transfer(handle, &transaction);
463  *
464  * // Then switch chip select pin and perform transfer to the second slave
465  * SPI_control(handle, SPICC26X2DMA_SET_CSN_PIN, &csnPin1);
466  * SPI_transfer(handle, &transaction);
467  * }
468  * @endcode
469  *
470  * ### Queueing Transactions in Callback Mode #
471  * @anchor USE_CASE_QUEUE
472  * Below is an example of queueing three transactions
473  * @code
474  * // SPI already opened in callback mode
475  * SPI_Transaction t0, t1, t2;
476  *
477  * t0.txBuf = txBuff0;
478  * t0.rxBuf = rxBuff0;
479  * t0.count = 2000;
480  *
481  * t1.txBuf = txBuff1;
482  * t1.rxBuf = rxBuff1;
483  * t1.count = 1000;
484  *
485  * t2.txBuf = txBuff2;
486  * t2.rxBuf = NULL;
487  * t2.count = 1000;
488  *
489  * bool transferOk = false;
490  *
491  * if (SPI_transfer(spiHandle, &t0)) {
492  * if (SPI_transfer(spiHandle, &t1)) {
493  * transferOk = SPI_transfer(spiHandle, &t2);
494  * }
495  * }
496  * }
497  * @endcode
498  *
499  * ### Queueing in Manual Start Mode#
500  * This example shows a slave device queueing two transactions that will
501  * complete one after the other. From the master's perspective there will be
502  * one long transfer.
503  * @note Manual mode also works while the device is in #SPI_MASTER mode. The
504  * control call to MANUAL_START will start the transfers.
505  *
506  * @warning Manual start mode should not be enabled or disabled while a
507  * transaction is in progress.
508  *
509  * @anchor USE_CASE_MANUAL_START
510  * @code
511  * SPI_Handle spi;
512  * SPI_Params params;
513  * SPI_Transaction t0, t1;
514  * uint8_t status = SPI_STATUS_SUCCESS;
515  *
516  * SPI_Params_init(&params);
517  * params.mode = SPI_SLAVE;
518  * spi = SPI_open(CONFIG_SPI, &params);
519  *
520  * if (spi == NULL) {
521  * exit(0);
522  * }
523  *
524  * // Enable manual start mode
525  * SPI_control(spi, SPICC26X2DMA_CMD_SET_MANUAL, NULL);
526  *
527  * // Queue transactions
528  * t0.txBuf = txBuff0;
529  * t0.rxBuf = rxBuff0;
530  * t0.count = 2000;
531  * if (!SPI_transfer(spi, &t0)) {
532  * status = SPI_STATUS_FAIL;
533  * }
534  *
535  * t1.txBuf = txBuff1;
536  * t1.rxBuf = rxBuff1;
537  * t1.count = 1000;
538  * if (!SPI_transfer(spi, &t1)) {
539  * status = SPI_STATUS_FAIL;
540  * }
541  *
542  * // Enable the transfers
543  * if (status == SPI_STATUS_SUCCESS) {
544  * SPI_control(spi, SPICC26X2DMA_CMD_MANUAL_START, NULL);
545  * }
546  * else {
547  * status = SPI_STATUS_FAILURE;
548  * }
549  *
550  * // At this point the slave is ready for the master to start the transfer
551  * // Assume the callback implementation (not shown) posts a semaphore when
552  * // the last transaction completes
553  * sem_wait(&spiSemaphore);
554  *
555  * // Disable manual start mode
556  * SPI_control(spi, SPICC26X2DMA_CMD_CLR_MANUAL, NULL);
557  *
558  * @endcode
559  *
560  * ### Ensure low power during inactive periods @anchor USE_CASE_LPWR_X2 #
561  * External hardware connected on the SPI, i.e. SPI host/slave, might have configured
562  * a pull on one or more of the SPI lines. Dependent on the hardware, it might conflict
563  * with the pull used for the CC26XX SPI. To avoid increased leakage and ensure the lowest
564  * possible power consumption when the SPI is inactive, the application must configure a
565  * matching pull on the SPI IOs. An example of how this can be done is shown below.
566  *
567  * @code
568  * SPI_Params params;
569  * SPI_Transaction transaction;
570  * uint8_t txBuf[] = "Heartbeat"; // Transmit buffer
571  * uint8_t rxBuf[9]; // Receive buffer
572  * uint32_t standbyDurationMs = 100;
573  *
574  * // Init SPI and specify non-default parameters
575  * SPI_Params_init(&params);
576  * params.bitRate = 1000000;
577  * params.frameFormat = SPI_POL1_PHA1;
578  * params.mode = SPI_MASTER;
579  *
580  * // Configure the transaction
581  * transaction.count = sizeof(txBuf);
582  * transaction.txBuf = txBuf;
583  * transaction.rxBuf = rxBuf;
584  *
585  * // Open the SPI and perform the transfer
586  * handle = SPI_open(CONFIG_SPI_0, &params);
587  *
588  * // Apply low power sleep pull config for MISO
589  * GPIO_setConfig(CONFIG_GPIO_SPI_0_MISO, GPIO_CFG_IN_PU);
590  *
591  * // Do forever
592  * while(1) {
593  * // Transfer data
594  * SPI_transfer(handle, &transaction);
595  * // Sleep
596  * Task_sleep(standbyDurationMs*100);
597  * }
598  * @endcode
599  *
600  * ### Wake Up On Chip Select Deassertion In Slave Mode Using #SPI_MODE_CALLBACK #
601  * This example demonstrates using a GPIO callback on Chip Select to wake up the device
602  * to allow low power modes while waiting for a chip select edge.
603  *
604  * In sysconfig or the board file, the CSN GPIO should be configured
605  * as input/pull up with an interrupt on falling edge. Otherwise, SPI_close()
606  * will reset the pin to the wrong settings and you may see line glitches.
607  *
608  * *Note: The SPI master must allow enough time between deasserting the chip select and the
609  * start of the transaction for the SPI slave to wake up and open up the SPI driver.
610  *
611  * @code
612  * // Global variables
613  * SPI_Handle spiHandle
614  * SPI_Params spiParams;
615  * SPI_Transaction spiTransaction;
616  * const uint8_t transferSize = 8;
617  * uint8_t txBuf[8];
618  *
619  * // Chip select callback
620  * static void chipSelectCallback(uint_least8_t)
621  * {
622  * // Open SPI driver, which will override any previous GPIO configuration
623  * spiHandle = SPI_open(CONFIG_SPI, &spiParams);
624  * // Issue the transfer
625  * SPI_transfer(spiHandle, &spiTransaction);
626  * }
627  *
628  * // SPI transfer callback
629  * static void transferCallback(SPI_Handle handle, SPI_Transaction *transaction)
630  * {
631  * // Close the SPI driver
632  * SPI_close(handle);
633  *
634  * // Note: SPI_close() will reset the pin configuration, so it is important to
635  * // set the default values correctly in sysconfig. We just need to set the
636  * // callback and enable the falling edge interrupt
637  *
638  * GPIO_setCallback(CS_PIN_INDEX, chipSelectCallback);
639  * GPIO_enableInt(CS_PIN_INDEX);
640  * }
641  *
642  * // From your_application.c
643  * static void taskFxn(uintptr_t a0, uintptr_t a1)
644  * {
645  * uint8_t i;
646  *
647  * // Setup SPI params
648  * SPI_Params_init(&spiParams);
649  * spiParams.bitRate = 1000000;
650  * spiParams.frameFormat = SPI_POL1_PHA1;
651  * spiParams.mode = SPI_SLAVE;
652  * spiParams.dataSize = transferSize;
653  * spiParams.transferMode = SPI_MODE_CALLBACK;
654  * spiParams.transferCallbackFxn = transferCallback;
655  *
656  * // Setup SPI transaction
657  * spiTransaction.arg = NULL;
658  * spiTransaction.count = transferSize;
659  * spiTransaction.txBuf = txBuf;
660  * spiTransaction.rxBuf = txBuf;
661  *
662  * // First echo message
663  * for (i = 0; i < transferSize; i++) {
664  * txBuf[i] = i;
665  * }
666  *
667  * // Configure chip select callback
668  * GPIO_setCallback(CS_PIN_INDEX, chipSelectCallback);
669  * GPIO_enableInt(CS_PIN_INDEX);
670  *
671  * // Wait forever
672  * while(true);
673  * }
674  * @endcode
675  *
676  * <hr>
677  */
678 
679 #ifndef ti_drivers_spi_SPICC26X2DMA__include
680 #define ti_drivers_spi_SPICC26X2DMA__include
681 
682 #include <stdint.h>
683 #include <ti/drivers/SPI.h>
685 #include <ti/drivers/Power.h>
687 
688 #include <ti/drivers/dpl/HwiP.h>
689 #include <ti/drivers/dpl/SemaphoreP.h>
690 #include <ti/drivers/dpl/SwiP.h>
691 
692 #ifdef __cplusplus
693 extern "C" {
694 #endif
695 
706 /* Add SPICC26X2DMA_STATUS_* macros here */
707 
728 #define SPICC26X2DMA_CMD_RETURN_PARTIAL_ENABLE (SPI_CMD_RESERVED + 0)
729 
737 #define SPICC26X2DMA_CMD_RETURN_PARTIAL_DISABLE (SPI_CMD_RESERVED + 1)
738 
750 #define SPICC26X2DMA_CMD_SET_CSN_PIN (SPI_CMD_RESERVED + 2)
751 
761 #define SPICC26X2DMA_CMD_CLEAR_CSN_PIN (SPI_CMD_RESERVED + 3)
762 
776 #define SPICC26X2DMA_CMD_SET_MANUAL (SPI_CMD_RESERVED + 4)
777 
787 #define SPICC26X2DMA_CMD_CLR_MANUAL (SPI_CMD_RESERVED + 5)
788 
799 #define SPICC26X2DMA_CMD_MANUAL_START (SPI_CMD_RESERVED + 6)
800 
803 /* BACKWARDS COMPATIBILITY */
804 #define SPICC26X2DMA_RETURN_PARTIAL_ENABLE SPICC26X2DMA_CMD_RETURN_PARTIAL_ENABLE
805 #define SPICC26X2DMA_RETURN_PARTIAL_DISABLE SPICC26X2DMA_CMD_RETURN_PARTIAL_DISABLE
806 #define SPICC26X2DMA_SET_CSN_PIN SPICC26X2DMA_CMD_SET_CSN_PIN
807 /* END BACKWARDS COMPATIBILITY */
808 
815 
825 typedef enum
826 {
830 
838 typedef enum
839 {
844 
899 typedef struct
900 {
902  uint32_t baseAddr;
904  uint8_t intNum;
919  uint8_t intPriority;
926  uint32_t swiPriority;
928  PowerCC26XX_Resource powerMngrId;
936  volatile tDMAControlTable *dmaTxTableEntryPri;
938  volatile tDMAControlTable *dmaRxTableEntryPri;
940  volatile tDMAControlTable *dmaTxTableEntryAlt;
942  volatile tDMAControlTable *dmaRxTableEntryAlt;
944  int32_t txPinMux;
946  int32_t rxPinMux;
948  int32_t clkPinMux;
950  int32_t csnPinMux;
952  uint_least8_t mosiPin;
954  uint_least8_t misoPin;
956  uint_least8_t clkPin;
958  uint_least8_t csnPin;
959 
963 
969 typedef struct
970 {
971  HwiP_Struct hwi;
973  SwiP_Struct swi;
974  SemaphoreP_Struct transferComplete;
975 
981 
982  size_t framesQueued;
986 
987  uint32_t activeChannel;
988  uint32_t bitRate;
989  uint32_t dataSize;
990  uint32_t transferTimeout;
991  uint32_t busyBit;
992 
993  uint16_t rxScratchBuf;
994  uint16_t txScratchBuf;
995 
998  uint8_t format;
999  uint_least8_t csnPin;
1001  bool isOpen;
1004 
1005 #ifdef __cplusplus
1006 }
1007 #endif
1008 
1009 #endif /* ti_drivers_spi_SPICC26X2DMA__include */
Definition: SPICC26X2DMA.h:842
uint_least8_t csnPin
Definition: SPICC26X2DMA.h:999
uint16_t defaultTxBufValue
Definition: SPICC26X2DMA.h:930
uint32_t minDmaTransferSize
Definition: SPICC26X2DMA.h:961
SPI_Transaction * headPtr
Definition: SPICC26X2DMA.h:977
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:586
uint32_t txChannelBitMask
Definition: SPICC26X2DMA.h:934
SPI_Transaction * completedTransfers
Definition: SPICC26X2DMA.h:979
uint32_t bitRate
Definition: SPICC26X2DMA.h:988
uint_least8_t misoPin
Definition: SPICC26X2DMA.h:954
uint32_t rxChannelBitMask
Definition: SPICC26X2DMA.h:932
SPI_TransferMode
SPI transfer mode determines the whether the SPI controller operates synchronously or asynchronously...
Definition: SPI.h:623
SPI_Transaction * tailPtr
Definition: SPICC26X2DMA.h:978
Power Manager.
uint_least8_t clkPin
Definition: SPICC26X2DMA.h:956
UDMACC26XX Global configuration.
Definition: UDMACC26XX.h:252
Power manager interface for CC26XX/CC13XX.
int32_t rxPinMux
Definition: SPICC26X2DMA.h:946
Power_NotifyObj spiPostObj
Definition: SPICC26X2DMA.h:972
uint16_t rxScratchBuf
Definition: SPICC26X2DMA.h:993
uint32_t transferTimeout
Definition: SPICC26X2DMA.h:990
volatile tDMAControlTable * dmaTxTableEntryAlt
Definition: SPICC26X2DMA.h:940
uint32_t activeChannel
Definition: SPICC26X2DMA.h:987
volatile tDMAControlTable * dmaRxTableEntryAlt
Definition: SPICC26X2DMA.h:942
size_t altTransferSize
Definition: SPICC26X2DMA.h:985
SPI_Mode mode
Definition: SPICC26X2DMA.h:997
uint8_t intNum
Definition: SPICC26X2DMA.h:904
SPI_TransferMode transferMode
Definition: SPICC26X2DMA.h:996
const SPI_FxnTable SPICC26X2DMA_fxnTable
Definition: SPICC26X2DMA.h:827
The definition of a SPI function table that contains the required set of functions to control a speci...
Definition: SPI.h:712
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:926
SPICC26X2DMA_ReturnPartial returnPartial
Definition: SPICC26X2DMA.h:1000
size_t framesQueued
Definition: SPICC26X2DMA.h:982
SPICC26X2DMA Hardware attributes.
Definition: SPICC26X2DMA.h:899
uint8_t format
Definition: SPICC26X2DMA.h:998
SwiP_Struct swi
Definition: SPICC26X2DMA.h:973
volatile tDMAControlTable * dmaRxTableEntryPri
Definition: SPICC26X2DMA.h:938
volatile tDMAControlTable * dmaTxTableEntryPri
Definition: SPICC26X2DMA.h:936
UDMACC26XX driver implementation.
uint32_t busyBit
Definition: SPICC26X2DMA.h:991
A SPI_Transaction data structure is used with SPI_transfer(). It indicates how many SPI_FrameFormat f...
Definition: SPI.h:564
Power notify object structure.
Definition: Power.h:442
Definition: SPICC26X2DMA.h:840
SPI_Mode
Definitions for various SPI modes of operation.
Definition: SPI.h:591
UDMACC26XX_Handle udmaHandle
Definition: SPICC26X2DMA.h:980
SemaphoreP_Struct transferComplete
Definition: SPICC26X2DMA.h:974
SPICC26X2DMA_ReturnPartial
Definition: SPICC26X2DMA.h:838
int32_t clkPinMux
Definition: SPICC26X2DMA.h:948
uint_least8_t mosiPin
Definition: SPICC26X2DMA.h:952
uint_least8_t csnPin
Definition: SPICC26X2DMA.h:958
Definition: SPICC26X2DMA.h:828
size_t framesTransferred
Definition: SPICC26X2DMA.h:983
uint16_t txScratchBuf
Definition: SPICC26X2DMA.h:994
SPICC26X2DMA_FrameSize
Definition: SPICC26X2DMA.h:825
int32_t csnPinMux
Definition: SPICC26X2DMA.h:950
size_t priTransferSize
Definition: SPICC26X2DMA.h:984
int32_t txPinMux
Definition: SPICC26X2DMA.h:944
bool manualStart
Definition: SPICC26X2DMA.h:1002
SPI_CallbackFxn transferCallbackFxn
Definition: SPICC26X2DMA.h:976
bool isOpen
Definition: SPICC26X2DMA.h:1001
PowerCC26XX_Resource powerMngrId
Definition: SPICC26X2DMA.h:928
SPICC26X2DMA Object.
Definition: SPICC26X2DMA.h:969
Definition: SPICC26X2DMA.h:841
HwiP_Struct hwi
Definition: SPICC26X2DMA.h:971
uint32_t dataSize
Definition: SPICC26X2DMA.h:989
uint8_t intPriority
SPI CC26XXDMA Peripheral&#39;s interrupt priority.
Definition: SPICC26X2DMA.h:919
uint32_t baseAddr
SPI Peripheral&#39;s base address.
Definition: SPICC26X2DMA.h:902
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale