1 /******************************************************************************
2 * Filename: i2s.h
3 * Revised: 2018-11-16 11:16:53 +0100 (Fri, 16 Nov 2018)
4 * Revision: 53356
5 *
6 * Description: Defines and prototypes for the I2S.
7 *
8 * Copyright (c) 2015 - 2020, 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 "debug.h"
69 #include "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 //! \deprecated This structure will be removed in a future release.
101 //!
102 //! These fields are used by the I2S and normally it is not necessary for
103 //! software to directly read or write fields in the table.
104 //!
105 //! \note The control table must be defined by the user as a global variable and
106 //! the global pointer must then be assigned the address of the control table
107 //! inside a user function (but before calling any I2S-function).
108 //!
109 /*!
110 \verbatim
111 I2SControlTable g_controlTable; // Define global
112 g_pControlTable = &g_controlTable; // Assign pointer (inside a function)
113 \endverbatim
114 */
115 //!
116 //
117 //*****************************************************************************
118 #ifndef DEPRECATED
119 typedef struct
120 {
121 uint16_t ui16DMABufSize; //!< Size of DMA buffer in number of samples.
122 uint16_t ui16ChBufSize; //!< Size of Channel buffer.
123 uint8_t ui8InChan; //!< Input Channel.
124 uint8_t ui8OutChan; //!< Output Channel.
125 uint16_t ui16MemLen; //!< Length of the audio words stored in memory.
126 uint32_t ui32InBase; //!< Base address of the input buffer.
127 uint32_t ui32InOffset; //!< Value of the current input pointer offset.
128 uint32_t ui32OutBase; //!< Base address of the output buffer.
129 uint32_t ui32OutOffset; //!< Value of the current output pointer offset.
130 } I2SControlTable;
131 #endif
132
133 //*****************************************************************************
134 //
135 // Declare global pointer to the I2S data structure.
136 //
137 // The control table must be defined by the user as a global variable and the
138 // global pointer must then be assigned the address of the control table:
139 //
140 // I2SControlTable g_controlTable;
141 // g_pControlTable = &g_controlTable;
142 //
143 //*****************************************************************************
144 #ifndef DEPRECATED
145 extern I2SControlTable *g_pControlTable;
146 #endif
147
148 //*****************************************************************************
149 //
150 // Defines for the I2S DMA buffer sizes
151 //
152 //*****************************************************************************
153 #ifndef DEPRECATED
154 #define I2S_DMA_BUF_SIZE_64 0x00000040
155 #define I2S_DMA_BUF_SIZE_128 0x00000080
156 #define I2S_DMA_BUF_SIZE_256 0x00000100
157 #endif
158
159 //*****************************************************************************
160 //
161 // Defines for the I2S audio clock configuration
162 //
163 //*****************************************************************************
164 #ifndef DEPRECATED
165 #define I2S_EXT_WCLK 0x00000001
166 #define I2S_INT_WCLK 0x00000002
167 #define I2S_INVERT_WCLK 0x00000004
168 #define I2S_NORMAL_WCLK 0x00000000
169 #endif
170
171 //*****************************************************************************
172 //
173 // Defines for the audio data line input/output configuration
174 //
175 //*****************************************************************************
176 #ifndef DEPRECATED
177 #define I2S_LINE_UNUSED 0x00000000
178 #define I2S_LINE_INPUT 0x00000001
179 #define I2S_LINE_OUTPUT 0x00000002
180 #define I2S_LINE_MASK 0x00000003
181 #endif
182
183 //*****************************************************************************
184 //
185 // Defines for activating an audio channel.
186 //
187 //*****************************************************************************
188 #ifndef DEPRECATED
189 #define I2S_CHAN0_ACT 0x00000100
190 #define I2S_CHAN1_ACT 0x00000200
191 #define I2S_CHAN2_ACT 0x00000400
192 #define I2S_CHAN3_ACT 0x00000800
193 #define I2S_CHAN4_ACT 0x00001000
194 #define I2S_CHAN5_ACT 0x00002000
195 #define I2S_CHAN6_ACT 0x00004000
196 #define I2S_CHAN7_ACT 0x00008000
197 #define I2S_MONO_MODE 0x00000100
198 #define I2S_STEREO_MODE 0x00000300
199 #define I2S_CHAN_CFG_MASK 0x0000FF00
200 #endif
201
202 #define I2S_CHAN0_MASK 0x00000001
203 #define I2S_CHAN1_MASK 0x00000002
204 #define I2S_CHAN2_MASK 0x00000004
205 #define I2S_CHAN3_MASK 0x00000008
206 #define I2S_CHAN4_MASK 0x00000010
207 #define I2S_CHAN5_MASK 0x00000020
208 #define I2S_CHAN6_MASK 0x00000040
209 #define I2S_CHAN7_MASK 0x00000080
210
211 //*****************************************************************************
212 //
213 // Defines for the audio format configuration
214 //
215 //*****************************************************************************
216 #define I2S_MEM_LENGTH_16 0x00000000 // 16 bit size of word in memory
217 #define I2S_MEM_LENGTH_24 0x00000080 // 24 bit size of word in memory
218 #define I2S_POS_EDGE 0x00000040 // Sample on positive edge
219 #define I2S_NEG_EDGE 0x00000000 // Sample on negative edge
220 #define I2S_DUAL_PHASE_FMT 0x00000020 // Dual Phased audio format
221 #define I2S_SINGLE_PHASE_FMT 0x00000000 // Single Phased audio format
222 #define I2S_WORD_LENGTH_8 0x00000008 // Word length is 8 bits
223 #define I2S_WORD_LENGTH_16 0x00000010 // Word length is 16 bits
224 #define I2S_WORD_LENGTH_24 0x00000018 // Word length is 24 bits
225
226 //*****************************************************************************
227 //
228 // Defines for the sample stamp counters
229 //
230 //*****************************************************************************
231 #ifndef DEPRECATED
232 #define I2S_STMP0 0x00000001 // Sample stamp counter channel 0
233 #define I2S_STMP1 0x00000002 // Sample stamp counter channel 1
234 #endif
235 #define I2S_STMP_SATURATION 0x0000FFFF // The saturation value used when
236 // calculating the sample stamp
237
238 //*****************************************************************************
239 //
240 // Defines for the interrupt
241 //
242 //*****************************************************************************
243 #define I2S_INT_DMA_IN 0x00000020 // DMA output buffer full interrupt
244 #define I2S_INT_DMA_OUT 0x00000010 // DMA input buffer empty interrupt
245 #define I2S_INT_TIMEOUT 0x00000008 // Word Clock Timeout
246 #define I2S_INT_BUS_ERR 0x00000004 // DMA Bus error
247 #define I2S_INT_WCLK_ERR 0x00000002 // Word Clock error
248 #define I2S_INT_PTR_ERR 0x00000001 // Data pointer error (DMA data was not updated in time).
249 #define I2S_INT_ALL 0x0000003F // All interrupts
250
251 //*****************************************************************************
252 //
253 // API Functions and prototypes
254 //
255 //*****************************************************************************
256
257 #ifdef DRIVERLIB_DEBUG
258 //*****************************************************************************
259 //
260 //! \internal
261 //!
262 //! \brief Checks an I2S base address.
263 //!
264 //! This function determines if an I2S port base address is valid.
265 //!
266 //! \param ui32Base is the base address of the I2S port.
267 //!
268 //! \return Returns \c true if the base address is valid and \c false
269 //! otherwise.
270 //
271 //*****************************************************************************
272 static bool
I2SBaseValid(uint32_t ui32Base)273 I2SBaseValid(uint32_t ui32Base)
274 {
275 return(ui32Base == I2S0_BASE);
276 }
277 #endif
278
279 //*****************************************************************************
280 //
281 //! \brief Enables the I2S module for operation.
282 //!
283 //! \deprecated This function will be removed in a future release.
284 //!
285 //! \note The module should only be enabled after configuration. When the
286 //! module is disabled, no data or clocks will be generated on the I2S signals.
287 //!
288 //! \note Immediately after enabling the module the programmer should update
289 //! the DMA data pointer registers using \ref I2SPointerUpdate() to ensure a new
290 //! pointer is written before the DMA transfer completes. Failure to update
291 //! the pointer in time will result in an \ref I2S_INT_PTR_ERR.
292 //!
293 //! \param ui32Base is the I2S module base address.
294 //!
295 //! \return None
296 //
297 //*****************************************************************************
298 #ifndef DEPRECATED
299 extern void I2SEnable(uint32_t ui32Base);
300 #endif
301
302 //*****************************************************************************
303 //
304 //! \brief Disables the I2S module for operation.
305 //!
306 //! \deprecated This function will be removed in a future release.
307 //!
308 //! This function will immediately disable the I2S module. To ensure that
309 //! all buffer operations are completed before shutting down, the correct
310 //! procedure is:
311 //! 1. Do not update the data pointers using \ref I2SPointerUpdate().
312 //! 2. Await next interrupt resulting in \ref I2S_INT_PTR_ERR.
313 //! 3. Disable the I2S using \ref I2SDisable() and clear the pointer error using
314 //! \ref I2SIntClear().
315 //! 4. Disable bit clock source (done externally).
316 //!
317 //! \param ui32Base is the I2S module base address.
318 //!
319 //! \return None
320 //
321 //*****************************************************************************
322 #ifndef DEPRECATED
323 __STATIC_INLINE void
I2SDisable(uint32_t ui32Base)324 I2SDisable(uint32_t ui32Base)
325 {
326 // Check the arguments.
327 ASSERT(I2SBaseValid(ui32Base));
328
329 // Disable the I2S module.
330 HWREG(I2S0_BASE + I2S_O_AIFDMACFG) = 0x0;
331 }
332 #endif
333
334 //*****************************************************************************
335 //
336 //! \brief Configures the I2S module.
337 //!
338 //! \deprecated This function will be removed in a future release.
339 //!
340 //! The word length defines the size of the word transmitted on the data
341 //! lines. For single phased formats \c I2S_WORD_LENGTH_x is the exact number
342 //! of bits per word. In dual phased format this is the maximum number of bits
343 //! per word. The size is set using \ref I2S_WORD_LENGTH_8,
344 //! \ref I2S_WORD_LENGTH_16 or \ref I2S_WORD_LENGTH_24.
345 //!
346 //! \param ui32Base is the I2S module base address.
347 //! \param ui32FmtCfg is the bitwise OR of several options:
348 //! - Sample size:
349 //! - \ref I2S_MEM_LENGTH_16
350 //! - \ref I2S_MEM_LENGTH_24
351 //! - Clock edge sampling:
352 //! - \ref I2S_POS_EDGE
353 //! - \ref I2S_NEG_EDGE
354 //! - Phase:
355 //! - \ref I2S_DUAL_PHASE_FMT
356 //! - \ref I2S_SINGLE_PHASE_FMT
357 //! - Word length:
358 //! - \ref I2S_WORD_LENGTH_8
359 //! - \ref I2S_WORD_LENGTH_16
360 //! - \ref I2S_WORD_LENGTH_24
361 //! \param ui32BitClkDelay defines the bit clock delay by setting the number of bit clock periods between the
362 //! positive word clock edge and the MSB of the first word in a phase. The bit
363 //! clock delay is determined by the ratio between the bit clock and the frame
364 //! clock and the chosen audio format. The bit clock delay \b must be configured
365 //! depending on the chosen audio format:
366 //! - 0 : Left Justified Format (LJF).
367 //! - 1 : I2S and DSP format.
368 //! - 2-255 : Right Justified format (RJF).
369 //!
370 //! \return None
371 //!
372 //! \sa \ref I2SChannelConfigure()
373 //
374 //*****************************************************************************
375 #ifndef DEPRECATED
376 extern void I2SAudioFormatConfigure(uint32_t ui32Base, uint32_t ui32FmtCfg,
377 uint32_t ui32BitClkDelay);
378 #endif
379
380 //****************************************************************************
381 //
382 //! \brief Setup the audio channel configuration.
383 //!
384 //! \deprecated This function will be removed in a future release.
385 //!
386 //! The channel configuration is a bitwise OR of the input/output mode of each
387 //! data line and the active audio channels within a specific audio frame.
388 //!
389 //! Setting up the input/output mode use one of:
390 //! - \ref I2S_LINE_UNUSED
391 //! - \ref I2S_LINE_INPUT
392 //! - \ref I2S_LINE_OUTPUT
393 //!
394 //! For dual phased audio (LJF,RJF,I2S) only mono and stereo modes are allowed.
395 //! For single phased audio format (DSP) up to 8 active channels are allowed
396 //! on a single data line. For setting up the active channels in a frame use:
397 //! - Single phased, use a bitwise OR'ed combination of:
398 //! - \ref I2S_CHAN0_ACT
399 //! - \ref I2S_CHAN1_ACT
400 //! - \ref I2S_CHAN2_ACT
401 //! - \ref I2S_CHAN3_ACT
402 //! - \ref I2S_CHAN4_ACT
403 //! - \ref I2S_CHAN5_ACT
404 //! - \ref I2S_CHAN6_ACT
405 //! - \ref I2S_CHAN7_ACT
406 //! - Dual phased, use one of:
407 //! - \ref I2S_MONO_MODE (same as \ref I2S_CHAN0_ACT)
408 //! - \ref I2S_STEREO_MODE (same as \ref I2S_CHAN0_ACT | \ref I2S_CHAN1_ACT)
409 //!
410 //! \note The audio format and the clock configuration should be set using
411 //! \ref I2SAudioFormatConfigure()
412 //!
413 //! \param ui32Base is base address of the I2S module.
414 //! \param ui32Chan0Cfg defines the channel configuration for data line 0.
415 //! \param ui32Chan1Cfg defines the channel configuration for data line 1.
416 //!
417 //! \return None
418 //!
419 //! \sa \ref I2SAudioFormatConfigure()
420 //
421 //****************************************************************************
422 #ifndef DEPRECATED
423 extern void I2SChannelConfigure(uint32_t ui32Base, uint32_t ui32Chan0Cfg,
424 uint32_t ui32Chan1Cfg);
425 #endif
426
427 //****************************************************************************
428 //
429 //! \brief Configure the I2S frame clock.
430 //!
431 //! \deprecated This function will be removed in a future release.
432 //!
433 //! Configure I2S clock to be either internal or external and either normal
434 //! or inverted.
435 //!
436 //! \note The bit clock configuration is done externally, but the internal/
437 //! external setting must match what is chosen internally in the I2S module
438 //! for the frame clock.
439 //!
440 //! \param ui32Base is the base address of the I2S module.
441 //! \param ui32ClkConfig is the clock configuration parameter. Bitwise OR'ed
442 //! combination of clock source and clock polarity:
443 //! - Clock source:
444 //! - \ref I2S_EXT_WCLK : External clock.
445 //! - \ref I2S_INT_WCLK : Internal clock.
446 //! - Clock polarity:
447 //! - \ref I2S_NORMAL_WCLK : Normal clock.
448 //! - \ref I2S_INVERT_WCLK : Inverted clock.
449 //!
450 //! \return None
451 //
452 //****************************************************************************
453 #ifndef DEPRECATED
454 __STATIC_INLINE void
I2SClockConfigure(uint32_t ui32Base,uint32_t ui32ClkConfig)455 I2SClockConfigure(uint32_t ui32Base, uint32_t ui32ClkConfig)
456 {
457 // Check the arguments.
458 ASSERT(I2SBaseValid(ui32Base));
459
460 // Setup register WCLK Source.
461 HWREG(I2S0_BASE + I2S_O_AIFWCLKSRC) = ui32ClkConfig &
462 (I2S_AIFWCLKSRC_WCLK_INV_M |
463 I2S_AIFWCLKSRC_WCLK_SRC_M);
464 }
465 #endif
466
467 //****************************************************************************
468 //
469 //! \brief Set the input buffer pointers.
470 //!
471 //! \deprecated This function will be removed in a future release.
472 //!
473 //! The next pointer should always be written while the DMA is using the
474 //! previous written pointer. If not written in time an \ref I2S_INT_PTR_ERR will
475 //! occur and all outputs will be disabled.
476 //!
477 //! \note At startup the next data pointer should be
478 //! written just before and just after calling the \ref I2SEnable().
479 //!
480 //! \param ui32Base is the base address of the I2S module.
481 //! \param ui32InBufBase is the address of the input buffer.
482 //! \param ui32OutBufBase is the address of the output buffer.
483 //! \param ui16DMABufSize is the size of the DMA buffers. Must be greater than 0!
484 //! \param ui16ChanBufSize is the size of the channel buffers.
485 //!
486 //! \return None
487 //
488 //****************************************************************************
489 #ifndef DEPRECATED
490 extern void I2SBufferConfig(uint32_t ui32Base, uint32_t ui32InBufBase,
491 uint32_t ui32OutBufBase, uint16_t ui16DMABufSize,
492 uint16_t ui16ChanBufSize);
493 #endif
494
495 //****************************************************************************
496 //
497 //! \brief Update the buffer pointers.
498 //!
499 //! \deprecated This function will be removed in a future release.
500 //!
501 //! The next pointer should always be written while the DMA is using the
502 //! previous written pointer. If not written in time an \ref I2S_INT_PTR_ERR will occur
503 //! and all outputs will be disabled. Nothing is preventing the pointers from
504 //! being identical, but this function relies on both pointers (input or
505 //! output pointers) are pointing to a valid address.
506 //!
507 //! \note It is recommended that the pointer update is done in an interrupt context
508 //! to ensure that the update is performed before the buffer is full.
509 //!
510 //! \param ui32Base is the base address of the I2S module.
511 //! \param bInput determines whether to update input or output pointer.
512 //! - \c true : Update input pointer.
513 //! - \c false : Update output pointer
514 //!
515 //! \return None
516 //!
517 //! \sa \ref I2SPointerSet()
518 //
519 //****************************************************************************
520 #ifndef DEPRECATED
521 extern void I2SPointerUpdate(uint32_t ui32Base, bool bInput);
522 #endif
523
524 //****************************************************************************
525 //
526 //! \brief Set a buffer pointer (input or output) directly.
527 //!
528 //! \deprecated This function will be removed in a future release.
529 //!
530 //! This function allows bypassing of the pointers in the global control table.
531 //!
532 //! The next pointer should always be written while the DMA is using the
533 //! previous written pointer. If not written in time an \ref I2S_INT_PTR_ERR will occur
534 //! and all outputs will be disabled. Nothing is preventing the pointers from
535 //! being identical, but this function relies on both pointers (input or
536 //! output pointers) are pointing to a valid address.
537 //!
538 //! \note It is recommended that the pointer update is done in an interrupt context
539 //! to ensure that the update is performed before the buffer is full.
540 //!
541 //! \param ui32Base is the base address of the I2S module.
542 //! \param bInput determines whether to update input or output pointer.
543 //! - \c true : Update input pointer.
544 //! - \c false : Update output pointer
545 //! \param pNextPointer is a void pointer to user defined buffer.
546 //!
547 //! \return None
548 //!
549 //! \sa \ref I2SPointerUpdate()
550 //
551 //****************************************************************************
552 #ifndef DEPRECATED
553 extern void I2SPointerSet(uint32_t ui32Base, bool bInput, void * pNextPointer);
554 #endif
555
556 //*****************************************************************************
557 //
558 //! \brief Registers an interrupt handler for an I2S interrupt in the dynamic interrupt table.
559 //!
560 //! \deprecated This function will be removed in a future release.
561 //!
562 //! \note Only use this function if you want to use the dynamic vector table (in SRAM)!
563 //!
564 //! This function registers a function as the interrupt handler for a specific
565 //! interrupt and enables the corresponding interrupt in the interrupt controller.
566 //!
567 //! Specific I2S interrupts must be enabled via \ref I2SIntEnable(). It is the interrupt
568 //! handler's responsibility to clear the interrupt source.
569 //!
570 //! \param ui32Base is the base address of the I2S module.
571 //! \param pfnHandler is a pointer to the function to be called when the
572 //! I2S interrupt occurs.
573 //!
574 //! \return None
575 //!
576 //! \sa \ref IntRegister() for important information about registering interrupt
577 //! handlers.
578 //
579 //*****************************************************************************
580 #ifndef DEPRECATED
581 __STATIC_INLINE void
I2SIntRegister(uint32_t ui32Base,void (* pfnHandler)(void))582 I2SIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
583 {
584 // Check the arguments.
585 ASSERT(I2SBaseValid(ui32Base));
586
587 // Register the interrupt handler.
588 IntRegister(INT_I2S_IRQ, pfnHandler);
589
590 // Enable the I2S interrupt.
591 IntEnable(INT_I2S_IRQ);
592 }
593 #endif
594
595 //*****************************************************************************
596 //
597 //! \brief Unregisters an interrupt handler for a I2S interrupt in the dynamic interrupt table.
598 //!
599 //! \deprecated This function will be removed in a future release.
600 //!
601 //! This function does the actual unregistering of the interrupt handler. It
602 //! clears the handler to be called when an I2S interrupt occurs. This
603 //! function also masks off the interrupt in the interrupt controller so that
604 //! the interrupt handler no longer is called.
605 //!
606 //! \param ui32Base is the base address of the I2S port.
607 //!
608 //! \return None
609 //!
610 //! \sa \ref IntRegister() for important information about registering interrupt
611 //! handlers.
612 //
613 //*****************************************************************************
614 #ifndef DEPRECATED
615 __STATIC_INLINE void
I2SIntUnregister(uint32_t ui32Base)616 I2SIntUnregister(uint32_t ui32Base)
617 {
618 // Check the arguments.
619 ASSERT(I2SBaseValid(ui32Base));
620
621 // Disable the interrupt.
622 IntDisable(INT_I2S_IRQ);
623
624 // Unregister the interrupt handler.
625 IntUnregister(INT_I2S_IRQ);
626 }
627 #endif
628
629 //*****************************************************************************
630 //
631 //! \brief Configure the sample stamp generator.
632 //!
633 //! \deprecated This function will be removed in a future release.
634 //!
635 //! Use this function to configure the sample stamp generator.
636 //!
637 //! \param ui32Base is the base address of the I2S module.
638 //! \param bInput enables triggering of the sample stamp generator on input.
639 //! \param bOutput enables triggering of the sample stamp generator on output.
640 //!
641 //! \return None
642 //
643 //*****************************************************************************
644 #ifndef DEPRECATED
645 extern void I2SSampleStampConfigure(uint32_t ui32Base, bool bInput,
646 bool bOutput);
647 #endif
648
649 //*****************************************************************************
650 //
651 //! \brief Enables individual I2S interrupt sources.
652 //!
653 //! This function enables the indicated I2S interrupt sources. Only the
654 //! sources that are enabled can be reflected to the processor interrupt;
655 //! disabled sources have no effect on the processor.
656 //!
657 //! \param ui32Base is the base address of the I2S port.
658 //! \param ui32IntFlags is the bit mask of the interrupt sources to be enabled.
659 //! The parameter is the bitwise OR of any of the following:
660 //! - \ref I2S_INT_DMA_IN
661 //! - \ref I2S_INT_DMA_OUT
662 //! - \ref I2S_INT_TIMEOUT
663 //! - \ref I2S_INT_BUS_ERR
664 //! - \ref I2S_INT_WCLK_ERR
665 //! - \ref I2S_INT_PTR_ERR
666 //! - \ref I2S_INT_ALL (covers all the above)
667 //!
668 //! \return None.
669 //
670 //*****************************************************************************
671 __STATIC_INLINE void
I2SIntEnable(uint32_t ui32Base,uint32_t ui32IntFlags)672 I2SIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
673 {
674 // Check the arguments.
675 ASSERT(I2SBaseValid(ui32Base));
676
677 // Enable the specified interrupts.
678 HWREG(I2S0_BASE + I2S_O_IRQMASK) |= ui32IntFlags;
679 }
680
681 //*****************************************************************************
682 //
683 //! \brief Disables individual I2S interrupt sources.
684 //!
685 //! This function disables the indicated I2S interrupt sources. Only the
686 //! sources that are enabled can be reflected to the processor interrupt;
687 //! disabled sources have no effect on the processor.
688 //!
689 //! \param ui32Base is the base address of the I2S port.
690 //! \param ui32IntFlags is the bit mask of the interrupt sources to be disabled.
691 //! The parameter is the bitwise OR of any of the following:
692 //! - \ref I2S_INT_DMA_IN
693 //! - \ref I2S_INT_DMA_OUT
694 //! - \ref I2S_INT_TIMEOUT
695 //! - \ref I2S_INT_BUS_ERR
696 //! - \ref I2S_INT_WCLK_ERR
697 //! - \ref I2S_INT_PTR_ERR
698 //! - \ref I2S_INT_ALL (covers all the above)
699 //!
700 //! \return None.
701 //
702 //*****************************************************************************
703 __STATIC_INLINE void
I2SIntDisable(uint32_t ui32Base,uint32_t ui32IntFlags)704 I2SIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
705 {
706 // Check the arguments.
707 ASSERT(I2SBaseValid(ui32Base));
708
709 // Disable the specified interrupts.
710 HWREG(I2S0_BASE + I2S_O_IRQMASK) &= ~ui32IntFlags;
711 }
712
713 //*****************************************************************************
714 //
715 //! \brief Gets the current interrupt status.
716 //!
717 //! This function returns the interrupt status for the specified I2S. Either
718 //! the raw interrupt status or the status of interrupts that are allowed to
719 //! reflect to the processor can be returned.
720 //!
721 //! \param ui32Base is the base address of the I2S port
722 //! \param bMasked selects between raw and masked interrupt status:
723 //! - \c false : Raw interrupt status is required.
724 //! - \c true : Masked interrupt status is required.
725 //!
726 //! \return Returns the current interrupt status as a vector of:
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 //
734 //*****************************************************************************
735 __STATIC_INLINE uint32_t
I2SIntStatus(uint32_t ui32Base,bool bMasked)736 I2SIntStatus(uint32_t ui32Base, bool bMasked)
737 {
738 uint32_t ui32Mask;
739
740 // Check the arguments.
741 ASSERT(I2SBaseValid(ui32Base));
742
743 // Return either the interrupt status or the raw interrupt status as
744 // requested.
745 if(bMasked)
746 {
747 ui32Mask = HWREG(I2S0_BASE + I2S_O_IRQFLAGS);
748 return(ui32Mask & HWREG(I2S0_BASE + I2S_O_IRQMASK));
749 }
750 else
751 {
752 return(HWREG(I2S0_BASE + I2S_O_IRQFLAGS));
753 }
754 }
755
756 //*****************************************************************************
757 //
758 //! \brief Clears I2S interrupt sources.
759 //!
760 //! The specified I2S interrupt sources are cleared, so that they no longer
761 //! assert. This function must be called in the interrupt handler to keep the
762 //! interrupt from being recognized again immediately upon exit.
763 //!
764 //! \note Due to write buffers and synchronizers in the system it may take several
765 //! clock cycles from a register write clearing an event in a module and until the
766 //! event is actually cleared in the NVIC of the system CPU. It is recommended to
767 //! clear the event source early in the interrupt service routine (ISR) to allow
768 //! the event clear to propagate to the NVIC before returning from the ISR.
769 //! At the same time, an early event clear allows new events of the same type to be
770 //! pended instead of ignored if the event is cleared later in the ISR.
771 //! It is the responsibility of the programmer to make sure that enough time has passed
772 //! before returning from the ISR to avoid false re-triggering of the cleared event.
773 //! A simple, although not necessarily optimal, way of clearing an event before
774 //! returning from the ISR is:
775 //! -# Write to clear event (interrupt source). (buffered write)
776 //! -# Dummy read from the event source module. (making sure the write has propagated)
777 //! -# Wait two system CPU clock cycles (user code or two NOPs). (allowing cleared event to propagate through any synchronizers)
778 //!
779 //! \param ui32Base is the base address of the I2S port.
780 //! \param ui32IntFlags is a bit mask of the interrupt sources to be cleared.
781 //! The parameter is the bitwise OR of any of the following:
782 //! - \ref I2S_INT_DMA_IN
783 //! - \ref I2S_INT_DMA_OUT
784 //! - \ref I2S_INT_TIMEOUT
785 //! - \ref I2S_INT_BUS_ERR
786 //! - \ref I2S_INT_WCLK_ERR
787 //! - \ref I2S_INT_PTR_ERR
788 //! - \ref I2S_INT_ALL (covers all the above)
789 //!
790 //! \return None
791 //
792 //*****************************************************************************
793 __STATIC_INLINE void
I2SIntClear(uint32_t ui32Base,uint32_t ui32IntFlags)794 I2SIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
795 {
796 // Check the arguments.
797 ASSERT(I2SBaseValid(ui32Base));
798
799 // Clear the requested interrupt sources.
800 HWREG(I2S0_BASE + I2S_O_IRQCLR) = ui32IntFlags;
801 }
802
803 //*****************************************************************************
804 //
805 //! \brief Enable the Sample Stamp generator.
806 //!
807 //! Use this function to enable the sample stamp generators.
808 //!
809 //! \note It is the user's responsibility to ensure that the sample stamp
810 //! generator is properly configured before it is enabled. It is the setting
811 //! of the Input and Output triggers configured using \ref I2SSampleStampConfigure()
812 //! that triggers the start point of the audio streams.
813 //!
814 //! \return None
815 //
816 //*****************************************************************************
817 __STATIC_INLINE void
I2SSampleStampEnable(uint32_t ui32Base)818 I2SSampleStampEnable(uint32_t ui32Base)
819 {
820 // Check the arguments.
821 ASSERT(I2SBaseValid(ui32Base));
822
823 // Set the enable bit.
824 HWREG(I2S0_BASE + I2S_O_STMPCTL) = I2S_STMPCTL_STMP_EN;
825 }
826
827 //*****************************************************************************
828 //
829 //! \brief Disable the Sample Stamp generator.
830 //!
831 //! Use this function to disable the sample stamp generators. When the sample
832 //! stamp generator is disabled, the clock counters are automatically cleared.
833 //!
834 //! \return None
835 //
836 //*****************************************************************************
837 __STATIC_INLINE void
I2SSampleStampDisable(uint32_t ui32Base)838 I2SSampleStampDisable(uint32_t ui32Base)
839 {
840 // Check the arguments.
841 ASSERT(I2SBaseValid(ui32Base));
842
843 // Clear the enable bit.
844 HWREG(I2S0_BASE + I2S_O_STMPCTL) = 0;
845
846 }
847
848 //*****************************************************************************
849 //
850 //! \brief Get the current value of a sample stamp counter.
851 //!
852 //! \param ui32Base is the base address of the I2S module.
853 //! \param ui32Channel is the sample stamp counter to sample
854 //!
855 //! \return Returns the current value of the selected sample stamp channel.
856 //
857 //*****************************************************************************
858 extern uint32_t I2SSampleStampGet(uint32_t ui32Base, uint32_t ui32Channel);
859
860 //*****************************************************************************
861 //
862 //! \brief Starts the I2S.
863 //!
864 //! I2S must be configured before it is started.
865 //!
866 //! \note Immediately after enabling the module the programmer must update
867 //! the DMA data pointer registers using \ref I2SInPointerSet() and
868 //! \ref I2SOutPointerSet() to ensure a new pointer is written before the DMA
869 //! transfer completes. Failure to update the pointer in time will result in
870 //! an \ref I2S_INT_PTR_ERR.
871 //!
872 //! \param ui32Base is the I2S module base address.
873 //! \param ui8FixDMALength is the length of the DMA buffer: this will allow
874 //! the DMA to read ui8FixDMALength between to pointer refreshes.
875 //!
876 //! \return None
877 //!
878 //! \sa \ref I2SStop()
879 //
880 //*****************************************************************************
I2SStart(uint32_t ui32Base,uint8_t ui8FixDMALength)881 __STATIC_INLINE void I2SStart(uint32_t ui32Base, uint8_t ui8FixDMALength)
882 {
883 // Check the arguments.
884 ASSERT(I2SBaseValid(ui32Base));
885
886 // Enable the I2S module.
887 HWREG(I2S0_BASE + I2S_O_AIFDMACFG) = ui8FixDMALength;
888 }
889
890 //*****************************************************************************
891 //
892 //! \brief Stops the I2S module for operation.
893 //!
894 //! This function will immediately disable the I2S module. To ensure that
895 //! all buffer operations are completed before shutting down, the correct
896 //! procedure is:
897 //! 1. Do not update the data pointers using \ref I2SInPointerSet() and
898 //! \ref I2SOutPointerSet().
899 //! 2. Await that values returned by \ref I2SInPointerNextGet(),
900 //! \ref I2SOutPointerNextGet(), \ref I2SInPointerGet() and \ref I2SOutPointerGet()
901 //! are zero.
902 //! 3. Disable the I2S using \ref I2SStop() and clear the pointer
903 //! error using \ref I2SIntClear().
904 //! 4. Disable bit clock source (done externally).
905 //!
906 //! \param ui32Base is the I2S module base address.
907 //!
908 //! \return None
909 //!
910 //! \sa \ref I2SStart()
911 //
912 //*****************************************************************************
I2SStop(uint32_t ui32Base)913 __STATIC_INLINE void I2SStop(uint32_t ui32Base)
914 {
915 // Check the arguments.
916 ASSERT(I2SBaseValid(ui32Base));
917
918 // Disable the I2S module.
919 HWREG(I2S0_BASE + I2S_O_AIFDMACFG) = 0x00;
920 }
921
922 //*****************************************************************************
923 //
924 //! \brief Configure the serial format of the I2S module.
925 //!
926 //! The word length defines the size of the word transmitted on the data
927 //! lines. For single phased formats \c ui8BitsPerSample is the exact number
928 //! of bits per word. In dual phased format this is the maximum number of bits
929 //! per word.
930 //!
931 //! \param ui32Base is the I2S module base address.
932 //! \param ui8iDataDelay is the number of BCLK periods between the first WCLK
933 //! edge and the MSB of the first audio channel data transferred during
934 //! the phase.
935 //! \param ui8iMemory24Bits selects if the samples in memory are coded on 16 bits
936 //! or 24 bits. Possible values are:
937 //! - \ref I2S_MEM_LENGTH_16
938 //! - \ref I2S_MEM_LENGTH_24
939 //! \param ui8iSamplingEdge selects if sampling on falling or rising edges.
940 //! Possible values are:
941 //! - \ref I2S_NEG_EDGE
942 //! - \ref I2S_POS_EDGE
943 //! \param boolDualPhase must be set to true for dual phase and to false for
944 //! single phase and user-defined phase.
945 //! \param ui8BitsPerSample is the number of bits transmitted for each sample.
946 //! If this number does not match with the memory length selected
947 //! (16 bits or24 bits), samples will be truncated or padded.
948 //! \param ui16transmissionDelay is the number of WCLK periods before the first
949 //! transmission.
950 //!
951 //! \return None
952 //!
953 //! \sa \ref I2SFrameConfigure()
954 //
955 //*****************************************************************************
956 __STATIC_INLINE void
I2SFormatConfigure(uint32_t ui32Base,uint8_t ui8iDataDelay,uint8_t ui8iMemory24Bits,uint8_t ui8iSamplingEdge,bool boolDualPhase,uint8_t ui8BitsPerSample,uint16_t ui16transmissionDelay)957 I2SFormatConfigure(uint32_t ui32Base,
958 uint8_t ui8iDataDelay,
959 uint8_t ui8iMemory24Bits,
960 uint8_t ui8iSamplingEdge,
961 bool boolDualPhase,
962 uint8_t ui8BitsPerSample,
963 uint16_t ui16transmissionDelay)
964 {
965 // Check the arguments.
966 ASSERT(I2SBaseValid(ui32Base));
967 ASSERT(ui8BitsPerSample <= I2S_AIFFMTCFG_WORD_LEN_MAX);
968 ASSERT(ui8BitsPerSample >= I2S_AIFFMTCFG_WORD_LEN_MIN);
969
970 // Setup register AIFFMTCFG Source.
971 HWREGH(I2S0_BASE + I2S_O_AIFFMTCFG) =
972 (ui8iDataDelay << I2S_AIFFMTCFG_DATA_DELAY_S) |
973 (ui8iMemory24Bits << I2S_AIFFMTCFG_MEM_LEN_24_S) |
974 (ui8iSamplingEdge << I2S_AIFFMTCFG_SMPL_EDGE_S ) |
975 (boolDualPhase << I2S_AIFFMTCFG_DUAL_PHASE_S) |
976 (ui8BitsPerSample << I2S_AIFFMTCFG_WORD_LEN_S );
977
978 // Number of WCLK periods before the first read / write
979 HWREGH(I2S0_BASE + I2S_O_STMPWPER) = ui16transmissionDelay;
980 }
981
982 //****************************************************************************
983 //
984 //! \brief Setup the two interfaces SD0 and SD1 (also called AD0 and AD1).
985 //!
986 //! This function sets interface's direction and activated channels.
987 //!
988 //! \param ui32Base is base address of the I2S module.
989 //! \param ui8StatusAD0 defines the usage of AD0
990 //! 0x00: AD0 is disabled
991 //! 0x01, AD0 is an input
992 //! 0x02, AD0 is an output
993 //! \param ui8ChanAD0 defines the channel mask for AD0.
994 //! Use a bitwise OR'ed combination of:
995 //! - \ref I2S_CHAN0_MASK
996 //! - \ref I2S_CHAN1_MASK
997 //! - \ref I2S_CHAN2_MASK
998 //! - \ref I2S_CHAN3_MASK
999 //! - \ref I2S_CHAN4_MASK
1000 //! - \ref I2S_CHAN5_MASK
1001 //! - \ref I2S_CHAN6_MASK
1002 //! - \ref I2S_CHAN7_MASK
1003 //! \param ui8StatusAD1 defines the usage of AD1
1004 //! 0x00: AD1 is disabled
1005 //! 0x10, AD1 is an input
1006 //! 0x20, AD1 is an output
1007 //! \param ui8ChanAD1 defines the channel mask for AD1.
1008 //! Use a bitwise OR'ed combination of:
1009 //! - \ref I2S_CHAN0_MASK
1010 //! - \ref I2S_CHAN1_MASK
1011 //! - \ref I2S_CHAN2_MASK
1012 //! - \ref I2S_CHAN3_MASK
1013 //! - \ref I2S_CHAN4_MASK
1014 //! - \ref I2S_CHAN5_MASK
1015 //! - \ref I2S_CHAN6_MASK
1016 //! - \ref I2S_CHAN7_MASK
1017 //!
1018 //! \return None
1019 //!
1020 //! \sa \ref I2SFormatConfigure()
1021 //
1022 //****************************************************************************
1023 __STATIC_INLINE void
I2SFrameConfigure(uint32_t ui32Base,uint8_t ui8StatusAD0,uint8_t ui8ChanAD0,uint8_t ui8StatusAD1,uint8_t ui8ChanAD1)1024 I2SFrameConfigure(uint32_t ui32Base,
1025 uint8_t ui8StatusAD0, uint8_t ui8ChanAD0,
1026 uint8_t ui8StatusAD1, uint8_t ui8ChanAD1)
1027 {
1028 // Check the arguments.
1029 ASSERT(I2SBaseValid(ui32Base));
1030
1031 // Configure input/output channels.
1032 HWREGB(I2S0_BASE + I2S_O_AIFDIRCFG) = (ui8StatusAD0 | ui8StatusAD1);
1033
1034 // Configure the valid channel mask.
1035 HWREGB(I2S0_BASE + I2S_O_AIFWMASK0) = ui8ChanAD0;
1036 HWREGB(I2S0_BASE + I2S_O_AIFWMASK1) = ui8ChanAD1;
1037 }
1038
1039 //****************************************************************************
1040 //
1041 //! \brief Configure the I2S frame clock (also called WCLK or WS).
1042 //!
1043 //! Configure WCLK clock to be either internal (master) or external (slave).
1044 //! Configure WCLK clock either normal or inverted.
1045 //!
1046 //! \note The bit clock configuration is done externally, but the internal/
1047 //! external setting must match what is chosen internally in the I2S module
1048 //! for the frame clock.
1049 //!
1050 //! \param ui32Base is the base address of the I2S module.
1051 //! \param boolMaster false: the device is a slave (external clock)
1052 //! true: the device is a master (internal clock)
1053 //! \param boolWCLKInvert false: WCLK is not inverted
1054 //! true: WCLK is internally inverted
1055 //!
1056 //! \return None
1057 //
1058 //****************************************************************************
1059 __STATIC_INLINE void
I2SWclkConfigure(uint32_t ui32Base,bool boolMaster,bool boolWCLKInvert)1060 I2SWclkConfigure(uint32_t ui32Base,
1061 bool boolMaster,
1062 bool boolWCLKInvert)
1063 {
1064 // Check the arguments.
1065 ASSERT(I2SBaseValid(ui32Base));
1066 ASSERT(ui8ClkSource < I2S_AIFWCLKSRC_WCLK_SRC_RESERVED);
1067
1068 // if(boolMaster == 0) then ui8ClkSource = 1
1069 // if(boolMaster == 1) then ui8ClkSource = 2
1070 uint8_t ui8ClkSource = (uint8_t)boolMaster + 0x01;
1071
1072 // Setup register WCLK Source.
1073 HWREGB(I2S0_BASE + I2S_O_AIFWCLKSRC) =
1074 ((ui8ClkSource << I2S_AIFWCLKSRC_WCLK_SRC_S) |
1075 (boolWCLKInvert << I2S_AIFWCLKSRC_WCLK_INV_S ));
1076 }
1077
1078 //****************************************************************************
1079 //
1080 //! \brief Set the input buffer pointer.
1081 //!
1082 //! The next pointer should always be written while the DMA is using the
1083 //! previous written pointer. If not written in time an \ref I2S_INT_PTR_ERR
1084 //! will occur and all inputs and outputs will be disabled.
1085 //! This function relies on pointer is pointing to a valid address.
1086 //!
1087 //! \note It is recommended that the pointer update is done in an interrupt context
1088 //! to ensure that the update is performed before the buffer is full.
1089 //!
1090 //! \param ui32Base is the base address of the I2S module.
1091 //! \param ui32NextPointer is the adress of the data
1092 //!
1093 //! \return None
1094 //!
1095 //! \sa \ref I2SOutPointerSet()
1096 //
1097 //****************************************************************************
1098 __STATIC_INLINE void
I2SInPointerSet(uint32_t ui32Base,uint32_t ui32NextPointer)1099 I2SInPointerSet(uint32_t ui32Base, uint32_t ui32NextPointer)
1100 {
1101 // Check the arguments.
1102 ASSERT(I2SBaseValid(ui32Base));
1103
1104 HWREG(I2S0_BASE + I2S_O_AIFINPTRNEXT) = ui32NextPointer;
1105 }
1106
1107 //****************************************************************************
1108 //
1109 //! \brief Set the output buffer pointer.
1110 //!
1111 //! The next pointer should always be written while the DMA is using the
1112 //! previous written pointer. If not written in time an \ref I2S_INT_PTR_ERR
1113 //! will occur and all inputs and outputs will be disabled.
1114 //! This function relies on pointer is pointing to a valid address.
1115 //!
1116 //! \note It is recommended that the pointer update is done in an interrupt context
1117 //! to ensure that the update is performed before the buffer is full.
1118 //!
1119 //! \param ui32Base is the base address of the I2S module.
1120 //! \param ui32NextPointer is the adress of the data
1121 //!
1122 //! \return None
1123 //!
1124 //! \sa \ref I2SInPointerSet()
1125 //
1126 //****************************************************************************
1127 __STATIC_INLINE void
I2SOutPointerSet(uint32_t ui32Base,uint32_t ui32NextPointer)1128 I2SOutPointerSet(uint32_t ui32Base, uint32_t ui32NextPointer)
1129 {
1130 // Check the arguments.
1131 ASSERT(I2SBaseValid(ui32Base));
1132
1133 HWREG(I2S0_BASE + I2S_O_AIFOUTPTRNEXT) = ui32NextPointer;
1134 }
1135
1136 //****************************************************************************
1137 //
1138 //! \brief Get value stored in PTR NEXT IN register
1139 //!
1140 //! \param ui32Base is the base address of the I2S module.
1141 //!
1142 //! \return the value of PTR NEXT IN.
1143 //
1144 //****************************************************************************
1145 __STATIC_INLINE uint32_t
I2SInPointerNextGet(uint32_t ui32Base)1146 I2SInPointerNextGet(uint32_t ui32Base)
1147 {
1148 // Check the arguments.
1149 ASSERT(I2SBaseValid(ui32Base));
1150
1151 return (HWREG(I2S0_BASE + I2S_O_AIFINPTRNEXT));
1152 }
1153
1154
1155 //****************************************************************************
1156 //
1157 //! \brief Get value stored in PTR NEXT OUT register
1158 //!
1159 //! \param ui32Base is the base address of the I2S module.
1160 //!
1161 //! \return the value of PTR NEXT OUT.
1162 //
1163 //****************************************************************************
1164 __STATIC_INLINE uint32_t
I2SOutPointerNextGet(uint32_t ui32Base)1165 I2SOutPointerNextGet(uint32_t ui32Base)
1166 {
1167 // Check the arguments.
1168 ASSERT(I2SBaseValid(ui32Base));
1169
1170 return (HWREG(I2S0_BASE + I2S_O_AIFOUTPTRNEXT));
1171 }
1172
1173 //****************************************************************************
1174 //
1175 //! \brief Get value stored in PTR IN register
1176 //!
1177 //! \param ui32Base is the base address of the I2S module.
1178 //!
1179 //! \return the value of PTR IN.
1180 //
1181 //****************************************************************************
1182 __STATIC_INLINE uint32_t
I2SInPointerGet(uint32_t ui32Base)1183 I2SInPointerGet(uint32_t ui32Base)
1184 {
1185 // Check the arguments.
1186 ASSERT(I2SBaseValid(ui32Base));
1187
1188 return (HWREG(I2S0_BASE + I2S_O_AIFINPTR));
1189 }
1190
1191 //****************************************************************************
1192 //
1193 //! \brief Get value stored in PTR OUT register
1194 //!
1195 //! \param ui32Base is the base address of the I2S module.
1196 //!
1197 //! \return the value of PTR OUT.
1198 //
1199 //****************************************************************************
1200 __STATIC_INLINE uint32_t
I2SOutPointerGet(uint32_t ui32Base)1201 I2SOutPointerGet(uint32_t ui32Base)
1202 {
1203 // Check the arguments.
1204 ASSERT(I2SBaseValid(ui32Base));
1205
1206 return (HWREG(I2S0_BASE + I2S_O_AIFOUTPTR));
1207 }
1208
1209 //*****************************************************************************
1210 //
1211 //! \brief Configure the IN sample stamp generator.
1212 //!
1213 //! Use this function to configure the sample stamp generator.
1214 //!
1215 //! \param ui32Base is the base address of the I2S module.
1216 //! \param ui16TrigValue value used to set the trigger.
1217 //!
1218 //! \return None
1219 //
1220 //*****************************************************************************
1221 __STATIC_INLINE void
I2SSampleStampInConfigure(uint32_t ui32Base,uint16_t ui16TrigValue)1222 I2SSampleStampInConfigure(uint32_t ui32Base, uint16_t ui16TrigValue)
1223 {
1224 // Check the arguments.
1225 ASSERT(I2SBaseValid(ui32Base));
1226
1227 // Setup the sample stamp trigger for input streams.
1228 HWREGH(I2S0_BASE + I2S_O_STMPINTRIG) = ui16TrigValue;
1229 }
1230
1231 //*****************************************************************************
1232 //
1233 //! \brief Configure the OUT sample stamp generator.
1234 //!
1235 //! Use this function to configure the sample stamp generator.
1236 //!
1237 //! \param ui32Base is the base address of the I2S module.
1238 //! \param ui16TrigValue value used to set the trigger.
1239 //!
1240 //! \return None
1241 //
1242 //*****************************************************************************
1243 __STATIC_INLINE void
I2SSampleStampOutConfigure(uint32_t ui32Base,uint16_t ui16TrigValue)1244 I2SSampleStampOutConfigure(uint32_t ui32Base, uint16_t ui16TrigValue)
1245 {
1246 // Check the arguments.
1247 ASSERT(I2SBaseValid(ui32Base));
1248
1249 // Setup the sample stamp trigger for output streams.
1250 HWREGH(I2S0_BASE + I2S_O_STMPOUTTRIG) = ui16TrigValue;
1251 }
1252
1253 //*****************************************************************************
1254 //
1255 //! \brief Add the specified value to the WCLK count.
1256 //!
1257 //! \param ui32Base is the base address of the I2S module.
1258 //! \param i16Value is the offset to add to the counter (this value can be negative)
1259 //!
1260 //! \return None
1261 //
1262 //*****************************************************************************
1263 __STATIC_INLINE void
I2SWclkCounterConfigure(uint32_t ui32Base,int16_t i16Value)1264 I2SWclkCounterConfigure(uint32_t ui32Base, int16_t i16Value)
1265 {
1266 uint16_t ui16MinusValue;
1267
1268 // Check the arguments.
1269 ASSERT(I2SBaseValid(ui32Base));
1270
1271 if (i16Value >= 0)
1272 {
1273 HWREGH(I2S0_BASE + I2S_O_STMPWADD) = i16Value;
1274 }
1275 else
1276 {
1277 ui16MinusValue = (uint16_t)(-i16Value);
1278 HWREGH(I2S0_BASE + I2S_O_STMPWADD) = HWREGH(I2S0_BASE + I2S_O_STMPWPER) - ui16MinusValue;
1279 }
1280 }
1281
1282 //*****************************************************************************
1283 //
1284 //! \brief Reset the WCLK count.
1285 //!
1286 //! \param ui32Base is the base address of the I2S module.
1287 //!
1288 //! \return None
1289 //
1290 //*****************************************************************************
1291 __STATIC_INLINE void
I2SWclkCounterReset(uint32_t ui32Base)1292 I2SWclkCounterReset(uint32_t ui32Base)
1293 {
1294 // Check the arguments.
1295 ASSERT(I2SBaseValid(ui32Base));
1296
1297 HWREGH(I2S0_BASE + I2S_O_STMPWSET) = 0;
1298 }
1299
1300 //*****************************************************************************
1301 //
1302 // Support for DriverLib in ROM:
1303 // Redirect to implementation in ROM when available.
1304 //
1305 //*****************************************************************************
1306 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
1307 #include "../driverlib/rom.h"
1308 #ifdef ROM_I2SEnable
1309 #undef I2SEnable
1310 #define I2SEnable ROM_I2SEnable
1311 #endif
1312 #ifdef ROM_I2SAudioFormatConfigure
1313 #undef I2SAudioFormatConfigure
1314 #define I2SAudioFormatConfigure ROM_I2SAudioFormatConfigure
1315 #endif
1316 #ifdef ROM_I2SChannelConfigure
1317 #undef I2SChannelConfigure
1318 #define I2SChannelConfigure ROM_I2SChannelConfigure
1319 #endif
1320 #ifdef ROM_I2SBufferConfig
1321 #undef I2SBufferConfig
1322 #define I2SBufferConfig ROM_I2SBufferConfig
1323 #endif
1324 #ifdef ROM_I2SPointerUpdate
1325 #undef I2SPointerUpdate
1326 #define I2SPointerUpdate ROM_I2SPointerUpdate
1327 #endif
1328 #ifdef ROM_I2SPointerSet
1329 #undef I2SPointerSet
1330 #define I2SPointerSet ROM_I2SPointerSet
1331 #endif
1332 #ifdef ROM_I2SSampleStampConfigure
1333 #undef I2SSampleStampConfigure
1334 #define I2SSampleStampConfigure ROM_I2SSampleStampConfigure
1335 #endif
1336 #ifdef ROM_I2SSampleStampGet
1337 #undef I2SSampleStampGet
1338 #define I2SSampleStampGet ROM_I2SSampleStampGet
1339 #endif
1340 #endif
1341
1342 //*****************************************************************************
1343 //
1344 // Mark the end of the C bindings section for C++ compilers.
1345 //
1346 //*****************************************************************************
1347 #ifdef __cplusplus
1348 }
1349 #endif
1350
1351 #endif // __I2S_H__
1352
1353 //****************************************************************************
1354 //
1355 //! Close the Doxygen group.
1356 //! @}
1357 //! @}
1358 //
1359 //****************************************************************************
1360