- Note
- IP Supported: TDM Configures audio TDM/I2S.
The functions and other declarations used in this driver are in cy_tdm.h. You can include cy_pdl.h (ModusToolbox only) to get access to all functions and declarations in the PDL.
Features:
- Supports I2S mode and TDM mode.
- Master and slave functionality.
- Full-duplex transmitter and receiver operation.
- Support for up to 32 channels.
- Programmable channel size (up to 32 bits)
- Programmable channel delay of 0 or 1 bit.
- Delayed sampling support.
- Programmable PCM sample formatting (8, 10, 12, 14, 16, 18, 20, 24, 32 bits).
- Programmable synchronization pulse type.
- Left-aligned and right-aligned sample formatting.
- 128 entry TX FIFO with interrupt and trigger support.
- 128 entry RX FIFO with interrupt and trigger support.
Configuration Considerations
To set up a TDM driver, initialize the TDM Transmitter module in accordance with a configuration structure.
- Each TDM/I2S (TX, RX) pair consists of a TDM/I2S transmitter and a TDM/I2S receiver.
- The transmitter and receiver can function simultaneously and have dedicated clock control.
- The transmitter and receiver have dedicated MMIO registers and a dedicated FIFO.
- The transmitter and receiver have a dedicated FIFO interrupt and FIFO trigger.
- The transmitter trigger is activated when a programmable number of PCM data slots is available in the TX FIFO.
- The receiver trigger is activated when a programmable number of PCM data words is received into the RX FIFO.
To set up TDM, provide the configuration parameters in the cy_stc_tdm_config_t structure.
For example, for Tx configuration, set txEnabled to true, configure txDmaTrigger (depending on whether DMA is going to be used or not), set extClk (if an external clock is used), provide clkDiv, masterMode, sckPolarity, fsyncPolarity, channelSize, wordSize, either i2sMode or TDM (based on Mode setting), fifoTriggerLevel (when the Trig interrupt will be used) and format A similar setup is for the Rx configuration.
To initialize the TDM block, call the Cy_AudioTDM_Init function, providing the filled cy_stc_tdm_config_t structure. Before starting the transmission, enable the Tx Cy_AudioTDM_EnableTx, then fill the first Tx data frame by calling Cy_AudioTDM_WriteTxData. Then call the Cy_AudioTDM_ActivateTx. For the reception the sequence is the same except for filling the first data frame.
For example:
{
.clkDiv = 16,
.channelNum = 2,
.channelSize = 16,
.fifoTriggerLevel = 36,
.chEn = 0x3,
.signalInput = 0,
.i2sMode = true,
};
{
.clkDiv = 16,
.lateSample = false,
.channelNum = 2,
.channelSize = 16,
.fifoTriggerLevel = 32,
.chEn = 0x3,
.signalInput = 0,
.i2sMode = true,
};
{
.rx_config = &tdm_lpbk_rx_config,
};
{
}
bool enable
Enables/Disables TDM TX.
Definition: cy_tdm.h:309
bool enable
Enables/Disables TDM RX.
Definition: cy_tdm.h:333
cy_stc_tdm_config_tx_t * tx_config
TDM Initialization configuration for TX.
Definition: cy_tdm.h:364
cy_stc_tdm_config_rx_t
Definition: cy_tdm.h:332
cy_stc_tdm_config_t
Definition: cy_tdm.h:363
TDM Initialization configuration.
Definition: cy_tdm.h:308
@ CY_TDM_CH_PERIOD
TDM Channel Synchronization is duration of a channel period.
Definition: cy_tdm.h:281
@ CY_TDM_LEFT
Format is left aligned.
Definition: cy_tdm.h:234
@ CY_TDM_SIZE_16
PCM word size:16bit.
Definition: cy_tdm.h:223
@ CY_TDM_SUCCESS
Successful.
Definition: cy_tdm.h:289
@ CY_TDM_SEL_SRSS_CLK0
Interface clock is selected as clk_if_srss[0].
Definition: cy_tdm.h:256
@ CY_TDM_CLK
TDM Clock is used as is.
Definition: cy_tdm.h:266
@ CY_ZERO_EXTEND
Zero extended.
Definition: cy_tdm.h:249
@ CY_TDM_DEVICE_MASTER
Device is configured as master.
Definition: cy_tdm.h:243
@ CY_TDM_DEVICE_SLAVE
Device is configured as slave.
Definition: cy_tdm.h:242
@ CY_TDM_SIGN
TDM Sign is used as is.
Definition: cy_tdm.h:273
__STATIC_INLINE void Cy_AudioTDM_ClearRxInterrupt(TDM_RX_STRUCT_Type *base, uint32_t interrupt)
Clears RX interrupt.
Definition: cy_tdm.h:1189
__STATIC_INLINE void Cy_AudioTDM_SetRxInterruptMask(TDM_RX_STRUCT_Type *base, uint32_t interrupt)
Sets RX interrupt Mask.
Definition: cy_tdm.h:1245
__STATIC_INLINE void Cy_AudioTDM_SetTxInterruptMask(TDM_TX_STRUCT_Type *base, uint32_t interrupt)
Set TX interrupt Mask.
Definition: cy_tdm.h:1128
__STATIC_INLINE void Cy_AudioTDM_ClearTxInterrupt(TDM_TX_STRUCT_Type *base, uint32_t interrupt)
Clear TX interrupt.
Definition: cy_tdm.h:1072
__STATIC_INLINE void Cy_AudioTDM_EnableTx(TDM_TX_STRUCT_Type *base)
Starts an I2S/TDM transmission.
Definition: cy_tdm.h:583
__STATIC_INLINE void Cy_AudioTDM_EnableRx(TDM_RX_STRUCT_Type *base)
Starts an I2S/TDM transmission.
Definition: cy_tdm.h:622
cy_en_tdm_status_t Cy_AudioTDM_Init(TDM_STRUCT_Type *base, cy_stc_tdm_config_t const *config)
Initializes the TDM module in accordance with a configuration structure.
Definition: cy_tdm.c:58
If you use a DMA, the DMA channel should be previously configured. The TDM interrupts (if applicable) can be enabled by calling Cy_AudioTDM_SetTxInterruptMask.
For example, if the trigger interrupt is used during operation, the ISR should call the Cy_AudioTDM_WriteTxData as many times as required for your FIFO payload, but not more than the FIFO size. Then call Cy_AudioTDM_ClearTxInterrupt with appropriate parameters.
If a DMA is used and the DMA channel is properly configured - no CPU activity (or any application code) is needed for I2S/TDM operation.
The I2S frame appears as:
This is an example for the channel length = 32. A similar case exists for the rest channel length configuration, with one limitation: the word length should be less than or equal to the channel length. See the datasheet of your device for more details.
MISRA-C Compliance
The TDM driver has the following specific deviations:
| MISRA Rule | Rule Class (Required/Advisory) | Rule Description | Description of Deviation(s) |
| 10.3 | R | A composite expression of the "essentially unsigned" type is being cast to a different type category. | The value got from the bitfield physically cannot exceed the enumeration that describes this bitfield. So, the code is safe by design. |
| 11.4 | A | A cast should not be performed between a pointer to object type and a different pointer to object type. | |
| 20.3 | R | The validity of values passed to library functions shall be checked. | This violation is not caused by code changes, i.e. is not a regression. |