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
267  *(in bytes) of the buffer to transfer.
268  *
269  * <hr>
270  * @anchor ti_drivers_I2S_Example_Streaming
271  * ### Writing Data in Continuous Streaming Mode #
272  * The following example shows how to read and write data in streaming mode.
273  * A dummy treatment of the data is also done.
274  * This example is not complete (semaphore and tasks creation are not shown)
275  *
276  * <hr>
277  * @anchor ti_drivers_I2S_Example_Streaming_Code
278  * @code
279  * static I2S_Handle i2sHandle;
280  * static sem_t semDataReadyForTreatment;
281  *
282  * // These buffers will successively be written, treated and sent out
283  * static uint16_t readBuf1[500];
284  * static uint16_t readBuf2[500];
285  * static uint16_t readBuf3[500];
286  * static uint16_t readBuf4[500];
287  * static uint16_t writeBuf1[500]={0};
288  * static uint16_t writeBuf2[500]={0};
289  * static uint16_t writeBuf3[500]={0};
290  * static uint16_t writeBuf4[500]={0};
291  *
292  * // These transactions will successively be part of the
293  * // i2sReadList, the treatmentList and the i2sWriteList
294  * static I2S_Transaction i2sRead1;
295  * static I2S_Transaction i2sRead2;
296  * static I2S_Transaction i2sRead3;
297  * static I2S_Transaction i2sRead4;
298  * static I2S_Transaction i2sWrite1;
299  * static I2S_Transaction i2sWrite2;
300  * static I2S_Transaction i2sWrite3;
301  * static I2S_Transaction i2sWrite4;
302  *
303  * List_List i2sReadList;
304  * List_List treatmentList;
305  * List_List i2sWriteList;
306  *
307  * static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
308  *
309  * // We must remove the previous transaction (the current one is not over)
310  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
311  *
312  * if(transactionFinished != NULL){
313  * // Remove the finished transaction from the write queue
314  * List_remove(&i2sWriteList, (List_Elem*)transactionFinished);
315  *
316  * // This transaction must now feed the read queue (we do not need anymore the data of this transaction)
317  * transactionFinished->queueElement.next = NULL;
318  * List_put(&i2sReadList, (List_Elem*)transactionFinished);
319  *
320  * // We need to queue a new transaction: let's take one in the treatment queue
321  * I2S_Transaction *newTransaction = (I2S_Transaction*)List_head(&treatmentList);
322  * if(newTransaction != NULL){
323  * List_remove(&treatmentList, (List_Elem*)newTransaction);
324  * newTransaction->queueElement.next = NULL;
325  * List_put(&i2sWriteList, (List_Elem*)newTransaction);
326  * }
327  * }
328  * }
329  *
330  * static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
331  *
332  * // We must remove the previous transaction (the current one is not over)
333  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
334  *
335  * if(transactionFinished != NULL){
336  * // The finished transaction contains data that must be treated
337  * List_remove(&i2sReadList, (List_Elem*)transactionFinished);
338  * transactionFinished->queueElement.next = NULL;
339  * List_put(&treatmentList, (List_Elem*)transactionFinished);
340  *
341  * // Start the treatment of the data
342  * sem_post(&semDataReadyForTreatment);
343  *
344  * // We do not need to queue transaction here: writeCallbackFxn takes care of this :)
345  * }
346  * }
347  *
348  * static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
349  *
350  * // Handle the I2S error
351  * }
352  *
353  * void *echoExampleThread(void *arg0)
354  * {
355  * I2S_Params i2sParams;
356  *
357  * I2S_init();
358  *
359  * int retc = sem_init(&semDataReadyForTreatment, 0, 0);
360  * if (retc == -1) {
361  * while (1);
362  * }
363  *
364  * // Initialize the treatmentList (this list is initially empty)
365  * List_clearList(&treatmentList);
366  *
367  * //Initialize I2S opening parameters
368  * I2S_Params_init(&i2sParams);
369  * i2sParams.fixedBufferLength = 1000;
370  * i2sParams.writeCallback = writeCallbackFxn ;
371  * i2sParams.readCallback = readCallbackFxn ;
372  * i2sParams.errorCallback = errCallbackFxn;
373  *
374  * i2sHandle = I2S_open(CONFIG_I2S0, &i2sParams);
375  *
376  * // Initialize the read-transactions
377  * I2S_Transaction_init(&i2sRead1);
378  * I2S_Transaction_init(&i2sRead2);
379  * I2S_Transaction_init(&i2sRead3);
380  * I2S_Transaction_init(&i2sRead4);
381  * i2sRead1.bufPtr = readBuf1;
382  * i2sRead2.bufPtr = readBuf2;
383  * i2sRead3.bufPtr = readBuf3;
384  * i2sRead4.bufPtr = readBuf4;
385  * i2sRead1.bufSize = sizeof(readBuf1);
386  * i2sRead2.bufSize = sizeof(readBuf2);
387  * i2sRead3.bufSize = sizeof(readBuf3);
388  * i2sRead4.bufSize = sizeof(readBuf4);
389  * List_clearList(&i2sReadList);
390  * List_put(&i2sReadList, (List_Elem*)&i2sRead1);
391  * List_put(&i2sReadList, (List_Elem*)&i2sRead2);
392  * List_put(&i2sReadList, (List_Elem*)&i2sRead3);
393  * List_put(&i2sReadList, (List_Elem*)&i2sRead4);
394  *
395  * I2S_setReadQueueHead(i2sHandle, &i2sRead1);
396  *
397  * // Initialize the write-transactions
398  * I2S_Transaction_init(&i2sWrite1);
399  * I2S_Transaction_init(&i2sWrite2);
400  * I2S_Transaction_init(&i2sWrite3);
401  * I2S_Transaction_init(&i2sWrite4);
402  * i2sWrite1.bufPtr = writeBuf1;
403  * i2sWrite2.bufPtr = writeBuf2;
404  * i2sWrite3.bufPtr = writeBuf3;
405  * i2sWrite4.bufPtr = writeBuf4;
406  * i2sWrite1.bufSize = sizeof(writeBuf1);
407  * i2sWrite2.bufSize = sizeof(writeBuf2);
408  * i2sWrite3.bufSize = sizeof(writeBuf3);
409  * i2sWrite4.bufSize = sizeof(writeBuf4);
410  * List_clearList(&i2sWriteList);
411  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite1);
412  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite2);
413  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite3);
414  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite4);
415  *
416  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite1);
417  *
418  * I2S_startClocks(i2sHandle);
419  * I2S_startWrite(i2sHandle);
420  * I2S_startRead(i2sHandle);
421  *
422  * while (1) {
423  * uint8_t k = 0;
424  * I2S_Transaction* lastAchievedReadTransaction = NULL;
425  *
426  * retc = sem_wait(&semDataReadyForTreatment);
427  * if (retc == -1) {
428  * while (1);
429  * }
430  *
431  * lastAchievedReadTransaction = (I2S_Transaction*) List_head(&treatmentList);
432  *
433  * if(lastAchievedReadTransaction != NULL) {
434  *
435  * // Need a critical section to be sure to have corresponding bufPtr and bufSize
436  * uintptr_t key = HwiP_disable();
437  * uint16_t *buf = lastAchievedReadTransaction->bufPtr;
438  * uint16_t bufLength = lastAchievedReadTransaction->bufSize / sizeof(uint16_t);
439  * HwiP_restore(key);
440  *
441  * // My dummy data treatment...
442  * for(k=0; k<bufLength; k++) {
443  * buf[k]--;
444  * }
445  * for(k=0; k<bufLength; k++) {
446  * buf[k]++;
447  * }
448  * }
449  * }
450  * }
451  * @endcode
452  *
453  * <hr>
454  * @anchor ti_drivers_I2S_Example_RepeatMode
455  * ### Writing Data in repeat Mode #
456  * The following example shows how to read and write data in repeat mode.
457  * The same buffers are continuously written and send out while the driver is not stopped.
458  * Here, we decide to only stop sending out after an arbitrary number of sending.
459  *
460  * <hr>
461  * @anchor ti_drivers_I2S_Example_RepeatMode_Code
462  * @code
463  * static I2S_Handle i2sHandle;
464  *
465  * // This buffer will be continuously re-written
466  * static uint16_t readBuf[500];
467  * // This data will be continuously sent out
468  * static uint16_t writeBuf[500] = {...some cool data...};
469  *
470  * static I2S_Transaction i2sRead;
471  * static I2S_Transaction i2sWrite;
472  *
473  * List_List i2sReadList;
474  * List_List i2sWriteList;
475  *
476  * static volatile bool writeFinished = (bool)false;
477  * static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
478  *
479  * // Nothing to do here: the buffer(s) are queued in a ring list, the transfers are
480  * // executed without any action from the application.
481  *
482  * // We must consider the previous transaction (ok, when you have only one transaction it's the same)
483  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
484  *
485  * if(transactionFinished != NULL){
486  * // After an arbitrary number of completion of the transaction, we will stop writting
487  * if(transactionFinished->numberOfCompletions >= 10) {
488  *
489  * // Note: You cannot use I2S_stopRead() / I2S_stopWrite() in the callback.
490  * // The execution of these functions is potentially blocking and can mess up the
491  * // system.
492  *
493  * writeFinished = (bool)true;
494  * }
495  * }
496  * }
497  *
498  * static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
499  * // Nothing to do here: the buffer(s) are queued in a ring list, the transfers are
500  * // executed without any action from the application.
501  * }
502  *
503  * static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
504  *
505  * // Handle the I2S error
506  * }
507  *
508  * void *modeRepeat(void *arg0)
509  * {
510  * I2S_Params i2sParams;
511  *
512  * // Initialize I2S opening parameters
513  * I2S_Params_init(&i2sParams);
514  * i2sParams.fixedBufferLength = 1000; // No problem here: the driver consider
515  * // the list as an infinite list.
516  * i2sParams.writeCallback = writeCallbackFxn ;
517  * i2sParams.readCallback = readCallbackFxn ;
518  * i2sParams.errorCallback = errCallbackFxn;
519  *
520  * i2sHandle = I2S_open(CONFIG_I2S0, &i2sParams);
521  *
522  * // Initialize the read-transactions
523  * I2S_Transaction_init(&i2sRead);
524  * i2sRead.bufPtr = readBuf;
525  * i2sRead.bufSize = sizeof(readBuf);
526  * List_put(&i2sReadList, (List_Elem*)&i2sRead);
527  * List_tail(&i2sReadList)->next = List_head(&i2sReadList);// Read buffers are queued in a ring-list
528  * List_head(&i2sReadList)->prev = List_tail(&i2sReadList);
529  *
530  * I2S_setReadQueueHead(i2sHandle, &i2sRead);
531  *
532  * // Initialize the write-transactions
533  * I2S_Transaction_init(&i2sWrite);
534  * i2sWrite.bufPtr = writeBuf;
535  * i2sWrite.bufSize = sizeof(writeBuf);
536  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite);
537  * List_tail(&i2sWriteList)->next = List_head(&i2sWriteList); // Write buffers are queued in a ring-list
538  * List_head(&i2sWriteList)->prev = List_tail(&i2sWriteList);
539  *
540  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite);
541  *
542  * I2S_startClocks(i2sHandle);
543  * I2S_startWrite(i2sHandle);
544  * I2S_startRead(i2sHandle);
545  *
546  * while (1) {
547  *
548  * if(writeFinished){
549  * writeFinished = (bool)false;
550  * I2S_stopWrite(i2sHandle);
551  * }
552  * }
553  * }
554  * @endcode
555  *
556  * @note In the case of circular lists, there is no problem to put only
557  * one buffer in the queue.
558  *
559  * <hr>
560  * @anchor ti_drivers_I2S_Configuration
561  * # Configuration
562  *
563  * Refer to the @ref driver_configuration "Driver's Configuration" section
564  * for driver configuration information.
565  * <hr>
566  ******************************************************************************
567  */
568 
569 #ifndef ti_drivers_I2S__include
570 #define ti_drivers_I2S__include
571 
572 #include <stddef.h>
573 #include <stdbool.h>
574 #include <stdint.h>
575 
576 #include <ti/drivers/utils/List.h>
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
660 {
662  void *object;
663 
665  void const *hwAttrs;
666 } I2S_Config;
667 
672 
676 typedef struct
677 {
681  void *bufPtr;
683  size_t bufSize;
691  uintptr_t arg;
693 
707 typedef void (*I2S_Callback)(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr);
708 
717 typedef void (*I2S_RegUpdate)(uint32_t ui32Base, uint32_t ui32NextPointer);
718 
725 typedef void (*I2S_StopInterface)(I2S_Handle handle);
726 
734 typedef enum
735 {
736 
743 
750 typedef enum
751 {
752 
753  I2S_SLAVE = 0,
756 } I2S_Role;
757 
763 typedef enum
764 {
765 
770 
776 typedef enum
777 {
778 
782 } I2S_PhaseType;
783 
789 typedef enum
790 {
791 
793  I2S_SD0_INPUT = 0x01U,
794  I2S_SD0_OUTPUT = 0x02U,
796  I2S_SD1_INPUT = 0x10U,
797  I2S_SD1_OUTPUT = 0x20U
800 
806 typedef enum
807 {
808 
813  I2S_1_CHANNEL = 0x01U,
814  I2S_2_CHANNELS = 0x03U,
815  I2S_3_CHANNELS = 0x07U,
816  I2S_4_CHANNELS = 0x0FU,
817  I2S_5_CHANNELS = 0x1FU,
818  I2S_6_CHANNELS = 0x3FU,
819  I2S_7_CHANNELS = 0x7FU,
820  I2S_8_CHANNELS = 0xFFU,
824 
833 typedef struct
834 {
835 
844  bool invertWS;
860  I2S_MemoryLength memorySlotLength;
874  uint8_t bitsPerWord;
887  I2S_DataInterfaceUse SD0Use;
893  I2S_DataInterfaceUse SD1Use;
899  I2S_ChannelConfig SD0Channels;
923  I2S_ChannelConfig SD1Channels;
947  I2S_PhaseType phaseType;
959  uint16_t startUpDelay;
962  uint16_t MCLKDivider;
981  void *custom;
983 } I2S_Params;
984 
990 extern const I2S_Params I2S_defaultParams;
991 
1002 extern void I2S_close(I2S_Handle handle);
1003 
1012 extern void I2S_init(void);
1013 
1034 extern I2S_Handle I2S_open(uint_least8_t index, I2S_Params *params);
1035 
1071 extern void I2S_Params_init(I2S_Params *params);
1072 
1090 extern void I2S_Transaction_init(I2S_Transaction *transaction);
1091 
1108 extern void I2S_setReadQueueHead(I2S_Handle handle, I2S_Transaction *transaction);
1109 
1126 extern void I2S_setWriteQueueHead(I2S_Handle handle, I2S_Transaction *transaction);
1127 
1141 extern void I2S_startClocks(I2S_Handle handle);
1142 
1161 extern void I2S_stopClocks(I2S_Handle handle);
1162 
1186 extern void I2S_startRead(I2S_Handle handle);
1187 
1211 extern void I2S_startWrite(I2S_Handle handle);
1212 
1234 extern void I2S_stopRead(I2S_Handle handle);
1235 
1257 extern void I2S_stopWrite(I2S_Handle handle);
1258 
1259 #ifdef __cplusplus
1260 }
1261 #endif
1262 
1263 #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:734
Definition: I2S.h:795
void * object
Definition: I2S.h:662
Definition: I2S.h:811
Definition: I2S.h:737
size_t bytesTransferred
Definition: I2S.h:685
const I2S_Params I2S_defaultParams
Default I2S_Params structure.
Definition: I2S.h:792
bool isMSBFirst
Definition: I2S.h:849
Definition: I2S.h:753
uint8_t beforeWordPadding
Definition: I2S.h:867
Definition: I2S.h:739
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:707
Definition: I2S.h:817
Definition: I2S.h:819
void(* I2S_RegUpdate)(uint32_t ui32Base, uint32_t ui32NextPointer)
The definition of a function used to set the I2S register.
Definition: I2S.h:717
Definition: I2S.h:754
size_t untransferredBytes
Definition: I2S.h:687
uint16_t MCLKDivider
Definition: I2S.h:962
void I2S_setWriteQueueHead(I2S_Handle handle, I2S_Transaction *transaction)
Function to set the first write-transaction to consider.
I2S_DataInterfaceUse SD1Use
Definition: I2S.h:893
uint32_t samplingFrequency
Definition: I2S.h:966
I2S Global configuration.
Definition: I2S.h:659
I2S_DataInterfaceUse
I2S data interface configuration.
Definition: I2S.h:789
Definition: I2S.h:809
I2S_PhaseType
I2S phase setting.
Definition: I2S.h:776
Definition: I2S.h:793
Definition: I2S.h:821
I2S_Role
I2S master / slave selection.
Definition: I2S.h:750
uint16_t fixedBufferLength
Definition: I2S.h:954
Definition: I2S.h:766
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:689
bool isDMAUnused
Definition: I2S.h:854
Definition: I2S.h:767
I2S_MemoryLength memorySlotLength
Definition: I2S.h:860
I2S_SamplingEdge samplingEdge
Definition: I2S.h:882
Definition: I2S.h:738
List_Elem queueElement
Definition: I2S.h:679
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:671
void I2S_Transaction_init(I2S_Transaction *transaction)
Initialize an I2S_Transaction struct to known state.
I2S_ChannelConfig
Channels used selection.
Definition: I2S.h:806
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:763
bool invertWS
Definition: I2S.h:844
I2S_PhaseType phaseType
Definition: I2S.h:947
Definition: I2S.h:813
uint16_t startUpDelay
Definition: I2S.h:959
Definition: I2S.h:740
I2S_DataInterfaceUse SD0Use
Definition: I2S.h:887
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:725
bool trueI2sFormat
Definition: I2S.h:836
I2S_Callback errorCallback
Definition: I2S.h:978
I2S_Role moduleRole
Definition: I2S.h:877
void I2S_stopWrite(I2S_Handle handle)
Stop write transactions.
Definition: I2S.h:812
I2S_ChannelConfig SD1Channels
Definition: I2S.h:923
void I2S_stopRead(I2S_Handle handle)
Stop read transactions.
Definition: I2S.h:820
uintptr_t arg
Definition: I2S.h:691
size_t bufSize
Definition: I2S.h:683
void * custom
Definition: I2S.h:981
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:780
I2S_Callback writeCallback
Definition: I2S.h:975
Definition: I2S.h:815
Definition: I2S.h:797
Definition: I2S.h:796
uint8_t bitsPerWord
Definition: I2S.h:874
Definition: I2S.h:816
Definition: I2S.h:810
I2S_Callback readCallback
Definition: I2S.h:972
Definition: List.h:126
I2S transaction descriptor.
Definition: I2S.h:676
Definition: I2S.h:814
void const * hwAttrs
Definition: I2S.h:665
void I2S_close(I2S_Handle handle)
Function to close a given I2S peripheral specified by the I2S handle.
Definition: I2S.h:779
Definition: I2S.h:818
uint8_t afterWordPadding
Definition: I2S.h:871
I2S_ChannelConfig SD0Channels
Definition: I2S.h:899
Definition: I2S.h:794
Linked List interface for use in drivers.
Basic I2S Parameters.
Definition: I2S.h:833
void * bufPtr
Definition: I2S.h:681
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale