CC26xx Driver Library
[i2s] Inter-IC Sound

Data Structures

struct  I2SControlTable
 A structure that defines an audio control table. Note: Memory for this structure must be initialized by user application. See detailed description! More...
 

Functions

void I2SEnable (uint32_t ui32Base)
 Enables the I2S module for operation. More...
 
static void I2SDisable (uint32_t ui32Base)
 Disables the I2S module for operation. More...
 
void I2SAudioFormatConfigure (uint32_t ui32Base, uint32_t ui32FmtCfg, uint32_t ui32BitClkDelay)
 Configures the I2S module. More...
 
void I2SChannelConfigure (uint32_t ui32Base, uint32_t ui32Chan0Cfg, uint32_t ui32Chan1Cfg, uint32_t ui32Chan2Cfg)
 Setup the audio channel configuration. More...
 
static void I2SClockConfigure (uint32_t ui32Base, uint32_t ui32ClkConfig)
 Configure the I2S frame clock. More...
 
void I2SBufferConfig (uint32_t ui32Base, uint32_t ui32InBufBase, uint32_t ui32OutBufBase, uint16_t ui16DMABufSize, uint16_t ui16ChanBufSize)
 Set the input buffer pointers. More...
 
void I2SPointerUpdate (uint32_t ui32Base, bool bInput)
 Update the buffer pointers. More...
 
void I2SPointerSet (uint32_t ui32Base, bool bInput, void *pNextPointer)
 Set a buffer pointer (input or output) directly. More...
 
static void I2SIntRegister (uint32_t ui32Base, void(*pfnHandler)(void))
 Registers an interrupt handler for an I2S interrupt. More...
 
static void I2SIntUnregister (uint32_t ui32Base)
 Unregisters an interrupt handler for a I2S interrupt. More...
 
static void I2SIntEnable (uint32_t ui32Base, uint32_t ui32IntFlags)
 Enables individual I2S interrupt sources. More...
 
static void I2SIntDisable (uint32_t ui32Base, uint32_t ui32IntFlags)
 Disables individual I2S interrupt sources. More...
 
static uint32_t I2SIntStatus (uint32_t ui32Base, bool bMasked)
 Gets the current interrupt status. More...
 
static void I2SIntClear (uint32_t ui32Base, uint32_t ui32IntFlags)
 Clears I2S interrupt sources. More...
 
static void I2SSampleStampEnable (uint32_t ui32Base)
 Enable the Sample Stamp generator. More...
 
static void I2SSampleStampDisable (uint32_t ui32Base)
 Disable the Sample Stamp generator. More...
 
void I2SSampleStampConfigure (uint32_t ui32Base, bool bInput, bool bOutput)
 Configure the sample stamp generator. More...
 
uint32_t I2SSampleStampGet (uint32_t ui32Base, uint32_t ui32Channel)
 Get the current value of a sample stamp counter. More...
 

Variables

I2SControlTableg_pControlTable
 

Detailed Description

Function Documentation

void I2SAudioFormatConfigure ( uint32_t  ui32Base,
uint32_t  ui32FmtCfg,
uint32_t  ui32BitClkDelay 
)

Configures the I2S module.

The word length defines the size of the word transmitted on the data lines. For single phased formats I2S_WORD_LENGTH_x is the exact number of bits per word. In dual phased format this is the maximum number of bits per word. The size is set using I2S_WORD_LENGTH_8, I2S_WORD_LENGTH_16 or I2S_WORD_LENGTH_24.

Parameters
ui32Baseis the I2S module base address.
ui32FmtCfgis the bitwise OR of several options:
ui32BitClkDelaydefines the bit clock delay by setting the number of bit clock periods between the positive word clock edge and the MSB of the first word in a phase. The bit clock delay is determined by the ratio between the bit clock and the frame clock and the chosen audio format. The bit clock delay must be configured depending on the chosen audio format:
  • 0 : Left Justified Format (LJF).
  • 1 : I2S and DSP format.
  • 2-255 : Right Justified format (RJF).
