CC13xx Driver Library
i2s.h
Go to the documentation of this file.
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 //
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 //
107 
113 //
115 //*****************************************************************************
116 typedef struct
117 {
118  uint16_t ui16DMABufSize;
119  uint16_t ui16ChBufSize;
120  uint8_t ui8InChan;
121  uint8_t ui8OutChan;
122  uint16_t ui16MemLen;
123  uint32_t ui32InBase;
124  uint32_t ui32InOffset;
125  uint32_t ui32OutBase;
126  uint32_t ui32OutOffset;
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 //*****************************************************************************
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 //
245 //
246 //*****************************************************************************
247 static bool
248 I2SBaseValid(uint32_t ui32Base)
249 {
250  return(ui32Base == I2S0_BASE);
251 }
252 #endif
253 
254 //*****************************************************************************
255 //
269 //
270 //*****************************************************************************
271 extern void I2SEnable(uint32_t ui32Base);
272 
273 //*****************************************************************************
274 //
289 //
290 //*****************************************************************************
291 __STATIC_INLINE void
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 //
342 //
343 //*****************************************************************************
344 extern void I2SAudioFormatConfigure(uint32_t ui32Base, uint32_t ui32FmtCfg,
345  uint32_t ui32BitClkDelay);
346 
347 //****************************************************************************
348 //
386 //
387 //****************************************************************************
388 extern void I2SChannelConfigure(uint32_t ui32Base, uint32_t ui32Chan0Cfg,
389  uint32_t ui32Chan1Cfg, uint32_t ui32Chan2Cfg);
390 
391 //****************************************************************************
392 //
413 //
414 //****************************************************************************
415 __STATIC_INLINE void
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 &
429 }
430 
431 //****************************************************************************
432 //
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 //
476 //
477 //****************************************************************************
478 extern void I2SPointerUpdate(uint32_t ui32Base, bool bInput);
479 
480 //****************************************************************************
481 //
504 //
505 //****************************************************************************
506 extern void I2SPointerSet(uint32_t ui32Base, bool bInput, void * pNextPointer);
507 
508 //*****************************************************************************
509 //
525 //
526 //*****************************************************************************
527 __STATIC_INLINE 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 //
561 //
562 //*****************************************************************************
563 __STATIC_INLINE void
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 //
602 //
603 //*****************************************************************************
604 __STATIC_INLINE void
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 //
638 //
639 //*****************************************************************************
640 __STATIC_INLINE void
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 //
674 //
675 //*****************************************************************************
676 __STATIC_INLINE uint32_t
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 //
736 //
737 //*****************************************************************************
738 __STATIC_INLINE void
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 //
764 //
765 //*****************************************************************************
766 __STATIC_INLINE void
767 I2SSampleStampEnable(uint32_t ui32Base)
768 {
769  //
770  // Set the enable bit.
771  //
773 }
774 
775 //*****************************************************************************
776 //
783 //
784 //*****************************************************************************
785 __STATIC_INLINE void
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 //
806 //
807 //*****************************************************************************
808 extern void I2SSampleStampConfigure(uint32_t ui32Base, bool bInput,
809  bool bOutput);
810 
811 //*****************************************************************************
812 //
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 //
881 //
882 //****************************************************************************
void I2SSampleStampConfigure(uint32_t ui32Base, bool bInput, bool bOutput)
Configure the sample stamp generator.
Definition: i2s.c:373
static void I2SIntRegister(uint32_t ui32Base, void(*pfnHandler)(void))
Registers an interrupt handler for an I2S interrupt.
Definition: i2s.h:528
static void I2SIntUnregister(uint32_t ui32Base)
Unregisters an interrupt handler for a I2S interrupt.
Definition: i2s.h:564
void I2SPointerSet(uint32_t ui32Base, bool bInput, void *pNextPointer)
Set a buffer pointer (input or output) directly.
Definition: i2s.c:304
void I2SBufferConfig(uint32_t ui32Base, uint32_t ui32InBufBase, uint32_t ui32OutBufBase, uint16_t ui16DMABufSize, uint16_t ui16ChanBufSize)
Set the input buffer pointers.
Definition: i2s.c:279
static void I2SDisable(uint32_t ui32Base)
Disables the I2S module for operation.
Definition: i2s.h:292
uint16_t ui16DMABufSize
Size of DMA buffer in number of samples.
Definition: i2s.h:118
uint32_t ui32InOffset
Value of the current input pointer offset.
Definition: i2s.h:124
uint32_t I2SSampleStampGet(uint32_t ui32Base, uint32_t ui32Channel)
Get the current value of a sample stamp counter.
Definition: i2s.c:409
uint32_t ui32OutOffset
Value of the current output pointer offset.
Definition: i2s.h:126
static void I2SIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
Disables individual I2S interrupt sources.
Definition: i2s.h:641
static void I2SSampleStampEnable(uint32_t ui32Base)
Enable the Sample Stamp generator.
Definition: i2s.h:767
uint32_t ui32OutBase
Base address of the output buffer.
Definition: i2s.h:125
void I2SPointerUpdate(uint32_t ui32Base, bool bInput)
Update the buffer pointers.
Definition: i2s.c:330
uint16_t ui16MemLen
Length of the audio words stored in memory.
Definition: i2s.h:122
A structure that defines an audio control table. Note: Memory for this structure must be initialized ...
Definition: i2s.h:116
uint8_t ui8InChan
Input Channel.
Definition: i2s.h:120
#define ASSERT(expr)
Definition: debug.h:74
void I2SEnable(uint32_t ui32Base)
Enables the I2S module for operation.
Definition: i2s.c:79
uint32_t ui32InBase
Base address of the input buffer.
Definition: i2s.h:123
static void I2SIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
Clears I2S interrupt sources.
Definition: i2s.h:739
void I2SAudioFormatConfigure(uint32_t ui32Base, uint32_t ui32FmtCfg, uint32_t ui32BitClkDelay)
Configures the I2S module.
Definition: i2s.c:114
uint8_t ui8OutChan
Output Channel.
Definition: i2s.h:121
static uint32_t I2SIntStatus(uint32_t ui32Base, bool bMasked)
Gets the current interrupt status.
Definition: i2s.h:677
void IntUnregister(uint32_t ui32Interrupt)
Unregisters the function to be called when an interrupt occurs.
Definition: interrupt.c:200
static void I2SIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
Enables individual I2S interrupt sources.
Definition: i2s.h:605
void I2SChannelConfigure(uint32_t ui32Base, uint32_t ui32Chan0Cfg, uint32_t ui32Chan1Cfg, uint32_t ui32Chan2Cfg)
Setup the audio channel configuration.
Definition: i2s.c:140
I2SControlTable * g_pControlTable
Definition: i2s.c:71
static void I2SSampleStampDisable(uint32_t ui32Base)
Disable the Sample Stamp generator.
Definition: i2s.h:786
uint16_t ui16ChBufSize
Size of Channel buffer.
Definition: i2s.h:119
static void I2SClockConfigure(uint32_t ui32Base, uint32_t ui32ClkConfig)
Configure the I2S frame clock.
Definition: i2s.h:416
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:378
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function to be called when an interrupt occurs.
Definition: interrupt.c:152
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:318