I2S.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 I2S.h
34  * @brief Inter-Integrated Circuit Sound (I2S) Bus Driver
35  *
36  * The I2S header file should be included in an application as follows:
37  * @code
38  * #include <ti/drivers/I2S.h>
39  * @endcode
40  *
41  * @anchor ti_drivers_I2S_Overview
42  * # Overview #
43  *
44  * The I2S driver facilitates the use of Inter-IC Sound (I2S), which is
45  * used to connect digital audio devices so that audio signals can be
46  * communicated between devices. The I2S driver simplifies reading and
47  * writing to any of the Multichannel Audio Serial Port (McASP) peripherals
48  * on the board with Receive and Transmit support. These include read and
49  * write characters on the McASP peripheral.
50  *
51  * I2S interfaces typically consist of 4 or 5 signals. The 5th signal is not
52  * systematically used.
53  * @li <b>Serial Clock (SCK)</b> also called Bit Clock (BCLK) or Multichannel
54  * Audio Frame Synchronization (McAFSX)
55  * @li <b>Word Select (WS)</b> also called Word Clock (WCLK), Left Right
56  * Clock (LRCLK) or Multichannel Audio Clock (McACLK)
57  * @li <b>Serial Data (SD0)</b> also called AD0, AD1, McAXR0, or possibly SDI
58  * @li <b>Serial Data (SD1)</b> also called AD1, ADI, McAXR1, or possibly SDI
59  * @li <b>Master Clock (MCLK)</b>
60  *
61  * <hr>
62  * @anchor ti_drivers_I2S_Usage
63  * # Usage #
64  *
65  * <b>The I2S driver provides the following APIs:</b>
66  * @li I2S_init(): @copybrief I2S_init
67  * @li I2S_open(): @copybrief I2S_open
68  * @li I2S_Params_init(): @copybrief I2S_Params_init
69  * @li I2S_Transaction_init(): @copybrief I2S_Transaction_init
70  * @li I2S_setReadQueueHead(): @copybrief I2S_setReadQueueHead
71  * @li I2S_setWriteQueueHead(): @copybrief I2S_setWriteQueueHead
72  * @li I2S_startClocks(): @copybrief I2S_startClocks
73  * @li I2S_startRead(): @copybrief I2S_startRead
74  * @li I2S_startWrite(): @copybrief I2S_startWrite
75  * @li I2S_stopRead(): @copybrief I2S_stopRead
76  * @li I2S_stopWrite(): @copybrief I2S_stopWrite
77  * @li I2S_stopClocks(): @copybrief I2S_stopClocks
78  * @li I2S_close(): @copybrief I2S_close
79  *
80  * <hr>
81  * @anchor ti_drivers_I2S_Driver_Transactions
82  * ### Transactions #
83  *
84  * Data transfers are achieved through #I2S_Transaction structures. Application is
85  * responsible to maintain the transactions queues. The I2S driver completes the
86  * transactions one by one. When a transaction is over, the I2S driver takes in
87  * consideration the next transaction (if the next transaction is NULL, the I2S
88  * drivers signals this to the user).
89  * The I2S driver relies on the following fields of the #I2S_Transaction to
90  * complete it:
91  * - the buffer
92  * - the length of the buffer
93  * - a pointer on the next transaction to achieve (kept in a List_Elem structure)
94  * .
95  * The I2S driver provides the following elements (fields of the #I2S_Transaction):
96  * - the number of untransferred bytes: the driver is designed to avoid memory corruption and will
97  * not complete an incomplete transaction (meaning a transaction where the buffer size would not
98  * permit to send or receive a whole number of samples). In this case, the system considers the
99  * samples of the beginning of the buffer and read/write as much as possible samples and ignore the
100  * end of the buffer. The number of untransafered bytes is the number of bytes left at the end of
101  * the buffer)
102  * - the number of completions of the transaction. This value is basically incremented by one
103  * every time the transaction is completed.
104  *
105  * Please note that these two fields are valid only when the transaction has been completed.
106  * Consult examples to get more details on the transaction usage.
107  *
108  * <hr>
109  * @anchor ti_drivers_I2S_Driver_ProvidingData
110  * ### Providing data to the I2S driver #
111  * Application is responsible to handle the queues of transactions.
112  * Application is also responsible to provide to the driver a pointer on
113  * the first transaction to consider (considering that all the following
114  * transactions are correctly queued).
115  * #I2S_setReadQueueHead() and #I2S_setWriteQueueHead() allow the user to
116  * set the first transaction to consider. These functions should be used only
117  * when no transaction is running on the considered interface.
118  *
119  * <hr>
120  * @anchor ti_drivers_I2S_Driver_StartStopClocks
121  * ### Start and stop clocks and transactions #
122  * Clocks can be started and stopped by the application.
123  * Read and write can be started and stopped independently.
124  * To start a transfer, clocks must be running.
125  * To stop the clocks no transfer must be running.
126  * Refer to the following functions for more details:
127  * @li I2S_startClocks() @li I2S_startRead() @li I2S_startWrite()
128  * @li I2S_stopRead() @li I2S_stopWrite() @li I2S_stopClocks()
129  *
130  * @note
131  * @li In #I2S_SLAVE mode, clocks must be started and stopped exactly like
132  * it is done in #I2S_MASTER mode.
133  * @li If the queue of transaction is not empty, the calls to #I2S_stopRead()
134  * and #I2S_stopWrite() are blocking and potentially long.
135  *
136  * <hr>
137  * @anchor ti_drivers_I2S_Examples
138  * ## Examples #
139  *
140  * @li @ref ti_drivers_I2S_Example_PlayAndStop "Play and Stop"
141  * @li @ref ti_drivers_I2S_Example_Streaming "Streaming"
142  * @li @ref ti_drivers_I2S_Example_RepeatMode "Repeat"
143  *
144  * <hr>
145  * @anchor ti_drivers_I2S_Example_PlayAndStop
146  * ### Mode Play and Stop #
147  * The following example shows how to simultaneously receive and send out a given amount of data.
148  *
149  * <hr>
150  * @anchor ti_drivers_I2S_Example_PlayAndStop_Code
151  * @code
152  * static I2S_Handle i2sHandle;
153  *
154  * static uint16_t readBuf1[500]; // the data read will end up in this buffer
155  * static uint16_t readBuf2[500]; // the data read will end up in this buffer
156  * static uint16_t readBuf3[500]; // the data read will end up in this buffer
157  * static uint16_t writeBuf1[250] = {...some data...}; // this buffer will be sent out
158  * static uint16_t writeBuf2[250] = {...some data...}; // this buffer will be sent out
159  * static uint16_t writeBuf3[250] = {...some data...}; // this buffer will be sent out
160  *
161  * static I2S_Transaction i2sRead1;
162  * static I2S_Transaction i2sRead2;
163  * static I2S_Transaction i2sRead3;
164  * static I2S_Transaction i2sWrite1;
165  * static I2S_Transaction i2sWrite2;
166  * static I2S_Transaction i2sWrite3;
167  *
168  * List_List i2sReadList;
169  * List_List i2sWriteList;
170  *
171  * static volatile bool readStopped = (bool)true;
172  * static volatile bool writeStopped = (bool)true;
173  *
174  * static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
175  *
176  * if(status & I2S_ALL_TRANSACTIONS_SUCCESS){
177  *
178  * // Note: Here we do not queue new transfers or set a new queue-head.
179  * // The driver will stop sending out data on its own.
180  * writeStopped = (bool)true;
181  * }
182  * }
183  *
184  * static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
185  *
186  * if(status & I2S_ALL_TRANSACTIONS_SUCCESS){
187  *
188  * // Note: Here we do not queue new transfers or set a new queue-head.
189  * // The driver will stop receiving data on its own.
190  * readStopped = (bool)true;
191  * }
192  * }
193  *
194  * static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
195  *
196  * // Handle the I2S error
197  * }
198  *
199  * void *modePlayAndStopThread(void *arg0)
200  * {
201  * I2S_Params i2sParams;
202  *
203  * I2S_init();
204  *
205  * // Initialize I2S opening parameters
206  * I2S_Params_init(&i2sParams);
207  * i2sParams.fixedBufferLength = 500; // fixedBufferLength is the greatest common
208  * // divisor of all the different buffers
209  * // (here buffers' size are 500 and 1000 bytes)
210  * i2sParams.writeCallback = writeCallbackFxn ;
211  * i2sParams.readCallback = readCallbackFxn ;
212  * i2sParams.errorCallback = errCallbackFxn;
213  *
214  * i2sHandle = I2S_open(CONFIG_I2S0, &i2sParams);
215  *
216  * // Initialize the read-transactions
217  * I2S_Transaction_init(&i2sRead1);
218  * I2S_Transaction_init(&i2sRead2);
219  * I2S_Transaction_init(&i2sRead3);
220  * i2sRead1.bufPtr = readBuf1;
221  * i2sRead2.bufPtr = readBuf2;
222  * i2sRead3.bufPtr = readBuf3;
223  * i2sRead1.bufSize = sizeof(readBuf1);
224  * i2sRead2.bufSize = sizeof(readBuf2);
225  * i2sRead3.bufSize = sizeof(readBuf3);
226  * List_put(&i2sReadList, (List_Elem*)&i2sRead1);
227  * List_put(&i2sReadList, (List_Elem*)&i2sRead2);
228  * List_put(&i2sReadList, (List_Elem*)&i2sRead3);
229  *
230  * I2S_setReadQueueHead(i2sHandle, &i2sRead1);
231  *
232  * // Initialize the write-transactions
233  * I2S_Transaction_init(&i2sWrite1);
234  * I2S_Transaction_init(&i2sWrite2);
235  * I2S_Transaction_init(&i2sWrite3);
236  * i2sWrite1.bufPtr = writeBuf1;
237  * i2sWrite2.bufPtr = writeBuf2;
238  * i2sWrite3.bufPtr = writeBuf3;
239  * i2sWrite1.bufSize = sizeof(writeBuf1);
240  * i2sWrite2.bufSize = sizeof(writeBuf2);
241  * i2sWrite3.bufSize = sizeof(writeBuf3);
242  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite1);
243  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite2);
244  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite3);
245  *
246  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite1);
247  *
248  * I2S_startClocks(i2sHandle);
249  * I2S_startWrite(i2sHandle);
250  * I2S_startRead(i2sHandle);
251  *
252  * readStopped = (bool)false;
253  * writeStopped = (bool)false;
254  *
255  * while (1) {
256  *
257  * if(readStopped && writeStopped) {
258  * I2S_stopClocks(i2sHandle);
259  * I2S_close(i2sHandle);
260  * while (1);
261  * }
262  * }
263  * }
264  * @endcode
265  *
266  * \note If you desire to put only one transaction in the queue, fixedBufferLength must be inferior to half the length (in bytes) of the buffer to transfer.
267  *
268  * <hr>
269  * @anchor ti_drivers_I2S_Example_Streaming
270  * ### Writing Data in Continuous Streaming Mode #
271  * The following example shows how to read and write data in streaming mode.
272  * A dummy treatment of the data is also done.
273  * This example is not complete (semaphore and tasks creation are not shown)
274  *
275  * <hr>
276  * @anchor ti_drivers_I2S_Example_Streaming_Code
277  * @code
278  * static I2S_Handle i2sHandle;
279  * static sem_t semDataReadyForTreatment;
280  *
281  * // These buffers will successively be written, treated and sent out
282  * static uint16_t readBuf1[500];
283  * static uint16_t readBuf2[500];
284  * static uint16_t readBuf3[500];
285  * static uint16_t readBuf4[500];
286  * static uint16_t writeBuf1[500]={0};
287  * static uint16_t writeBuf2[500]={0};
288  * static uint16_t writeBuf3[500]={0};
289  * static uint16_t writeBuf4[500]={0};
290  *
291  * // These transactions will successively be part of the
292  * // i2sReadList, the treatmentList and the i2sWriteList
293  * static I2S_Transaction i2sRead1;
294  * static I2S_Transaction i2sRead2;
295  * static I2S_Transaction i2sRead3;
296  * static I2S_Transaction i2sRead4;
297  * static I2S_Transaction i2sWrite1;
298  * static I2S_Transaction i2sWrite2;
299  * static I2S_Transaction i2sWrite3;
300  * static I2S_Transaction i2sWrite4;
301  *
302  * List_List i2sReadList;
303  * List_List treatmentList;
304  * List_List i2sWriteList;
305  *
306  * static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
307  *
308  * // We must remove the previous transaction (the current one is not over)
309  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
310  *
311  * if(transactionFinished != NULL){
312  * // Remove the finished transaction from the write queue
313  * List_remove(&i2sWriteList, (List_Elem*)transactionFinished);
314  *
315  * // This transaction must now feed the read queue (we do not need anymore the data of this transaction)
316  * transactionFinished->queueElement.next = NULL;
317  * List_put(&i2sReadList, (List_Elem*)transactionFinished);
318  *
319  * // We need to queue a new transaction: let's take one in the treatment queue
320  * I2S_Transaction *newTransaction = (I2S_Transaction*)List_head(&treatmentList);
321  * if(newTransaction != NULL){
322  * List_remove(&treatmentList, (List_Elem*)newTransaction);
323  * newTransaction->queueElement.next = NULL;
324  * List_put(&i2sWriteList, (List_Elem*)newTransaction);
325  * }
326  * }
327  * }
328  *
329  * static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
330  *
331  * // We must remove the previous transaction (the current one is not over)
332  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
333  *
334  * if(transactionFinished != NULL){
335  * // The finished transaction contains data that must be treated
336  * List_remove(&i2sReadList, (List_Elem*)transactionFinished);
337  * transactionFinished->queueElement.next = NULL;
338  * List_put(&treatmentList, (List_Elem*)transactionFinished);
339  *
340  * // Start the treatment of the data
341  * sem_post(&semDataReadyForTreatment);
342  *
343  * // We do not need to queue transaction here: writeCallbackFxn takes care of this :)
344  * }
345  * }
346  *
347  * static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
348  *
349  * // Handle the I2S error
350  * }
351  *
352  * void *echoExampleThread(void *arg0)
353  * {
354  * I2S_Params i2sParams;
355  *
356  * I2S_init();
357  *
358  * int retc = sem_init(&semDataReadyForTreatment, 0, 0);
359  * if (retc == -1) {
360  * while (1);
361  * }
362  *
363  * // Initialize the treatmentList (this list is initially empty)
364  * List_clearList(&treatmentList);
365  *
366  * //Initialize I2S opening parameters
367  * I2S_Params_init(&i2sParams);
368  * i2sParams.fixedBufferLength = 1000;
369  * i2sParams.writeCallback = writeCallbackFxn ;
370  * i2sParams.readCallback = readCallbackFxn ;
371  * i2sParams.errorCallback = errCallbackFxn;
372  *
373  * i2sHandle = I2S_open(CONFIG_I2S0, &i2sParams);
374  *
375  * // Initialize the read-transactions
376  * I2S_Transaction_init(&i2sRead1);
377  * I2S_Transaction_init(&i2sRead2);
378  * I2S_Transaction_init(&i2sRead3);
379  * I2S_Transaction_init(&i2sRead4);
380  * i2sRead1.bufPtr = readBuf1;
381  * i2sRead2.bufPtr = readBuf2;
382  * i2sRead3.bufPtr = readBuf3;
383  * i2sRead4.bufPtr = readBuf4;
384  * i2sRead1.bufSize = sizeof(readBuf1);
385  * i2sRead2.bufSize = sizeof(readBuf2);
386  * i2sRead3.bufSize = sizeof(readBuf3);
387  * i2sRead4.bufSize = sizeof(readBuf4);
388  * List_clearList(&i2sReadList);
389  * List_put(&i2sReadList, (List_Elem*)&i2sRead1);
390  * List_put(&i2sReadList, (List_Elem*)&i2sRead2);
391  * List_put(&i2sReadList, (List_Elem*)&i2sRead3);
392  * List_put(&i2sReadList, (List_Elem*)&i2sRead4);
393  *
394  * I2S_setReadQueueHead(i2sHandle, &i2sRead1);
395  *
396  * // Initialize the write-transactions
397  * I2S_Transaction_init(&i2sWrite1);
398  * I2S_Transaction_init(&i2sWrite2);
399  * I2S_Transaction_init(&i2sWrite3);
400  * I2S_Transaction_init(&i2sWrite4);
401  * i2sWrite1.bufPtr = writeBuf1;
402  * i2sWrite2.bufPtr = writeBuf2;
403  * i2sWrite3.bufPtr = writeBuf3;
404  * i2sWrite4.bufPtr = writeBuf4;
405  * i2sWrite1.bufSize = sizeof(writeBuf1);
406  * i2sWrite2.bufSize = sizeof(writeBuf2);
407  * i2sWrite3.bufSize = sizeof(writeBuf3);
408  * i2sWrite4.bufSize = sizeof(writeBuf4);
409  * List_clearList(&i2sWriteList);
410  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite1);
411  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite2);
412  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite3);
413  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite4);
414  *
415  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite1);
416  *
417  * I2S_startClocks(i2sHandle);
418  * I2S_startWrite(i2sHandle);
419  * I2S_startRead(i2sHandle);
420  *
421  * while (1) {
422  * uint8_t k = 0;
423  * I2S_Transaction* lastAchievedReadTransaction = NULL;
424  *
425  * retc = sem_wait(&semDataReadyForTreatment);
426  * if (retc == -1) {
427  * while (1);
428  * }
429  *
430  * lastAchievedReadTransaction = (I2S_Transaction*) List_head(&treatmentList);
431  *
432  * if(lastAchievedReadTransaction != NULL) {
433  *
434  * // Need a critical section to be sure to have corresponding bufPtr and bufSize
435  * uintptr_t key = HwiP_disable();
436  * uint16_t *buf = lastAchievedReadTransaction->bufPtr;
437  * uint16_t bufLength = lastAchievedReadTransaction->bufSize / sizeof(uint16_t);
438  * HwiP_restore(key);
439  *
440  * // My dummy data treatment...
441  * for(k=0; k<bufLength; k++) {
442  * buf[k]--;
443  * }
444  * for(k=0; k<bufLength; k++) {
445  * buf[k]++;
446  * }
447  * }
448  * }
449  * }
450  * @endcode
451  *
452  * <hr>
453  * @anchor ti_drivers_I2S_Example_RepeatMode
454  * ### Writing Data in repeat Mode #
455  * The following example shows how to read and write data in repeat mode.
456  * The same buffers are continuously written and send out while the driver is not stopped.
457  * Here, we decide to only stop sending out after an arbitrary number of sending.
458  *
459  * <hr>
460  * @anchor ti_drivers_I2S_Example_RepeatMode_Code
461  * @code
462  * static I2S_Handle i2sHandle;
463  *
464  * // This buffer will be continuously re-written
465  * static uint16_t readBuf[500];
466  * // This data will be continuously sent out
467  * static uint16_t writeBuf[500] = {...some cool data...};
468  *
469  * static I2S_Transaction i2sRead;
470  * static I2S_Transaction i2sWrite;
471  *
472  * List_List i2sReadList;
473  * List_List i2sWriteList;
474  *
475  * static volatile bool writeFinished = (bool)false;
476  * static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
477  *
478  * // Nothing to do here: the buffer(s) are queued in a ring list, the transfers are
479  * // executed without any action from the application.
480  *
481  * // We must consider the previous transaction (ok, when you have only one transaction it's the same)
482  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
483  *
484  * if(transactionFinished != NULL){
485  * // After an arbitrary number of completion of the transaction, we will stop writting
486  * if(transactionFinished->numberOfCompletions >= 10) {
487  *
488  * // Note: You cannot use I2S_stopRead() / I2S_stopWrite() in the callback.
489  * // The execution of these functions is potentially blocking and can mess up the
490  * // system.
491  *
492  * writeFinished = (bool)true;
493  * }
494  * }
495  * }
496  *
497  * static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
498  * // Nothing to do here: the buffer(s) are queued in a ring list, the transfers are
499  * // executed without any action from the application.
500  * }
501  *
502  * static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
503  *
504  * // Handle the I2S error
505  * }
506  *
507  * void *modeRepeat(void *arg0)
508  * {
509  * I2S_Params i2sParams;
510  *
511  * // Initialize I2S opening parameters
512  * I2S_Params_init(&i2sParams);
513  * i2sParams.fixedBufferLength = 1000; // No problem here: the driver consider
514  * // the list as an infinite list.
515  * i2sParams.writeCallback = writeCallbackFxn ;
516  * i2sParams.readCallback = readCallbackFxn ;
517  * i2sParams.errorCallback = errCallbackFxn;
518  *
519  * i2sHandle = I2S_open(CONFIG_I2S0, &i2sParams);
520  *
521  * // Initialize the read-transactions
522  * I2S_Transaction_init(&i2sRead);
523  * i2sRead.bufPtr = readBuf;
524  * i2sRead.bufSize = sizeof(readBuf);
525  * List_put(&i2sReadList, (List_Elem*)&i2sRead);
526  * List_tail(&i2sReadList)->next = List_head(&i2sReadList);// Read buffers are queued in a ring-list
527  * List_head(&i2sReadList)->prev = List_tail(&i2sReadList);
528  *
529  * I2S_setReadQueueHead(i2sHandle, &i2sRead);
530  *
531  * // Initialize the write-transactions
532  * I2S_Transaction_init(&i2sWrite);
533  * i2sWrite.bufPtr = writeBuf;
534  * i2sWrite.bufSize = sizeof(writeBuf);
535  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite);
536  * List_tail(&i2sWriteList)->next = List_head(&i2sWriteList); // Write buffers are queued in a ring-list
537  * List_head(&i2sWriteList)->prev = List_tail(&i2sWriteList);
538  *
539  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite);
540  *
541  * I2S_startClocks(i2sHandle);
542  * I2S_startWrite(i2sHandle);
543  * I2S_startRead(i2sHandle);
544  *
545  * while (1) {
546  *
547  * if(writeFinished){
548  * writeFinished = (bool)false;
549  * I2S_stopWrite(i2sHandle);
550  * }
551  * }
552  * }
553  * @endcode
554  *
555  * @note In the case of circular lists, there is no problem to put only
556  * one buffer in the queue.
557  *
558  * <hr>
559  * @anchor ti_drivers_I2S_Configuration
560  * # Configuration
561  *
562  * Refer to the @ref driver_configuration "Driver's Configuration" section
563  * for driver configuration information.
564  * <hr>
565  ******************************************************************************
566  */
567 
568 #ifndef ti_drivers_I2S__include
569 #define ti_drivers_I2S__include
570 
571 #include <stddef.h>
572 #include <stdbool.h>
573 #include <stdint.h>
574 
575 #include <ti/drivers/utils/List.h>
576 
577 
578 #ifdef __cplusplus
579 extern "C" {
580 #endif
581 
595  #define I2S_ALL_TRANSACTIONS_SUCCESS (0x0001U)
596 
603  #define I2S_TRANSACTION_SUCCESS (0x0002U)
604 
611  #define I2S_TIMEOUT_ERROR (0x0100U)
612 
620  #define I2S_BUS_ERROR (0x0200U)
621 
628  #define I2S_WS_ERROR (0x0400U)
629 
637  #define I2S_PTR_READ_ERROR (0x0800U)
638 
646  #define I2S_PTR_WRITE_ERROR (0x1000U)
647 
659 typedef struct {
661  void *object;
662 
664  void const *hwAttrs;
665 } I2S_Config;
666 
671 
675 typedef struct {
679  void *bufPtr;
681  size_t bufSize;
689  uintptr_t arg;
691 
705 typedef void (*I2S_Callback)(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr);
706 
715 typedef void (*I2S_RegUpdate)(uint32_t ui32Base, uint32_t ui32NextPointer);
716 
723 typedef void (*I2S_StopInterface)(I2S_Handle handle);
724 
732 typedef enum {
733 
740 
747 typedef enum {
748 
749  I2S_SLAVE = 0,
752 } I2S_Role;
753 
759 typedef enum {
760 
765 
771 typedef enum {
772 
776 } I2S_PhaseType;
777 
783 typedef enum {
784 
786  I2S_SD0_INPUT = 0x01U,
787  I2S_SD0_OUTPUT = 0x02U,
789  I2S_SD1_INPUT = 0x10U,
790  I2S_SD1_OUTPUT = 0x20U
793 
799 typedef enum {
800 
805  I2S_1_CHANNEL = 0x01U,
806  I2S_2_CHANNELS = 0x03U,
807  I2S_3_CHANNELS = 0x07U,
808  I2S_4_CHANNELS = 0x0FU,
809  I2S_5_CHANNELS = 0x1FU,
810  I2S_6_CHANNELS = 0x3FU,
811  I2S_7_CHANNELS = 0x7FU,
812  I2S_8_CHANNELS = 0xFFU,
816 
825 typedef struct {
826 
835  bool invertWS;
851  I2S_MemoryLength memorySlotLength;
864  uint8_t bitsPerWord;
877  I2S_DataInterfaceUse SD0Use;
883  I2S_DataInterfaceUse SD1Use;
889  I2S_ChannelConfig SD0Channels;
912  I2S_ChannelConfig SD1Channels;
935  I2S_PhaseType phaseType;
946  uint16_t startUpDelay;
949  uint16_t MCLKDivider;
967  void *custom;
969 } I2S_Params;
970 
976 extern const I2S_Params I2S_defaultParams;
977 
988 extern void I2S_close(I2S_Handle handle);
989 
998 extern void I2S_init(void);
999 
1020 extern I2S_Handle I2S_open(uint_least8_t index, I2S_Params *params);
1021 
1057 extern void I2S_Params_init(I2S_Params *params);
1058 
1076 extern void I2S_Transaction_init(I2S_Transaction *transaction);
1077 
1094 extern void I2S_setReadQueueHead(I2S_Handle handle, I2S_Transaction *transaction);
1095 
1112 extern void I2S_setWriteQueueHead(I2S_Handle handle, I2S_Transaction *transaction);
1113 
1127 extern void I2S_startClocks(I2S_Handle handle);
1128 
1147 extern void I2S_stopClocks(I2S_Handle handle);
1148 
1172 extern void I2S_startRead(I2S_Handle handle);
1173 
1197 extern void I2S_startWrite(I2S_Handle handle);
1198 
1220 extern void I2S_stopRead(I2S_Handle handle);
1221 
1243 extern void I2S_stopWrite(I2S_Handle handle);
1244 
1245 #ifdef __cplusplus
1246 }
1247 #endif
1248 
1249 #endif /* ti_drivers_I2S__include */
ADC_Params params
Definition: Driver_Init.h:11
I2S_Handle I2S_open(uint_least8_t index, I2S_Params *params)
Function to initialize a given I2S peripheral specified by the particular index value. The parameter specifies which mode the I2S will operate.
I2S_MemoryLength
I2S slot memory length setting.
Definition: I2S.h:732
Definition: I2S.h:788
void * object
Definition: I2S.h:661
Definition: I2S.h:803
Definition: I2S.h:734
size_t bytesTransferred
Definition: I2S.h:683
const I2S_Params I2S_defaultParams
Default I2S_Params structure.
Definition: I2S.h:785
bool isMSBFirst
Definition: I2S.h:840
Definition: I2S.h:749
uint8_t beforeWordPadding
Definition: I2S.h:858
Definition: I2S.h:736
void(* I2S_Callback)(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr)
The definition of a user-callback function used by the I2S driver.
Definition: I2S.h:705
Definition: I2S.h:809
Definition: I2S.h:811
void(* I2S_RegUpdate)(uint32_t ui32Base, uint32_t ui32NextPointer)
The definition of a function used to set the I2S register.
Definition: I2S.h:715
Definition: I2S.h:750
size_t untransferredBytes
Definition: I2S.h:685
uint16_t MCLKDivider
Definition: I2S.h:949
void I2S_setWriteQueueHead(I2S_Handle handle, I2S_Transaction *transaction)
Function to set the first write-transaction to consider.
I2S_DataInterfaceUse SD1Use
Definition: I2S.h:883
uint32_t samplingFrequency
Definition: I2S.h:952
I2S Global configuration.
Definition: I2S.h:659
I2S_DataInterfaceUse
I2S data interface configuration.
Definition: I2S.h:783
Definition: I2S.h:801
I2S_PhaseType
I2S phase setting.
Definition: I2S.h:771
Definition: I2S.h:786
Definition: I2S.h:813
I2S_Role
I2S master / slave selection.
Definition: I2S.h:747
uint16_t fixedBufferLength
Definition: I2S.h:942
Definition: I2S.h:761
void I2S_init(void)
Function to initializes the I2S module.
void I2S_startClocks(I2S_Handle handle)
Start the WS, SCK and MCLK clocks.
uint16_t numberOfCompletions
Definition: I2S.h:687
bool isDMAUnused
Definition: I2S.h:845
Definition: I2S.h:762
I2S_MemoryLength memorySlotLength
Definition: I2S.h:851
I2S_SamplingEdge samplingEdge
Definition: I2S.h:872
Definition: I2S.h:735
List_Elem queueElement
Definition: I2S.h:677
void I2S_startWrite(I2S_Handle handle)
Start write transactions.
I2S_Config * I2S_Handle
A handle that is returned from a I2S_open() call.
Definition: I2S.h:670
void I2S_Transaction_init(I2S_Transaction *transaction)
Initialize an I2S_Transaction struct to known state.
I2S_ChannelConfig
Channels used selection.
Definition: I2S.h:799
void I2S_setReadQueueHead(I2S_Handle handle, I2S_Transaction *transaction)
Function to set the first read-transaction to consider.
I2S_SamplingEdge
I2S sampling setting.
Definition: I2S.h:759
bool invertWS
Definition: I2S.h:835
I2S_PhaseType phaseType
Definition: I2S.h:935
Definition: I2S.h:805
uint16_t startUpDelay
Definition: I2S.h:946
Definition: I2S.h:737
I2S_DataInterfaceUse SD0Use
Definition: I2S.h:877
void I2S_stopClocks(I2S_Handle handle)
Stops the WS, SCK and MCLK clocks.
void(* I2S_StopInterface)(I2S_Handle handle)
The definition of a function used to stop an I2S interface.
Definition: I2S.h:723
bool trueI2sFormat
Definition: I2S.h:827
I2S_Callback errorCallback
Definition: I2S.h:964
I2S_Role moduleRole
Definition: I2S.h:867
void I2S_stopWrite(I2S_Handle handle)
Stop write transactions.
Definition: I2S.h:804
I2S_ChannelConfig SD1Channels
Definition: I2S.h:912
void I2S_stopRead(I2S_Handle handle)
Stop read transactions.
Definition: I2S.h:812
uintptr_t arg
Definition: I2S.h:689
size_t bufSize
Definition: I2S.h:681
void * custom
Definition: I2S.h:967
void I2S_Params_init(I2S_Params *params)
Function to initialize the I2S_Params struct to its defaults.
void I2S_startRead(I2S_Handle handle)
Start read transactions.
Definition: I2S.h:774
I2S_Callback writeCallback
Definition: I2S.h:961
Definition: I2S.h:807
Definition: I2S.h:790
Definition: I2S.h:789
uint8_t bitsPerWord
Definition: I2S.h:864
Definition: I2S.h:808
Definition: I2S.h:802
I2S_Callback readCallback
Definition: I2S.h:958
Definition: List.h:126
I2S transaction descriptor.
Definition: I2S.h:675
Definition: I2S.h:806
void const * hwAttrs
Definition: I2S.h:664
void I2S_close(I2S_Handle handle)
Function to close a given I2S peripheral specified by the I2S handle.
Definition: I2S.h:773
Definition: I2S.h:810
uint8_t afterWordPadding
Definition: I2S.h:861
I2S_ChannelConfig SD0Channels
Definition: I2S.h:889
Definition: I2S.h:787
Linked List interface for use in drivers.
Basic I2S Parameters.
Definition: I2S.h:825
void * bufPtr
Definition: I2S.h:679
© Copyright 1995-2021, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale