CC26xx Driver Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
i2s.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: i2s.h
3 * Revised: 2015-01-14 12:12:44 +0100 (on, 14 jan 2015)
4 * Revision: 42373
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 //
43 //
44 //****************************************************************************
45 
46 #ifndef __I2S_H__
47 #define __I2S_H__
48 
49 //*****************************************************************************
50 //
51 // If building with a C++ compiler, make all of the definitions in this header
52 // have a C binding.
53 //
54 //*****************************************************************************
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59 
60 #include <stdbool.h>
61 #include <stdint.h>
62 #include <inc/hw_types.h>
63 #include <inc/hw_memmap.h>
64 #include <inc/hw_ints.h>
65 #include <inc/hw_i2s.h>
66 #include <driverlib/debug.h>
67 #include <driverlib/interrupt.h>
68 
69 //*****************************************************************************
70 //
71 // Support for DriverLib in ROM:
72 // This section renames all functions that are not "static inline", so that
73 // calling these functions will default to implementation in flash. At the end
74 // of this file a second renaming will change the defaults to implementation in
75 // ROM for available functions.
76 //
77 // To force use of the implementation in flash, e.g. for debugging:
78 // - Globally: Define DRIVERLIB_NOROM at project level
79 // - Per function: Use prefix "NOROM_" when calling the function
80 //
81 // Do not define DRIVERLIB_GENERATE_ROM!
82 //
83 //*****************************************************************************
84 #ifndef DRIVERLIB_GENERATE_ROM
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 //
106 
112 //
114 //*****************************************************************************
115 typedef struct
116 {
117  uint16_t ui16DMABufSize;
118  uint16_t ui16ChBufSize;
119  uint8_t ui8InChan;
120  uint8_t ui8OutChan;
121  uint16_t ui16MemLen;
122  uint32_t ui32InBase;
123  uint32_t ui32InOffset;
124  uint32_t ui32OutBase;
125  uint32_t ui32OutOffset;
127 
128 //*****************************************************************************
129 //
130 // Declare global pointer to the I2S data structure.
131 //
132 // The control table must be defined by the user as a global variable and the
133 // global pointer must then be assigned the address of the control table:
134 //
135 // I2SControlTable g_controlTable;
136 // g_pControlTable = &g_controlTable;
137 //
138 //*****************************************************************************
140 
141 //*****************************************************************************
142 //
143 // Defines for the I2S DMA buffer sizes
144 //
145 //*****************************************************************************
146 #define I2S_DMA_BUF_SIZE_64 0x00000040
147 #define I2S_DMA_BUF_SIZE_128 0x00000080
148 #define I2S_DMA_BUF_SIZE_256 0x00000100
149 
150 //*****************************************************************************
151 //
152 // Defines for the I2S audio clock configuration
153 //
154 //*****************************************************************************
155 #define I2S_EXT_WCLK 0x00000001
156 #define I2S_INT_WCLK 0x00000002
157 #define I2S_INVERT_WCLK 0x00000004
158 #define I2S_NORMAL_WCLK 0x00000000
159 
160 //*****************************************************************************
161 //
162 // Defines for the audio data line input/output configuration
163 //
164 //*****************************************************************************
165 #define I2S_LINE_UNUSED 0x00000000
166 #define I2S_LINE_INPUT 0x00000001
167 #define I2S_LINE_OUTPUT 0x00000002
168 #define I2S_LINE_MASK 0x00000003
169 
170 //*****************************************************************************
171 //
172 // Defines for activating an audio channel.
173 //
174 //*****************************************************************************
175 #define I2S_CHAN0_ACT 0x00000100
176 #define I2S_CHAN1_ACT 0x00000200
177 #define I2S_CHAN2_ACT 0x00000400
178 #define I2S_CHAN3_ACT 0x00000800
179 #define I2S_CHAN4_ACT 0x00001000
180 #define I2S_CHAN5_ACT 0x00002000
181 #define I2S_CHAN6_ACT 0x00004000
182 #define I2S_CHAN7_ACT 0x00008000
183 #define I2S_MONO_MODE 0x00000100
184 #define I2S_STEREO_MODE 0x00000300
185 #define I2S_CHAN_CFG_MASK 0x0000FF00
186 
187 //*****************************************************************************
188 //
189 // Defines for the audio format configuration
190 //
191 //*****************************************************************************
192 #define I2S_MEM_LENGTH_16 0x00000000 // 16 bit size of word in memory
193 #define I2S_MEM_LENGTH_24 0x00000080 // 24 bit size of word in memory
194 #define I2S_POS_EDGE 0x00000040 // Sample on positive edge
195 #define I2S_NEG_EDGE 0x00000000 // Sample on negative edge
196 #define I2S_DUAL_PHASE_FMT 0x00000020 // Dual Phased audio format
197 #define I2S_SINGLE_PHASE_FMT 0x00000000 // Single Phased audio format
198 #define I2S_WORD_LENGTH_8 0x00000008 // Word length is 8 bits
199 #define I2S_WORD_LENGTH_16 0x00000010 // Word length is 16 bits
200 #define I2S_WORD_LENGTH_24 0x00000018 // Word length is 24 bits
201 
202 //*****************************************************************************
203 //
204 // Defines for the sample stamp counters
205 //
206 //*****************************************************************************
207 #define I2S_STMP0 0x00000001 // Sample stamp counter channel 0
208 #define I2S_STMP1 0x00000002 // Sample stamp counter channel 1
209 #define I2S_STMP_SATURATION 0x0000FFFF // The saturation value used when
210  // calculating the sample stamp
211 
212 //*****************************************************************************
213 //
214 // Defines for the interrupt
215 //
216 //*****************************************************************************
217 #define I2S_INT_DMA_IN 0x00000020 // DMA output buffer full interrupt
218 #define I2S_INT_DMA_OUT 0x00000010 // DMA input buffer empty interrupt
219 #define I2S_INT_TIMEOUT 0x00000008 // Word Clock Timeout
220 #define I2S_INT_BUS_ERR 0x00000004 // DMA Bus error
221 #define I2S_INT_WCLK_ERR 0x00000002 // Word Clock error
222 #define I2S_INT_PTR_ERR 0x00000001 // Data pointer error (DMA data was not updated in time).
223 #define I2S_INT_ALL 0x0000003F // All interrupts
224 
225 //*****************************************************************************
226 //
227 // API Functions and prototypes
228 //
229 //*****************************************************************************
230 
231 #ifdef DRIVERLIB_DEBUG
232 //*****************************************************************************
233 //
244 //
245 //*****************************************************************************
246 static bool
247 I2SBaseValid(uint32_t ui32Base)
248 {
249  return(ui32Base == I2S0_BASE);
250 }
251 #endif
252 
253 //*****************************************************************************
254 //
268 //
269 //*****************************************************************************
270 extern void I2SEnable(uint32_t ui32Base);
271 
272 //*****************************************************************************
273 //
288 //
289 //*****************************************************************************
290 __STATIC_INLINE void
291 I2SDisable(uint32_t ui32Base)
292 {
293  //
294  // Check the arguments.
295  //
296  ASSERT(I2SBaseValid(ui32Base));
297 
298  //
299  // Disable the I2S module.
300  //
301  HWREG(ui32Base + I2S_O_AIFDMACFG) = 0x0;
302 }
303 
304 //*****************************************************************************
305 //
341 //
342 //*****************************************************************************
343 extern void I2SAudioFormatConfigure(uint32_t ui32Base, uint32_t ui32FmtCfg,
344  uint32_t ui32BitClkDelay);
345 
346 //****************************************************************************
347 //
385 //
386 //****************************************************************************
387 extern void I2SChannelConfigure(uint32_t ui32Base, uint32_t ui32Chan0Cfg,
388  uint32_t ui32Chan1Cfg, uint32_t ui32Chan2Cfg);
389 
390 //****************************************************************************
391 //
412 //
413 //****************************************************************************
414 __STATIC_INLINE void
415 I2SClockConfigure(uint32_t ui32Base, uint32_t ui32ClkConfig)
416 {
417  //
418  // Check the arguments.
419  //
420  ASSERT(I2SBaseValid(ui32Base));
421 
422  //
423  // Setup register WCLK Source.
424  //
425  HWREG(I2S0_BASE + I2S_O_AIFWCLKSRC) = ui32ClkConfig &
428 }
429 
430 //****************************************************************************
431 //
451 //
452 //****************************************************************************
453 extern void I2SBufferConfig(uint32_t ui32Base, uint32_t ui32InBufBase,
454  uint32_t ui32OutBufBase, uint16_t ui16DMABufSize,
455  uint16_t ui16ChanBufSize);
456 
457 //****************************************************************************
458 //
478 //
479 //****************************************************************************
480 extern void I2SPointerUpdate(uint32_t ui32Base, bool bInput);
481 
482 //****************************************************************************
483 //
506 //
507 //****************************************************************************
508 extern void I2SPointerSet(uint32_t ui32Base, bool bInput, void * pNextPointer);
509 
510 //*****************************************************************************
511 //
527 //
528 //*****************************************************************************
529 __STATIC_INLINE void
530 I2SIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
531 {
532  //
533  // Check the arguments.
534  //
535  ASSERT(I2SBaseValid(ui32Base));
536 
537  //
538  // Register the interrupt handler.
539  //
540  IntRegister(INT_I2S, pfnHandler);
541 
542  //
543  // Enable the I2S interrupt.
544  //
545  IntEnable(INT_I2S);
546 }
547 
548 //*****************************************************************************
549 //
563 //
564 //*****************************************************************************
565 __STATIC_INLINE void
566 I2SIntUnregister(uint32_t ui32Base)
567 {
568  //
569  // Check the arguments.
570  //
571  ASSERT(I2SBaseValid(ui32Base));
572 
573  //
574  // Disable the interrupt.
575  //
576  IntDisable(INT_I2S);
577 
578  //
579  // Unregister the interrupt handler.
580  //
581  IntUnregister(INT_I2S);
582 }
583 
584 //*****************************************************************************
585 //
604 //
605 //*****************************************************************************
606 __STATIC_INLINE void
607 I2SIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
608 {
609  //
610  // Check the arguments.
611  //
612  ASSERT(I2SBaseValid(ui32Base));
613 
614  //
615  // Enable the specified interrupts.
616  //
617  HWREG(ui32Base + I2S_O_IRQMASK) |= ui32IntFlags;
618 }
619 
620 //*****************************************************************************
621 //
640 //
641 //*****************************************************************************
642 __STATIC_INLINE void
643 I2SIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
644 {
645  //
646  // Check the arguments.
647  //
648  ASSERT(I2SBaseValid(ui32Base));
649 
650  //
651  // Disable the specified interrupts.
652  //
653  HWREG(ui32Base + I2S_O_IRQMASK) &= ~ui32IntFlags;
654 }
655 
656 //*****************************************************************************
657 //
676 //
677 //*****************************************************************************
678 __STATIC_INLINE uint32_t
679 I2SIntStatus(uint32_t ui32Base, bool bMasked)
680 {
681  uint32_t ui32Mask;
682 
683  //
684  // Check the arguments.
685  //
686  ASSERT(I2SBaseValid(ui32Base));
687 
688  //
689  // Return either the interrupt status or the raw interrupt status as
690  // requested.
691  //
692  if(bMasked)
693  {
694  ui32Mask = HWREG(ui32Base + I2S_O_IRQFLAGS);
695  return(ui32Mask & HWREG(ui32Base + I2S_O_IRQMASK));
696  }
697  else
698  {
699  return(HWREG(ui32Base + I2S_O_IRQFLAGS));
700  }
701 }
702 
703 //*****************************************************************************
704 //
732 //
733 //*****************************************************************************
734 __STATIC_INLINE void
735 I2SIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
736 {
737  //
738  // Check the arguments.
739  //
740  ASSERT(I2SBaseValid(ui32Base));
741 
742  //
743  // Clear the requested interrupt sources.
744  //
745  HWREG(ui32Base + I2S_O_IRQCLR) = ui32IntFlags;
746 }
747 
748 //*****************************************************************************
749 //
760 //
761 //*****************************************************************************
762 __STATIC_INLINE void
763 I2SSampleStampEnable(uint32_t ui32Base)
764 {
765  //
766  // Set the enable bit.
767  //
768  HWREG(ui32Base + I2S_O_STMPCTL) = I2S_STMPCTL_STMP_EN;
769 }
770 
771 //*****************************************************************************
772 //
779 //
780 //*****************************************************************************
781 __STATIC_INLINE void
782 I2SSampleStampDisable(uint32_t ui32Base)
783 {
784  //
785  // Clear the enable bit.
786  //
787  HWREG(ui32Base + I2S_O_STMPCTL) = 0;
788 
789 }
790 
791 //*****************************************************************************
792 //
805 //
806 //*****************************************************************************
807 extern void I2SSampleStampConfigure(uint32_t ui32Base, bool bInput,
808  bool bOutput);
809 
810 //*****************************************************************************
811 //
818 //
819 //*****************************************************************************
820 extern uint32_t I2SSampleStampGet(uint32_t ui32Base, uint32_t ui32Channel);
821 
822 //*****************************************************************************
823 //
824 // Support for DriverLib in ROM:
825 // Redirect to implementation in ROM when available.
826 //
827 //*****************************************************************************
828 #ifndef DRIVERLIB_NOROM
829  #include <driverlib/rom.h>
830  #ifdef ROM_I2SEnable
831  #undef I2SEnable
832  #define I2SEnable ROM_I2SEnable
833  #endif
834  #ifdef ROM_I2SAudioFormatConfigure
835  #undef I2SAudioFormatConfigure
836  #define I2SAudioFormatConfigure ROM_I2SAudioFormatConfigure
837  #endif
838  #ifdef ROM_I2SChannelConfigure
839  #undef I2SChannelConfigure
840  #define I2SChannelConfigure ROM_I2SChannelConfigure
841  #endif
842  #ifdef ROM_I2SBufferConfig
843  #undef I2SBufferConfig
844  #define I2SBufferConfig ROM_I2SBufferConfig
845  #endif
846  #ifdef ROM_I2SPointerUpdate
847  #undef I2SPointerUpdate
848  #define I2SPointerUpdate ROM_I2SPointerUpdate
849  #endif
850  #ifdef ROM_I2SPointerSet
851  #undef I2SPointerSet
852  #define I2SPointerSet ROM_I2SPointerSet
853  #endif
854  #ifdef ROM_I2SSampleStampConfigure
855  #undef I2SSampleStampConfigure
856  #define I2SSampleStampConfigure ROM_I2SSampleStampConfigure
857  #endif
858  #ifdef ROM_I2SSampleStampGet
859  #undef I2SSampleStampGet
860  #define I2SSampleStampGet ROM_I2SSampleStampGet
861  #endif
862 #endif
863 
864 //*****************************************************************************
865 //
866 // Mark the end of the C bindings section for C++ compilers.
867 //
868 //*****************************************************************************
869 #ifdef __cplusplus
870 }
871 #endif
872 
873 #endif // __I2S_H__
874 
875 //****************************************************************************
876 //
879 //
880 //****************************************************************************
void I2SSampleStampConfigure(uint32_t ui32Base, bool bInput, bool bOutput)
Configure the sample stamp generator.
Definition: i2s.c:373
__STATIC_INLINE void I2SSampleStampDisable(uint32_t ui32Base)
Disable the Sample Stamp generator.
Definition: i2s.h:782
void I2SPointerSet(uint32_t ui32Base, bool bInput, void *pNextPointer)
Set a buffer pointer (input or output) directly.
Definition: i2s.c:304
__STATIC_INLINE void I2SIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
Enables individual I2S interrupt sources.
Definition: i2s.h:607
__STATIC_INLINE void I2SDisable(uint32_t ui32Base)
Disables the I2S module for operation.
Definition: i2s.h:291
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
#define ASSERT(expr)
Definition: debug.h:65
uint16_t ui16DMABufSize
Size of DMA buffer in number of samples.
Definition: i2s.h:117
uint32_t ui32InOffset
Value of the current input pointer offset.
Definition: i2s.h:123
__STATIC_INLINE void I2SIntRegister(uint32_t ui32Base, void(*pfnHandler)(void))
Registers an interrupt handler for an I2S interrupt.
Definition: i2s.h:530
uint32_t I2SSampleStampGet(uint32_t ui32Base, uint32_t ui32Channel)
Get the current value of a sample stamp counter.
Definition: i2s.c:409
__STATIC_INLINE uint32_t I2SIntStatus(uint32_t ui32Base, bool bMasked)
Gets the current interrupt status.
Definition: i2s.h:679
uint32_t ui32OutOffset
Value of the current output pointer offset.
Definition: i2s.h:125
uint32_t ui32OutBase
Base address of the output buffer.
Definition: i2s.h:124
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:121
__STATIC_INLINE void I2SSampleStampEnable(uint32_t ui32Base)
Enable the Sample Stamp generator.
Definition: i2s.h:763
A structure that defines an audio control table. Note: Memory for this structure must be initialized ...
Definition: i2s.h:115
uint8_t ui8InChan
Input Channel.
Definition: i2s.h:119
__STATIC_INLINE void I2SIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
Clears I2S interrupt sources.
Definition: i2s.h:735
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:122
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:120
void IntUnregister(uint32_t ui32Interrupt)
Unregisters the function to be called when an interrupt occurs.
Definition: interrupt.c:205
__STATIC_INLINE void I2SIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
Disables individual I2S interrupt sources.
Definition: i2s.h:643
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
uint16_t ui16ChBufSize
Size of Channel buffer.
Definition: i2s.h:118
__STATIC_INLINE void I2SClockConfigure(uint32_t ui32Base, uint32_t ui32ClkConfig)
Configure the I2S frame clock.
Definition: i2s.h:415
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:383
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function to be called when an interrupt occurs.
Definition: interrupt.c:157
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:323
__STATIC_INLINE void I2SIntUnregister(uint32_t ui32Base)
Unregisters an interrupt handler for a I2S interrupt.
Definition: i2s.h:566