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: You should normally avoid to use I2S_stopRead() / I2S_stopWrite() in the callback.
177  * //However, here we do not have any transaction left in the queue (cf. status' value) so
178  * //the call to I2S_stoWrite() will not block.
179  * //Moreover, by delaying I2S_stopWrite() the driver could raise an error (data underflow).
180  *
181  * I2S_stopWrite(i2sHandle);
182  * writeStopped = (bool)true;
183  * }
184  * }
185  *
186  * static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
187  *
188  * if(status & I2S_ALL_TRANSACTIONS_SUCCESS){
189  *
190  * //Note: You should normally avoid to use I2S_stopRead() / I2S_stopWrite() in the callback.
191  * //However, here we do not have any transaction left in the queue (cf. status' value) so
192  * //the call to I2S_stopRead() will not block.
193  * //Moreover, by delaying I2S_stopRead() the driver could raise an error (data overflow).
194  *
195  * I2S_stopRead(i2sHandle);
196  * readStopped = (bool)true;
197  * }
198  * }
199  *
200  * static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
201  * I2S_stopRead(handle);
202  * I2S_stopWrite(handle);
203  * I2S_stopClocks(handle);
204  * I2S_close(handle);
205  * }
206  *
207  * void *modePlayAndStopThread(void *arg0)
208  * {
209  * I2S_Params i2sParams;
210  *
211  * I2S_init();
212  *
213  * // Initialize I2S opening parameters
214  * I2S_Params_init(&i2sParams);
215  * i2sParams.fixedBufferLength = 500; // fixedBufferLength is the greatest common
216  * // divisor of all the different buffers
217  * // (here buffers' size are 500 and 1000 bytes)
218  * i2sParams.writeCallback = writeCallbackFxn ;
219  * i2sParams.readCallback = readCallbackFxn ;
220  * i2sParams.errorCallback = errCallbackFxn;
221  *
222  * i2sHandle = I2S_open(Board_I2S0, &i2sParams);
223  *
224  * // Initialize the read-transactions
225  * I2S_Transaction_init(&i2sRead1);
226  * I2S_Transaction_init(&i2sRead2);
227  * I2S_Transaction_init(&i2sRead3);
228  * i2sRead1.bufPtr = readBuf1;
229  * i2sRead2.bufPtr = readBuf2;
230  * i2sRead3.bufPtr = readBuf3;
231  * i2sRead1.bufSize = sizeof(readBuf1);
232  * i2sRead2.bufSize = sizeof(readBuf2);
233  * i2sRead3.bufSize = sizeof(readBuf3);
234  * List_put(&i2sReadList, (List_Elem*)&i2sRead1);
235  * List_put(&i2sReadList, (List_Elem*)&i2sRead2);
236  * List_put(&i2sReadList, (List_Elem*)&i2sRead3);
237  *
238  * I2S_setReadQueueHead(i2sHandle, &i2sRead1);
239  *
240  * // Initialize the write-transactions
241  * I2S_Transaction_init(&i2sWrite1);
242  * I2S_Transaction_init(&i2sWrite2);
243  * I2S_Transaction_init(&i2sWrite3);
244  * i2sWrite1.bufPtr = writeBuf1;
245  * i2sWrite2.bufPtr = writeBuf2;
246  * i2sWrite3.bufPtr = writeBuf3;
247  * i2sWrite1.bufSize = sizeof(writeBuf1);
248  * i2sWrite2.bufSize = sizeof(writeBuf2);
249  * i2sWrite3.bufSize = sizeof(writeBuf3);
250  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite1);
251  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite2);
252  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite3);
253  *
254  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite1);
255  *
256  * I2S_startClocks(i2sHandle);
257  * I2S_startWrite(i2sHandle);
258  * I2S_startRead(i2sHandle);
259  *
260  * readStopped = (bool)false;
261  * writeStopped = (bool)false;
262  *
263  * while(1) {
264  *
265  * if(readStopped && writeStopped) {
266  * I2S_stopClocks(i2sHandle);
267  * I2S_close(i2sHandle);
268  * while(1);
269  * }
270  * }
271  * }
272  * @endcode
273  *
274  * \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.
275  *
276  * <hr>
277  * @anchor ti_drivers_I2S_Example_Streaming
278  * ### Writing Data in Continuous Streaming Mode #
279  * The following example shows how to read and write data in streaming mode.
280  * A dummy treatment of the data is also done.
281  * This example is not complete (semaphore and tasks creation are not shown)
282  *
283  * <hr>
284  * @anchor ti_drivers_I2S_Example_Streaming_Code
285  * @code
286  * static I2S_Handle i2sHandle;
287  * static I2S_Config i2sConfig;
288  *
289  * // These buffers will successively be written, treated and sent out
290  * static uint16_t readBuf1[500];
291  * static uint16_t readBuf2[500];
292  * static uint16_t readBuf3[500];
293  * static uint16_t readBuf4[500];
294  * static uint16_t writeBuf1[500]={0};
295  * static uint16_t writeBuf2[500]={0};
296  * static uint16_t writeBuf3[500]={0};
297  * static uint16_t writeBuf4[500]={0};
298  *
299  * // These transactions will successively be part of the
300  * // i2sReadList, the treatmentList and the i2sWriteList
301  * static I2S_Transaction i2sRead1;
302  * static I2S_Transaction i2sRead2;
303  * static I2S_Transaction i2sRead3;
304  * static I2S_Transaction i2sRead4;
305  * static I2S_Transaction i2sWrite1;
306  * static I2S_Transaction i2sWrite2;
307  * static I2S_Transaction i2sWrite3;
308  * static I2S_Transaction i2sWrite4;
309  *
310  * List_List i2sReadList;
311  * List_List treatmentList;
312  * List_List i2sWriteList;
313  *
314  * static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
315  *
316  * // We must remove the previous transaction (the current one is not over)
317  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
318  *
319  * if(transactionFinished != NULL){
320  * // Remove the finished transaction from the write queue
321  * List_remove(&i2sWriteList, (List_Elem*)transactionFinished);
322  *
323  * // This transaction must now feed the read queue (we do not need anymore the data of this transaction)
324  * transactionFinished->queueElement.next = NULL;
325  * List_put(&i2sReadList, (List_Elem*)transactionFinished);
326  *
327  * // We need to queue a new transaction: let's take one in the treatment queue
328  * I2S_Transaction *newTransaction = (I2S_Transaction*)List_head(&treatmentList);
329  * if(newTransaction != NULL){
330  * List_remove(&treatmentList, (List_Elem*)newTransaction);
331  * newTransaction->queueElement.next = NULL;
332  * List_put(&i2sWriteList, (List_Elem*)newTransaction);
333  * }
334  * }
335  * }
336  *
337  * static void readCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
338  *
339  * // We must remove the previous transaction (the current one is not over)
340  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
341  *
342  * if(transactionFinished != NULL){
343  * // The finished transaction contains data that must be treated
344  * List_remove(&i2sReadList, (List_Elem*)transactionFinished);
345  * transactionFinished->queueElement.next = NULL;
346  * List_put(&treatmentList, (List_Elem*)transactionFinished);
347  *
348  * // Start the treatment of the data
349  * Semaphore_post(dataReadyForTreatment);
350  *
351  * // We do not need to queue transaction here: writeCallbackFxn takes care of this :)
352  * }
353  * }
354  *
355  * static void errCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
356  *
357  * }
358  *
359  * void *myTreatmentThread(void *arg0){
360  *
361  * int k;
362  *
363  * while(1) {
364  * Semaphore_pend(dataReadyForTreatment, BIOS_WAIT_FOREVER);
365  *
366  * if(lastAchievedReadTransaction != NULL) {
367  *
368  * // Need a critical section to be sure to have corresponding bufPtr and bufSize
369  * uintptr_t key = HwiP_disable();
370  * uint16_t *buf = lastAchievedReadTransaction->bufPtr;
371  * uint16_t bufLength = lastAchievedReadTransaction->bufSize / sizeof(uint16_t);
372  * HwiP_restore(key);
373  *
374  * // My dummy data treatment...
375  * for(k=0; k<bufLength; k++) {buf[k] --;}
376  * for(k=0; k<bufLength; k++) {buf[k] ++;}
377  * }
378  * }
379  * }
380  *
381  * void *echoExampleThread(void *arg0)
382  * {
383  * I2S_Params i2sParams;
384  *
385  * I2S_init();
386  *
387  * // Initialize the treatmentList (this list is initially empty)
388  * List_clearList(&treatmentList);
389  *
390  * //Initialize I2S opening parameters
391  * I2S_Params_init(&i2sParams);
392  * i2sParams.fixedBufferLength = 1000;
393  * i2sParams.writeCallback = writeCallbackFxn ;
394  * i2sParams.readCallback = readCallbackFxn ;
395  * i2sParams.errorCallback = errCallbackFxn;
396  *
397  * i2sHandle = I2S_open(Board_I2S0, &i2sParams);
398  *
399  * // Initialize the read-transactions
400  * I2S_Transaction_init(&i2sRead1);
401  * I2S_Transaction_init(&i2sRead2);
402  * I2S_Transaction_init(&i2sRead3);
403  * I2S_Transaction_init(&i2sRead4);
404  * i2sRead1.bufPtr = readBuf1;
405  * i2sRead2.bufPtr = readBuf2;
406  * i2sRead3.bufPtr = readBuf3;
407  * i2sRead4.bufPtr = readBuf4;
408  * i2sRead1.bufSize = sizeof(readBuf1);
409  * i2sRead2.bufSize = sizeof(readBuf2);
410  * i2sRead3.bufSize = sizeof(readBuf3);
411  * i2sRead4.bufSize = sizeof(readBuf4);
412  * List_clearList(&i2sReadList);
413  * List_put(&i2sReadList, (List_Elem*)&i2sRead1);
414  * List_put(&i2sReadList, (List_Elem*)&i2sRead2);
415  * List_put(&i2sReadList, (List_Elem*)&i2sRead3);
416  * List_put(&i2sReadList, (List_Elem*)&i2sRead4);
417  *
418  * I2S_setReadQueueHead(i2sHandle, &i2sRead1);
419  *
420  * // Initialize the write-transactions
421  * I2S_Transaction_init(&i2sWrite1);
422  * I2S_Transaction_init(&i2sWrite2);
423  * I2S_Transaction_init(&i2sWrite3);
424  * I2S_Transaction_init(&i2sWrite4);
425  * i2sWrite1.bufPtr = writeBuf1;
426  * i2sWrite2.bufPtr = writeBuf2;
427  * i2sWrite3.bufPtr = writeBuf3;
428  * i2sWrite4.bufPtr = writeBuf4;
429  * i2sWrite1.bufSize = sizeof(writeBuf1);
430  * i2sWrite2.bufSize = sizeof(writeBuf2);
431  * i2sWrite3.bufSize = sizeof(writeBuf3);
432  * i2sWrite4.bufSize = sizeof(writeBuf4);
433  * List_clearList(&i2sWriteList);
434  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite1);
435  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite2);
436  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite3);
437  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite4);
438  *
439  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite1);
440  *
441  * I2S_startClocks(i2sHandle);
442  * I2S_startWrite(i2sHandle);
443  * I2S_startRead(i2sHandle);
444  *
445  * while(1);
446  * }
447  * @endcode
448  *
449  * <hr>
450  * @anchor ti_drivers_I2S_Example_RepeatMode
451  * ### Writing Data in repeat Mode #
452  * The following example shows how to read and write data in repeat mode.
453  * The same buffers are continuously written and send out while the driver is not stopped.
454  * Here, we decide to only stop sending out after an arbitrary number of sending.
455  *
456  * <hr>
457  * @anchor ti_drivers_I2S_Example_RepeatMode_Code
458  * @code
459  * static I2S_Handle i2sHandle;
460  * static I2S_Config i2sConfig;
461  * static I2SCC26XX_Object i2sObject;
462  *
463  * // This buffer will be continuously re-written
464  * static uint16_t readBuf[500];
465  * // This data will be continuously sent out
466  * static uint16_t writeBuf[500] = {...some cool data...};
467  *
468  * static I2S_Transaction i2sRead;
469  * static I2S_Transaction i2sWrite;
470  *
471  * List_List i2sReadList;
472  * List_List i2sWriteList;
473  *
474  * static volatile bool writeFinished = (bool)false;
475  * static void writeCallbackFxn(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr) {
476  *
477  * // Nothing to do here: the buffer(s) are queued in a ring list, the transfers are
478  * // executed without any action from the application.
479  *
480  * // We must consider the previous transaction (ok, when you have only one transaction it's the same)
481  * I2S_Transaction *transactionFinished = (I2S_Transaction*)List_prev(&transactionPtr->queueElement);
482  *
483  * if(transactionFinished != NULL){
484  * // After an arbitrary number of completion of the transaction, we will stop writting
485  * if(transactionFinished->numberOfCompletions >= 10) {
486  *
487  * // Note: You should avoid to use I2S_stopRead() / I2S_stopWrite() in the callback,
488  * // especially if you do not want to stop both read and write transfers.
489  * // The execution of these functions is potentially blocking and can mess up the
490  * // other transfers.
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  * }
505  *
506  * void *modeRepeat(void *arg0)
507  * {
508  * I2S_Params i2sParams;
509  *
510  * // Initialize I2S opening parameters
511  * I2S_Params_init(&i2sParams);
512  * i2sParams.fixedBufferLength = 1000; // No problem here: the driver consider
513  * // the list as an infinite list.
514  * i2sParams.writeCallback = writeCallbackFxn ;
515  * i2sParams.readCallback = readCallbackFxn ;
516  * i2sParams.errorCallback = errCallbackFxn;
517  *
518  * i2sHandle = I2S_open(0, &i2sParams);
519  *
520  * // Initialize the read-transactions
521  * I2S_Transaction_init(&i2sRead);
522  * i2sRead.bufPtr = readBuf;
523  * i2sRead.bufSize = sizeof(readBuf);
524  * List_put(&i2sReadList, (List_Elem*)&i2sRead);
525  * List_tail(&i2sReadList)->next = List_head(&i2sReadList);// Read buffers are queued in a ring-list
526  * List_head(&i2sReadList)->prev = List_tail(&i2sReadList);
527  *
528  * I2S_setReadQueueHead(i2sHandle, &i2sRead);
529  *
530  * // Initialize the write-transactions
531  * I2S_Transaction_init(&i2sWrite);
532  * i2sWrite.bufPtr = writeBuf;
533  * i2sWrite.bufSize = sizeof(writeBuf);
534  * List_put(&i2sWriteList, (List_Elem*)&i2sWrite);
535  * List_tail(&i2sWriteList)->next = List_head(&i2sWriteList); // Write buffers are queued in a ring-list
536  * List_head(&i2sWriteList)->prev = List_tail(&i2sWriteList);
537  *
538  * I2S_setWriteQueueHead(i2sHandle, &i2sWrite);
539  *
540  * I2S_startClocks(i2sHandle);
541  * I2S_startWrite(i2sHandle);
542  * I2S_startRead(i2sHandle);
543  *
544  * while(1){
545  *
546  * if(writeFinished){
547  * writeFinished = (bool)false;
548  * I2S_stopWrite(i2sHandle);
549  * }
550  * }
551  * }
552  * @endcode
553  *
554  * @note In the case of circular lists, there is no problem to put only
555  * one buffer in the queue.
556  *
557  * <hr>
558  * @anchor ti_drivers_I2S_Configuration
559  * # Configuration
560  *
561  * Refer to the @ref driver_configuration "Driver's Configuration" section
562  * for driver configuration information.
563  * <hr>
564  ******************************************************************************
565  */
566 
567 #ifndef ti_drivers_I2S__include
568 #define ti_drivers_I2S__include
569 
570 #include <stddef.h>
571 #include <stdbool.h>
572 #include <stdint.h>
573 
574 #include <ti/drivers/utils/List.h>
575 
576 
577 #ifdef __cplusplus
578 extern "C" {
579 #endif
580 
594  #define I2S_ALL_TRANSACTIONS_SUCCESS (0x0001U)
595 
602  #define I2S_TRANSACTION_SUCCESS (0x0002U)
603 
610  #define I2S_TIMEOUT_ERROR (0x0100U)
611 
619  #define I2S_BUS_ERROR (0x0200U)
620 
627  #define I2S_WS_ERROR (0x0400U)
628 
636  #define I2S_PTR_READ_ERROR (0x0800U)
637 
645  #define I2S_PTR_WRITE_ERROR (0x1000U)
646 
651 typedef struct I2S_Config_ *I2S_Handle;
652 
656 typedef struct I2S_Transaction_ {
660  void *bufPtr;
662  size_t bufSize;
670  uintptr_t arg;
672 
686 typedef void (*I2S_Callback)(I2S_Handle handle, int_fast16_t status, I2S_Transaction *transactionPtr);
687 
696 typedef void (*I2S_RegUpdate)(uint32_t ui32Base, uint32_t ui32NextPointer);
697 
704 typedef enum I2S_MemoryLength_ {
705 
712 
719 typedef enum I2S_Role_ {
720 
721  I2S_SLAVE = 0,
724 } I2S_Role;
725 
731 typedef enum I2S_SamplingEdge_ {
732 
737 
743 typedef enum I2S_PhaseType_ {
744 
748 } I2S_PhaseType;
749 
755 typedef enum I2S_DataInterfaceUse_ {
756 
758  I2S_SD0_INPUT = 0x01U,
759  I2S_SD0_OUTPUT = 0x02U,
761  I2S_SD1_INPUT = 0x10U,
762  I2S_SD1_OUTPUT = 0x20U
765 
771 typedef enum I2S_ChannelConfig_ {
772 
777  I2S_1_CHANNEL = 0x01U,
778  I2S_2_CHANNELS = 0x03U,
779  I2S_3_CHANNELS = 0x07U,
780  I2S_4_CHANNELS = 0x0FU,
781  I2S_5_CHANNELS = 0x1FU,
782  I2S_6_CHANNELS = 0x3FU,
783  I2S_7_CHANNELS = 0x7FU,
784  I2S_8_CHANNELS = 0xFFU,
788 
797 typedef struct I2S_Params_ {
798 
799  bool invertWS;
815  I2S_MemoryLength memorySlotLength;
828  uint8_t bitsPerWord;
841  I2S_DataInterfaceUse SD0Use;
847  I2S_DataInterfaceUse SD1Use;
853  I2S_ChannelConfig SD0Channels;
876  I2S_ChannelConfig SD1Channels;
899  I2S_PhaseType phaseType;
910  uint16_t startUpDelay;
913  uint16_t MCLKDivider;
931  void *custom;
933 } I2S_Params;
934 
940 extern const I2S_Params I2S_defaultParams;
941 
952 typedef struct I2S_Config_ {
954  void *object;
955 
957  void const *hwAttrs;
958 } I2S_Config;
959 
970 extern void I2S_close(I2S_Handle handle);
971 
980 extern void I2S_init(void);
981 
1002 extern I2S_Handle I2S_open(uint_least8_t index, I2S_Params *params);
1003 
1038 extern void I2S_Params_init(I2S_Params *params);
1039 
1057 extern void I2S_Transaction_init(I2S_Transaction *transaction);
1058 
1075 extern void I2S_setReadQueueHead(I2S_Handle handle, I2S_Transaction *transaction);
1076 
1093 extern void I2S_setWriteQueueHead(I2S_Handle handle, I2S_Transaction *transaction);
1094 
1108 extern void I2S_startClocks(I2S_Handle handle);
1109 
1124 extern void I2S_stopClocks(I2S_Handle handle);
1125 
1140 extern void I2S_startRead(I2S_Handle handle);
1141 
1156 extern void I2S_startWrite(I2S_Handle handle);
1157 
1169 extern void I2S_stopRead(I2S_Handle handle);
1170 
1182 extern void I2S_stopWrite(I2S_Handle handle);
1183 
1184 #ifdef __cplusplus
1185 }
1186 #endif
1187 
1188 #endif /* ti_drivers_I2S__include */
I2S_Callback writeCallback
Definition: I2S.h:925
I2S_MemoryLength_
I2S slot memory length setting.
Definition: I2S.h:704
Definition: I2S.h:784
struct I2S_Params_ I2S_Params
Basic I2S Parameters.
void * custom
Definition: I2S.h:931
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.
void * bufPtr
Definition: I2S.h:660
Definition: I2S.h:706
enum I2S_ChannelConfig_ I2S_ChannelConfig
Channels used selection.
enum I2S_Role_ I2S_Role
I2S master / slave selection.
const I2S_Params I2S_defaultParams
Default I2S_Params structure.
enum I2S_SamplingEdge_ I2S_SamplingEdge
I2S sampling setting.
Definition: I2S.h:780
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:686
enum I2S_MemoryLength_ I2S_MemoryLength
I2S slot memory length setting.
Definition: I2S.h:762
uint8_t afterWordPadding
Definition: I2S.h:825
uint16_t startUpDelay
Definition: I2S.h:910
Definition: I2S.h:745
I2S_MemoryLength memorySlotLength
Definition: I2S.h:815
Definition: I2S.h:779
Basic I2S Parameters.
Definition: I2S.h:797
enum I2S_DataInterfaceUse_ I2S_DataInterfaceUse
I2S data interface configuration.
void(* I2S_RegUpdate)(uint32_t ui32Base, uint32_t ui32NextPointer)
The definition of a function used to set the I2S register.
Definition: I2S.h:696
I2S_ChannelConfig_
Channels used selection.
Definition: I2S.h:771
void I2S_setWriteQueueHead(I2S_Handle handle, I2S_Transaction *transaction)
Function to set the first write-transaction to consider.
I2S_DataInterfaceUse_
I2S data interface configuration.
Definition: I2S.h:755
Definition: I2S.h:733
Definition: I2S.h:759
I2S_PhaseType_
I2S phase setting.
Definition: I2S.h:743
Definition: I2S.h:757
I2S_ChannelConfig SD0Channels
Definition: I2S.h:853
Definition: I2S.h:746
uint16_t MCLKDivider
Definition: I2S.h:913
Definition: I2S.h:708
size_t untransferredBytes
Definition: I2S.h:666
I2S_DataInterfaceUse SD1Use
Definition: I2S.h:847
void I2S_init(void)
Function to initializes the I2S module.
Definition: I2S.h:709
Definition: List.h:126
void I2S_startClocks(I2S_Handle handle)
Start the WS, SCK and MCLK clocks.
Definition: I2S.h:776
void const * hwAttrs
Definition: I2S.h:957
I2S_Role_
I2S master / slave selection.
Definition: I2S.h:719
uint8_t bitsPerWord
Definition: I2S.h:828
Definition: I2S.h:773
Definition: I2S.h:734
void I2S_startWrite(I2S_Handle handle)
Start write transactions.
enum I2S_PhaseType_ I2S_PhaseType
I2S phase setting.
Definition: I2S.h:761
void I2S_Transaction_init(I2S_Transaction *transaction)
Initialize an I2S_Transaction struct to known state.
Definition: I2S.h:760
void I2S_setReadQueueHead(I2S_Handle handle, I2S_Transaction *transaction)
Function to set the first read-transaction to consider.
Definition: I2S.h:722
I2S_DataInterfaceUse SD0Use
Definition: I2S.h:841
Definition: I2S.h:781
uint16_t fixedBufferLength
Definition: I2S.h:906
I2S transaction descriptor.
Definition: I2S.h:656
size_t bufSize
Definition: I2S.h:662
void I2S_stopClocks(I2S_Handle handle)
Stops the WS, SCK and MCLK clocks.
size_t bytesTransferred
Definition: I2S.h:664
I2S_SamplingEdge_
I2S sampling setting.
Definition: I2S.h:731
Definition: I2S.h:778
I2S_Callback errorCallback
Definition: I2S.h:928
void I2S_stopWrite(I2S_Handle handle)
Stop write transactions.
bool invertWS
Definition: I2S.h:799
void I2S_stopRead(I2S_Handle handle)
Stop read transactions.
struct I2S_Transaction_ I2S_Transaction
I2S transaction descriptor.
I2S Global configuration.
Definition: I2S.h:952
I2S_ChannelConfig SD1Channels
Definition: I2S.h:876
I2S_PhaseType phaseType
Definition: I2S.h:899
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.
uint16_t numberOfCompletions
Definition: I2S.h:668
Definition: I2S.h:785
Definition: I2S.h:707
uint32_t samplingFrequency
Definition: I2S.h:916
List_Elem queueElement
Definition: I2S.h:658
I2S_Callback readCallback
Definition: I2S.h:922
Definition: I2S.h:777
uint8_t beforeWordPadding
Definition: I2S.h:822
Definition: I2S.h:774
I2S_Role moduleRole
Definition: I2S.h:831
Definition: I2S.h:783
void * object
Definition: I2S.h:954
Definition: I2S.h:758
void I2S_close(I2S_Handle handle)
Function to close a given I2S peripheral specified by the I2S handle.
bool isDMAUnused
Definition: I2S.h:809
struct I2S_Config_ * I2S_Handle
A handle that is returned from a I2S_open() call.
Definition: I2S.h:651
struct I2S_Config_ I2S_Config
I2S Global configuration.
uintptr_t arg
Definition: I2S.h:670
Definition: I2S.h:782
Definition: I2S.h:721
Definition: I2S.h:775
Linked List interface for use in drivers.
bool isMSBFirst
Definition: I2S.h:804
I2S_SamplingEdge samplingEdge
Definition: I2S.h:836
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale