Skip to content

Commit 381e47b

Browse files
committed
applications: nrf5340_audio: Rework to use GPPI API
nrfx_dppi is deprecated and nrfx_gppi need to be used. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 3eafacc commit 381e47b

File tree

2 files changed

+45
-76
lines changed

2 files changed

+45
-76
lines changed

applications/nrf5340_audio/src/audio/Kconfig.defaults

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ config NRFX_TIMER
99
default y
1010

1111
# Audio sync timer
12-
config NRFX_DPPI
12+
config NRFX_GPPI
1313
default y

applications/nrf5340_audio/src/modules/audio_sync_timer.c

Lines changed: 44 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <zephyr/kernel.h>
1010
#include <zephyr/init.h>
11-
#include <nrfx_dppi.h>
11+
#include <helpers/nrfx_gppi.h>
1212
#include <nrfx_i2s.h>
1313
#include <nrfx_ipc.h>
1414
#include <nrfx_rtc.h>
@@ -31,7 +31,7 @@ LOG_MODULE_REGISTER(audio_sync_timer, CONFIG_AUDIO_SYNC_TIMER_LOG_LEVEL);
3131
static nrfx_timer_t audio_sync_hf_timer_instance =
3232
NRFX_TIMER_INSTANCE(NRF_TIMER_INST_GET(AUDIO_SYNC_HF_TIMER_INSTANCE_NUMBER));
3333

34-
static uint8_t dppi_channel_i2s_frame_start;
34+
static nrfx_gppi_handle_t dppi_handle_i2s_frame_start;
3535

3636
#define AUDIO_SYNC_LF_TIMER_INSTANCE_NUMBER 0
3737

@@ -41,15 +41,15 @@ static uint8_t dppi_channel_i2s_frame_start;
4141
#define AUDIO_SYNC_LF_TIMER_CURR_TIME_CAPTURE NRF_RTC_TASK_CAPTURE_1
4242
#define CC_GET_CALLS_MAX 20
4343

44-
static uint8_t dppi_channel_curr_time_capture;
44+
static nrfx_gppi_handle_t dppi_handle_curr_time_capture;
4545

4646
static const nrfx_rtc_config_t rtc_cfg = NRFX_RTC_DEFAULT_CONFIG;
4747

4848
static const nrfx_rtc_t audio_sync_lf_timer_instance =
4949
NRFX_RTC_INSTANCE(AUDIO_SYNC_LF_TIMER_INSTANCE_NUMBER);
5050

51-
static uint8_t dppi_channel_timer_sync_with_rtc;
52-
static uint8_t dppi_channel_rtc_start;
51+
static nrfx_gppi_handle_t dppi_handle_timer_sync_with_rtc;
52+
static nrfx_gppi_handle_t dppi_handle_rtc_start;
5353
static volatile uint32_t num_rtc_overflows;
5454

5555
static nrfx_timer_config_t cfg = {.frequency = NRFX_MHZ_TO_HZ(1UL),
@@ -171,7 +171,7 @@ static void rtc_isr_handler(nrfx_rtc_int_type_t int_type)
171171
static int audio_sync_timer_init(void)
172172
{
173173
nrfx_err_t ret;
174-
nrfx_dppi_t dppi = NRFX_DPPI_INSTANCE(0);
174+
uint32_t eep0, tep0, tep1;
175175

176176
ret = nrfx_timer_init(&audio_sync_hf_timer_instance, &cfg, unused_timer_isr_handler);
177177
if (ret - NRFX_ERROR_BASE_NUM) {
@@ -189,92 +189,61 @@ static int audio_sync_timer_init(void)
189189
nrfx_rtc_overflow_enable(&audio_sync_lf_timer_instance, true);
190190

191191
/* Initialize capturing of I2S frame start event timestamps */
192-
ret = nrfx_dppi_channel_alloc(&dppi, &dppi_channel_i2s_frame_start);
193-
if (ret - NRFX_ERROR_BASE_NUM) {
192+
eep0 = nrf_i2s_event_address_get(NRF_I2S0, NRF_I2S_EVENT_FRAMESTART);
193+
tep0 = nrfx_rtc_task_address_get(&audio_sync_lf_timer_instance,
194+
AUDIO_SYNC_LF_TIMER_I2S_FRAME_START_EVT_CAPTURE);
195+
tep1 = nrfx_timer_task_address_get(&audio_sync_hf_timer_instance,
196+
AUDIO_SYNC_HF_TIMER_I2S_FRAME_START_EVT_CAPTURE);
197+
198+
ret = nrfx_gppi_conn_alloc(eep0, tep0, &dppi_handle_i2s_frame_start);
199+
if (ret < 0) {
194200
LOG_ERR("nrfx DPPI channel alloc error (I2S frame start): %d", ret);
195-
return -ENOMEM;
201+
return ret;
196202
}
197203

198-
nrf_timer_subscribe_set(audio_sync_hf_timer_instance.p_reg,
199-
AUDIO_SYNC_HF_TIMER_I2S_FRAME_START_EVT_CAPTURE,
200-
dppi_channel_i2s_frame_start);
201-
202-
/* Initialize capturing of I2S frame start event timestamps at the RTC as well. */
203-
nrf_rtc_subscribe_set(audio_sync_lf_timer_instance.p_reg,
204-
AUDIO_SYNC_LF_TIMER_I2S_FRAME_START_EVT_CAPTURE,
205-
dppi_channel_i2s_frame_start);
206-
207-
nrf_i2s_publish_set(NRF_I2S0, NRF_I2S_EVENT_FRAMESTART, dppi_channel_i2s_frame_start);
208-
ret = nrfx_dppi_channel_enable(&dppi, dppi_channel_i2s_frame_start);
209-
if (ret - NRFX_ERROR_BASE_NUM) {
210-
LOG_ERR("nrfx DPPI channel enable error (I2S frame start): %d", ret);
211-
return -EIO;
212-
}
204+
nrfx_gppi_ep_attach(tep1, dppi_handle_i2s_frame_start);
205+
nrfx_gppi_conn_enable(dppi_handle_i2s_frame_start);
213206

214207
/* Initialize capturing of current timestamps */
215-
ret = nrfx_dppi_channel_alloc(&dppi, &dppi_channel_curr_time_capture);
216-
if (ret - NRFX_ERROR_BASE_NUM) {
208+
eep0 = nrf_egu_event_address_get(NRF_EGU0, NRF_EGU_EVENT_TRIGGERED0);
209+
tep0 = nrfx_rtc_task_address_get(&audio_sync_lf_timer_instance,
210+
AUDIO_SYNC_LF_TIMER_CURR_TIME_CAPTURE);
211+
tep1 = nrfx_timer_task_address_get(&audio_sync_hf_timer_instance,
212+
AUDIO_SYNC_HF_TIMER_CURR_TIME_CAPTURE);
213+
214+
ret = nrfx_gppi_conn_alloc(eep0, tep0, &dppi_handle_curr_time_capture);
215+
if (ret < 0) {
217216
LOG_ERR("nrfx DPPI channel alloc error (I2S frame start): %d", ret);
218-
return -ENOMEM;
219-
}
220-
221-
nrf_rtc_subscribe_set(audio_sync_lf_timer_instance.p_reg,
222-
AUDIO_SYNC_LF_TIMER_CURR_TIME_CAPTURE,
223-
dppi_channel_curr_time_capture);
224-
225-
nrf_timer_subscribe_set(audio_sync_hf_timer_instance.p_reg,
226-
AUDIO_SYNC_HF_TIMER_CURR_TIME_CAPTURE,
227-
dppi_channel_curr_time_capture);
228-
229-
nrf_egu_publish_set(NRF_EGU0, NRF_EGU_EVENT_TRIGGERED0, dppi_channel_curr_time_capture);
230-
231-
ret = nrfx_dppi_channel_enable(&dppi, dppi_channel_curr_time_capture);
232-
if (ret - NRFX_ERROR_BASE_NUM) {
233-
LOG_ERR("nrfx DPPI channel enable error (I2S frame start): %d", ret);
234-
return -EIO;
217+
return ret;
235218
}
219+
nrfx_gppi_ep_attach(tep1, dppi_handle_curr_time_capture);
220+
nrfx_gppi_conn_enable(dppi_handle_curr_time_capture);
236221

237222
/* Initialize functionality for synchronization between APP and NET core */
238-
ret = nrfx_dppi_channel_alloc(&dppi, &dppi_channel_rtc_start);
239-
if (ret - NRFX_ERROR_BASE_NUM) {
240-
LOG_ERR("nrfx DPPI channel alloc error (timer clear): %d", ret);
241-
return -ENOMEM;
223+
eep0 = nrf_ipc_event_address_get(NRF_IPC, AUDIO_SYNC_TIMER_NET_APP_IPC_EVT);
224+
tep0 = nrfx_rtc_task_address_get(&audio_sync_lf_timer_instance, NRF_RTC_TASK_CLEAR);
225+
tep1 = nrfx_timer_task_address_get(&audio_sync_hf_timer_instance, NRF_TIMER_TASK_START);
226+
ret = nrfx_gppi_conn_alloc(eep0, tep0, &dppi_handle_rtc_start);
227+
if (ret < 0) {
228+
LOG_ERR("nrfx DPPI channel alloc error (I2S frame start): %d", ret);
229+
return ret;
242230
}
243-
244-
nrf_rtc_subscribe_set(audio_sync_lf_timer_instance.p_reg, NRF_RTC_TASK_CLEAR,
245-
dppi_channel_rtc_start);
246-
nrf_timer_subscribe_set(audio_sync_hf_timer_instance.p_reg, NRF_TIMER_TASK_START,
247-
dppi_channel_rtc_start);
248-
231+
nrfx_gppi_ep_attach(tep1, dppi_handle_rtc_start);
249232
nrf_ipc_receive_config_set(NRF_IPC, AUDIO_SYNC_TIMER_NET_APP_IPC_EVT_CHANNEL,
250233
NRF_IPC_CHANNEL_4);
251-
nrf_ipc_publish_set(NRF_IPC, AUDIO_SYNC_TIMER_NET_APP_IPC_EVT, dppi_channel_rtc_start);
252-
253-
ret = nrfx_dppi_channel_enable(&dppi, dppi_channel_rtc_start);
254-
if (ret - NRFX_ERROR_BASE_NUM) {
255-
LOG_ERR("nrfx DPPI channel enable error (timer clear): %d", ret);
256-
return -EIO;
257-
}
234+
nrfx_gppi_conn_enable(dppi_handle_curr_time_capture);
258235

259236
/* Initialize functionality for synchronization between RTC and TIMER */
260-
ret = nrfx_dppi_channel_alloc(&dppi, &dppi_channel_timer_sync_with_rtc);
261-
if (ret - NRFX_ERROR_BASE_NUM) {
262-
LOG_ERR("nrfx DPPI channel alloc error (timer clear): %d", ret);
263-
return -ENOMEM;
237+
eep0 = nrfx_rtc_event_address_get(&audio_sync_lf_timer_instance, NRF_RTC_EVENT_TICK);
238+
tep0 = nrfx_timer_task_address_get(&audio_sync_hf_timer_instance, NRF_TIMER_TASK_CLEAR);
239+
ret = nrfx_gppi_conn_alloc(eep0, tep0, &dppi_handle_timer_sync_with_rtc);
240+
if (ret < 0) {
241+
LOG_ERR("nrfx DPPI channel alloc error (I2S frame start): %d", ret);
242+
return ret;
264243
}
265244

266-
nrf_rtc_publish_set(audio_sync_lf_timer_instance.p_reg, NRF_RTC_EVENT_TICK,
267-
dppi_channel_timer_sync_with_rtc);
268-
nrf_timer_subscribe_set(audio_sync_hf_timer_instance.p_reg, NRF_TIMER_TASK_CLEAR,
269-
dppi_channel_timer_sync_with_rtc);
270-
271245
nrfx_rtc_tick_enable(&audio_sync_lf_timer_instance, false);
272-
273-
ret = nrfx_dppi_channel_enable(&dppi, dppi_channel_timer_sync_with_rtc);
274-
if (ret - NRFX_ERROR_BASE_NUM) {
275-
LOG_ERR("nrfx DPPI channel enable error (timer clear): %d", ret);
276-
return -EIO;
277-
}
246+
nrfx_gppi_conn_enable(dppi_handle_timer_sync_with_rtc);
278247

279248
nrfx_rtc_enable(&audio_sync_lf_timer_instance);
280249

0 commit comments

Comments
 (0)