1 /******************************************************************************
2 *  Filename:       i2s.h
3 *  Revised:        2015-11-16 19:41:47 +0100 (Mon, 16 Nov 2015)
4 *  Revision:       45094
5 *
6 *  Description:    Defines and prototypes for the I2S.
7 *
8 *  Copyright (c) 2015, Texas Instruments Incorporated
9 *  All rights reserved.
10 *
11 *  Redistribution and use in source and binary forms, with or without
12 *  modification, are permitted provided that the following conditions are met:
13 *
14 *  1) Redistributions of source code must retain the above copyright notice,
15 *     this list of conditions and the following disclaimer.
16 *
17 *  2) Redistributions in binary form must reproduce the above copyright notice,
18 *     this list of conditions and the following disclaimer in the documentation
19 *     and/or other materials provided with the distribution.
20 *
21 *  3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 *     be used to endorse or promote products derived from this software without
23 *     specific prior written permission.
24 *
25 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 *  POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 //****************************************************************************
40 //
41 //! \addtogroup peripheral_group
42 //! @{
43 //! \addtogroup i2s_api
44 //! @{
45 //
46 //****************************************************************************
47 
48 #ifndef __I2S_H__
49 #define __I2S_H__
50 
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include <inc/hw_types.h>
65 #include <inc/hw_memmap.h>
66 #include <inc/hw_ints.h>
67 #include <inc/hw_i2s.h>
68 #include <driverlib/debug.h>
69 #include <driverlib/interrupt.h>
70 
71 //*****************************************************************************
72 //
73 // Support for DriverLib in ROM:
74 // This section renames all functions that are not "static inline", so that
75 // calling these functions will default to implementation in flash. At the end
76 // of this file a second renaming will change the defaults to implementation in
77 // ROM for available functions.
78 //
79 // To force use of the implementation in flash, e.g. for debugging:
80 // - Globally: Define DRIVERLIB_NOROM at project level
81 // - Per function: Use prefix "NOROM_" when calling the function
82 //
83 //*****************************************************************************
84 #if !defined(DOXYGEN)
85     #define I2SEnable                       NOROM_I2SEnable
86     #define I2SAudioFormatConfigure         NOROM_I2SAudioFormatConfigure
87     #define I2SChannelConfigure             NOROM_I2SChannelConfigure
88     #define I2SBufferConfig                 NOROM_I2SBufferConfig
89     #define I2SPointerUpdate                NOROM_I2SPointerUpdate
90     #define I2SPointerSet                   NOROM_I2SPointerSet
91     #define I2SSampleStampConfigure         NOROM_I2SSampleStampConfigure
92     #define I2SSampleStampGet               NOROM_I2SSampleStampGet
93 #endif
94 
95 //*****************************************************************************
96 //
97 //! \brief A structure that defines an audio control table. Note: Memory for this
98 //! structure \b must be initialized by user application. See detailed description!
99 //!
100 //! These fields are used by the I2S and normally it is not necessary for
101 //! software to directly read or write fields in the table.
102 //!
103 //! \note The control table must be defined by the user as a global variable and
104 //! the global pointer must then be assigned the address of the control table
105 //! inside a user function (but before calling any I2S-function).
106 //!
107 /*!
108 \verbatim
109  I2SControlTable g_controlTable;    // Define global
110  g_pControlTable = &g_controlTable; // Assign pointer (inside a function)
111 \endverbatim
112 */
113 //!
114 //
115 //*****************************************************************************
116 typedef struct
117 {
118     uint16_t ui16DMABufSize;        //!< Size of DMA buffer in number of samples.
119     uint16_t ui16ChBufSize;         //!< Size of Channel buffer.
120     uint8_t ui8InChan;              //!< Input Channel.
121     uint8_t ui8OutChan;             //!< Output Channel.
122     uint16_t ui16MemLen;            //!< Length of the audio words stored in memory.
123     uint32_t ui32InBase;            //!< Base address of the input buffer.
124     uint32_t ui32InOffset;          //!< Value of the current input pointer offset.
125     uint32_t ui32OutBase;           //!< Base address of the output buffer.
126     uint32_t ui32OutOffset;         //!< Value of the current output pointer offset.
127 } I2SControlTable;
128 
129 //*****************************************************************************
130 //
131 // Declare global pointer to the I2S data structure.
132 //
133 // The control table must be defined by the user as a global variable and the
134 // global pointer must then be assigned the address of the control table:
135 //
136 // I2SControlTable g_controlTable;
137 // g_pControlTable = &g_controlTable;
138 //
139 //*****************************************************************************
140 extern I2SControlTable *g_pControlTable;
141 
142 //*****************************************************************************
143 //
144 // Defines for the I2S DMA buffer sizes
145 //
146 //*****************************************************************************
147 #define I2S_DMA_BUF_SIZE_64     0x00000040
148 #define I2S_DMA_BUF_SIZE_128    0x00000080
149 #define I2S_DMA_BUF_SIZE_256    0x00000100
150 
151 //*****************************************************************************
152 //
153 // Defines for the I2S audio clock configuration
154 //
155 //*****************************************************************************
156 #define I2S_EXT_WCLK            0x00000001
157 #define I2S_INT_WCLK            0x00000002
158 #define I2S_INVERT_WCLK         0x00000004
159 #define I2S_NORMAL_WCLK         0x00000000
160 
161 //*****************************************************************************
162 //
163 // Defines for the audio data line input/output configuration
164 //
165 //*****************************************************************************
166 #define I2S_LINE_UNUSED         0x00000000
167 #define I2S_LINE_INPUT          0x00000001
168 #define I2S_LINE_OUTPUT         0x00000002
169 #define I2S_LINE_MASK           0x00000003
170 
171 //*****************************************************************************
172 //
173 // Defines for activating an audio channel.
174 //
175 //*****************************************************************************
176 #define I2S_CHAN0_ACT           0x00000100
177 #define I2S_CHAN1_ACT           0x00000200
178 #define I2S_CHAN2_ACT           0x00000400
179 #define I2S_CHAN3_ACT           0x00000800
180 #define I2S_CHAN4_ACT           0x00001000
181 #define I2S_CHAN5_ACT           0x00002000
182 #define I2S_CHAN6_ACT           0x00004000
183 #define I2S_CHAN7_ACT           0x00008000
184 #define I2S_MONO_MODE           0x00000100
185 #define I2S_STEREO_MODE         0x00000300
186 #define I2S_CHAN_CFG_MASK       0x0000FF00
187 
188 //*****************************************************************************
189 //
190 // Defines for the audio format configuration
191 //
192 //*****************************************************************************
193 #define I2S_MEM_LENGTH_16       0x00000000  // 16 bit size of word in memory
194 #define I2S_MEM_LENGTH_24       0x00000080  // 24 bit size of word in memory
195 #define I2S_POS_EDGE            0x00000040  // Sample on positive edge
196 #define I2S_NEG_EDGE            0x00000000  // Sample on negative edge
197 #define I2S_DUAL_PHASE_FMT      0x00000020  // Dual Phased audio format
198 #define I2S_SINGLE_PHASE_FMT    0x00000000  // Single Phased audio format
199 #define I2S_WORD_LENGTH_8       0x00000008  // Word length is 8 bits
200 #define I2S_WORD_LENGTH_16      0x00000010  // Word length is 16 bits
201 #define I2S_WORD_LENGTH_24      0x00000018  // Word length is 24 bits
202 
203 //*****************************************************************************
204 //
205 // Defines for the sample stamp counters
206 //
207 //*****************************************************************************
208 #define I2S_STMP0               0x00000001  // Sample stamp counter channel 0
209 #define I2S_STMP1               0x00000002  // Sample stamp counter channel 1
210 #define I2S_STMP_SATURATION     0x0000FFFF  // The saturation value used when
211                                             // calculating the sample stamp
212 
213 //*****************************************************************************
214 //
215 // Defines for the interrupt
216 //
217 //*****************************************************************************
218 #define I2S_INT_DMA_IN          0x00000020  // DMA output buffer full interrupt
219 #define I2S_INT_DMA_OUT         0x00000010  // DMA input buffer empty interrupt
220 #define I2S_INT_TIMEOUT         0x00000008  // Word Clock Timeout
221 #define I2S_INT_BUS_ERR         0x00000004  // DMA Bus error
222 #define I2S_INT_WCLK_ERR        0x00000002  // Word Clock error
223 #define I2S_INT_PTR_ERR         0x00000001  // Data pointer error (DMA data was not updated in time).
224 #define I2S_INT_ALL             0x0000003F  // All interrupts
225 
226 //*****************************************************************************
227 //
228 // API Functions and prototypes
229 //
230 //*****************************************************************************
231 
232 #ifdef DRIVERLIB_DEBUG
233 //*****************************************************************************
234 //
235 //! \internal
236 //!
237 //! \brief Checks an I2S base address.
238 //!
239 //! This function determines if an I2S port base address is valid.
240 //!
241 //! \param ui32Base is the base address of the I2S port.
242 //!
243 //! \return Returns \c true if the base address is valid and \c false
244 //! otherwise.
245 //
246 //*****************************************************************************
247 static bool
I2SBaseValid(uint32_t ui32Base)248 I2SBaseValid(uint32_t ui32Base)
249 {
250     return(ui32Base == I2S0_BASE);
251 }
252 #endif
253 
254 //*****************************************************************************
255 //
256 //! \brief Enables the I2S module for operation.
257 //!
258 //! \note The module should only be enabled after configuration. When the
259 //! module is disabled, no data or clocks will be generated on the I2S signals.
260 //!
261 //! \note Immediately after enabling the module the programmer should update
262 //! the DMA data pointer registers using \ref I2SPointerUpdate() to ensure a new
263 //! pointer is written before the DMA transfer completes. Failure to update
264 //! the pointer in time will result in an \ref I2S_INT_PTR_ERR.
265 //!
266 //! \param ui32Base is the I2S module base address.
267 //!
268 //! \return None
269 //
270 //*****************************************************************************
271 extern void I2SEnable(uint32_t ui32Base);
272 
273 //*****************************************************************************
274 //
275 //! \brief Disables the I2S module for operation.
276 //!
277 //! This function will immediately disable the I2S module. To ensure that
278 //! all buffer operations are completed before shutting down, the correct
279 //! procedure is:
280 //! 1. Do not update the data pointers using \ref I2SPointerUpdate().
281 //! 2. Await next interrupt resulting in \ref I2S_INT_PTR_ERR.
282 //! 3. Disable the I2S using \ref I2SDisable() and clear the pointer error using
283 //!    \ref I2SIntClear().
284 //! 4. Disable bit clock source (done externally).
285 //!
286 //! \param ui32Base is the I2S module base address.
287 //!
288 //! \return None
289 //
290 //*****************************************************************************
291 __STATIC_INLINE void
I2SDisable(uint32_t ui32Base)292 I2SDisable(uint32_t ui32Base)
293 {
294     //
295     // Check the arguments.
296     //
297     ASSERT(I2SBaseValid(ui32Base));
298 
299     //
300     // Disable the I2S module.
301     //
302     HWREG(I2S0_BASE + I2S_O_AIFDMACFG) = 0x0;
303 }
304 
305 //*****************************************************************************
306 //
307 //! \brief Configures the I2S module.
308 //!
309 //! The word length defines the size of the word transmitted on the data
310 //! lines. For single phased formats \c I2S_WORD_LENGTH_x is the exact number
311 //! of bits per word. In dual phased format this is the maximum number of bits
312 //! per word. The size is set using \ref I2S_WORD_LENGTH_8,
313 //! \ref I2S_WORD_LENGTH_16 or \ref I2S_WORD_LENGTH_24.
314 //!
315 //! \param ui32Base is the I2S module base address.
316 //! \param ui32FmtCfg is the bitwise OR of several options:
317 //! - Sample size:
318 //!   - \ref I2S_MEM_LENGTH_16
319 //!   - \ref I2S_MEM_LENGTH_24
320 //! - Clock edge sampling:
321 //!   - \ref I2S_POS_EDGE
322 //!   - \ref I2S_NEG_EDGE
323 //! - Phase:
324 //!   - \ref I2S_DUAL_PHASE_FMT
325 //!   - \ref I2S_SINGLE_PHASE_FMT
326 //! - Word length:
327 //!   - \ref I2S_WORD_LENGTH_8
328 //!   - \ref I2S_WORD_LENGTH_16
329 //!   - \ref I2S_WORD_LENGTH_24
330 //! \param ui32BitClkDelay defines the bit clock delay by setting the number of bit clock periods between the
331 //! positive word clock edge and the MSB of the first word in a phase. The bit
332 //! clock delay is determined by the ratio between the bit clock and the frame
333 //! clock and the chosen audio format. The bit clock delay \b must be configured
334 //! depending on the chosen audio format:
335 //! - 0     : Left Justified Format (LJF).
336 //! - 1     : I2S and DSP format.
337 //! - 2-255 : Right Justified format (RJF).
338 //!
339 //! \return None
340 //!
341 //! \sa \ref I2SChannelConfigure()
342 //
343 //*****************************************************************************
344 extern void I2SAudioFormatConfigure(uint32_t ui32Base, uint32_t ui32FmtCfg,
345                                     uint32_t ui32BitClkDelay);
346 
347 //****************************************************************************
348 //
349 //! \brief Setup the audio channel configuration.
350 //!
351 //! The channel configuration is a bitwise OR of the input/output mode of each
352 //! data line and the active audio channels within a specific audio frame.
353 //!
354 //! Setting up the input/output mode use one of:
355 //! - \ref I2S_LINE_UNUSED
356 //! - \ref I2S_LINE_INPUT
357 //! - \ref I2S_LINE_OUTPUT
358 //!
359 //! For dual phased audio (LJF,RJF,I2S) only mono and stereo modes are allowed.
360 //! For single phased audio format (DSP) up to 8 active channels are allowed
361 //! on a single data line. For setting up the active channels in a frame use:
362 //! - Single phased, use a bitwise OR'ed combination of:
363 //!   - \ref I2S_CHAN0_ACT
364 //!   - \ref I2S_CHAN1_ACT
365 //!   - \ref I2S_CHAN2_ACT
366 //!   - \ref I2S_CHAN3_ACT
367 //!   - \ref I2S_CHAN4_ACT
368 //!   - \ref I2S_CHAN5_ACT
369 //!   - \ref I2S_CHAN6_ACT
370 //!   - \ref I2S_CHAN7_ACT
371 //! - Dual phased, use one of:
372 //!   - \ref I2S_MONO_MODE (same as \ref I2S_CHAN0_ACT)
373 //!   - \ref I2S_STEREO_MODE (same as \ref I2S_CHAN0_ACT | \ref I2S_CHAN1_ACT)
374 //!
375 //! \note The audio format and the clock configuration should be set using
376 //! \ref I2SAudioFormatConfigure()
377 //!
378 //! \param ui32Base is base address of the I2S module.
379 //! \param ui32Chan0Cfg defines the channel configuration for data line 0.
380 //! \param ui32Chan1Cfg defines the channel configuration for data line 1.
381 //! \param ui32Chan2Cfg defines the channel configuration for data line 2.
382 //!
383 //! \return None
384 //!
385 //! \sa \ref I2SAudioFormatConfigure()
386 //
387 //****************************************************************************
388 extern void I2SChannelConfigure(uint32_t ui32Base, uint32_t ui32Chan0Cfg,
389                                 uint32_t ui32Chan1Cfg, uint32_t ui32Chan2Cfg);
390 
391 //****************************************************************************
392 //
393 //! \brief Configure the I2S frame clock.
394 //!
395 //! Configure I2S clock to be either internal or external and either normal
396 //! or inverted.
397 //!
398 //! \note The bit clock configuration is done externally, but the internal/
399 //! external setting must match what is chosen internally in the I2S module
400 //! for the frame clock.
401 //!
402 //! \param ui32Base is the base address of the I2S module.
403 //! \param ui32ClkConfig is the clock configuration parameter. Bitwise OR'ed
404 //! combination of clock source and clock polarity:
405 //! - Clock source:
406 //!   - \ref I2S_EXT_WCLK : External clock.
407 //!   - \ref I2S_INT_WCLK : Internal clock.
408 //! - Clock polarity:
409 //!   - \ref I2S_NORMAL_WCLK : Normal clock.
410 //!   - \ref I2S_INVERT_WCLK : Inverted clock.
411 //!
412 //! \return None
413 //
414 //****************************************************************************
415 __STATIC_INLINE void
I2SClockConfigure(uint32_t ui32Base,uint32_t ui32ClkConfig)416 I2SClockConfigure(uint32_t ui32Base, uint32_t ui32ClkConfig)
417 {
418     //
419     // Check the arguments.
420     //
421     ASSERT(I2SBaseValid(ui32Base));
422 
423     //
424     // Setup register WCLK Source.
425     //
426     HWREG(I2S0_BASE + I2S_O_AIFWCLKSRC) = ui32ClkConfig &
427                                          (I2S_AIFWCLKSRC_WCLK_INV_M |
428                                           I2S_AIFWCLKSRC_WCLK_SRC_M);
429 }
430 
431 //****************************************************************************
432 //
433 //! \brief Set the input buffer pointers.
434 //!
435 //! The next pointer should always be written while the DMA is using the
436 //! previous written pointer. If not written in time an \ref I2S_INT_PTR_ERR will
437 //! occur and all outputs will be disabled.
438 //!
439 //! \note At startup the next data pointer should be
440 //! written just before and just after calling the \ref I2SEnable().
441 //!
442 //! \param ui32Base is the base address of the I2S module.
443 //! \param ui32InBufBase is the address of the input buffer.
444 //! \param ui32OutBufBase is the address of the output  buffer.
445 //! \param ui16DMABufSize is the size of the DMA buffers. Must be greater than 0!
446 //! \param ui16ChanBufSize is the size of the channel buffers.
447 //!
448 //! \return None
449 //
450 //****************************************************************************
451 extern void I2SBufferConfig(uint32_t ui32Base, uint32_t ui32InBufBase,
452                             uint32_t ui32OutBufBase, uint16_t ui16DMABufSize,
453                             uint16_t ui16ChanBufSize);
454 
455 //****************************************************************************
456 //
457 //! \brief Update the buffer pointers.
458 //!
459 //! The next pointer should always be written while the DMA is using the
460 //! previous written pointer. If not written in time an \ref I2S_INT_PTR_ERR will occur
461 //! and all outputs will be disabled. Nothing is preventing the pointers from
462 //! being identical, but this function relies on both pointers (input or
463 //! output pointers) are pointing to a valid address.
464 //!
465 //! \note It is recommended that the pointer update is done in an interrupt context
466 //! to ensure that the update is performed before the buffer is full.
467 //!
468 //! \param ui32Base is the base address of the I2S module.
469 //! \param bInput determines whether to update input or output pointer.
470 //! - \c true  : Update input pointer.
471 //! - \c false : Update output pointer
472 //!
473 //! \return None
474 //!
475 //! \sa \ref I2SPointerSet()
476 //
477 //****************************************************************************
478 extern void I2SPointerUpdate(uint32_t ui32Base, bool bInput);
479 
480 //****************************************************************************
481 //
482 //! \brief Set a buffer pointer (input or output) directly.
483 //!
484 //! This function allows bypassing of the pointers in the global control table.
485 //!
486 //! The next pointer should always be written while the DMA is using the
487 //! previous written pointer. If not written in time an \ref I2S_INT_PTR_ERR will occur
488 //! and all outputs will be disabled. Nothing is preventing the pointers from
489 //! being identical, but this function relies on both pointers (input or
490 //! output pointers) are pointing to a valid address.
491 //!
492 //! \note It is recommended that the pointer update is done in an interrupt context
493 //! to ensure that the update is performed before the buffer is full.
494 //!
495 //! \param ui32Base is the base address of the I2S module.
496 //! \param bInput determines whether to update input or output pointer.
497 //! - \c true  : Update input pointer.
498 //! - \c false : Update output pointer
499 //! \param pNextPointer is a void pointer to user defined buffer.
500 //!
501 //! \return None
502 //!
503 //! \sa \ref I2SPointerUpdate()
504 //
505 //****************************************************************************
506 extern void I2SPointerSet(uint32_t ui32Base, bool bInput, void * pNextPointer);
507 
508 //*****************************************************************************
509 //
510 //! \brief Registers an interrupt handler for an I2S interrupt.
511 //!
512 //! This function does the actual registering of the interrupt handler. This
513 //! function enables the global interrupt in the interrupt controller; specific
514 //! I2S interrupts must be enabled via \ref I2SIntEnable(). It is the interrupt
515 //! handler's responsibility to clear the interrupt source.
516 //!
517 //! \param ui32Base is the base address of the I2S port.
518 //! \param pfnHandler is a pointer to the function to be called when the
519 //! I2S interrupt occurs.
520 //!
521 //! \return None
522 //!
523 //! \sa \ref IntRegister() for important information about registering interrupt
524 //! handlers.
525 //
526 //*****************************************************************************
527 __STATIC_INLINE void
I2SIntRegister(uint32_t ui32Base,void (* pfnHandler)(void))528 I2SIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
529 {
530     //
531     // Check the arguments.
532     //
533     ASSERT(I2SBaseValid(ui32Base));
534 
535     //
536     // Register the interrupt handler.
537     //
538     IntRegister(INT_I2S_IRQ, pfnHandler);
539 
540     //
541     // Enable the I2S interrupt.
542     //
543     IntEnable(INT_I2S_IRQ);
544 }
545 
546 //*****************************************************************************
547 //
548 //! \brief Unregisters an interrupt handler for a I2S interrupt.
549 //!
550 //! This function does the actual unregistering of the interrupt handler. It
551 //! clears the handler to be called when an I2S interrupt occurs.  This
552 //! function also masks off the interrupt in the interrupt controller so that
553 //! the interrupt handler no longer is called.
554 //!
555 //! \param ui32Base is the base address of the I2S port.
556 //!
557 //! \return None
558 //!
559 //! \sa \ref IntRegister() for important information about registering interrupt
560 //! handlers.
561 //
562 //*****************************************************************************
563 __STATIC_INLINE void
I2SIntUnregister(uint32_t ui32Base)564 I2SIntUnregister(uint32_t ui32Base)
565 {
566     //
567     // Check the arguments.
568     //
569     ASSERT(I2SBaseValid(ui32Base));
570 
571     //
572     // Disable the interrupt.
573     //
574     IntDisable(INT_I2S_IRQ);
575 
576     //
577     // Unregister the interrupt handler.
578     //
579     IntUnregister(INT_I2S_IRQ);
580 }
581 
582 //*****************************************************************************
583 //
584 //! \brief Enables individual I2S interrupt sources.
585 //!
586 //! This function enables the indicated I2S interrupt sources. Only the
587 //! sources that are enabled can be reflected to the processor interrupt;
588 //! disabled sources have no effect on the processor.
589 //!
590 //! \param ui32Base is the base address of the I2S port.
591 //! \param ui32IntFlags is the bit mask of the interrupt sources to be enabled.
592 //! The parameter is the bitwise OR of any of the following:
593 //! - \ref I2S_INT_DMA_IN
594 //! - \ref I2S_INT_DMA_OUT
595 //! - \ref I2S_INT_TIMEOUT
596 //! - \ref I2S_INT_BUS_ERR
597 //! - \ref I2S_INT_WCLK_ERR
598 //! - \ref I2S_INT_PTR_ERR
599 //! - \ref I2S_INT_ALL (covers all the above)
600 //!
601 //! \return None.
602 //
603 //*****************************************************************************
604 __STATIC_INLINE void
I2SIntEnable(uint32_t ui32Base,uint32_t ui32IntFlags)605 I2SIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
606 {
607     //
608     // Check the arguments.
609     //
610     ASSERT(I2SBaseValid(ui32Base));
611 
612     //
613     // Enable the specified interrupts.
614     //
615     HWREG(I2S0_BASE + I2S_O_IRQMASK) |= ui32IntFlags;
616 }
617 
618 //*****************************************************************************
619 //
620 //! \brief Disables individual I2S interrupt sources.
621 //!
622 //! This function disables the indicated I2S interrupt sources. Only the
623 //! sources that are enabled can be reflected to the processor interrupt;
624 //! disabled sources have no effect on the processor.
625 //!
626 //! \param ui32Base is the base address of the I2S port.
627 //! \param ui32IntFlags is the bit mask of the interrupt sources to be disabled.
628 //! The parameter is the bitwise OR of any of the following:
629 //! - \ref I2S_INT_DMA_IN
630 //! - \ref I2S_INT_DMA_OUT
631 //! - \ref I2S_INT_TIMEOUT
632 //! - \ref I2S_INT_BUS_ERR
633 //! - \ref I2S_INT_WCLK_ERR
634 //! - \ref I2S_INT_PTR_ERR
635 //! - \ref I2S_INT_ALL (covers all the above)
636 //!
637 //! \return None.
638 //
639 //*****************************************************************************
640 __STATIC_INLINE void
I2SIntDisable(uint32_t ui32Base,uint32_t ui32IntFlags)641 I2SIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
642 {
643     //
644     // Check the arguments.
645     //
646     ASSERT(I2SBaseValid(ui32Base));
647 
648     //
649     // Disable the specified interrupts.
650     //
651     HWREG(I2S0_BASE + I2S_O_IRQMASK) &= ~ui32IntFlags;
652 }
653 
654 //*****************************************************************************
655 //
656 //! \brief Gets the current interrupt status.
657 //!
658 //! This function returns the interrupt status for the specified I2S. Either
659 //! the raw interrupt status or the status of interrupts that are allowed to
660 //! reflect to the processor can be returned.
661 //!
662 //! \param ui32Base is the base address of the I2S port
663 //! \param bMasked selects between raw and masked interrupt status:
664 //! - \c false : Raw interrupt status is required.
665 //! - \c true  : Masked interrupt status is required.
666 //!
667 //! \return Returns the current interrupt status as a vector of:
668 //! - \ref I2S_INT_DMA_IN
669 //! - \ref I2S_INT_DMA_OUT
670 //! - \ref I2S_INT_TIMEOUT
671 //! - \ref I2S_INT_BUS_ERR
672 //! - \ref I2S_INT_WCLK_ERR
673 //! - \ref I2S_INT_PTR_ERR
674 //
675 //*****************************************************************************
676 __STATIC_INLINE uint32_t
I2SIntStatus(uint32_t ui32Base,bool bMasked)677 I2SIntStatus(uint32_t ui32Base, bool bMasked)
678 {
679     uint32_t ui32Mask;
680 
681     //
682     // Check the arguments.
683     //
684     ASSERT(I2SBaseValid(ui32Base));
685 
686     //
687     // Return either the interrupt status or the raw interrupt status as
688     // requested.
689     //
690     if(bMasked)
691     {
692         ui32Mask = HWREG(I2S0_BASE + I2S_O_IRQFLAGS);
693         return(ui32Mask & HWREG(I2S0_BASE + I2S_O_IRQMASK));
694     }
695     else
696     {
697         return(HWREG(I2S0_BASE + I2S_O_IRQFLAGS));
698     }
699 }
700 
701 //*****************************************************************************
702 //
703 //! \brief Clears I2S interrupt sources.
704 //!
705 //! The specified I2S interrupt sources are cleared, so that they no longer
706 //! assert. This function must be called in the interrupt handler to keep the
707 //! interrupt from being recognized again immediately upon exit.
708 //!
709 //! \note Due to write buffers and synchronizers in the system it may take several
710 //! clock cycles from a register write clearing an event in a module and until the
711 //! event is actually cleared in the NVIC of the system CPU. It is recommended to
712 //! clear the event source early in the interrupt service routine (ISR) to allow
713 //! the event clear to propagate to the NVIC before returning from the ISR.
714 //! At the same time, an early event clear allows new events of the same type to be
715 //! pended instead of ignored if the event is cleared later in the ISR.
716 //! It is the responsibility of the programmer to make sure that enough time has passed
717 //! before returning from the ISR to avoid false re-triggering of the cleared event.
718 //! A simple, although not necessarily optimal, way of clearing an event before
719 //! returning from the ISR is:
720 //! -# Write to clear event (interrupt source). (buffered write)
721 //! -# Dummy read from the event source module. (making sure the write has propagated)
722 //! -# Wait two system CPU clock cycles (user code or two NOPs). (allowing cleared event to propagate through any synchronizers)
723 //!
724 //! \param ui32Base is the base address of the I2S port.
725 //! \param ui32IntFlags is a bit mask of the interrupt sources to be cleared.
726 //! The parameter is the bitwise OR of any of the following:
727 //! - \ref I2S_INT_DMA_IN
728 //! - \ref I2S_INT_DMA_OUT
729 //! - \ref I2S_INT_TIMEOUT
730 //! - \ref I2S_INT_BUS_ERR
731 //! - \ref I2S_INT_WCLK_ERR
732 //! - \ref I2S_INT_PTR_ERR
733 //! - \ref I2S_INT_ALL (covers all the above)
734 //!
735 //! \return None
736 //
737 //*****************************************************************************
738 __STATIC_INLINE void
I2SIntClear(uint32_t ui32Base,uint32_t ui32IntFlags)739 I2SIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
740 {
741     //
742     // Check the arguments.
743     //
744     ASSERT(I2SBaseValid(ui32Base));
745 
746     //
747     // Clear the requested interrupt sources.
748     //
749     HWREG(I2S0_BASE + I2S_O_IRQCLR) = ui32IntFlags;
750 }
751 
752 //*****************************************************************************
753 //
754 //! \brief Enable the Sample Stamp generator.
755 //!
756 //! Use this function to enable the sample stamp generators.
757 //!
758 //! \note It is the user's responsibility to ensure that the sample stamp
759 //! generator is properly configured before it is enabled. It is the setting
760 //! of the Input and Output triggers configured using \ref I2SSampleStampConfigure()
761 //! that triggers the start point of the audio streams.
762 //!
763 //! \return None
764 //
765 //*****************************************************************************
766 __STATIC_INLINE void
I2SSampleStampEnable(uint32_t ui32Base)767 I2SSampleStampEnable(uint32_t ui32Base)
768 {
769     //
770     // Set the enable bit.
771     //
772     HWREG(I2S0_BASE + I2S_O_STMPCTL) = I2S_STMPCTL_STMP_EN;
773 }
774 
775 //*****************************************************************************
776 //
777 //! \brief Disable the Sample Stamp generator.
778 //!
779 //! Use this function to disable the sample stamp generators. When the sample
780 //! stamp generator is disabled, the clock counters are automatically cleared.
781 //!
782 //! \return None
783 //
784 //*****************************************************************************
785 __STATIC_INLINE void
I2SSampleStampDisable(uint32_t ui32Base)786 I2SSampleStampDisable(uint32_t ui32Base)
787 {
788     //
789     // Clear the enable bit.
790     //
791     HWREG(I2S0_BASE + I2S_O_STMPCTL) = 0;
792 
793 }
794 
795 //*****************************************************************************
796 //
797 //! \brief Configure the sample stamp generator.
798 //!
799 //! Use this function to configure the sample stamp generator.
800 //!
801 //! \param ui32Base is the base address of the I2S module.
802 //! \param bInput enables triggering of the sample stamp generator on input.
803 //! \param bOutput enables triggering of the sample stamp generator on output.
804 //!
805 //! \return None
806 //
807 //*****************************************************************************
808 extern void I2SSampleStampConfigure(uint32_t ui32Base, bool bInput,
809                                     bool bOutput);
810 
811 //*****************************************************************************
812 //
813 //! \brief Get the current value of a sample stamp counter.
814 //!
815 //! \param ui32Base is the base address of the I2S module.
816 //! \param ui32Channel is the sample stamp counter to sample
817 //!
818 //! \return Returns the current value of the selected sample stamp channel.
819 //
820 //*****************************************************************************
821 extern uint32_t I2SSampleStampGet(uint32_t ui32Base, uint32_t ui32Channel);
822 
823 //*****************************************************************************
824 //
825 // Support for DriverLib in ROM:
826 // Redirect to implementation in ROM when available.
827 //
828 //*****************************************************************************
829 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
830     #include <driverlib/rom.h>
831     #ifdef ROM_I2SEnable
832         #undef  I2SEnable
833         #define I2SEnable                       ROM_I2SEnable
834     #endif
835     #ifdef ROM_I2SAudioFormatConfigure
836         #undef  I2SAudioFormatConfigure
837         #define I2SAudioFormatConfigure         ROM_I2SAudioFormatConfigure
838     #endif
839     #ifdef ROM_I2SChannelConfigure
840         #undef  I2SChannelConfigure
841         #define I2SChannelConfigure             ROM_I2SChannelConfigure
842     #endif
843     #ifdef ROM_I2SBufferConfig
844         #undef  I2SBufferConfig
845         #define I2SBufferConfig                 ROM_I2SBufferConfig
846     #endif
847     #ifdef ROM_I2SPointerUpdate
848         #undef  I2SPointerUpdate
849         #define I2SPointerUpdate                ROM_I2SPointerUpdate
850     #endif
851     #ifdef ROM_I2SPointerSet
852         #undef  I2SPointerSet
853         #define I2SPointerSet                   ROM_I2SPointerSet
854     #endif
855     #ifdef ROM_I2SSampleStampConfigure
856         #undef  I2SSampleStampConfigure
857         #define I2SSampleStampConfigure         ROM_I2SSampleStampConfigure
858     #endif
859     #ifdef ROM_I2SSampleStampGet
860         #undef  I2SSampleStampGet
861         #define I2SSampleStampGet               ROM_I2SSampleStampGet
862     #endif
863 #endif
864 
865 //*****************************************************************************
866 //
867 // Mark the end of the C bindings section for C++ compilers.
868 //
869 //*****************************************************************************
870 #ifdef __cplusplus
871 }
872 #endif
873 
874 #endif //  __I2S_H__
875 
876 //****************************************************************************
877 //
878 //! Close the Doxygen group.
879 //! @}
880 //! @}
881 //
882 //****************************************************************************
883