I2S.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2019, 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_startClocks(): @copybrief I2S_startClocks
72  * @li I2S_startRead(): @copybrief I2S_startRead
73  * @li I2S_stopRead(): @copybrief I2S_stopRead
74  * @li I2S_stopClocks(): @copybrief I2S_stopClocks
75  * @li I2S_close(): @copybrief I2S_close
76  *
77  * <hr>
78  * @anchor ti_drivers_I2S_Driver_Transactions
79  * ### Transactions #
80  *
81  * Data transfers are achieved through #I2S_Transaction structures. Application is
82  * responsible to maintain the transactions queues. The I2S driver completes the
83  * transactions one by one. When a transaction is over, the I2S driver takes in
84  * consideration the next transaction (if the next transaction is NULL, the I2S
85  * drivers signals this to the user).
86  * The I2S driver relies on the following fields of the #I2S_Transaction to
87  * complete it:
88  * - the buffer
89  * - the length of the buffer
90  * - a pointer on the next transaction to achieve (kept in a List_Elem structure)
91  * .
92  * The I2S driver provides the following elements (fields of the #I2S_Transaction):
93  * - the number of untransferred bytes: the driver is designed to avoid memory corruption and will
94  * not complete an incomplete transaction (meaning a transaction where the buffer size would not
95  * permit to send or receive a whole number of samples). In this case, the system considers the
96  * samples of the beginning of the buffer and read/write as much as possible samples and ignore the
97  * end of the buffer. The number of untransafered bytes is the number of bytes left at the end of
98  * the buffer)
99  * - the number of completions of the transaction. This value is basically incremented by one
100  * every time the transaction is completed.
101  * .
102  * Please note that these two fields are valid only when the transaction has been completed.
103  * Consult examples to get more details on the transaction usage.
104  *
105  * <hr>
106  * @anchor ti_drivers_I2S_Driver_ProvidingData
107  * ### Providing data to the I2S driver #
108  * Application is responsible to handle the queues of transactions.
109  * Application is also responsible to provide to the driver a pointer on
110  * the first transaction to consider (considering that all the following
111  * transactions are correctly queued).
112  * #I2S_setReadQueueHead() and #I2S_setWriteQueueHead() allow the user to
113  * set the first transaction to consider. These functions should be used only
114  * when no transaction is running on the considered interface.
115  *
116  * <hr>
117  * @anchor ti_drivers_I2S_Driver_StartStopClocks
118  * ### Start and stop clocks and transactions #
119  * Clocks can be started and stopped by the application.
120  * Read and write can be started and stopped independently.
121  * To start a transfer, clocks must be running.
122  * To stop the clocks no transfer must be running.
123  * Refer to the following functions for more details:
124  * @li I2S_startClocks() @li I2S_startRead() @li I2S_startWrite()
125  * @li I2S_stopRead() @li I2S_stopWrite() @li I2S_stopClocks()
126  *
127  * @note
128  * @li In #I2S_SLAVE mode, clocks must be started and stopped exactly like
129  * it is done in #I2S_MASTER mode.
130  * @li If the queue of transaction is not empty, the calls to #I2S_stopRead()
131  * and #I2S_stopWrite() are blocking and potentially long.
132  *
133  * <hr>
134  * @anchor ti_drivers_I2S_Examples
135  * ## Examples #
136  *
137  * @li @ref ti_drivers_I2S_Example_PlayAndStop "Play and Stop"
138  * @li @ref ti_drivers_I2S_Example_Streaming "Streaming"
139  * @li @ref ti_drivers_I2S_Example_RepeatMode "Repeat"
140  *
141  * <hr>
142  * @anchor ti_drivers_I2S_Example_PlayAndStop
143  * ### Mode Play and Stop #
144  * The following example shows how to simultaneously receive and send out a given amount of data.
145  *
146  * <hr>
147  * @anchor ti_drivers_I2S_Example_PlayAndStop_Code
148  * @code
149  * static I2S_Handle i2sHandle;
150  * static I2S_Config i2sConfig;
151  *
152  * static uint16_t readBuf1[500]; // the data read will end up in this buffer
153  * static uint16_t readBuf2[500]; // the data read will end up in this buffer
154  * static uint16_t readBuf3[500]; // the data read will end up in this buffer
155  * static uint16_t writeBuf1[250] = {...some data...}; // this buffer will be sent out
156  * static uint16_t writeBuf2[250] = {...some data...}; // this buffer will be sent out
157  * static uint16_t writeBuf3[250] = {...some data...}; // this buffer will be sent out
158  *
159  * static I2S_Transaction i2sRead1;
160  * static I2S_Transaction i2sRead2;
161  * static I2S_Transaction i2sRead3;
162  * static I2S_Transaction i2sWrite1;
163  * static I2S_Transaction i2sWrite2;
164  * static I2S_Transaction i2sWrite3;
165  *
166  * List_List i2sReadList;
167  * List_List i2sWriteList;
168  *
169  * static volatile bool readStopped = (bool)true;
170  * static volatile bool writeStopped = (bool)true;
171  *
172  * static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
173  *
174  * if(status & I2S_ALL_TRANSACTIONS_SUCCESS){
175  *
176  * // Note: Here we do not queue new transfers or set a new queue-head.
177  * // The driver will stop sending out data on its own.
178  * writeStopped = (bool)true;
179  * }
180  * }
181  *
182  * static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
183  *
184  * if(status & I2S_ALL_TRANSACTIONS_SUCCESS){
185  *
186  * // Note: Here we do not queue new transfers or set a new queue-head.
187  * // The driver will stop receiving data on its own.
188  * readStopped = (bool)true;
189  * }
190  * }
191  *
192  * static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
193  *
194  * // Handle the I2S error
195  * }
196  *
197  * void *modePlayAndStopThread(void *arg0)
198  * {
199  * I2S_Params i2sParams;
200  *
201  * I2S_init();
202  *
203  * // Initialize I2S opening parameters
204  * I2S_Params_init(&i2sParams);
205  * i2sParams.fixedBufferLength = 500; // fixedBufferLength is the greatest common
206  * // divisor of all the different buffers
207  * // (here buffers' size are 500 and 1000 bytes)
208  * i2sParams.writeCallback = writeCallbackFxn ;
209  * i2sParams.readCallback = readCallbackFxn ;
210  * i2sParams.errorCallback = errCallbackFxn;
211  *
212  * i2sHandle = I2S_open(CONFIG_I2S0, &i2sParams);
213  *
214  * // Initialize the read-transactions
215  * I2S_Transaction_init(&i2sRead1);
216  * I2S_Transaction_init(&i2sRead2);
217  * I2S_Transaction_init(&i2sRead3);
218  * i2sRead1.bufPtr = readBuf1;
219  * i2sRead2.bufPtr = readBuf2;
220  * i2sRead3.bufPtr = readBuf3;
221  * i2sRead1.bufSize = sizeof(readBuf1);
222  * i2sRead2.bufSize = sizeof(readBuf2);
223  * i2sRead3.bufSize = sizeof(readBuf3);
224  * List_put(&i2sReadList, (List_Elem*)&i2sRead1);
225  * List_put(&i2sReadList, (List_Elem*)&i2sRead2);
226  * List_put(&i2sReadList, (List_Elem*)&i2sRead3);
227  *
228  * I2S_setReadQueueHead(i2sHandle, &i2sRead1);
229  *
230  * // Initialize the write-transactions
231  * I2S_Transaction_init(&i2sWrite1);
232  * I2S_Transaction_init(&i2sWrite2);
233  * I2S_Transaction_init(&i2sWrite3);
234  * i2sWrite1.bufPtr = writeBuf1;
235  * i2sWrite2.bufPtr = writeBuf2;
236  * i2sWrite3.bufPtr = writeBuf3;
237  * i2sWrite1.bufSize = sizeof(writeBuf1);
238  * i2sWrite2.bufSize = sizeof(writeBuf2);
239  * i2sWrite3.bufSize = sizeof(writeBuf3);
240  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite1);
241  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite2);
242  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite3);
243  *
244  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite1);
245  *
246  * I2S_startClocks(i2sHandle);
247  * I2S_startWrite(i2sHandle);
248  * I2S_startRead(i2sHandle);
249  *
250  * readStopped = (bool)false;
251  * writeStopped = (bool)false;
252  *
253  * while(1) {
254  *
255  * if(readStopped && writeStopped) {
256  * I2S_stopClocks(i2sHandle);
257  * I2S_close(i2sHandle);
258  * while(1);
259  * }
260  * }
261  * }
262  * @endcode
263  *
264  * \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.
265  *
266  * <hr>
267  * @anchor ti_drivers_I2S_Example_Streaming
268  * ### Writing Data in Continuous Streaming Mode #
269  * The following example shows how to read and write data in streaming mode.
270  * A dummy treatment of the data is also done.
271  * This example is not complete (semaphore and tasks creation are not shown)
272  *
273  * <hr>
274  * @anchor ti_drivers_I2S_Example_Streaming_Code
275  * @code
276  * static I2S_Handle i2sHandle;
277  * static I2S_Config i2sConfig;
278  *
279  * // These buffers will successively be written, treated and sent out
280  * static uint16_t readBuf1[500];
281  * static uint16_t readBuf2[500];
282  * static uint16_t readBuf3[500];
283  * static uint16_t readBuf4[500];
284  * static uint16_t writeBuf1[500]={0};
285  * static uint16_t writeBuf2[500]={0};
286  * static uint16_t writeBuf3[500]={0};
287  * static uint16_t writeBuf4[500]={0};
288  *
289  * // These transactions will successively be part of the
290  * // i2sReadList, the treatmentList and the i2sWriteList
291  * static I2S_Transaction i2sRead1;
292  * static I2S_Transaction i2sRead2;
293  * static I2S_Transaction i2sRead3;
294  * static I2S_Transaction i2sRead4;
295  * static I2S_Transaction i2sWrite1;
296  * static I2S_Transaction i2sWrite2;
297  * static I2S_Transaction i2sWrite3;
298  * static I2S_Transaction i2sWrite4;
299  *
300  * List_List i2sReadList;
301  * List_List treatmentList;
302  * List_List i2sWriteList;
303  *
304  * static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
305  *
306  * // We must remove the previous transaction (the current one is not over)
307  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
308  *
309  * if(transactionFinished != NULL){
310  * // Remove the finished transaction from the write queue
311  * List_remove(&i2sWriteList, (List_Elem*)transactionFinished);
312  *
313  * // This transaction must now feed the read queue (we do not need anymore the data of this transaction)
314  * transactionFinished->queueElement.next = NULL;
315  * List_put(&i2sReadList, (List_Elem*)transactionFinished);
316  *
317  * // We need to queue a new transaction: let's take one in the treatment queue
318  * I2S_Transaction *newTransaction = (I2S_Transaction*)List_head(&treatmentList);
319  * if(newTransaction != NULL){
320  * List_remove(&treatmentList, (List_Elem*)newTransaction);
321  * newTransaction->queueElement.next = NULL;
322  * List_put(&i2sWriteList, (List_Elem*)newTransaction);
323  * }
324  * }
325  * }
326  *
327  * static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
328  *
329  * // We must remove the previous transaction (the current one is not over)
330  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
331  *
332  * if(transactionFinished != NULL){
333  * // The finished transaction contains data that must be treated
334  * List_remove(&i2sReadList, (List_Elem*)transactionFinished);
335  * transactionFinished->queueElement.next = NULL;
336  * List_put(&treatmentList, (List_Elem*)transactionFinished);
337  *
338  * // Start the treatment of the data
339  * Semaphore_post(dataReadyForTreatment);
340  *
341  * // We do not need to queue transaction here: writeCallbackFxn takes care of this :)
342  * }
343  * }
344  *
345  * static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
346  *
347  * // Handle the I2S error
348  * }
349  *
350  * void *myTreatmentThread(void *arg0){
351  *
352  * int k;
353  *
354  * while(1) {
355  * Semaphore_pend(dataReadyForTreatment, BIOS_WAIT_FOREVER);
356  *
357  * if(lastAchievedReadTransaction != NULL) {
358  *
359  * // Need a critical section to be sure to have corresponding bufPtr and bufSize
360  * uintptr_t key = HwiP_disable();
361  * uint16_t *buf = lastAchievedReadTransaction->bufPtr;
362  * uint16_t bufLength = lastAchievedReadTransaction->bufSize / sizeof(uint16_t);
363  * HwiP_restore(key);
364  *
365  * // My dummy data treatment...
366  * for(k=0; k<bufLength; k++) {buf[k] --;}
367  * for(k=0; k<bufLength; k++) {buf[k] ++;}
368  * }
369  * }
370  * }
371  *
372  * void *echoExampleThread(void *arg0)
373  * {
374  * I2S_Params i2sParams;
375  *
376  * I2S_init();
377  *
378  * // Initialize the treatmentList (this list is initially empty)
379  * List_clearList(&treatmentList);
380  *
381  * //Initialize I2S opening parameters
382  * I2S_Params_init(&i2sParams);
383  * i2sParams.fixedBufferLength = 1000;
384  * i2sParams.writeCallback = writeCallbackFxn ;
385  * i2sParams.readCallback = readCallbackFxn ;
386  * i2sParams.errorCallback = errCallbackFxn;
387  *
388  * i2sHandle = I2S_open(CONFIG_I2S0, &i2sParams);
389  *
390  * // Initialize the read-transactions
391  * I2S_Transaction_init(&i2sRead1);
392  * I2S_Transaction_init(&i2sRead2);
393  * I2S_Transaction_init(&i2sRead3);
394  * I2S_Transaction_init(&i2sRead4);
395  * i2sRead1.bufPtr = readBuf1;
396  * i2sRead2.bufPtr = readBuf2;
397  * i2sRead3.bufPtr = readBuf3;
398  * i2sRead4.bufPtr = readBuf4;
399  * i2sRead1.bufSize = sizeof(readBuf1);
400  * i2sRead2.bufSize = sizeof(readBuf2);
401  * i2sRead3.bufSize = sizeof(readBuf3);
402  * i2sRead4.bufSize = sizeof(readBuf4);
403  * List_clearList(&i2sReadList);
404  * List_put(&i2sReadList, (List_Elem*)&i2sRead1);
405  * List_put(&i2sReadList, (List_Elem*)&i2sRead2);
406  * List_put(&i2sReadList, (List_Elem*)&i2sRead3);
407  * List_put(&i2sReadList, (List_Elem*)&i2sRead4);
408  *
409  * I2S_setReadQueueHead(i2sHandle, &i2sRead1);
410  *
411  * // Initialize the write-transactions
412  * I2S_Transaction_init(&i2sWrite1);
413  * I2S_Transaction_init(&i2sWrite2);
414  * I2S_Transaction_init(&i2sWrite3);
415  * I2S_Transaction_init(&i2sWrite4);
416  * i2sWrite1.bufPtr = writeBuf1;
417  * i2sWrite2.bufPtr = writeBuf2;
418  * i2sWrite3.bufPtr = writeBuf3;
419  * i2sWrite4.bufPtr = writeBuf4;
420  * i2sWrite1.bufSize = sizeof(writeBuf1);
421  * i2sWrite2.bufSize = sizeof(writeBuf2);
422  * i2sWrite3.bufSize = sizeof(writeBuf3);
423  * i2sWrite4.bufSize = sizeof(writeBuf4);
424  * List_clearList(&i2sWriteList);
425  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite1);
426  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite2);
427  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite3);
428  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite4);
429  *
430  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite1);
431  *
432  * I2S_startClocks(i2sHandle);
433  * I2S_startWrite(i2sHandle);
434  * I2S_startRead(i2sHandle);
435  *
436  * while(1);
437  * }
438  * @endcode
439  *
440  * <hr>
441  * @anchor ti_drivers_I2S_Example_RepeatMode
442  * ### Writing Data in repeat Mode #
443  * The following example shows how to read and write data in repeat mode.
444  * The same buffers are continuously written and send out while the driver is not stopped.
445  * Here, we decide to only stop sending out after an arbitrary number of sending.
446  *
447  * <hr>
448  * @anchor ti_drivers_I2S_Example_RepeatMode_Code
449  * @code
450  * static I2S_Handle i2sHandle;
451  * static I2S_Config i2sConfig;
452  * static I2SCC26XX_Object i2sObject;
453  *
454  * // This buffer will be continuously re-written
455  * static uint16_t readBuf[500];
456  * // This data will be continuously sent out
457  * static uint16_t writeBuf[500] = {...some cool data...};
458  *
459  * static I2S_Transaction i2sRead;
460  * static I2S_Transaction i2sWrite;
461  *
462  * List_List i2sReadList;
463  * List_List i2sWriteList;
464  *
465  * static volatile bool writeFinished = (bool)false;
466  * static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
467  *
468  * // Nothing to do here: the buffer(s) are queued in a ring list, the transfers are
469  * // executed without any action from the application.
470  *
471  * // We must consider the previous transaction (ok, when you have only one transaction it's the same)
472  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
473  *
474  * if(transactionFinished != NULL){
475  * // After an arbitrary number of completion of the transaction, we will stop writting
476  * if(transactionFinished->numberOfCompletions >= 10) {
477  *
478  * // Note: You cannot use I2S_stopRead() / I2S_stopWrite() in the callback.
479  * // The execution of these functions is potentially blocking and can mess up the
480  * // system.
481  *
482  * writeFinished = (bool)true;
483  * }
484  * }
485  * }
486  *
487  * static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
488  * // Nothing to do here: the buffer(s) are queued in a ring list, the transfers are
489  * // executed without any action from the application.
490  * }
491  *
492  * static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
493  *
494  * // Handle the I2S error
495  * }
496  *
497  * void *modeRepeat(void *arg0)
498  * {
499  * I2S_Params i2sParams;
500  *
501  * // Initialize I2S opening parameters
502  * I2S_Params_init(&i2sParams);
503  * i2sParams.fixedBufferLength = 1000; // No problem here: the driver consider
504  * // the list as an infinite list.
505  * i2sParams.writeCallback = writeCallbackFxn ;
506  * i2sParams.readCallback = readCallbackFxn ;
507  * i2sParams.errorCallback = errCallbackFxn;
508  *
509  * i2sHandle = I2S_open(CONFIG_I2S0, &i2sParams);
510  *
511  * // Initialize the read-transactions
512  * I2S_Transaction_init(&i2sRead);
513  * i2sRead.bufPtr = readBuf;
514  * i2sRead.bufSize = sizeof(readBuf);
515  * List_put(&i2sReadList, (List_Elem*)&i2sRead);
516  * List_tail(&i2sReadList)->next = List_head(&i2sReadList);// Read buffers are queued in a ring-list
517  * List_head(&i2sReadList)->prev = List_tail(&i2sReadList);
518  *
519  * I2S_setReadQueueHead(i2sHandle, &i2sRead);
520  *
521  * // Initialize the write-transactions
522  * I2S_Transaction_init(&i2sWrite);
523  * i2sWrite.bufPtr = writeBuf;
524  * i2sWrite.bufSize = sizeof(writeBuf);
525  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite);
526  * List_tail(&i2sWriteList)->next = List_head(&i2sWriteList); // Write buffers are queued in a ring-list
527  * List_head(&i2sWriteList)->prev = List_tail(&i2sWriteList);
528  *
529  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite);
530  *
531  * I2S_startClocks(i2sHandle);
532  * I2S_startWrite(i2sHandle);
533  * I2S_startRead(i2sHandle);
534  *
535  * while(1){
536  *
537  * if(writeFinished){
538  * writeFinished = (bool)false;
539  * I2S_stopWrite(i2sHandle);
540  * }
541  * }
542  * }
543  * @endcode
544  *
545  * @note In the case of circular lists, there is no problem to put only
546  * one buffer in the queue.
547  *
548  * <hr>
549  * @anchor ti_drivers_I2S_Configuration
550  * # Configuration
551  *
552  * Refer to the @ref driver_configuration "Driver's Configuration" section
553  * for driver configuration information.
554  * <hr>
555  ******************************************************************************
556  */
557 
558 #ifndef ti_drivers_I2S__include
559 #define ti_drivers_I2S__include
560 
561 #include <stddef.h>
562 #include <stdbool.h>
563 #include <stdint.h>
564 
565 #include <ti/drivers/utils/List.h>
566 
567 
568 #ifdef __cplusplus
569 extern "C" {
570 #endif
571 
585  #define I2S_ALL_TRANSACTIONS_SUCCESS (0x0001U)
586 
593  #define I2S_TRANSACTION_SUCCESS (0x0002U)
594 
601  #define I2S_TIMEOUT_ERROR (0x0100U)
602 
610  #define I2S_BUS_ERROR (0x0200U)
611 
618  #define I2S_WS_ERROR (0x0400U)
619 
627  #define I2S_PTR_READ_ERROR (0x0800U)
628 
636  #define I2S_PTR_WRITE_ERROR (0x1000U)
637 
649 typedef struct {
651  void *object;
652 
654  void const *hwAttrs;
655 } I2S_Config;
656 
661 
665 typedef struct {
669  void *bufPtr;
671  size_t bufSize;
679  uintptr_t arg;
681 
695 typedef void (*I2S_Callback)(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr);
696 
705 typedef void (*I2S_RegUpdate)(uint32_t ui32Base, uint32_t ui32NextPointer);
706 
713 typedef void (*I2S_StopInterface)(I2S_Handle handle);
714 
721 typedef enum {
722 
729 
736 typedef enum {
737 
738  I2S_SLAVE = 0,
741 } I2S_Role;
742 
748 typedef enum {
749 
754 
760 typedef enum {
761 
765 } I2S_PhaseType;
766 
772 typedef enum {
773 
775  I2S_SD0_INPUT = 0x01U,
776  I2S_SD0_OUTPUT = 0x02U,
778  I2S_SD1_INPUT = 0x10U,
779  I2S_SD1_OUTPUT = 0x20U
782 
788 typedef enum {
789 
794  I2S_1_CHANNEL = 0x01U,
795  I2S_2_CHANNELS = 0x03U,
796  I2S_3_CHANNELS = 0x07U,
797  I2S_4_CHANNELS = 0x0FU,
798  I2S_5_CHANNELS = 0x1FU,
799  I2S_6_CHANNELS = 0x3FU,
800  I2S_7_CHANNELS = 0x7FU,
801  I2S_8_CHANNELS = 0xFFU,
805 
814 typedef struct {
815 
824  bool invertWS;
840  I2S_MemoryLength memorySlotLength;
853  uint8_t bitsPerWord;
866  I2S_DataInterfaceUse SD0Use;
872  I2S_DataInterfaceUse SD1Use;
878  I2S_ChannelConfig SD0Channels;
901  I2S_ChannelConfig SD1Channels;
924  I2S_PhaseType phaseType;
935  uint16_t startUpDelay;
938  uint16_t MCLKDivider;
956  void *custom;
958 } I2S_Params;
959 
965 extern const I2S_Params I2S_defaultParams;
966 
977 extern void I2S_close(I2S_Handle handle);
978 
987 extern void I2S_init(void);
988 
1009 extern I2S_Handle I2S_open(uint_least8_t index, I2S_Params *params);
1010 
1046 extern void I2S_Params_init(I2S_Params *params);
1047 
1065 extern void I2S_Transaction_init(I2S_Transaction *transaction);
1066 
1083 extern void I2S_setReadQueueHead(I2S_Handle handle, I2S_Transaction *transaction);
1084 
1101 extern void I2S_setWriteQueueHead(I2S_Handle handle, I2S_Transaction *transaction);
1102 
1116 extern void I2S_startClocks(I2S_Handle handle);
1117 
1136 extern void I2S_stopClocks(I2S_Handle handle);
1137 
1161 extern void I2S_startRead(I2S_Handle handle);
1162 
1186 extern void I2S_startWrite(I2S_Handle handle);
1187 
1209 extern void I2S_stopRead(I2S_Handle handle);
1210 
1232 extern void I2S_stopWrite(I2S_Handle handle);
1233 
1234 #ifdef __cplusplus
1235 }
1236 #endif
1237 
1238 #endif /* ti_drivers_I2S__include */
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:721
Definition: I2S.h:777
void * object
Definition: I2S.h:651
Definition: I2S.h:792
Definition: I2S.h:723
size_t bytesTransferred
Definition: I2S.h:673
const I2S_Params I2S_defaultParams
Default I2S_Params structure.
Definition: I2S.h:774
bool isMSBFirst
Definition: I2S.h:829
Definition: I2S.h:738
uint8_t beforeWordPadding
Definition: I2S.h:847
Definition: I2S.h:725
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:695
Definition: I2S.h:798
Definition: I2S.h:800
void(* I2S_RegUpdate)(uint32_t ui32Base, uint32_t ui32NextPointer)
The definition of a function used to set the I2S register.
Definition: I2S.h:705
Definition: I2S.h:739
size_t untransferredBytes
Definition: I2S.h:675
uint16_t MCLKDivider
Definition: I2S.h:938
void I2S_setWriteQueueHead(I2S_Handle handle, I2S_Transaction *transaction)
Function to set the first write-transaction to consider.
I2S_DataInterfaceUse SD1Use
Definition: I2S.h:872
uint32_t samplingFrequency
Definition: I2S.h:941
I2S Global configuration.
Definition: I2S.h:649
I2S_DataInterfaceUse
I2S data interface configuration.
Definition: I2S.h:772
Definition: I2S.h:790
I2S_PhaseType
I2S phase setting.
Definition: I2S.h:760
Definition: I2S.h:775
Definition: I2S.h:802
I2S_Role
I2S master / slave selection.
Definition: I2S.h:736
uint16_t fixedBufferLength
Definition: I2S.h:931
Definition: I2S.h:750
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:677
bool isDMAUnused
Definition: I2S.h:834
Definition: I2S.h:751
I2S_MemoryLength memorySlotLength
Definition: I2S.h:840
I2S_SamplingEdge samplingEdge
Definition: I2S.h:861
Definition: I2S.h:724
List_Elem queueElement
Definition: I2S.h:667
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:660
void I2S_Transaction_init(I2S_Transaction *transaction)
Initialize an I2S_Transaction struct to known state.
I2S_ChannelConfig
Channels used selection.
Definition: I2S.h:788
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:748
bool invertWS
Definition: I2S.h:824
I2S_PhaseType phaseType
Definition: I2S.h:924
Definition: I2S.h:794
uint16_t startUpDelay
Definition: I2S.h:935
Definition: I2S.h:726
I2S_DataInterfaceUse SD0Use
Definition: I2S.h:866
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:713
bool trueI2sFormat
Definition: I2S.h:816
I2S_Callback errorCallback
Definition: I2S.h:953
I2S_Role moduleRole
Definition: I2S.h:856
void I2S_stopWrite(I2S_Handle handle)
Stop write transactions.
Definition: I2S.h:793
I2S_ChannelConfig SD1Channels
Definition: I2S.h:901
void I2S_stopRead(I2S_Handle handle)
Stop read transactions.
Definition: I2S.h:801
uintptr_t arg
Definition: I2S.h:679
size_t bufSize
Definition: I2S.h:671
void * custom
Definition: I2S.h:956
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:763
I2S_Callback writeCallback
Definition: I2S.h:950
Definition: I2S.h:796
Definition: I2S.h:779
Definition: I2S.h:778
uint8_t bitsPerWord
Definition: I2S.h:853
Definition: I2S.h:797
Definition: I2S.h:791
I2S_Callback readCallback
Definition: I2S.h:947
Definition: List.h:126
I2S transaction descriptor.
Definition: I2S.h:665
Definition: I2S.h:795
void const * hwAttrs
Definition: I2S.h:654
void I2S_close(I2S_Handle handle)
Function to close a given I2S peripheral specified by the I2S handle.
Definition: I2S.h:762
Definition: I2S.h:799
uint8_t afterWordPadding
Definition: I2S.h:850
I2S_ChannelConfig SD0Channels
Definition: I2S.h:878
Definition: I2S.h:776
Linked List interface for use in drivers.
Basic I2S Parameters.
Definition: I2S.h:814
void * bufPtr
Definition: I2S.h:669
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale