11/*
2- * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
2121
2222#include <stdint.h>
2323#include "driver/i2s_types.h"
24+ #include "esp_err.h"
2425
2526#ifdef __cplusplus
2627extern "C" {
@@ -31,6 +32,7 @@ extern "C" {
3132/**
3233 * @brief Get the counter number of BCLK ticks
3334 * @note The BCLK tick count reflects the real data that have sent on line
35+ * @note It will be reset automatically when `I2S_ETM_TASK_SYNC_FIFO` is triggered
3436 *
3537 * @param[in] tx_handle The I2S tx channel handle
3638 * @return
@@ -43,6 +45,7 @@ uint32_t i2s_sync_get_bclk_count(i2s_chan_handle_t tx_handle);
4345 * @note The FIFO count reflects how many slots have processed
4446 * Normally, fifo_cnt = slot_bit_width * bclk_cnt
4547 * If fifo_cnt < slot_bit_width * bclk_cnt, that means some data are still stuck in the I2S controller
48+ * @note It will be reset automatically when `I2S_ETM_TASK_SYNC_FIFO` is triggered
4649 *
4750 * @param[in] tx_handle The I2S tx channel handle
4851 * @return
@@ -66,6 +69,78 @@ void i2s_sync_reset_fifo_count(i2s_chan_handle_t tx_handle);
6669
6770#endif // SOC_I2S_SUPPORTS_TX_SYNC_CNT
6871
72+ #if SOC_I2S_SUPPORTS_TX_FIFO_SYNC
73+ /**
74+ * @brief I2S hardware FIFO synchronization supplement mode
75+ * @note When the FIFO sync difference count is out of threshold, the hardware will supplement data automatically
76+ * This type is to specify which data will be supplemented
77+ */
78+ typedef enum {
79+ I2S_SYNC_SUPPL_MODE_LAST_DATA = 0 , /*!< Supplement with the last transmitted data */
80+ I2S_SYNC_SUPPL_MODE_STATIC_DATA = 1 , /*!< Supplement with static data specified in config */
81+ } i2s_sync_suppl_mode_t ;
82+
83+ /**
84+ * @brief I2S hardware FIFO synchronization configuration
85+ * @note This configuration is used for multi I2S port synchronization via ETM
86+ */
87+ typedef struct {
88+ uint32_t hw_low_thresh ; /*!< Lower threshold for FIFO sync difference counter
89+ - If difference count < hw_low_thresh, do nothing
90+ - If difference count >= hw_low_thresh, the hardware will supplement data automatically */
91+ uint32_t sw_high_thresh ; /*!< Upper threshold for FIFO sync difference counter
92+ - If difference count <= sw_high_thresh, the hardware supplement data automatically
93+ - If difference count > sw_high_thresh, sync interrupt triggered and
94+ the software is responsible to decide how to handle this severe asynchronization */
95+ uint32_t ideal_cnt ; /*!< Ideal count for FIFO sync difference counter, it depends on the ETM sync task interval and the data rate */
96+ i2s_sync_suppl_mode_t suppl_mode ; /*!< Data supplement mode when FIFO sync difference is out of threshold */
97+ uint32_t suppl_data ; /*!< Static supplement data, only valid when suppl_mode is I2S_SYNC_SUPPL_MODE_STATIC_DATA */
98+ } i2s_sync_fifo_sync_config_t ;
99+
100+ /**
101+ * @brief Get the counter number of FIFO sync difference
102+ * @note The FIFO sync difference count reflects the difference between current FIFO count and ideal count
103+ *
104+ * @param[in] tx_handle The I2S tx channel handle
105+ * @return
106+ * - FIFO sync difference count
107+ */
108+ uint32_t i2s_sync_get_fifo_sync_diff_count (i2s_chan_handle_t tx_handle );
109+
110+ /**
111+ * @brief Reset the FIFO sync difference counter
112+ *
113+ * @param[in] tx_handle The I2S tx channel handle
114+ */
115+ void i2s_sync_reset_fifo_sync_diff_count (i2s_chan_handle_t tx_handle );
116+
117+ /**
118+ * @brief Enable or disable hardware FIFO synchronization
119+ * @note When enabled, hardware will automatically supplement data when FIFO sync difference is greater than hw_low_thresh
120+ *
121+ * @param[in] tx_handle The I2S tx channel handle
122+ * @param[in] enable true to enable, false to disable
123+ * @return
124+ * - ESP_OK on success
125+ * - ESP_ERR_NOT_SUPPORTED if called on RX channel
126+ */
127+ esp_err_t i2s_sync_enable_hw_fifo_sync (i2s_chan_handle_t tx_handle , bool enable );
128+
129+ /**
130+ * @brief Configure hardware FIFO synchronization parameters
131+ * @note This function configures the thresholds and supplement mode for hardware FIFO sync
132+ *
133+ * @param[in] tx_handle The I2S tx channel handle
134+ * @param[in] config Configuration for hardware FIFO synchronization
135+ * @return
136+ * - ESP_OK on success
137+ * - ESP_ERR_INVALID_ARG if invalid arguments
138+ * - ESP_ERR_NOT_SUPPORTED if called on RX channel
139+ */
140+ esp_err_t i2s_sync_config_hw_fifo_sync (i2s_chan_handle_t tx_handle , const i2s_sync_fifo_sync_config_t * config );
141+
142+ #endif
143+
69144#ifdef __cplusplus
70145}
71146#endif
0 commit comments