1 /***************************************************************************//**
2 * \file cy_tdm.h
3 * \version 1.0
4 *
5 * \brief
6 * The header file of the Audio TDM driver.
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright 2021 Cypress Semiconductor Corporation
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 *     http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *******************************************************************************/
25 
26 /**
27 * \addtogroup group_tdm
28 * \{
29 * \note IP Supported: TDM
30 * \note Device Categories: CAT1B. Please refer <a href="usergroup1.html">Device Catalog</a>.
31 * Configures audio TDM/I2S.
32 *
33 * The functions and other declarations used in this driver are in cy_tdm.h.
34 * You can include cy_pdl.h (ModusToolbox only) to get access to all functions
35 * and declarations in the PDL.
36 *
37 *
38 * Features:
39 * * Supports I2S mode and TDM mode.
40 * * Master and slave functionality.
41 * * Full-duplex transmitter and receiver operation.
42 * * Support for up to 32 channels.
43 * * Programmable channel size (up to 32 bits)
44 * * Programmable channel delay of 0 or 1 bit.
45 * * Delayed sampling support.
46 * * Programmable PCM sample formatting (8, 10, 12, 14, 16, 18, 20, 24, 32 bits).
47 * * Programmable synchronization pulse type.
48 * * Left-aligned and right-aligned sample formatting.
49 * * 128 entry TX FIFO with interrupt and trigger support.
50 * * 128 entry RX FIFO with interrupt and trigger support.
51 *
52 * \section group_tdm_configuration Configuration Considerations
53 *
54 * To set up a TDM driver, initialize the TDM Transmitter module in accordance with a configuration structure.
55 *
56 * * Each TDM/I2S (TX, RX) pair consists of a TDM/I2S transmitter and a TDM/I2S receiver.
57 * * The transmitter and receiver can function simultaneously and have dedicated clock control.
58 * * The transmitter and receiver have dedicated MMIO registers and a dedicated FIFO.
59 * * The transmitter and receiver have a dedicated FIFO interrupt and FIFO trigger.
60 * * The transmitter trigger is activated when a programmable number of PCM data slots is available in the TX FIFO.
61 * * The receiver trigger is activated when a programmable number of PCM data words is received into the RX FIFO.
62 *
63 *
64 * To set up TDM, provide the configuration parameters in the
65 * \ref cy_stc_tdm_config_t structure.
66 *
67 * For example, for Tx configuration, set txEnabled to true, configure
68 * txDmaTrigger (depending on whether DMA is going to be used or not), set
69 * extClk (if an external clock is used), provide clkDiv, masterMode,
70 * sckPolarity, fsyncPolarity, channelSize, wordSize,
71 * either i2sMode or TDM (based on Mode setting),
72 * fifoTriggerLevel (when the Trig interrupt will be used) and format
73 * A similar setup is for the Rx configuration.
74 *
75 * To initialize the TDM block, call the \ref Cy_AudioTDM_Init function, providing the
76 * filled \ref cy_stc_tdm_config_t structure.
77 * Before starting the transmission, enable the Tx \ref Cy_AudioTDM_EnableTx, then
78 * fill the first Tx data frame by calling \ref Cy_AudioTDM_WriteTxData. Then
79 * call the \ref Cy_AudioTDM_ActivateTx.
80 * For the reception the sequence is the same except for filling the first data
81 * frame.
82 *
83 * For example:
84 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_Init
85 *
86 * If you use a DMA, the DMA channel should be previously configured. The TDM interrupts
87 * (if applicable) can be enabled by calling \ref Cy_AudioTDM_SetTxInterruptMask.
88 *
89 * For example, if the trigger interrupt is used during operation, the ISR
90 * should call the \ref Cy_AudioTDM_WriteTxData as many times as required for your
91 * FIFO payload, but not more than the FIFO size. Then call \ref Cy_AudioTDM_ClearTxInterrupt
92 * with appropriate parameters.
93 *
94 * If a DMA is used and the DMA channel is properly configured - no CPU activity
95 * (or any application code) is needed for I2S/TDM operation.
96 *
97 * The I2S frame appears as:
98 * \image html i2s_frame.png
99 * This is an example for the channel length = 32. A similar case exists for the rest
100 * channel length configuration, with one limitation: the word length should be less than or equal
101 * to the channel length. See the datasheet of your device for more details.
102 *
103 * \section group_tdm_MISRA MISRA-C Compliance
104 * The TDM driver has the following specific deviations:
105 *
106 * <table class="doxtable">
107 *   <tr>
108 *     <th>MISRA Rule</th>
109 *     <th>Rule Class (Required/Advisory)</th>
110 *     <th>Rule Description</th>
111 *     <th>Description of Deviation(s)</th>
112 *   </tr>
113 *   <tr>
114 *     <td>10.3</td>
115 *     <td>R</td>
116 *     <td>A composite expression of the "essentially unsigned" type is being
117 *         cast to a different type category.</td>
118 *     <td>The value got from the bitfield physically cannot exceed the enumeration
119 *         that describes this bitfield. So, the code is safe by design.</td>
120 *   </tr>
121 *   <tr>
122 *     <td>11.4</td>
123 *     <td>A</td>
124 *     <td>A cast should not be performed between a pointer to object type and
125 *         a different pointer to object type.</td>
126 *   </tr>
127 *   <tr>
128 *     <td>20.3</td>
129 *     <td>R</td>
130 *     <td>The validity of values passed to library functions shall be checked.</td>
131 *     <td>This violation is not caused by code changes, i.e. is not a regression.</td>
132 *   </tr>
133 * </table>
134 *
135 * \section group_tdm_changelog Changelog
136 *
137 * <table class="doxtable">
138 *   <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
139 *   <tr>
140 *     <td>1.0</td>
141 *     <td>Initial version</td>
142 *     <td></td>
143 *   </tr>
144 * </table>
145 *
146 
147 * \defgroup group_tdm_i2s_macros_interrupt_masks Interrupt Masks
148 * \defgroup group_tdm_data_structures Data Structures
149 * \defgroup group_tdm_enums Enumerated Types
150 * \defgroup group_tdm_macros Macros
151 * \defgroup group_tdm_functions Functions
152 
153 */
154 
155 #if !defined (CY_TDM_H)
156 #define CY_TDM_H
157 
158 #include "cy_device.h"
159 
160 #if defined (CY_IP_MXTDM)
161 
162 #include "cy_syslib.h"
163 #include <stdint.h>
164 #include <stdbool.h>
165 #include <stddef.h>
166 
167 #if defined(__cplusplus)
168 extern "C" {
169 #endif
170 
171 CY_MISRA_DEVIATE_BLOCK_START('MISRA C-2012 Rule 14.3', 14, \
172 'Checked manually, passed true or false in _BOOL2FLD for appropriate functionality.')
173 
174 CY_MISRA_DEVIATE_BLOCK_START('MISRA C-2012 Rule 10.1', 14, \
175 'Checked manually, passed true or false in _BOOL2FLD for appropriate functionality.')
176 
177 /******************************************************************************
178  * Macro definitions                                                          *
179  ******************************************************************************/
180 
181 /**
182 * \addtogroup group_tdm_macros
183 * \{
184 */
185 
186 /** The driver major version */
187 #define CY_I2S_DRV_VERSION_MAJOR       1
188 
189 /** The driver minor version */
190 #define CY_I2S_DRV_VERSION_MINOR       0
191 
192 /** The TDM driver identifier */
193 #define CY_TDM_ID                      (CY_PDL_DRV_ID(0x50U))
194 
195 /** \} group_tdm_macros */
196 
197 /**
198 * \addtogroup group_tdm_i2s_macros_interrupt_masks
199 * \{
200 */
201 
202 /** Bit 0: Less entries in the TX FIFO than specified by Trigger Level. */
203 #define CY_TDM_INTR_TX_FIFO_TRIGGER         (TDM_TDM_STRUCT_TDM_TX_STRUCT_INTR_TX_FIFO_TRIGGER_Msk)
204 /** Bit 1: Attempt to write to a full TX FIFO. */
205 #define CY_TDM_INTR_TX_FIFO_OVERFLOW        (TDM_TDM_STRUCT_TDM_TX_STRUCT_INTR_TX_FIFO_OVERFLOW_Msk)
206 /** Bit 2: Attempt to read from an empty TX FIFO. */
207 #define CY_TDM_INTR_TX_FIFO_UNDERFLOW       (TDM_TDM_STRUCT_TDM_TX_STRUCT_INTR_TX_FIFO_UNDERFLOW_Msk)
208 /** Bit 8: Interface frequency is higher than PCM sample frequency. */
209 #define CY_TDM_INTR_TX_IF_UNDERFLOW         (TDM_TDM_STRUCT_TDM_TX_STRUCT_INTR_TX_IF_UNDERFLOW_Msk)
210 
211 /** Bit 0: Less entries in the RX FIFO than specified by Trigger Level. */
212 #define CY_TDM_INTR_RX_FIFO_TRIGGER         (TDM_TDM_STRUCT_TDM_RX_STRUCT_INTR_RX_FIFO_TRIGGER_Msk)
213 /** Bit 1: Attempt to write to a full RX FIFO. */
214 #define CY_TDM_INTR_RX_FIFO_OVERFLOW        (TDM_TDM_STRUCT_TDM_RX_STRUCT_INTR_RX_FIFO_OVERFLOW_Msk)
215 /** Bit 2: Attempt to read from an empty RX FIFO. */
216 #define CY_TDM_INTR_RX_FIFO_UNDERFLOW       (TDM_TDM_STRUCT_TDM_RX_STRUCT_INTR_RX_FIFO_UNDERFLOW_Msk)
217 /** Bit 8: Interface frequency is higher than PCM sample frequency. */
218 #define CY_TDM_INTR_RX_IF_UNDERFLOW         (TDM_TDM_STRUCT_TDM_RX_STRUCT_INTR_RX_IF_OVERFLOW_Msk)
219 
220 /** \} group_tdm_i2s_macros_interrupt_masks */
221 
222 
223 /**
224 * \addtogroup group_tdm_enums
225 * \{
226 */
227 
228 /** cy_en_tdm_ws_t */
229 typedef enum
230 {
231     CY_TDM_SIZE_8           = 0U, /**< PCM word size:8bit.  */
232     CY_TDM_SIZE_10          = 1U, /**< PCM word size:10bit. */
233     CY_TDM_SIZE_12          = 2U, /**< PCM word size:12bit. */
234     CY_TDM_SIZE_14          = 3U, /**< PCM word size:14bit. */
235     CY_TDM_SIZE_16          = 4U, /**< PCM word size:16bit. */
236     CY_TDM_SIZE_18          = 5U, /**< PCM word size:18bit. */
237     CY_TDM_SIZE_20          = 6U, /**< PCM word size:20bit. */
238     CY_TDM_SIZE_24          = 7U, /**< PCM word size:24bit. */
239     CY_TDM_SIZE_32          = 8U  /**< PCM word size:32bit. */
240 } cy_en_tdm_ws_t;
241 
242 /** cy_en_tdm_format_t */
243 typedef enum
244 {
245     CY_TDM_LEFT_DELAYED     = 0, /**< Format is left aligned and delayed. */
246     CY_TDM_LEFT             = 1, /**< Format is left aligned. */
247     CY_TDM_RIGHT_DELAYED    = 2, /**< Format is right aligned and delayed. */
248     CY_TDM_RIGHT            = 3  /**< Format is right aligned. */
249 } cy_en_tdm_format_t;
250 
251 /** cy_en_tdm_device_cfg_t */
252 typedef enum
253 {
254     CY_TDM_DEVICE_SLAVE     = 0U, /**< Device is configured as slave. */
255     CY_TDM_DEVICE_MASTER    = 1U  /**< Device is configured as master. */
256 } cy_en_tdm_device_cfg_t;
257 
258 /** cy_en_tdm_word_extend_cfg_t */
259 typedef enum
260 {
261     CY_ZERO_EXTEND      = 0U,    /**< Zero extended. */
262     CY_SIGN_EXTEND      = 1U    /**< sign extended. */
263 } cy_en_tdm_word_extend_cfg_t;
264 
265 /** cy_en_tdm_clock_sel_t */
266 typedef enum
267 {
268     CY_TDM_SEL_SRSS_CLK0    = 0U, /**< Interface clock is selected as clk_if_srss[0]. */
269     CY_TDM_SEL_SRSS_CLK1    = 1U, /**< Interface clock is selected as clk_if_srss[1]. */
270     CY_TDM_SEL_SRSS_CLK2    = 2U, /**< Interface clock is selected as clk_if_srss[2]. */
271     CY_TDM_SEL_SRSS_CLK3    = 3U, /**< Interface clock is selected as clk_if_srss[3]. */
272     CY_TDM_SEL_MCLK_IN      = 4U  /**< Interface clock is selected as tdm_tx/rx_mclk_in. */
273 } cy_en_tdm_clock_sel_t;
274 
275 /** cy_en_tdm_sckpolarity_t */
276 typedef enum
277 {
278     CY_TDM_CLK              = 0U, /**< TDM Clock is used as is. */
279     CY_TDM_CLK_INVERTED     = 1U  /**< TDM Clock is inverted. */
280 } cy_en_tdm_sckpolarity_t;
281 
282 /** cy_en_tdm_fsyncpolarity_t*/
283 typedef enum
284 {
285     CY_TDM_SIGN             = 0U, /**< TDM Sign is used as is. */
286     CY_TDM_SIGN_INVERTED    = 1U  /**< TDM Sign is inverted. */
287 } cy_en_tdm_fsyncpolarity_t;
288 
289 /** cy_en_tdm_fsyncformat_t */
290 typedef enum
291 {
292     CY_TDM_BIT_PERIOD       = 0U, /**< TDM Channel Synchronization is duration of a bit period. */
293     CY_TDM_CH_PERIOD        = 1U  /**< TDM Channel Synchronization is duration of a channel period. */
294 } cy_en_tdm_fsyncformat_t;
295 
296 /**
297 * TDM status definitions.
298 */
299 typedef enum
300 {
301     CY_TDM_SUCCESS          = 0x00UL,                                     /**< Successful. */
302     CY_TDM_BAD_PARAM        = CY_TDM_ID | CY_PDL_STATUS_ERROR | 0x01UL  /**< One or more invalid parameters. */
303 } cy_en_tdm_status_t;
304 
305 /** cy_en_tdm_source_status_t */
306 typedef enum
307 {
308     CY_TDM_OK                = 0x00UL, /**< Successful. */
309     CY_TDM_BAD               = 0x01UL  /**< Not Good    */
310 } cy_en_tdm_source_status_t;
311 
312 /** \} group_tdm_enums */
313 
314 /**
315 * \addtogroup group_tdm_data_structures
316 * \{
317 */
318 /** TDM Initialization configuration. */
319 typedef struct
320 {
321     bool                        enable;               /**<  Enables/Disables TDM TX */
322     cy_en_tdm_device_cfg_t      masterMode;           /**<  Master mode/Slave mode configuration. \ref cy_en_tdm_device_cfg_t */
323     cy_en_tdm_ws_t              wordSize;             /**<  TX word length. Channel size must be greater or equal to the word size.*/
324     cy_en_tdm_format_t          format;               /**<  TX data format, \ref cy_en_tdm_format_t. */
325     uint16_t                    clkDiv;               /**<  Should be set to an even value ({2, 4, 6, ..., 256}), to ensure a 50/50% duty cycle clock. Only for Master Mode */
326     cy_en_tdm_clock_sel_t       clkSel;               /**<  Interface clock "clk_if" selection, \ref cy_en_tdm_clock_sel_t. */
327     cy_en_tdm_sckpolarity_t     sckPolarity;          /**<  TX clock polarity, 0: as is and 1: inverted \ref cy_en_tdm_sckpolarity_t */
328     cy_en_tdm_fsyncpolarity_t   fsyncPolarity;        /**<  Synchronization polarity:0:as is 1:inverted. \ref cy_en_tdm_fsyncpolarity_t*/
329     cy_en_tdm_fsyncformat_t     fsyncFormat;          /**<  Channel synchronization pulse format \ref cy_en_tdm_fsyncformat_t */
330     uint8_t                     channelNum;           /**<  Number of channels in the frame:
331                                                             1 to 32 channels supported. In I2S mode number of channels should be 2. */
332     uint8_t                     channelSize;          /**<  Channel Size. Channel size must be greater or equal to the word size. */
333     uint8_t                     fifoTriggerLevel;     /**<  Trigger level. When the TX FIFO has less entries than the number of this field, a transmitter trigger event is generated. */
334     uint32_t                    chEn;                 /**<  Channels enabled: channel i is controlled by bit chEn[i]. For example : In I2S mode for 2 channels the chEn  will be 0x3 */
335     uint32_t                    signalInput;          /**<  Controls routing to the TX slave signaling  inputs (FSYNC/SCK):
336                                                               '0': TX slave signaling independent from RX signaling :
337                                                               '1': TX slave signaling inputs driven by RX Slave:
338                                                               '2': TX slave signaling inputs driven by RX Master: */
339     bool                        i2sMode;              /**<  IF set to 1 the IP is configured for I2S mode else for TDM mode    */
340 }cy_stc_tdm_config_tx_t;
341 
342 /** cy_stc_tdm_config_rx_t */
343 typedef struct
344 {
345     bool                        enable;               /**<  Enables/Disables TDM RX */
346     cy_en_tdm_device_cfg_t      masterMode;           /**<  Master mode/Slave mode configuration. \ref cy_en_tdm_device_cfg_t */
347     cy_en_tdm_ws_t              wordSize;             /**<  RX word length. Channel size must be greater or equal to the word size.*/
348     cy_en_tdm_word_extend_cfg_t signExtend;           /**<  Word extension \ref cy_en_tdm_word_extend_cfg_t */
349     cy_en_tdm_format_t          format;               /**<  RX data format, \ref cy_en_tdm_format_t. */
350     uint16_t                    clkDiv;               /**<  Should be set to an even value ({2, 4, 6, ..., 256}), to ensure a 50/50% duty cycle clock. Only for Master Mode */
351     cy_en_tdm_clock_sel_t       clkSel;               /**<  Interface clock "clk_if" selection, \ref cy_en_tdm_clock_sel_t. */
352     cy_en_tdm_sckpolarity_t     sckPolarity;          /**<  RX clock polarity, 0: as is and 1: inverted \ref cy_en_tdm_sckpolarity_t */
353     cy_en_tdm_fsyncpolarity_t   fsyncPolarity;        /**<  Channel synchronization polarity:'false':used "as is". 'true': inverted. */
354     bool                        lateSample;           /**<  Interface late sample delay.
355                                                           *   Slave configuration: "false": Sample PCM bit value on rising edge or falling edge of receiver "rx_sck_in
356                                                           *   "true": Sample PCM bit value on falling edge or rising edge of receiver "rx_sck_in" (half a cycle delay).
357                                                           *   Master configuration: "false": Sample PCM bit value on rising edge or falling edge of receiver "rx_sck_out".
358                                                           *   "true": Sample PCM bit value on falling edge or rising edge of receiver "rx_sck_out" (half a cycle delay). */
359                                                         /**<  RISING = 0  FALLING = 1 */
360     cy_en_tdm_fsyncformat_t     fsyncFormat;          /**<  Channel synchronization pulse format \ref cy_en_tdm_fsyncformat_t */
361     uint8_t                     channelNum;           /**<  Number of channels in the frame:
362                                                             1 to 32 channels supported. In I2S mode number of channels should be 2. */
363     uint8_t                     channelSize;          /**<  Channel Size. Channel size must be greater or equal to the word size. */
364     uint32_t                    chEn;                 /**<  Channels enabled: channel i is controlled by bit chEn[i]. For example : In I2S mode for 2 channels the chEn  will be 0x3 */
365     uint8_t                     fifoTriggerLevel;     /**<  Trigger level. When the TX FIFO has less entries than the number of this field, a transmitter trigger event is generated. */
366     uint32_t                    signalInput;          /**<  Controls routing to the RX slave signaling  inputs (FSYNC/SCK):
367                                                               '0': RX slave signaling independent from TX signaling :
368                                                               '1': RX slave signaling inputs driven by TX Slave:
369                                                               '2': RX slave signaling inputs driven by TX Master: */
370     bool                        i2sMode;              /**<  IF set to 1 the IP is configured for I2S mode else for TDM mode    */
371 } cy_stc_tdm_config_rx_t;
372 
373 /** cy_stc_tdm_config_t */
374 typedef struct
375 {
376     cy_stc_tdm_config_tx_t* tx_config;                    /**< TDM Initialization configuration for TX. */
377     cy_stc_tdm_config_rx_t* rx_config;                    /**< TDM Initialization configuration for RX. */
378 }cy_stc_tdm_config_t;
379 
380 /** \} group_tdm_data_structures */
381 
382 /**
383 * \addtogroup group_tdm_macros
384 * \{
385 */
386 /** \cond INTERNAL */
387 /*******************************************************************************/
388 /*                               Local definitions                             */
389 /********************************************************************************/
390 
391 #define CY_TDM_INTR_TX_MASK            (CY_TDM_INTR_TX_FIFO_TRIGGER     |\
392                                         CY_TDM_INTR_TX_FIFO_OVERFLOW    |\
393                                         CY_TDM_INTR_TX_FIFO_UNDERFLOW   |\
394                                         CY_TDM_INTR_TX_IF_UNDERFLOW)
395 
396 
397 #define CY_TDM_INTR_RX_MASK            (CY_TDM_INTR_RX_FIFO_TRIGGER     |\
398                                         CY_TDM_INTR_RX_FIFO_OVERFLOW    |\
399                                         CY_TDM_INTR_RX_FIFO_UNDERFLOW   |\
400                                         CY_TDM_INTR_RX_IF_UNDERFLOW)
401 
402 
403 /* Non-zero default values for TX_CTL register */
404 #define CY_TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_CTL_MS_DEFAULT               (0x1U)  /**<  Default mode is selected as master */
405 
406 #define CY_TDM_TX_CTL_DEFAULT                                           (_VAL2FLD(TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_CTL_MS, CY_TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_CTL_MS_DEFAULT))
407 
408 /* Non-zero default values for TX_IF_CTL register */
409 #define CY_TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_IF_CTL_CLOCK_DIV_DEFAULT     (0x7U)  /**< Default clock is clk_if/(CLOCK_DIV+1) */
410 #define CY_TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_IF_CTL_CLOCK_SEL_DEFAULT     (0x7U)  /**< Default clock is selected as clk_if_srss[0], later it will be off */
411 #define CY_TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_IF_CTL_CH_SIZE_DEFAULT       (0x1FU) /**< Default channel size is 32 bits */
412 
413 #define CY_TDM_TX_IF_CTL_DEFAULT               (_VAL2FLD(TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_IF_CTL_CLOCK_DIV, CY_TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_IF_CTL_CLOCK_DIV_DEFAULT) | \
414                                                 _VAL2FLD(TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_IF_CTL_CLOCK_SEL, CY_TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_IF_CTL_CLOCK_SEL_DEFAULT) | \
415                                                 _VAL2FLD(TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_IF_CTL_CH_SIZE, CY_TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_IF_CTL_CH_SIZE_DEFAULT))
416 
417 /* Non-zero default values for RX_CTL register */
418 #define CY_TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_CTL_WORD_SIGN_EXTEND_DEFAULT (0x1U)  /**< Default RX data word with sign extension */
419 
420 #define CY_TDM_RX_CTL_DEFAULT                   (_VAL2FLD(TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_CTL_WORD_SIGN_EXTEND, CY_TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_CTL_WORD_SIGN_EXTEND_DEFAULT))
421 
422 
423 /* Non-zero default values for RX_IF_CTL register */
424 #define CY_TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_IF_CTL_CLOCK_DIV_DEFAULT     (0x7U)  /**< Default clock is clk_if/(CLOCK_DIV+1) */
425 #define CY_TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_IF_CTL_CLOCK_SEL_DEFAULT     (0x7U)  /**< Default clock is selected as clk_if_srss[0], later it will be off */
426 #define CY_TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_IF_CTL_CH_SIZE_DEFAULT       (0x1FU) /**< Default channel size is 32 bits */
427 
428 #define CY_TDM_RX_IF_CTL_DEFAULT               (_VAL2FLD(TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_IF_CTL_CLOCK_DIV, CY_TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_IF_CTL_CLOCK_DIV_DEFAULT) | \
429                                                 _VAL2FLD(TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_IF_CTL_CLOCK_SEL, CY_TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_IF_CTL_CLOCK_SEL_DEFAULT) | \
430                                                 _VAL2FLD(TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_IF_CTL_CH_SIZE, CY_TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_IF_CTL_CH_SIZE_DEFAULT))
431 
432 /** \endcond */
433 
434 /** TDM Macro */
435 #define CY_TDM_IS_CLK_DIV_VALID(clkDiv)      (clkDiv <= 255U)
436 /** TDM Macro */
437 #define CY_TDM_IS_CHANNELS_VALID(channels)   (((channels) > 0UL) && ((channels) <= 31UL))
438 /** TDM Macro */
439 #define CY_TDM_IS_CHANNEL_SIZE_VALID(channel_size)   (((channel_size) > 2UL) && ((channel_size) <= 31UL))
440 /** TDM Macro */
441 #define CY_I2S_TDM_INTR_TX_MASK_VALID(interrupt) (0UL == ((interrupt) & ((uint32_t) ~CY_TDM_INTR_TX_MASK)))
442 /** TDM Macro */
443 #define CY_I2S_TDM_INTR_RX_MASK_VALID(interrupt) (0UL == ((interrupt) & ((uint32_t) ~CY_TDM_INTR_RX_MASK)))
444 /** TDM Macro */
445 #define CY_I2S_TDM_IS_INPUT_SIGNAL_MODE_VALID(signalInput)   (signalInput <= 2UL)
446 
447 /** \} group_tdm_macros */
448 
449 
450 /**
451 * \addtogroup group_tdm_functions
452 * \{
453 */
454 /*******************************************************************************/
455 /*                      Global initialization functions                        */
456 /*******************************************************************************/
457 
458 cy_en_tdm_status_t Cy_AudioTDM_Init( TDM_STRUCT_Type * base, cy_stc_tdm_config_t const * config);
459 void Cy_AudioTDM_DeInit( TDM_STRUCT_Type * base);
460 
461 
462 /*****************************************************************************/
463 /*                      Audio TDM Control and Status                         */
464 /*****************************************************************************/
465 
466 __STATIC_INLINE void        Cy_AudioTDM_EnableTx( TDM_TX_STRUCT_Type * base);
467 __STATIC_INLINE void        Cy_AudioTDM_DisableTx( TDM_TX_STRUCT_Type * base);
468 __STATIC_INLINE void        Cy_AudioTDM_EnableRx( TDM_RX_STRUCT_Type * base);
469 __STATIC_INLINE void        Cy_AudioTDM_DisableRx( TDM_RX_STRUCT_Type * base);
470 
471 __STATIC_INLINE void        Cy_AudioTDM_WriteTxData( TDM_TX_STRUCT_Type * base, uint32_t data);
472 __STATIC_INLINE void        Cy_AudioTDM_FreezeTxFifo( TDM_TX_STRUCT_Type * base);
473 __STATIC_INLINE void        Cy_AudioTDM_UnfreezeTxFifo( TDM_TX_STRUCT_Type * base);
474 __STATIC_INLINE void        Cy_AudioTDM_MuteTxFifo( TDM_TX_STRUCT_Type * base);
475 __STATIC_INLINE void        Cy_AudioTDM_ActivateTx( TDM_TX_STRUCT_Type * base);
476 __STATIC_INLINE void        Cy_AudioTDM_DeActivateTx( TDM_TX_STRUCT_Type * base);
477 __STATIC_INLINE void        Cy_AudioTDM_ReplayTxFifo( TDM_TX_STRUCT_Type * base);
478 __STATIC_INLINE uint8_t     Cy_AudioTDM_GetNumInTxFifo( TDM_TX_STRUCT_Type * base);
479 __STATIC_INLINE uint8_t     Cy_AudioTDM_GetTxReadPointer( TDM_TX_STRUCT_Type * base);
480 __STATIC_INLINE uint8_t     Cy_AudioTDM_GetTxWritePointer( TDM_TX_STRUCT_Type * base);
481 __STATIC_INLINE void        Cy_AudioTDM_EnableTxTestMode( TDM_TX_STRUCT_Type * base);
482 __STATIC_INLINE void        Cy_AudioTDM_DisableTxTestMode( TDM_TX_STRUCT_Type * base);
483 
484 __STATIC_INLINE uint32_t    Cy_AudioTDM_ReadRxData( TDM_RX_STRUCT_Type * base);
485 __STATIC_INLINE void        Cy_AudioTDM_FreezeRxFifo( TDM_RX_STRUCT_Type * base);
486 __STATIC_INLINE void        Cy_AudioTDM_UnfreezeRxFifo( TDM_RX_STRUCT_Type * base);
487 __STATIC_INLINE void        Cy_AudioTDM_ActivateRx( TDM_RX_STRUCT_Type * base);
488 __STATIC_INLINE void        Cy_AudioTDM_DeActivateRx( TDM_RX_STRUCT_Type * base);
489 __STATIC_INLINE uint32_t    Cy_AudioTDM_ReadSilentRXFifo( TDM_RX_STRUCT_Type * base);
490 __STATIC_INLINE uint8_t     Cy_AudioTDM_GetNumInRxFifo( TDM_RX_STRUCT_Type * base);
491 __STATIC_INLINE uint8_t     Cy_AudioTDM_GetRxReadPointer( TDM_RX_STRUCT_Type * base);
492 __STATIC_INLINE uint8_t     Cy_AudioTDM_GetRxWritePointer( TDM_RX_STRUCT_Type * base);
493 __STATIC_INLINE void        Cy_AudioTDM_EnableRxTestMode( TDM_RX_STRUCT_Type * base);
494 __STATIC_INLINE void        Cy_AudioTDM_DisableRxTestMode( TDM_RX_STRUCT_Type * base);
495 
496 
497 __STATIC_INLINE void        Cy_AudioTDM_ClearTxInterrupt( TDM_TX_STRUCT_Type * base, uint32_t interrupt);
498 __STATIC_INLINE void        Cy_AudioTDM_SetTxInterrupt( TDM_TX_STRUCT_Type * base, uint32_t interrupt);
499 __STATIC_INLINE uint32_t    Cy_AudioTDM_GetTxInterruptMask( TDM_TX_STRUCT_Type * base);
500 __STATIC_INLINE void        Cy_AudioTDM_SetTxInterruptMask( TDM_TX_STRUCT_Type * base, uint32_t interrupt);
501 __STATIC_INLINE uint32_t    Cy_AudioTDM_GetTxInterruptStatusMasked( TDM_TX_STRUCT_Type * base);
502 __STATIC_INLINE void        Cy_AudioTDM_SetTxTriggerInterruptMask( TDM_TX_STRUCT_Type * base);
503 __STATIC_INLINE void        Cy_AudioTDM_ClearTxTriggerInterruptMask( TDM_TX_STRUCT_Type * base);
504 
505 __STATIC_INLINE void        Cy_AudioTDM_ClearRxInterrupt( TDM_RX_STRUCT_Type * base, uint32_t interrupt);
506 __STATIC_INLINE void        Cy_AudioTDM_SetRxInterrupt( TDM_RX_STRUCT_Type * base, uint32_t interrupt);
507 __STATIC_INLINE uint32_t    Cy_AudioTDM_GetRxInterruptMask( TDM_RX_STRUCT_Type * base);
508 __STATIC_INLINE void        Cy_AudioTDM_SetRxInterruptMask( TDM_RX_STRUCT_Type * base, uint32_t interrupt);
509 __STATIC_INLINE uint32_t    Cy_AudioTDM_GetRxInterruptStatusMasked( TDM_RX_STRUCT_Type * base);
510 __STATIC_INLINE void        Cy_AudioTDM_SetRxTriggerInterruptMask( TDM_RX_STRUCT_Type * base);
511 __STATIC_INLINE void        Cy_AudioTDM_ClearRxTriggerInterruptMask( TDM_RX_STRUCT_Type * base);
512 
513 
514 /** \cond INTERNAL */
515 /*******************************************************************************
516 * These are legacy API for I2S.
517 * for backward compatibility.
518 * Do not use them in new designs.
519 *******************************************************************************/
520 
521 #define Cy_AudioI2S_Init                                 Cy_AudioTDM_Init
522 #define Cy_AudioI2S_DeInit                                Cy_AudioTDM_DeInit
523 
524 #define Cy_AudioI2S_EnableTx                              Cy_AudioTDM_EnableTx
525 #define Cy_AudioI2S_DisableTx                              Cy_AudioTDM_DisableTx
526 #define Cy_AudioI2S_EnableRx                               Cy_AudioTDM_EnableRx
527 #define Cy_AudioI2S_DisableRx                           Cy_AudioTDM_DisableRx
528 
529 #define Cy_AudioI2S_WriteTxData                           Cy_AudioTDM_WriteTxData
530 #define Cy_AudioI2S_FreezeTxFifo                           Cy_AudioTDM_FreezeTxFifo
531 #define Cy_AudioI2S_UnfreezeTxFifo                         Cy_AudioTDM_UnfreezeTxFifo
532 #define Cy_AudioI2S_MuteTxFifo                          Cy_AudioTDM_MuteTxFifo
533 #define Cy_AudioI2S_ActivateTx                             Cy_AudioTDM_ActivateTx
534 #define Cy_AudioI2S_DeActivateTx                           Cy_AudioTDM_DeActivateTx
535 #define Cy_AudioI2S_ReplayTxFifo                          Cy_AudioTDM_ReplayTxFifo
536 #define Cy_AudioI2S_GetNumInTxFifo                         Cy_AudioTDM_GetNumInTxFifo
537 #define Cy_AudioI2S_GetTxReadPointer                      Cy_AudioTDM_GetTxReadPointer
538 #define Cy_AudioI2S_GetTxWritePointer                      Cy_AudioTDM_GetTxWritePointer
539 #define Cy_AudioI2S_EnableTxTestMode                       Cy_AudioTDM_EnableTxTestMode
540 #define Cy_AudioI2S_DisableTxTestMode                   Cy_AudioTDM_DisableTxTestMode
541 
542 #define Cy_AudioI2S_ReadRxData                          Cy_AudioTDM_ReadRxData
543 #define Cy_AudioI2S_FreezeRxFifo                          Cy_AudioTDM_FreezeRxFifo
544 #define Cy_AudioI2S_UnfreezeRxFifo                         Cy_AudioTDM_UnfreezeRxFifo
545 #define Cy_AudioI2S_ActivateRx                          Cy_AudioTDM_ActivateRx
546 #define Cy_AudioI2S_DeActivateRx                          Cy_AudioTDM_DeActivateRx
547 #define Cy_AudioI2S_ReadSilentRXFifo                      Cy_AudioTDM_ReadSilentRXFifo
548 #define Cy_AudioI2S_GetNumInRxFifo                         Cy_AudioTDM_GetNumInRxFifo
549 #define Cy_AudioI2S_GetRxReadPointer                    Cy_AudioTDM_GetRxReadPointer
550 #define Cy_AudioI2S_GetRxWritePointer                      Cy_AudioTDM_GetRxWritePointer
551 #define Cy_AudioI2S_EnableRxTestMode                      Cy_AudioTDM_EnableRxTestMode
552 #define Cy_AudioI2S_DisableRxTestMode                      Cy_AudioTDM_DisableRxTestMode
553 
554 #define Cy_AudioI2S_ClearTxInterrupt                      Cy_AudioTDM_ClearTxInterrupt
555 #define Cy_AudioI2S_SetTxInterrupt                         Cy_AudioTDM_SetTxInterrupt
556 #define Cy_AudioI2S_GetTxInterruptMask                  Cy_AudioTDM_GetTxInterruptMask
557 #define Cy_AudioI2S_SetTxInterruptMask                  Cy_AudioTDM_SetTxInterruptMask
558 #define Cy_AudioI2S_GetTxInterruptStatusMasked          Cy_AudioTDM_GetTxInterruptStatusMasked
559 #define Cy_AudioI2S_SetTxTriggerInterruptMask           Cy_AudioTDM_SetTxTriggerInterruptMask
560 #define Cy_AudioI2S_ClearTxTriggerInterruptMask         Cy_AudioTDM_ClearTxTriggerInterruptMask
561 
562 #define Cy_AudioI2S_ClearRxInterrupt                      Cy_AudioTDM_ClearRxInterrupt
563 #define Cy_AudioI2S_SetRxInterrupt                         Cy_AudioTDM_SetRxInterrupt
564 #define Cy_AudioI2S_GetRxInterruptMask                  Cy_AudioTDM_GetRxInterruptMask
565 #define Cy_AudioI2S_SetRxInterruptMask                  Cy_AudioTDM_SetRxInterruptMask
566 #define Cy_AudioI2S_GetRxInterruptStatusMasked          Cy_AudioTDM_GetRxInterruptStatusMasked
567 #define Cy_AudioI2S_SetRxTriggerInterruptMask           Cy_AudioTDM_SetRxTriggerInterruptMask
568 #define Cy_AudioI2S_ClearRxTriggerInterruptMask         Cy_AudioTDM_ClearRxTriggerInterruptMask
569 
570 /** \endcond */
571 
572 /** \} group_tdm_functions */
573 
574 /**
575 * \addtogroup group_tdm_functions
576 * \{
577 */
578 
579 /*******************************************************************************
580 * Function Name: Cy_AudioTDM_EnableTx
581 ****************************************************************************//**
582 *
583 * Starts an I2S/TDM transmission. Interrupt enabling (by the
584 * \ref Cy_AudioTDM_SetTxInterrupt) is required after this function call, in case
585 * if any I2S/TDM interrupts are used in the application.
586 *
587 * \pre Cy_AudioTDM_Init() must be called before.
588 *
589 * \param base The pointer to the I2S/TDM instance address.
590 *
591 * \funcusage
592 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_EnableTx
593 *******************************************************************************/
594 
Cy_AudioTDM_EnableTx(TDM_TX_STRUCT_Type * base)595 __STATIC_INLINE void Cy_AudioTDM_EnableTx( TDM_TX_STRUCT_Type * base)
596 {
597     TDM_STRUCT_TX_CTL(base) |= TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_CTL_ENABLED_Msk;
598 }
599 
600 /*******************************************************************************
601 * Function Name: Cy_AudioTDM_DisableTx
602 ****************************************************************************//**
603 *
604 * Stops an I2S/TDM transmission.
605 *
606 * \pre TX interrupt disabling (by the \ref Cy_AudioTDM_SetTxInterrupt) is required
607 * prior to this function call, in case any TX I2S/TDM interrupts are used.
608 *
609 * \param base The pointer to the I2S/TDM instance address.
610 *
611 * \funcusage
612 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_DisableTx
613 *******************************************************************************/
Cy_AudioTDM_DisableTx(TDM_TX_STRUCT_Type * base)614 __STATIC_INLINE void Cy_AudioTDM_DisableTx( TDM_TX_STRUCT_Type * base)
615 {
616     TDM_STRUCT_TX_CTL(base) &= (uint32_t) ~TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_CTL_ENABLED_Msk;
617 }
618 
619 /*******************************************************************************
620 * Function Name: Cy_AudioTDM_EnableRx
621 ****************************************************************************//**
622 *
623 * Starts an I2S/TDM transmission. Interrupt enabling (by the
624 * \ref Cy_AudioTDM_SetRxInterrupt) is required after this function call, in case
625 * if any I2S/TDM interrupts are used in the application.
626 *
627 * \pre Cy_AudioTDM_Init() must be called before.
628 *
629 * \param base The pointer to the I2S/TDM instance address.
630 *
631 * \funcusage
632 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_EnableRx
633 *******************************************************************************/
Cy_AudioTDM_EnableRx(TDM_RX_STRUCT_Type * base)634 __STATIC_INLINE void Cy_AudioTDM_EnableRx( TDM_RX_STRUCT_Type * base)
635 {
636     TDM_STRUCT_RX_CTL(base) |= TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_CTL_ENABLED_Msk;
637 }
638 
639 /*******************************************************************************
640 * Function Name: Cy_AudioTDM_DisableRx
641 ****************************************************************************//**
642 *
643 * Stops an I2S/TDM transmission.
644 *
645 * \pre TX interrupt disabling (by the \ref Cy_AudioTDM_SetRxInterrupt) is required
646 * prior to this function call, in case any TX I2S/TDM interrupts are used.
647 *
648 * \param base The pointer to the I2S/TDM instance address.
649 *
650 * \funcusage
651 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_DisableRx
652 *******************************************************************************/
653 
Cy_AudioTDM_DisableRx(TDM_RX_STRUCT_Type * base)654 __STATIC_INLINE void Cy_AudioTDM_DisableRx( TDM_RX_STRUCT_Type * base)
655 {
656     TDM_STRUCT_RX_CTL(base) &= (uint32_t) ~TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_CTL_ENABLED_Msk;
657 }
658 
659 /*******************************************************************************
660 * Function Name: Cy_AudioTDM_WriteTxData
661 ****************************************************************************//**
662 *
663 * Writes data to the TX FIFO. Increases the TX FIFO level.
664 *
665 * \param base The pointer to the I2S/TDM instance address.
666 *
667 * \param data Data to be written to the TX FIFO.
668 *
669 * \funcusage
670 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_WriteTxData
671 *******************************************************************************/
672 
Cy_AudioTDM_WriteTxData(TDM_TX_STRUCT_Type * base,uint32_t data)673 __STATIC_INLINE void Cy_AudioTDM_WriteTxData( TDM_TX_STRUCT_Type * base, uint32_t data)
674 {
675     TDM_STRUCT_TX_FIFO_WR(base) = data;
676 }
677 
678 /*******************************************************************************
679 * Function Name: Cy_AudioTDM_FreezeTxFifo
680 ****************************************************************************//**
681 *
682 * Freezes the TX FIFO. This function is for debug purposes.
683 * HW uses a constant PCM data value of "0" or the previous channel PCM data is replayed.
684 * Freeze does not advance the FIFO read pointer (the FIFO data is not used).
685 *
686 * \param base The pointer to the I2S/TDM instance address.
687 *
688 * \funcusage
689 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_FreezeTxFifo
690 *******************************************************************************/
Cy_AudioTDM_FreezeTxFifo(TDM_TX_STRUCT_Type * base)691 __STATIC_INLINE void Cy_AudioTDM_FreezeTxFifo( TDM_TX_STRUCT_Type * base)
692 {
693     TDM_STRUCT_TX_FIFO_CTL(base) &= ~TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_FREEZE_Msk;
694     TDM_STRUCT_TX_FIFO_CTL(base) &= ~TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_REPLAY_Msk;
695     TDM_STRUCT_TX_FIFO_CTL(base) |= _BOOL2FLD(TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_FREEZE, 1U) |
696                            _BOOL2FLD(TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_REPLAY, 0U);
697 }
698 
699 /*******************************************************************************
700 * Function Name: Cy_AudioTDM_UnfreezeTxFifo
701 ****************************************************************************//**
702 *
703 * Unfreezes the TX FIFO. This function is for debug purposes.
704 * HW uses TX FIFO data and advances the FIFO read pointer.
705 *
706 * \param base The pointer to the I2S/TDM instance address.
707 *
708 * \funcusage
709 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_UnFreezeTxFifo
710 *******************************************************************************/
Cy_AudioTDM_UnfreezeTxFifo(TDM_TX_STRUCT_Type * base)711 __STATIC_INLINE void Cy_AudioTDM_UnfreezeTxFifo( TDM_TX_STRUCT_Type * base)
712 {
713     TDM_STRUCT_TX_FIFO_CTL(base) &= ~TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_FREEZE_Msk;
714     TDM_STRUCT_TX_FIFO_CTL(base) |= _BOOL2FLD(TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_FREEZE, 0U);
715 }
716 
717 /***************************************************************************/
718 /* Function Name: Cy_AudioTDM_MuteTxFifo                                   */
719 /***************************************************************************//**
720 *
721 * Mutes the TX FIFO.
722 * HW uses a constant PCM data value of "0". Mute does advance the FIFO read pointer.
723 *
724 * \param base The pointer to the I2S/TDM instance address.
725 *
726 * \funcusage
727 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_MuteTxFifo
728 *******************************************************************************/
Cy_AudioTDM_MuteTxFifo(TDM_TX_STRUCT_Type * base)729 __STATIC_INLINE void Cy_AudioTDM_MuteTxFifo( TDM_TX_STRUCT_Type * base)
730 {
731     TDM_STRUCT_TX_FIFO_CTL(base) &= ~TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_MUTE_Msk;
732     TDM_STRUCT_TX_FIFO_CTL(base) |= _BOOL2FLD(TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_MUTE, 1U);
733 }
734 
735 /***************************************************************************/
736 /* Function Name: Cy_AudioTDM_ActivateTx                                      */
737 /***************************************************************************//**
738 *
739 * Activate/start the TX FIFO.
740 * This will set the transmitter state to on.
741 *
742 * \param base The pointer to the I2S/TDM instance address.
743 *
744 * \funcusage
745 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_ActivateTx
746 *******************************************************************************/
Cy_AudioTDM_ActivateTx(TDM_TX_STRUCT_Type * base)747 __STATIC_INLINE void Cy_AudioTDM_ActivateTx( TDM_TX_STRUCT_Type * base)
748 {
749     TDM_STRUCT_TX_FIFO_CTL(base) &= ~TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_ACTIVE_Msk;
750     TDM_STRUCT_TX_FIFO_CTL(base) |= _BOOL2FLD(TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_ACTIVE, 1U);
751 }
752 
753 /***************************************************************************/
754 /* Function Name: Cy_AudioTDM_DeActivateTx                                       */
755 /***************************************************************************//**
756 *
757 * Stop the TX FIFO.
758 * This will set the transmitter state to off.
759 *
760 * \param base The pointer to the I2S/TDM instance address.
761 *
762 * \funcusage
763 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_DeActivateTx
764 *******************************************************************************/
Cy_AudioTDM_DeActivateTx(TDM_TX_STRUCT_Type * base)765 __STATIC_INLINE void Cy_AudioTDM_DeActivateTx( TDM_TX_STRUCT_Type * base)
766 {
767     TDM_STRUCT_TX_FIFO_CTL(base) &= ~TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_ACTIVE_Msk;
768     TDM_STRUCT_TX_FIFO_CTL(base) |= _BOOL2FLD(TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_ACTIVE, 0U);
769 }
770 /***************************************************************************/
771 /* Function Name: Cy_AudioTDM_ReplayTxFifo                           */
772 /***************************************************************************//**
773 *
774 * Replay functionality (used when FREEZE is '1' or in case of a FIFO underflow event).
775 * HW uses the previous PCM data value.
776 *
777 * \param base The pointer to the I2S/TDM instance address.
778 *
779 *******************************************************************************/
780 //data replay
Cy_AudioTDM_ReplayTxFifo(TDM_TX_STRUCT_Type * base)781 __STATIC_INLINE void Cy_AudioTDM_ReplayTxFifo( TDM_TX_STRUCT_Type * base)
782 {
783     TDM_STRUCT_TX_FIFO_CTL(base) &= ~TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_FREEZE_Msk;
784     TDM_STRUCT_TX_FIFO_CTL(base) &= ~TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_REPLAY_Msk;
785     TDM_STRUCT_TX_FIFO_CTL(base) |= _BOOL2FLD(TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_FREEZE, 1U) |
786                            _BOOL2FLD(TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_REPLAY, 1U);
787 }
788 /***************************************************************************/
789 /* Function Name: Cy_AudioTDM_GetNumInTxFifo                               */
790 /***************************************************************************//**
791 *
792 * Gets the number of used words in the TX FIFO.,
793 * Number of used/occupied entries in the TX FIFO. The field value is in the range [0, 128].
794 * When "0", the FIFO is empty. When "128", the FIFO is full.
795 *
796 * \param base The pointer to the I2S/TDM instance address.
797 *
798 * \return The current number of used words in the TX FIFO.
799 *
800 * \funcusage
801 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_GetNumInTxFifo
802 *******************************************************************************/
Cy_AudioTDM_GetNumInTxFifo(TDM_TX_STRUCT_Type * base)803 __STATIC_INLINE uint8_t Cy_AudioTDM_GetNumInTxFifo( TDM_TX_STRUCT_Type * base)
804 {
805     return ((uint8_t)(TDM_STRUCT_TX_FIFO_STATUS(base) & TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_STATUS_USED_Msk));
806 }
807 
808 /***************************************************************************/
809 /* Function Name: Cy_AudioTDM_GetTxReadPointer                             */
810 /***************************************************************************//**
811 *
812 * Get the TX FIFO Read Pointer.
813 * TX FIFO read pointer: FIFO location from which a data is read.
814 * This functionality is intended for debugging purposes.
815 *
816 * \param base The pointer to the I2S/TDM instance address.
817 *
818 * \funcusage
819 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_GetTxReadPointer
820 *******************************************************************************/
Cy_AudioTDM_GetTxReadPointer(TDM_TX_STRUCT_Type * base)821 __STATIC_INLINE uint8_t Cy_AudioTDM_GetTxReadPointer( TDM_TX_STRUCT_Type * base)
822 {
823     uint32_t reg_value;
824     reg_value = (TDM_STRUCT_TX_FIFO_STATUS(base) & TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_STATUS_RD_PTR_Msk);
825     return ((uint8_t)(reg_value >> TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_STATUS_RD_PTR_Pos));
826 }
827 
828 /***************************************************************************/
829 /* Function Name: Cy_AudioTDM_GetTxWritePointer                            */
830 /***************************************************************************//**
831 *
832 * Get the TX FIFO Write Pointer.
833 * TX FIFO write pointer: FIFO location at which a new data is written by the hardware.
834 * This functionality is intended for debugging purposes.
835 *
836 * \param base The pointer to the I2S/TDM instance address.
837 *
838 * \funcusage
839 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_GetTxWritePointer
840 *******************************************************************************/
Cy_AudioTDM_GetTxWritePointer(TDM_TX_STRUCT_Type * base)841 __STATIC_INLINE uint8_t Cy_AudioTDM_GetTxWritePointer( TDM_TX_STRUCT_Type * base)
842 {
843     uint32_t reg_value;
844     reg_value = (TDM_STRUCT_TX_FIFO_STATUS(base) & TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_STATUS_WR_PTR_Msk);
845     return ((uint8_t)(reg_value >> TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_STATUS_WR_PTR_Pos));
846 }
847 /***************************************************************************/
848 /* Function Name: Cy_AudioTDM_EnableTxTestMode                            */
849 /***************************************************************************//**
850 *
851 * Enables the test mode. Used for debugging purposes only.
852 * Tx and Rx test modes cannot be enabled simultaneously.
853 *
854 * \param base The pointer to the I2S/TDM instance address.
855 *
856 *******************************************************************************/
Cy_AudioTDM_EnableTxTestMode(TDM_TX_STRUCT_Type * base)857 __STATIC_INLINE void Cy_AudioTDM_EnableTxTestMode( TDM_TX_STRUCT_Type * base)
858 {
859     TDM_STRUCT_TX_TEST_CTL(base) |= TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_TEST_CTL_ENABLED_Msk;
860 }
861 
862 /***************************************************************************/
863 /* Function Name: Cy_AudioTDM_DisableTxTestMode                            */
864 /***************************************************************************//**
865 *
866 * Disables Test mode.
867 *
868 * \param base The pointer to the I2S/TDM instance address.
869 *
870 *******************************************************************************/
Cy_AudioTDM_DisableTxTestMode(TDM_TX_STRUCT_Type * base)871 __STATIC_INLINE void Cy_AudioTDM_DisableTxTestMode( TDM_TX_STRUCT_Type * base)
872 {
873     TDM_STRUCT_TX_TEST_CTL(base) &= (uint32_t) ~TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_TEST_CTL_ENABLED_Msk;
874 }
875 
876 /***************************************************************************/
877 /* Function Name: Cy_AudioTDM_ReadRxData                                   */
878 /***************************************************************************//**
879 *
880 * Read Rx data from the Rx FIFO.
881 * Data (PCM sample) read from the RX FIFO. Reading removes the data from the RX FIFO.
882 * Reading from an empty RX FIFO activates FIFO_UNDERFLOW interrupt.
883 *
884 * \param base The pointer to the I2S/TDM instance address.
885 *
886 * \funcusage
887 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_ReadRxData
888 *******************************************************************************/
Cy_AudioTDM_ReadRxData(TDM_RX_STRUCT_Type * base)889 __STATIC_INLINE uint32_t Cy_AudioTDM_ReadRxData( TDM_RX_STRUCT_Type * base)
890 {
891     return (TDM_STRUCT_RX_FIFO_RD(base));
892 }
893 
894 /***************************************************************************/
895 /* Function Name: Cy_AudioTDM_FreezeRxFifo                                 */
896 /***************************************************************************//**
897 *
898 * Freeze RX FIFO.
899 * HW writes from the RX FIFO have no effect: freeze will not advance the FIFO write pointer.
900 * This functionality is intended for debugging purposes.
901 *
902 * \param base The pointer to the I2S/TDM instance address.
903 *
904 * \funcusage
905 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_FreezeRxFifo
906 *******************************************************************************/
Cy_AudioTDM_FreezeRxFifo(TDM_RX_STRUCT_Type * base)907 __STATIC_INLINE void Cy_AudioTDM_FreezeRxFifo( TDM_RX_STRUCT_Type * base)
908 {
909     TDM_STRUCT_RX_FIFO_CTL(base) &= ~TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FIFO_CTL_FREEZE_Msk;
910     TDM_STRUCT_RX_FIFO_CTL(base) |= _BOOL2FLD(TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FIFO_CTL_FREEZE, 1U);
911 }
912 /***************************************************************************/
913 /* Function Name: Cy_AudioTDM_UnfreezeRxFifo                               */
914 /***************************************************************************//**
915 *
916 * UnFreeze Rx FIFO.
917 * HW writes to the RX FIFO and advances the FIFO write pointer.
918 *
919 * \param base The pointer to the I2S/TDM instance address.
920 *
921 * \funcusage
922 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_UnfreezeRxFifo
923 *******************************************************************************/
Cy_AudioTDM_UnfreezeRxFifo(TDM_RX_STRUCT_Type * base)924 __STATIC_INLINE void Cy_AudioTDM_UnfreezeRxFifo( TDM_RX_STRUCT_Type * base)
925 {
926     TDM_STRUCT_RX_FIFO_CTL(base) &= ~TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FIFO_CTL_FREEZE_Msk;
927     TDM_STRUCT_RX_FIFO_CTL(base) |= _BOOL2FLD(TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FIFO_CTL_FREEZE, 0U);
928 }
929 
930 /***************************************************************************/
931 /* Function Name: Cy_AudioTDM_ActivateRx                                      */
932 /***************************************************************************//**
933 *
934 * Start Rx FIFO.
935 * Sets Receiver state to on.
936 *
937 * \param base The pointer to the I2S/TDM instance address.
938 *
939 * \funcusage
940 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_ActivateRx
941 *******************************************************************************/
Cy_AudioTDM_ActivateRx(TDM_RX_STRUCT_Type * base)942 __STATIC_INLINE void Cy_AudioTDM_ActivateRx( TDM_RX_STRUCT_Type * base)
943 {
944     TDM_STRUCT_RX_FIFO_CTL(base) |= TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FIFO_CTL_ACTIVE_Msk;
945 }
946 
947 /***************************************************************************/
948 /* Function Name: Cy_AudioTDM_DeActivateRx                                       */
949 /***************************************************************************//**
950 *
951 * Stop Rx FIFO.
952 * Sets Receiver state to off.
953 *
954 * \param base The pointer to the I2S/TDM instance address.
955 *
956 * \funcusage
957 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_DeActivateRx
958 *******************************************************************************/
Cy_AudioTDM_DeActivateRx(TDM_RX_STRUCT_Type * base)959 __STATIC_INLINE void Cy_AudioTDM_DeActivateRx( TDM_RX_STRUCT_Type * base)
960 {
961     TDM_STRUCT_RX_FIFO_CTL(base) &= ~TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FIFO_CTL_ACTIVE_Msk;
962     TDM_STRUCT_RX_FIFO_CTL(base) |= _BOOL2FLD(TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FIFO_CTL_ACTIVE, 0U);
963 }
964 
965 /***************************************************************************/
966 /* Function Name: Cy_AudioTDM_ReadSilentRXFifo                             */
967 /***************************************************************************//**
968 *
969 * When the RX FIFO is empty, a read from this register returns "0".
970 *
971 * \param base The pointer to the I2S/TDM instance address.
972 *
973 * \funcusage
974 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_ReadSilentRXFifo
975 *******************************************************************************/
Cy_AudioTDM_ReadSilentRXFifo(TDM_RX_STRUCT_Type * base)976 __STATIC_INLINE uint32_t Cy_AudioTDM_ReadSilentRXFifo( TDM_RX_STRUCT_Type * base)
977 {
978     return (TDM_STRUCT_RX_FIFO_RD_SILENT(base));
979 }
980 /***************************************************************************/
981 /* Function Name: Cy_AudioTDM_GetNumInRxFifo                               */
982 /***************************************************************************//**
983 *
984 * Reads RX FIFO status.
985 * Number of used/occupied entries in the RX FIFO. The field value is in the range [0, 128].
986 * When "0", the FIFO is empty. When "128", the FIFO is full.
987 *
988 * \param base The pointer to the I2S/TDM instance address.
989 *
990 * \funcusage
991 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_GetNumInRxFifo
992 *******************************************************************************/
Cy_AudioTDM_GetNumInRxFifo(TDM_RX_STRUCT_Type * base)993 __STATIC_INLINE uint8_t Cy_AudioTDM_GetNumInRxFifo( TDM_RX_STRUCT_Type * base)
994 {
995     return ((uint8_t)(TDM_STRUCT_RX_FIFO_STATUS(base) & TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FIFO_STATUS_USED_Msk));
996 }
997 
998 /***************************************************************************/
999 /* Function Name: Cy_AudioTDM_GetRxReadPointer                            */
1000 /***************************************************************************//**
1001 *
1002 * Reads RX FIFO Read Pointer
1003 * RX FIFO read pointer: FIFO location from which a data is read.
1004 * This functionality is intended for debugging purposes.
1005 *
1006 * \param base The pointer to the I2S/TDM instance address.
1007 *
1008 * \return The current RX Read pointer value.
1009 *
1010 * \funcusage
1011 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_GetRxReadPointer
1012 *******************************************************************************/
Cy_AudioTDM_GetRxReadPointer(TDM_RX_STRUCT_Type * base)1013 __STATIC_INLINE uint8_t Cy_AudioTDM_GetRxReadPointer( TDM_RX_STRUCT_Type * base)
1014 {
1015     uint32_t reg_value;
1016     reg_value = (TDM_STRUCT_RX_FIFO_STATUS(base) & TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FIFO_STATUS_RD_PTR_Msk);
1017     return ((uint8_t)(reg_value >> TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FIFO_STATUS_RD_PTR_Pos));
1018 }
1019 
1020 /***************************************************************************/
1021 /* Function Name: Cy_AudioTDM_GetRxWritePointer                            */
1022 /***************************************************************************//**
1023 *
1024 * Reads RX FIFO Write Pointer
1025 * RX FIFO write pointer: FIFO location at which a new data is written by the hardware.
1026 * This functionality is intended for debugging purposes.
1027 *
1028 * \param base The pointer to the I2S/TDM instance address.
1029 *
1030 * \return The current RX Write pointer value.
1031 *
1032 * \funcusage
1033 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_GetRxWritePointer
1034 *******************************************************************************/
Cy_AudioTDM_GetRxWritePointer(TDM_RX_STRUCT_Type * base)1035 __STATIC_INLINE uint8_t Cy_AudioTDM_GetRxWritePointer( TDM_RX_STRUCT_Type * base)
1036 {
1037     uint32_t reg_value;
1038     reg_value = (TDM_STRUCT_RX_FIFO_STATUS(base) & TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FIFO_STATUS_WR_PTR_Msk);
1039     return ((uint8_t)(reg_value >> TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FIFO_STATUS_WR_PTR_Pos));
1040 }
1041 
1042 /***************************************************************************/
1043 /* Function Name: Cy_AudioTDM_EnableRxTestMode                             */
1044 /***************************************************************************//**
1045 *
1046 * Enables Test mode (intended to be used with (master transmitter, slave receiver) configuration).
1047 * Both TX and RX should not be set in Test mode simultaneously.
1048 *
1049 * \param base The pointer to the I2S/TDM instance address.
1050 *
1051 *******************************************************************************/
Cy_AudioTDM_EnableRxTestMode(TDM_RX_STRUCT_Type * base)1052 __STATIC_INLINE void Cy_AudioTDM_EnableRxTestMode( TDM_RX_STRUCT_Type * base)
1053 {
1054     TDM_STRUCT_RX_TEST_CTL(base) |= TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_TEST_CTL_ENABLED_Msk;
1055 }
1056 
1057 /***************************************************************************/
1058 /* Function Name: Cy_AudioTDM_DisableRxTestMode                            */
1059 /***************************************************************************//**
1060 *
1061 * Disable RX test mode
1062 *
1063 * \param base The pointer to the I2S/TDM instance address.
1064 *
1065 *******************************************************************************/
Cy_AudioTDM_DisableRxTestMode(TDM_RX_STRUCT_Type * base)1066 __STATIC_INLINE void Cy_AudioTDM_DisableRxTestMode( TDM_RX_STRUCT_Type * base)
1067 {
1068     TDM_STRUCT_RX_TEST_CTL(base) &= ~TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_TEST_CTL_ENABLED_Msk;
1069     TDM_STRUCT_RX_TEST_CTL(base) |= _BOOL2FLD(TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_TEST_CTL_ENABLED, 0U);
1070 }
1071 
1072 /***************************************************************************/
1073 /* Function Name: Cy_AudioTDM_ClearTxInterrupt                             */
1074 /***************************************************************************//**
1075 *
1076 * Clear TX interrupt
1077 *
1078 * \param base The pointer to the I2S/TDM instance address.
1079 * \param interrupt interrupt
1080 *
1081 * \funcusage
1082 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_ClearTxInterrupt
1083 *******************************************************************************/
Cy_AudioTDM_ClearTxInterrupt(TDM_TX_STRUCT_Type * base,uint32_t interrupt)1084 __STATIC_INLINE void Cy_AudioTDM_ClearTxInterrupt( TDM_TX_STRUCT_Type * base, uint32_t interrupt)
1085 {
1086     CY_ASSERT_L2(CY_I2S_TDM_INTR_TX_MASK_VALID(interrupt));
1087 
1088     TDM_STRUCT_TX_INTR_TX(base) = interrupt;
1089     /* This dummy reading is necessary here. It provides a guarantee that interrupt is cleared at returning from this function. */
1090     (void) TDM_STRUCT_TX_INTR_TX(base);
1091 }
1092 
1093 /***************************************************************************/
1094 /* Function Name: Cy_AudioTDM_SetTxInterrupt                               */
1095 /***************************************************************************//**
1096 *
1097 * Set the Tx Interrupt
1098 *
1099 * \param base The pointer to the I2S/TDM instance address.
1100 * \param interrupt interrupts to set.
1101 *
1102 * \funcusage
1103 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_SetTxInterrupt
1104 *******************************************************************************/
Cy_AudioTDM_SetTxInterrupt(TDM_TX_STRUCT_Type * base,uint32_t interrupt)1105 __STATIC_INLINE void Cy_AudioTDM_SetTxInterrupt( TDM_TX_STRUCT_Type * base, uint32_t interrupt)
1106 {
1107     CY_ASSERT_L2(CY_I2S_TDM_INTR_TX_MASK_VALID(interrupt));
1108 
1109     TDM_STRUCT_TX_INTR_TX_SET(base) = interrupt;
1110 }
1111 
1112 /***************************************************************************/
1113 /* Function Name: Cy_AudioTDM_GetTxInterruptMask                             */
1114 /***************************************************************************//**
1115 *
1116 * Get TX interrupt Mask
1117 *
1118 * \param base The pointer to the I2S/TDM instance address.
1119 *
1120 * \funcusage
1121 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_GetTxInterruptMask
1122 *******************************************************************************/
Cy_AudioTDM_GetTxInterruptMask(TDM_TX_STRUCT_Type * base)1123 __STATIC_INLINE uint32_t Cy_AudioTDM_GetTxInterruptMask( TDM_TX_STRUCT_Type * base)
1124 {
1125     return (TDM_STRUCT_TX_INTR_TX_MASK(base));
1126 }
1127 
1128 /***************************************************************************/
1129 /* Function Name: Cy_AudioTDM_SetTxInterruptMask                             */
1130 /***************************************************************************//**
1131 *
1132 * Set TX interrupt Mask
1133 *
1134 * \param base The pointer to the I2S/TDM instance address.
1135 * \param interrupt interrupt
1136 *
1137 * \funcusage
1138 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_SetTxInterruptMask
1139 *******************************************************************************/
Cy_AudioTDM_SetTxInterruptMask(TDM_TX_STRUCT_Type * base,uint32_t interrupt)1140 __STATIC_INLINE void Cy_AudioTDM_SetTxInterruptMask( TDM_TX_STRUCT_Type * base, uint32_t interrupt)
1141 {
1142     CY_ASSERT_L2(CY_I2S_TDM_INTR_TX_MASK_VALID(interrupt));
1143 
1144     TDM_STRUCT_TX_INTR_TX_MASK(base) = interrupt;
1145 }
1146 
1147 /***************************************************************************/
1148 /* Function Name: Cy_AudioTDM_GetTxInterruptStatusMasked                   */
1149 /***************************************************************************//**
1150 *
1151 *  Reflects a bitwise AND between the INTR_TX and INTR_TX_MASK registers.
1152 *
1153 * \param base The pointer to the I2S/TDM instance address.
1154 *
1155 *******************************************************************************/
Cy_AudioTDM_GetTxInterruptStatusMasked(TDM_TX_STRUCT_Type * base)1156 __STATIC_INLINE uint32_t Cy_AudioTDM_GetTxInterruptStatusMasked( TDM_TX_STRUCT_Type * base)
1157 {
1158     return (TDM_STRUCT_TX_INTR_TX_MASKED(base));
1159 }
1160 
1161 /***************************************************************************/
1162 /* Function Name: Cy_AudioTDM_SetTxTriggerInterruptMask                     */
1163 /***************************************************************************//**
1164 *
1165 * Sets TX interrupt Mask
1166 *
1167 * \param base The pointer to the I2S/TDM instance address.
1168 *
1169 *******************************************************************************/
Cy_AudioTDM_SetTxTriggerInterruptMask(TDM_TX_STRUCT_Type * base)1170 __STATIC_INLINE void Cy_AudioTDM_SetTxTriggerInterruptMask( TDM_TX_STRUCT_Type * base)
1171 {
1172     TDM_STRUCT_TX_INTR_TX_MASK(base) |= TDM_TDM_STRUCT_TDM_TX_STRUCT_INTR_TX_MASK_FIFO_TRIGGER_Msk;
1173 }
1174 
1175 /***************************************************************************/
1176 /* Function Name: Cy_AudioTDM_ClearTxTriggerInterruptMask                  */
1177 /***************************************************************************//**
1178 *
1179 *  Clears TX interrupt Mask
1180 *
1181 * \param base The pointer to the I2S/TDM instance address.
1182 *
1183 *******************************************************************************/
Cy_AudioTDM_ClearTxTriggerInterruptMask(TDM_TX_STRUCT_Type * base)1184 __STATIC_INLINE void Cy_AudioTDM_ClearTxTriggerInterruptMask( TDM_TX_STRUCT_Type * base)
1185 {
1186     TDM_STRUCT_TX_INTR_TX_MASK(base) &= ~TDM_TDM_STRUCT_TDM_TX_STRUCT_INTR_TX_MASK_FIFO_TRIGGER_Msk;
1187     TDM_STRUCT_TX_INTR_TX_MASK(base) |= _BOOL2FLD(TDM_TDM_STRUCT_TDM_TX_STRUCT_INTR_TX_MASK_FIFO_TRIGGER, 0U);
1188 }
1189 /***************************************************************************/
1190 /* Function Name: Cy_AudioTDM_ClearRxInterrupt                             */
1191 /***************************************************************************//**
1192 *
1193 *  Clears RX interrupt
1194 *
1195 * \param base The pointer to the I2S/TDM instance address.
1196 * \param interrupt interrupt
1197 *
1198 * \funcusage
1199 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_ClearRxInterrupt
1200 *******************************************************************************/
Cy_AudioTDM_ClearRxInterrupt(TDM_RX_STRUCT_Type * base,uint32_t interrupt)1201 __STATIC_INLINE void Cy_AudioTDM_ClearRxInterrupt( TDM_RX_STRUCT_Type * base, uint32_t interrupt)
1202 {
1203     CY_ASSERT_L2(CY_I2S_TDM_INTR_RX_MASK_VALID(interrupt));
1204 
1205     TDM_STRUCT_RX_INTR_RX(base) = interrupt;
1206     /* This dummy reading is necessary here. It provides a guarantee that interrupt is cleared at returning from this function. */
1207     (void) TDM_STRUCT_RX_INTR_RX(base);
1208 
1209 }
1210 
1211 /***************************************************************************/
1212 /* Function Name: Cy_AudioTDM_SetRxInterrupt                               */
1213 /***************************************************************************//**
1214 *
1215 *  Sets RX interrupt
1216 *
1217 * \param base The pointer to the I2S/TDM instance address.
1218 * \param interrupt interrupt
1219 *
1220 * \funcusage
1221 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_SetRxInterrupt
1222 *******************************************************************************/
Cy_AudioTDM_SetRxInterrupt(TDM_RX_STRUCT_Type * base,uint32_t interrupt)1223 __STATIC_INLINE void Cy_AudioTDM_SetRxInterrupt( TDM_RX_STRUCT_Type * base, uint32_t interrupt)
1224 {
1225     CY_ASSERT_L2(CY_I2S_TDM_INTR_RX_MASK_VALID(interrupt));
1226 
1227     TDM_STRUCT_RX_INTR_RX_SET(base) = interrupt;
1228 }
1229 
1230 /***************************************************************************/
1231 /* Function Name: Cy_AudioTDM_GetRxInterruptMask                           */
1232 /***************************************************************************//**
1233 *
1234 * Returns RX interrupt Mask
1235 *
1236 * \param base The pointer to the I2S/TDM instance address.
1237 *
1238 * \funcusage
1239 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_GetRxInterruptMask
1240 *******************************************************************************/
Cy_AudioTDM_GetRxInterruptMask(TDM_RX_STRUCT_Type * base)1241 __STATIC_INLINE uint32_t Cy_AudioTDM_GetRxInterruptMask( TDM_RX_STRUCT_Type * base)
1242 {
1243     return (TDM_STRUCT_RX_INTR_RX_MASK(base));
1244 }
1245 /***************************************************************************/
1246 /* Function Name: Cy_AudioTDM_SetRxInterruptMask                             */
1247 /***************************************************************************//**
1248 *
1249 * Sets RX interrupt Mask
1250 *
1251 * \param base The pointer to the I2S/TDM instance address.
1252 * \param interrupt interrupt
1253 *
1254 * \funcusage
1255 * \snippet tdm/snippet/main.c snippet_Cy_AudioTDM_SetRxInterruptMask
1256 *******************************************************************************/
Cy_AudioTDM_SetRxInterruptMask(TDM_RX_STRUCT_Type * base,uint32_t interrupt)1257 __STATIC_INLINE void Cy_AudioTDM_SetRxInterruptMask( TDM_RX_STRUCT_Type * base, uint32_t interrupt)
1258 {
1259     CY_ASSERT_L2(CY_I2S_TDM_INTR_RX_MASK_VALID(interrupt));
1260 
1261     TDM_STRUCT_RX_INTR_RX_MASK(base) = interrupt;
1262 }
1263 
1264 /***************************************************************************/
1265 /* Function Name: Cy_AudioTDM_GetRxInterruptStatusMasked                  */
1266 /***************************************************************************//**
1267 *
1268 * Returns  a bitwise AND between the INTR_RX and INTR_RX_MASK registers
1269 *
1270 * \param base The pointer to the I2S/TDM instance address.
1271 *
1272 * \return The interrupt bit mask(s).
1273 *
1274 *******************************************************************************/
Cy_AudioTDM_GetRxInterruptStatusMasked(TDM_RX_STRUCT_Type * base)1275 __STATIC_INLINE uint32_t Cy_AudioTDM_GetRxInterruptStatusMasked( TDM_RX_STRUCT_Type * base)
1276 {
1277     return (TDM_STRUCT_RX_INTR_RX_MASKED(base));
1278 }
1279 /***************************************************************************/
1280 /* Function Name: Cy_AudioTDM_SetRxTriggerInterruptMask                   */
1281 /***************************************************************************//**
1282 *
1283 * Sets Rx Interrupt Mask
1284 *
1285 * \param base The pointer to the I2S/TDM instance address.
1286 *
1287 *******************************************************************************/
Cy_AudioTDM_SetRxTriggerInterruptMask(TDM_RX_STRUCT_Type * base)1288 __STATIC_INLINE void Cy_AudioTDM_SetRxTriggerInterruptMask( TDM_RX_STRUCT_Type * base)
1289 {
1290     TDM_STRUCT_RX_INTR_RX_MASK(base) |= TDM_TDM_STRUCT_TDM_RX_STRUCT_INTR_RX_MASK_FIFO_TRIGGER_Msk;
1291 }
1292 
1293 /***************************************************************************/
1294 /* Function Name: Cy_AudioTDM_ClearRxTriggerInterruptMask                  */
1295 /***************************************************************************//**
1296 *
1297 * Clear RX interrupt Mask
1298 *
1299 * \param base The pointer to the I2S/TDM instance address.
1300 *
1301 *******************************************************************************/
Cy_AudioTDM_ClearRxTriggerInterruptMask(TDM_RX_STRUCT_Type * base)1302 __STATIC_INLINE void Cy_AudioTDM_ClearRxTriggerInterruptMask( TDM_RX_STRUCT_Type * base)
1303 {
1304     TDM_STRUCT_RX_INTR_RX_MASK(base) &= ~TDM_TDM_STRUCT_TDM_RX_STRUCT_INTR_RX_MASK_FIFO_TRIGGER_Msk;
1305     TDM_STRUCT_RX_INTR_RX_MASK(base) |= _BOOL2FLD(TDM_TDM_STRUCT_TDM_RX_STRUCT_INTR_RX_MASK_FIFO_TRIGGER, 0U);
1306 }
1307 
1308 /** \} group_tdm_functions */
1309 
1310 
1311 #if defined(__cplusplus)
1312 }
1313 #endif
1314 
1315 #endif  /* (CY_TDM_H) */
1316 
1317 /** \} group_tdm */
1318 
1319 CY_MISRA_BLOCK_END('MISRA C-2012 Rule 10.1')
1320 
1321 CY_MISRA_BLOCK_END('MISRA C-2012 Rule 14.3')
1322 
1323 #endif /* CY_IP_MXTDM */
1324 /* [] END OF FILE */
1325