Skip to content

Commit bb586b3

Browse files
committed
applications: nrf5340_audio: Changed nrf_rtc_cc_get loop delay.
- OCT-3368 - The existing delay was not sufficient for certain sample rates. - Timer capture is on FRAMESTART which is later than the ISR execution. Signed-off-by: Kristoffer Rist Skøien <[email protected]>
1 parent c7fd0e7 commit bb586b3

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

applications/nrf5340_audio/src/modules/audio_i2s.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ static void i2s_comp_handler(nrfx_i2s_buffers_t const *released_bufs, uint32_t s
6666
{
6767
if ((status == NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED) && released_bufs &&
6868
i2s_blk_comp_callback && (released_bufs->p_rx_buffer || released_bufs->p_tx_buffer)) {
69-
i2s_blk_comp_callback(audio_sync_timer_capture_get(), released_bufs->p_rx_buffer,
70-
released_bufs->p_tx_buffer);
69+
i2s_blk_comp_callback(audio_sync_timer_frame_start_capture_get(),
70+
released_bufs->p_rx_buffer, released_bufs->p_tx_buffer);
7171
}
7272
}
7373

applications/nrf5340_audio/src/modules/audio_sync_timer.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static uint8_t dppi_channel_i2s_frame_start;
3939
#define AUDIO_SYNC_LF_TIMER_I2S_FRAME_START_EVT_CAPTURE NRF_RTC_TASK_CAPTURE_0
4040
#define AUDIO_SYNC_LF_TIMER_CURR_TIME_CAPTURE_CHANNEL 1
4141
#define AUDIO_SYNC_LF_TIMER_CURR_TIME_CAPTURE NRF_RTC_TASK_CAPTURE_1
42-
#define CC_GET_CALLS_MAX 30
42+
#define CC_GET_CALLS_MAX 20
4343

4444
static uint8_t dppi_channel_curr_time_capture;
4545

@@ -107,44 +107,41 @@ uint32_t audio_sync_timer_capture(void)
107107
return timestamp_from_rtc_and_timer_get(tick, remainder_us);
108108
}
109109

110-
uint32_t audio_sync_timer_capture_get(void)
110+
uint32_t audio_sync_timer_frame_start_capture_get(void)
111111
{
112112
uint32_t cc_get_calls = 0;
113113
uint32_t tick = 0;
114114
static uint32_t prev_tick;
115115
uint32_t remainder_us = 0;
116-
static uint32_t prev_remainder_us;
117116

118-
/* This function is called too soon after I2S frame start may
119-
* result in values not yet being updated in the *_cc_get calls.
120-
* Ref: OCT-2585. To ensure new values are fetched, they are
121-
* read in a while-loop with a timeout.
117+
/* This ISR is called before the I2S FRAMESTART event which does timer capture,
118+
* resulting in values not yet being updated in the *_cc_get calls.
119+
* To ensure new values are fetched, they are read in a while-loop with a timeout.
120+
* Depending on variables such as sample frequency, this delay varies.
121+
* For 16 kHz sampling rate is about 20 us. Less for 24 kHz and 48 kHz.
122+
* Ref: OCT-2585 and OCT-3368.
122123
*/
123124

124125
do {
125126
tick = nrf_rtc_cc_get(audio_sync_lf_timer_instance.p_reg,
126127
AUDIO_SYNC_LF_TIMER_I2S_FRAME_START_EVT_CAPTURE_CHANNEL);
127128
cc_get_calls++;
128129
if (cc_get_calls > CC_GET_CALLS_MAX) {
129-
LOG_WRN("Unable to get new CC value");
130+
LOG_ERR("Unable to get new tick from nrf_rtc_cc_get");
130131
break;
131132
}
133+
k_busy_wait(1);
132134
} while (tick == prev_tick);
133135

134136
cc_get_calls = 0;
135137

136-
do {
137-
remainder_us = nrf_timer_cc_get(
138-
NRF_TIMER1, AUDIO_SYNC_HF_TIMER_I2S_FRAME_START_EVT_CAPTURE_CHANNEL);
139-
cc_get_calls++;
140-
if (cc_get_calls > CC_GET_CALLS_MAX) {
141-
LOG_WRN("Unable to get new CC value");
142-
break;
143-
}
144-
} while (remainder_us == prev_remainder_us);
138+
/* The HF timer is cleared on every I2S frame. Hence, this value can be
139+
* the same many times in a row.
140+
*/
141+
remainder_us = nrf_timer_cc_get(NRF_TIMER1,
142+
AUDIO_SYNC_HF_TIMER_I2S_FRAME_START_EVT_CAPTURE_CHANNEL);
145143

146144
prev_tick = tick;
147-
prev_remainder_us = remainder_us;
148145

149146
return timestamp_from_rtc_and_timer_get(tick, remainder_us);
150147
}
@@ -217,7 +214,7 @@ static int audio_sync_timer_init(void)
217214
/* Initialize capturing of current timestamps */
218215
ret = nrfx_dppi_channel_alloc(&dppi, &dppi_channel_curr_time_capture);
219216
if (ret - NRFX_ERROR_BASE_NUM) {
220-
LOG_ERR("nrfx DPPI channel alloc error (I2S frame start) - Return value: %d", ret);
217+
LOG_ERR("nrfx DPPI channel alloc error (I2S frame start): %d", ret);
221218
return -ENOMEM;
222219
}
223220

@@ -233,7 +230,7 @@ static int audio_sync_timer_init(void)
233230

234231
ret = nrfx_dppi_channel_enable(&dppi, dppi_channel_curr_time_capture);
235232
if (ret - NRFX_ERROR_BASE_NUM) {
236-
LOG_ERR("nrfx DPPI channel enable error (I2S frame start) - Return value: %d", ret);
233+
LOG_ERR("nrfx DPPI channel enable error (I2S frame start): %d", ret);
237234
return -EIO;
238235
}
239236

applications/nrf5340_audio/src/modules/audio_sync_timer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ uint32_t audio_sync_timer_capture(void);
3232
*
3333
* @retval The last captured timestamp of the audio sync timer.
3434
*/
35-
uint32_t audio_sync_timer_capture_get(void);
35+
uint32_t audio_sync_timer_frame_start_capture_get(void);
3636

3737
#endif /* _AUDIO_SYNC_TIMER_H_ */

doc/nrf/releases_and_maturity/known_issues.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,7 @@ The issues in this section are related to the :ref:`nrf53_audio_app` application
23072307

23082308
OCT-3368: For 16 and 24 kHz, the application may repeatedly print "audio_sync_timer: Unable to get new CC value"
23092309
This may cause degraded audio quality.
2310+
This issue is a related to issue OCT-2585 and it shows the same behavior.
23102311

23112312
.. rst-class:: v3-0-2 v3-0-1 v3-0-0 v2-9-0-nRF54H20-1 v2-9-1 v2-9-0 v2-8-0
23122313

0 commit comments

Comments
 (0)