Returns
None
See also
I2SChannelConfigure()
108 {
109  // Check the arguments.
110  ASSERT(I2SBaseValid(ui32Base));
111  ASSERT(ui32BitClkDelay <= 255);
112 
113  // Save the length of the audio words stored in memory.
114  g_pControlTable->ui16MemLen = (ui32FmtCfg & I2S_MEM_LENGTH_24) ? 24 : 16;
115 
116  // Write the configuration.
117  HWREG(I2S0_BASE + I2S_O_AIFFMTCFG) = ui32FmtCfg | (ui32BitClkDelay << I2S_AIFFMTCFG_DATA_DELAY_S);
118 }
#define I2S_MEM_LENGTH_24
Definition: i2s.h:194
uint16_t ui16MemLen
Length of the audio words stored in memory.
Definition: i2s.h:122
#define ASSERT(expr)
Definition: debug.h:74
I2SControlTable * g_pControlTable
Definition: i2s.c:71
void I2SBufferConfig ( uint32_t  ui32Base,
uint32_t  ui32InBufBase,
uint32_t  ui32OutBufBase,
uint16_t  ui16DMABufSize,
uint16_t  ui16ChanBufSize 
)

Set the input buffer pointers.

The next pointer should always be written while the DMA is using the previous written pointer. If not written in time an I2S_INT_PTR_ERR will occur and all outputs will be disabled.

Note
At startup the next data pointer should be written just before and just after calling the I2SEnable().
Parameters
ui32Baseis the base address of the I2S module.
ui32InBufBaseis the address of the input buffer.
ui32OutBufBaseis the address of the output buffer.
ui16DMABufSizeis the size of the DMA buffers. Must be greater than 0!
ui16ChanBufSizeis the size of the channel buffers.
Returns
None
248 {
249  // Check the arguments.
250  ASSERT(I2SBaseValid(ui32Base));
251  ASSERT(ui16DMABufSize > 0);
252 
253  // Setup the input data pointer and buffer sizes.
254  g_pControlTable->ui16DMABufSize = ui16DMABufSize;
255  g_pControlTable->ui16ChBufSize = ui16ChanBufSize;
256  g_pControlTable->ui32InBase = ui32InBufBase;
257  g_pControlTable->ui32OutBase = ui32OutBufBase;
258 }
uint16_t ui16DMABufSize
Size of DMA buffer in number of samples.
Definition: i2s.h:118
uint32_t ui32OutBase
Base address of the output buffer.
Definition: i2s.h:125
#define ASSERT(expr)
Definition: debug.h:74
uint32_t ui32InBase
Base address of the input buffer.
Definition: i2s.h:123
I2SControlTable * g_pControlTable
Definition: i2s.c:71
uint16_t ui16ChBufSize
Size of Channel buffer.
Definition: i2s.h:119
void I2SChannelConfigure ( uint32_t  ui32Base,
uint32_t  ui32Chan0Cfg,
uint32_t  ui32Chan1Cfg,
uint32_t  ui32Chan2Cfg 
)

Setup the audio channel configuration.

The channel configuration is a bitwise OR of the input/output mode of each data line and the active audio channels within a specific audio frame.

Setting up the input/output mode use one of:

For dual phased audio (LJF,RJF,I2S) only mono and stereo modes are allowed. For single phased audio format (DSP) up to 8 active channels are allowed on a single data line. For setting up the active channels in a frame use:

Note
The audio format and the clock configuration should be set using I2SAudioFormatConfigure()
Parameters
ui32Baseis base address of the I2S module.
ui32Chan0Cfgdefines the channel configuration for data line 0.
ui32Chan1Cfgdefines the channel configuration for data line 1.
ui32Chan2Cfgdefines the channel configuration for data line 2.
Returns
None
See also
I2SAudioFormatConfigure()
128 {
129  uint32_t ui32InChan;
130  uint32_t ui32OutChan;
131  uint32_t ui32ChanMask;
132 
133  // Check the arguments.
134  ASSERT(I2SBaseValid(ui32Base));
135  ASSERT(ui32Chan0Cfg & (I2S_CHAN_CFG_MASK | I2S_LINE_MASK))
136  ASSERT(ui32Chan1Cfg & (I2S_CHAN_CFG_MASK | I2S_LINE_MASK))
137  ASSERT(ui32Chan2Cfg & (I2S_CHAN_CFG_MASK | I2S_LINE_MASK))
138 
139  ui32InChan = 0;
140  ui32OutChan = 0;
141 
142  // Configure input/output channels.
143  HWREG(I2S0_BASE + I2S_O_AIFDIRCFG) = ((ui32Chan0Cfg << I2S_AIFDIRCFG_AD0_S)
145  ((ui32Chan1Cfg << I2S_AIFDIRCFG_AD1_S)
147  ((ui32Chan2Cfg << I2S_AIFDIRCFG_AD2_S)
149 
150  // Configure the valid channel mask.
151  HWREG(I2S0_BASE + I2S_O_AIFWMASK0) = (ui32Chan0Cfg >> 8) & I2S_AIFWMASK0_MASK_M;
152  HWREG(I2S0_BASE + I2S_O_AIFWMASK1) = (ui32Chan1Cfg >> 8) & I2S_AIFWMASK1_MASK_M;
153  HWREG(I2S0_BASE + I2S_O_AIFWMASK2) = (ui32Chan2Cfg >> 8) & I2S_AIFWMASK2_MASK_M;
154 
155  // Resolve and save the number of input and output channels.
156  ui32ChanMask = (ui32Chan0Cfg & I2S_CHAN_CFG_MASK) >> 8;
157  if(ui32Chan0Cfg & I2S_LINE_INPUT)
158  {
159  while(ui32ChanMask)
160  {
161  if(ui32ChanMask & 0x1)
162  {
163  ui32InChan++;
164  }
165  // Shift down channel mask
166  ui32ChanMask >>= 1;
167  }
168 
169  }
170  else if(ui32Chan0Cfg & I2S_LINE_OUTPUT)
171  {
172  while(ui32ChanMask)
173  {
174  if(ui32ChanMask & 0x1)
175  {
176  ui32OutChan++;
177  }
178  // Shift down channel mask
179  ui32ChanMask >>= 1;
180  }
181  }
182 
183  ui32ChanMask = (ui32Chan1Cfg & I2S_CHAN_CFG_MASK) >> 8;
184  if(ui32Chan1Cfg & I2S_LINE_INPUT)
185  {
186  while(ui32ChanMask)
187  {
188  if(ui32ChanMask & 0x1)
189  {
190  ui32InChan++;
191  }
192  // Shift down channel mask
193  ui32ChanMask >>= 1;
194  }
195  }
196  else if(ui32Chan1Cfg & I2S_LINE_OUTPUT)
197  {
198  while(ui32ChanMask)
199  {
200  if(ui32ChanMask & 0x1)
201  {
202  ui32OutChan++;
203  }
204  // Shift down channel mask
205  ui32ChanMask >>= 1;
206  }
207  }
208 
209  ui32ChanMask = (ui32Chan2Cfg & I2S_CHAN_CFG_MASK) >> 8;
210  if(ui32Chan2Cfg & I2S_LINE_INPUT)
211  {
212  while(ui32ChanMask)
213  {
214  if(ui32ChanMask & 0x1)
215  {
216  ui32InChan++;
217  }
218  // Shift down channel mask
219  ui32ChanMask >>= 1;
220  }
221  }
222  else if(ui32Chan2Cfg & I2S_LINE_OUTPUT)
223  {
224  while(ui32ChanMask)
225  {
226  if(ui32ChanMask & 0x1)
227  {
228  ui32OutChan++;
229  }
230  // Shift down channel mask
231  ui32ChanMask >>= 1;
232  }
233  }
234 
235  g_pControlTable->ui8InChan = (uint8_t)ui32InChan;
236  g_pControlTable->ui8OutChan = (uint8_t)ui32OutChan;
237 }
#define I2S_LINE_MASK
Definition: i2s.h:169
#define I2S_CHAN_CFG_MASK
Definition: i2s.h:186
#define I2S_LINE_INPUT
Definition: i2s.h:167
uint8_t ui8InChan
Input Channel.
Definition: i2s.h:120
#define ASSERT(expr)
Definition: debug.h:74
uint8_t ui8OutChan
Output Channel.
Definition: i2s.h:121
#define I2S_LINE_OUTPUT
Definition: i2s.h:168
I2SControlTable * g_pControlTable
Definition: i2s.c:71
static void I2SClockConfigure ( uint32_t  ui32Base,
uint32_t  ui32ClkConfig 
)
inlinestatic

Configure the I2S frame clock.

Configure I2S clock to be either internal or external and either normal or inverted.

Note
The bit clock configuration is done externally, but the internal/ external setting must match what is chosen internally in the I2S module for the frame clock.
Parameters
ui32Baseis the base address of the I2S module.
ui32ClkConfigis the clock configuration parameter. Bitwise OR'ed combination of clock source and clock polarity:
Returns
None
413 {
414  // Check the arguments.
415  ASSERT(I2SBaseValid(ui32Base));
416 
417  // Setup register WCLK Source.
418  HWREG(I2S0_BASE + I2S_O_AIFWCLKSRC) = ui32ClkConfig &
421 }
#define ASSERT(expr)
Definition: debug.h:74
static void I2SDisable ( uint32_t  ui32Base)
inlinestatic

Disables the I2S module for operation.

This function will immediately disable the I2S module. To ensure that all buffer operations are completed before shutting down, the correct procedure is:

  1. Do not update the data pointers using I2SPointerUpdate().
  2. Await next interrupt resulting in I2S_INT_PTR_ERR.
  3. Disable the I2S using I2SDisable() and clear the pointer error using I2SIntClear().
  4. Disable bit clock source (done externally).
Parameters
ui32Baseis the I2S module base address.
Returns
None
293 {
294  // Check the arguments.
295  ASSERT(I2SBaseValid(ui32Base));
296 
297  // Disable the I2S module.
298  HWREG(I2S0_BASE + I2S_O_AIFDMACFG) = 0x0;
299 }
#define ASSERT(expr)
Definition: debug.h:74
void I2SEnable ( uint32_t  ui32Base)

Enables the I2S module for operation.

Note
The module should only be enabled after configuration. When the module is disabled, no data or clocks will be generated on the I2S signals.
Immediately after enabling the module the programmer should update the DMA data pointer registers using I2SPointerUpdate() to ensure a new pointer is written before the DMA transfer completes. Failure to update the pointer in time will result in an I2S_INT_PTR_ERR.
Parameters
ui32Baseis the I2S module base address.
Returns
None
80 {
81  // Check the arguments.
82  ASSERT(I2SBaseValid(ui32Base));
83 
84  // Make sure the control table pointer is setup to a memory location.
85  if(!(g_pControlTable))
86  {
87  return;
88  }
89 
90  // Write the address to the first input/output buffer.
95 
96  // Enable the I2S module.
97  HWREG(I2S0_BASE + I2S_O_AIFDMACFG) = (uint32_t)g_pControlTable->ui16DMABufSize - 1;
98 }
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 ui32OutOffset
Value of the current output pointer offset.
Definition: i2s.h:126
uint32_t ui32OutBase
Base address of the output buffer.
Definition: i2s.h:125
#define ASSERT(expr)
Definition: debug.h:74
uint32_t ui32InBase
Base address of the input buffer.
Definition: i2s.h:123
I2SControlTable * g_pControlTable
Definition: i2s.c:71
static void I2SIntClear ( uint32_t  ui32Base,
uint32_t  ui32IntFlags 
)
inlinestatic

Clears I2S interrupt sources.

The specified I2S interrupt sources are cleared, so that they no longer assert. This function must be called in the interrupt handler to keep the interrupt from being recognized again immediately upon exit.

Note
Due to write buffers and synchronizers in the system it may take several clock cycles from a register write clearing an event in a module and until the event is actually cleared in the NVIC of the system CPU. It is recommended to clear the event source early in the interrupt service routine (ISR) to allow the event clear to propagate to the NVIC before returning from the ISR. At the same time, an early event clear allows new events of the same type to be pended instead of ignored if the event is cleared later in the ISR. It is the responsibility of the programmer to make sure that enough time has passed before returning from the ISR to avoid false re-triggering of the cleared event. A simple, although not necessarily optimal, way of clearing an event before returning from the ISR is:
  1. Write to clear event (interrupt source). (buffered write)
  2. Dummy read from the event source module. (making sure the write has propagated)
  3. Wait two system CPU clock cycles (user code or two NOPs). (allowing cleared event to propagate through any synchronizers)
Parameters
ui32Baseis the base address of the I2S port.
ui32IntFlagsis a bit mask of the interrupt sources to be cleared. The parameter is the bitwise OR of any of the following:
Returns
None
708 {
709  // Check the arguments.
710  ASSERT(I2SBaseValid(ui32Base));
711 
712  // Clear the requested interrupt sources.
713  HWREG(I2S0_BASE + I2S_O_IRQCLR) = ui32IntFlags;
714 }
#define ASSERT(expr)
Definition: debug.h:74
static void I2SIntDisable ( uint32_t  ui32Base,
uint32_t  ui32IntFlags 
)
inlinestatic

Disables individual I2S interrupt sources.

This function disables the indicated I2S interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt; disabled sources have no effect on the processor.

Parameters
ui32Baseis the base address of the I2S port.
ui32IntFlagsis the bit mask of the interrupt sources to be disabled. The parameter is the bitwise OR of any of the following:
Returns
None.
618 {
619  // Check the arguments.
620  ASSERT(I2SBaseValid(ui32Base));
621 
622  // Disable the specified interrupts.
623  HWREG(I2S0_BASE + I2S_O_IRQMASK) &= ~ui32IntFlags;
624 }
#define ASSERT(expr)
Definition: debug.h:74
static void I2SIntEnable ( uint32_t  ui32Base,
uint32_t  ui32IntFlags 
)
inlinestatic

Enables individual I2S interrupt sources.

This function enables the indicated I2S interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt; disabled sources have no effect on the processor.

Parameters
ui32Baseis the base address of the I2S port.
ui32IntFlagsis the bit mask of the interrupt sources to be enabled. The parameter is the bitwise OR of any of the following:
Returns
None.
586 {
587  // Check the arguments.
588  ASSERT(I2SBaseValid(ui32Base));
589 
590  // Enable the specified interrupts.
591  HWREG(I2S0_BASE + I2S_O_IRQMASK) |= ui32IntFlags;
592 }
#define ASSERT(expr)
Definition: debug.h:74
static void I2SIntRegister ( uint32_t  ui32Base,
void(*)(void)  pfnHandler 
)
inlinestatic

Registers an interrupt handler for an I2S interrupt.

This function does the actual registering of the interrupt handler. This function enables the global interrupt in the interrupt controller; specific I2S interrupts must be enabled via I2SIntEnable(). It is the interrupt handler's responsibility to clear the interrupt source.

Parameters
ui32Baseis the base address of the I2S port.
pfnHandleris a pointer to the function to be called when the I2S interrupt occurs.
Returns
None
See also
IntRegister() for important information about registering interrupt handlers.
521 {
522  // Check the arguments.
523  ASSERT(I2SBaseValid(ui32Base));
524 
525  // Register the interrupt handler.
526  IntRegister(INT_I2S_IRQ, pfnHandler);
527 
528  // Enable the I2S interrupt.
529  IntEnable(INT_I2S_IRQ);
530 }
#define ASSERT(expr)
Definition: debug.h:74
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:282

Here is the call graph for this function:

static uint32_t I2SIntStatus ( uint32_t  ui32Base,
bool  bMasked 
)
inlinestatic

Gets the current interrupt status.

This function returns the interrupt status for the specified I2S. Either the raw interrupt status or the status of interrupts that are allowed to reflect to the processor can be returned.

Parameters
ui32Baseis the base address of the I2S port
bMaskedselects between raw and masked interrupt status:
  • false : Raw interrupt status is required.
  • true : Masked interrupt status is required.
Returns
Returns the current interrupt status as a vector of:
650 {
651  uint32_t ui32Mask;
652 
653  // Check the arguments.
654  ASSERT(I2SBaseValid(ui32Base));
655 
656  // Return either the interrupt status or the raw interrupt status as
657  // requested.
658  if(bMasked)
659  {
660  ui32Mask = HWREG(I2S0_BASE + I2S_O_IRQFLAGS);
661  return(ui32Mask & HWREG(I2S0_BASE + I2S_O_IRQMASK));
662  }
663  else
664  {
665  return(HWREG(I2S0_BASE + I2S_O_IRQFLAGS));
666  }
667 }
#define ASSERT(expr)
Definition: debug.h:74
static void I2SIntUnregister ( uint32_t  ui32Base)
inlinestatic

Unregisters an interrupt handler for a I2S interrupt.

This function does the actual unregistering of the interrupt handler. It clears the handler to be called when an I2S interrupt occurs. This function also masks off the interrupt in the interrupt controller so that the interrupt handler no longer is called.

Parameters
ui32Baseis the base address of the I2S port.
Returns
None
See also
IntRegister() for important information about registering interrupt handlers.
551 {
552  // Check the arguments.
553  ASSERT(I2SBaseValid(ui32Base));
554 
555  // Disable the interrupt.
556  IntDisable(INT_I2S_IRQ);
557 
558  // Unregister the interrupt handler.
559  IntUnregister(INT_I2S_IRQ);
560 }
#define ASSERT(expr)
Definition: debug.h:74
void IntUnregister(uint32_t ui32Interrupt)
Unregisters the function to be called when an interrupt occurs.
Definition: interrupt.c:188
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:326

Here is the call graph for this function:

void I2SPointerSet ( uint32_t  ui32Base,
bool  bInput,
void *  pNextPointer 
)

Set a buffer pointer (input or output) directly.

This function allows bypassing of the pointers in the global control table.

The next pointer should always be written while the DMA is using the previous written pointer. If not written in time an I2S_INT_PTR_ERR will occur and all outputs will be disabled. Nothing is preventing the pointers from being identical, but this function relies on both pointers (input or output pointers) are pointing to a valid address.

Note
It is recommended that the pointer update is done in an interrupt context to ensure that the update is performed before the buffer is full.
Parameters
ui32Baseis the base address of the I2S module.
bInputdetermines whether to update input or output pointer.
  • true : Update input pointer.
  • false : Update output pointer
pNextPointeris a void pointer to user defined buffer.
Returns
None
See also
I2SPointerUpdate()

Set a buffer pointer (input or output) directly.

267 {
268  // Check the arguments.
269  ASSERT(I2SBaseValid(ui32Base));
270 
271  // Update the next input/output pointer with the correct address.
272  if(bInput == true)
273  {
274  HWREG(I2S0_BASE + I2S_O_AIFINPTRNEXT) = (uint32_t)pNextPointer;
275  }
276  else
277  {
278  HWREG(I2S0_BASE + I2S_O_AIFOUTPTRNEXT) = (uint32_t)pNextPointer;
279  }
280 }
#define ASSERT(expr)
Definition: debug.h:74
void I2SPointerUpdate ( uint32_t  ui32Base,
bool  bInput 
)

Update the buffer pointers.

The next pointer should always be written while the DMA is using the previous written pointer. If not written in time an I2S_INT_PTR_ERR will occur and all outputs will be disabled. Nothing is preventing the pointers from being identical, but this function relies on both pointers (input or output pointers) are pointing to a valid address.

Note
It is recommended that the pointer update is done in an interrupt context to ensure that the update is performed before the buffer is full.
Parameters
ui32Baseis the base address of the I2S module.
bInputdetermines whether to update input or output pointer.
  • true : Update input pointer.
  • false : Update output pointer
Returns
None
See also
I2SPointerSet()
289 {
290  uint32_t ui32NextPtr;
291 
292  // Check the arguments.
293  ASSERT(I2SBaseValid(ui32Base));
294 
295  // Update the next input/output pointer with the correct address.
296  if(bInput == true)
297  {
298  ui32NextPtr = (g_pControlTable->ui8InChan *
299  (g_pControlTable->ui16MemLen >> 3)) *
302  ui32NextPtr) %
306  }
307  else
308  {
309  ui32NextPtr = (g_pControlTable->ui8OutChan *
310  (g_pControlTable->ui16MemLen >> 3)) *
313  ui32NextPtr) %
315  HWREG(I2S0_BASE + I2S_O_AIFOUTPTRNEXT) =
318  }
319 }
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 ui32OutOffset
Value of the current output pointer offset.
Definition: i2s.h:126
uint32_t ui32OutBase
Base address of the output buffer.
Definition: i2s.h:125
uint16_t ui16MemLen
Length of the audio words stored in memory.
Definition: i2s.h:122
uint8_t ui8InChan
Input Channel.
Definition: i2s.h:120
#define ASSERT(expr)
Definition: debug.h:74
uint32_t ui32InBase
Base address of the input buffer.
Definition: i2s.h:123
uint8_t ui8OutChan
Output Channel.
Definition: i2s.h:121
I2SControlTable * g_pControlTable
Definition: i2s.c:71
uint16_t ui16ChBufSize
Size of Channel buffer.
Definition: i2s.h:119
void I2SSampleStampConfigure ( uint32_t  ui32Base,
bool  bInput,
bool  bOutput 
)

Configure the sample stamp generator.

Use this function to configure the sample stamp generator.

Parameters
ui32Baseis the base address of the I2S module.
bInputenables triggering of the sample stamp generator on input.
bOutputenables triggering of the sample stamp generator on output.
Returns
None
328 {
329  uint32_t ui32Trigger;
330 
331  // Check the arguments.
332  ASSERT(I2SBaseValid(ui32Base));
333 
334  ui32Trigger = HWREG(I2S0_BASE + I2S_O_STMPWCNT);
335  ui32Trigger = (ui32Trigger + 2) % g_pControlTable->ui16ChBufSize;
336 
337  // Setup the sample stamp trigger for input streams.
338  if(bInput)
339  {
340  HWREG(I2S0_BASE + I2S_O_STMPINTRIG) = ui32Trigger;
341  }
342 
343  // Setup the sample stamp trigger for output streams.
344  if(bOutput)
345  {
346  HWREG(I2S0_BASE + I2S_O_STMPOUTTRIG) = ui32Trigger;
347  }
348 
349 }
#define ASSERT(expr)
Definition: debug.h:74
I2SControlTable * g_pControlTable
Definition: i2s.c:71
uint16_t ui16ChBufSize
Size of Channel buffer.
Definition: i2s.h:119
static void I2SSampleStampDisable ( uint32_t  ui32Base)
inlinestatic

Disable the Sample Stamp generator.

Use this function to disable the sample stamp generators. When the sample stamp generator is disabled, the clock counters are automatically cleared.

Returns
None
749 {
750  // Clear the enable bit.
751  HWREG(I2S0_BASE + I2S_O_STMPCTL) = 0;
752 
753 }
static void I2SSampleStampEnable ( uint32_t  ui32Base)
inlinestatic

Enable the Sample Stamp generator.

Use this function to enable the sample stamp generators.

Note
It is the user's responsibility to ensure that the sample stamp generator is properly configured before it is enabled. It is the setting of the Input and Output triggers configured using I2SSampleStampConfigure() that triggers the start point of the audio streams.
Returns
None
732 {
733  // Set the enable bit.
735 }
uint32_t I2SSampleStampGet ( uint32_t  ui32Base,
uint32_t  ui32Channel 
)

Get the current value of a sample stamp counter.

Parameters
ui32Baseis the base address of the I2S module.
ui32Channelis the sample stamp counter to sample
Returns
Returns the current value of the selected sample stamp channel.
358 {
359  uint32_t ui32FrameClkCnt;
360  uint32_t ui32SysClkCnt;
361  uint32_t ui32PeriodSysClkCnt;
362  uint32_t ui32SampleStamp;
363 
364  // Get the number of Frame clock counts since last stamp.
365  ui32FrameClkCnt = HWREG(I2S0_BASE + I2S_O_STMPWCNTCAPT0);
366 
367  // Get the number of system clock ticks since last frame clock edge.
368  ui32SysClkCnt = HWREG(I2S0_BASE + I2S_O_STMPXCNTCAPT0);
369 
370  // Get the number system clock ticks in the last frame clock period.
371  ui32PeriodSysClkCnt = HWREG(I2S0_BASE + I2S_O_STMPXPER);
372 
373  // Calculate the sample stamp.
374  ui32SampleStamp = (ui32SysClkCnt << 16) / ui32PeriodSysClkCnt;
375  ui32SampleStamp = (ui32SampleStamp > I2S_STMP_SATURATION) ?
376  I2S_STMP_SATURATION : ui32SampleStamp;
377  ui32SampleStamp |= (ui32FrameClkCnt << 16);
378 
379  return (ui32SampleStamp);
380 }
#define I2S_STMP_SATURATION
Definition: i2s.h:210

Macro Definition Documentation

#define I2S_CHAN0_ACT   0x00000100
#define I2S_CHAN1_ACT   0x00000200
#define I2S_CHAN2_ACT   0x00000400
#define I2S_CHAN3_ACT   0x00000800
#define I2S_CHAN4_ACT   0x00001000
#define I2S_CHAN5_ACT   0x00002000
#define I2S_CHAN6_ACT   0x00004000
#define I2S_CHAN7_ACT   0x00008000
#define I2S_CHAN_CFG_MASK   0x0000FF00

Referenced by I2SChannelConfigure().

#define I2S_DMA_BUF_SIZE_128   0x00000080
#define I2S_DMA_BUF_SIZE_256   0x00000100
#define I2S_DMA_BUF_SIZE_64   0x00000040
#define I2S_DUAL_PHASE_FMT   0x00000020
#define I2S_EXT_WCLK   0x00000001
#define I2S_INT_ALL   0x0000003F
#define I2S_INT_BUS_ERR   0x00000004
#define I2S_INT_DMA_IN   0x00000020
#define I2S_INT_DMA_OUT   0x00000010
#define I2S_INT_PTR_ERR   0x00000001
#define I2S_INT_TIMEOUT   0x00000008
#define I2S_INT_WCLK   0x00000002
#define I2S_INT_WCLK_ERR   0x00000002
#define I2S_INVERT_WCLK   0x00000004
#define I2S_LINE_INPUT   0x00000001

Referenced by I2SChannelConfigure().

#define I2S_LINE_MASK   0x00000003

Referenced by I2SChannelConfigure().

#define I2S_LINE_OUTPUT   0x00000002

Referenced by I2SChannelConfigure().

#define I2S_LINE_UNUSED   0x00000000
#define I2S_MEM_LENGTH_16   0x00000000
#define I2S_MEM_LENGTH_24   0x00000080

Referenced by I2SAudioFormatConfigure().

#define I2S_MONO_MODE   0x00000100
#define I2S_NEG_EDGE   0x00000000
#define I2S_NORMAL_WCLK   0x00000000
#define I2S_POS_EDGE   0x00000040
#define I2S_SINGLE_PHASE_FMT   0x00000000
#define I2S_STEREO_MODE   0x00000300
#define I2S_STMP0   0x00000001
#define I2S_STMP1   0x00000002
#define I2S_STMP_SATURATION   0x0000FFFF

Referenced by I2SSampleStampGet().

#define I2S_WORD_LENGTH_16   0x00000010
#define I2S_WORD_LENGTH_24   0x00000018
#define I2S_WORD_LENGTH_8   0x00000008

Variable Documentation

I2SControlTable* g_pControlTable