Skip to content

Commit 2b344fe

Browse files
committed
samples: bluetooth: Align to the new GPPI API
Align samples to use the updated GPPI API. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent be6d060 commit 2b344fe

File tree

6 files changed

+146
-192
lines changed

6 files changed

+146
-192
lines changed

samples/bluetooth/conn_time_sync/src/controller_time_nrf52.c

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
static const nrfx_rtc_t app_rtc_instance = NRFX_RTC_INSTANCE(2);
2525
static const nrfx_timer_t app_timer_instance = NRFX_TIMER_INSTANCE(1);
2626

27-
static uint8_t ppi_chan_on_rtc_match;
27+
static nrfx_gppi_handle_t ppi_on_rtc_match;
2828
static volatile uint32_t num_rtc_overflows;
2929

3030
static uint32_t offset_ticks_and_controller_to_app_rtc;
@@ -110,13 +110,15 @@ static int rtc_config(void)
110110
static int timer_config(void)
111111
{
112112
int ret;
113-
uint8_t ppi_chan_timer_clear_on_rtc_tick;
113+
nrfx_gppi_handle_t ppi_handle_timer_clear_on_rtc_tick;
114114
const nrfx_timer_config_t timer_cfg = {
115115
.frequency = NRFX_MHZ_TO_HZ(1UL),
116116
.mode = NRF_TIMER_MODE_TIMER,
117117
.bit_width = NRF_TIMER_BIT_WIDTH_8,
118118
.interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY,
119119
.p_context = NULL};
120+
uint32_t eep;
121+
uint32_t tep;
120122

121123
ret = nrfx_timer_init(&app_timer_instance, &timer_cfg, unused_timer_isr_handler);
122124
if (ret != NRFX_SUCCESS) {
@@ -125,19 +127,15 @@ static int timer_config(void)
125127
}
126128

127129
/* Clear the TIMER every RTC tick. */
128-
if (nrfx_gppi_channel_alloc(&ppi_chan_timer_clear_on_rtc_tick) != NRFX_SUCCESS) {
130+
eep = nrfx_rtc_event_address_get(&app_rtc_instance, NRF_RTC_EVENT_TICK);
131+
tep = nrfx_timer_task_address_get(&app_timer_instance, NRF_TIMER_TASK_CLEAR);
132+
ret = nrfx_gppi_conn_alloc(eep, tep, &ppi_handle_timer_clear_on_rtc_tick);
133+
if (ret < 0) {
129134
printk("Failed allocating for clearing TIMER on RTC TICK\n");
130-
return -ENOMEM;
135+
return ret;
131136
}
132137

133-
nrfx_gppi_channel_endpoints_setup(ppi_chan_timer_clear_on_rtc_tick,
134-
nrfx_rtc_event_address_get(&app_rtc_instance,
135-
NRF_RTC_EVENT_TICK),
136-
nrfx_timer_task_address_get(&app_timer_instance,
137-
NRF_TIMER_TASK_CLEAR));
138-
139-
nrfx_gppi_channels_enable(BIT(ppi_chan_timer_clear_on_rtc_tick));
140-
138+
nrfx_gppi_conn_enable(ppi_handle_timer_clear_on_rtc_tick);
141139
nrfx_timer_enable(&app_timer_instance);
142140

143141
return 0;
@@ -154,36 +152,31 @@ static int timer_config(void)
154152
*/
155153
int config_egu_trigger_on_rtc_and_timer_match(void)
156154
{
157-
uint8_t ppi_chan_on_timer_match;
155+
nrfx_gppi_handle_t ppi_on_timer_match;
156+
nrfx_gppi_group_handle_t group;
157+
uint32_t eep0 = nrfx_rtc_event_address_get(&app_rtc_instance, NRF_RTC_EVENT_COMPARE_0);
158+
uint32_t eep1 = nrfx_timer_event_address_get(&app_timer_instance, NRF_TIMER_EVENT_COMPARE0);
159+
uint32_t tep1 = nrf_egu_task_address_get(NRF_EGU0, NRF_EGU_TASK_TRIGGER0);
160+
int ret;
158161

159-
if (nrfx_gppi_channel_alloc(&ppi_chan_on_rtc_match) != NRFX_SUCCESS) {
160-
printk("Failed allocating for RTC match\n");
161-
return -ENOMEM;
162+
ret = nrfx_gppi_group_alloc(&eep0, 1, &group);
163+
if (ret < 0) {
164+
printk("Failed allocating group\n");
165+
return ret;
162166
}
163167

164-
if (nrfx_gppi_channel_alloc(&ppi_chan_on_timer_match) != NRFX_SUCCESS) {
165-
printk("Failed allocating for TIMER match\n");
166-
return -ENOMEM;
168+
ret = nrfx_gppi_conn_alloc(eep0, nrfx_gppi_group_task_en_addr(group), &ppi_on_rtc_match);
169+
if (ret < 0) {
170+
printk("Failed allocating for RTC match\n");
171+
return ret;
167172
}
168173

169-
nrfx_gppi_group_clear(NRFX_GPPI_CHANNEL_GROUP0);
170-
nrfx_gppi_group_disable(NRFX_GPPI_CHANNEL_GROUP0);
171-
nrfx_gppi_channels_include_in_group(
172-
BIT(ppi_chan_on_timer_match) | BIT(ppi_chan_on_rtc_match),
173-
NRFX_GPPI_CHANNEL_GROUP0);
174-
175-
nrfx_gppi_channel_endpoints_setup(ppi_chan_on_rtc_match,
176-
nrfx_rtc_event_address_get(&app_rtc_instance,
177-
NRF_RTC_EVENT_COMPARE_0),
178-
nrfx_gppi_task_address_get(NRFX_GPPI_TASK_CHG0_EN));
179-
180-
nrfx_gppi_channel_endpoints_setup(ppi_chan_on_timer_match,
181-
nrfx_timer_event_address_get(&app_timer_instance,
182-
NRF_TIMER_EVENT_COMPARE0),
183-
nrf_egu_task_address_get(NRF_EGU0,
184-
NRF_EGU_TASK_TRIGGER0));
185-
nrfx_gppi_fork_endpoint_setup(ppi_chan_on_timer_match,
186-
nrfx_gppi_task_address_get(NRFX_GPPI_TASK_CHG0_DIS));
174+
ret = nrfx_gppi_conn_alloc(eep1, tep1, &ppi_on_timer_match);
175+
if (ret < 0) {
176+
printk("Failed allocating for RTC match\n");
177+
return ret;
178+
}
179+
(void)nrfx_gppi_ep_attach(ppi_on_timer_match, nrfx_gppi_group_task_dis_addr(group));
187180

188181
return 0;
189182
}
@@ -279,7 +272,7 @@ void controller_time_trigger_set(uint64_t timestamp_us)
279272
}
280273

281274
nrfx_timer_compare(&app_timer_instance, 0, timer_val, false);
282-
nrfx_gppi_channels_enable(BIT(ppi_chan_on_rtc_match));
275+
nrfx_gppi_conn_enable(ppi_on_rtc_match);
283276
}
284277

285278
uint32_t controller_time_trigger_event_addr_get(void)

samples/bluetooth/conn_time_sync/src/controller_time_nrf53_app.c

Lines changed: 37 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
static const nrfx_rtc_t app_rtc_instance = NRFX_RTC_INSTANCE(0);
2626
static const nrfx_timer_t app_timer_instance = NRFX_TIMER_INSTANCE(0);
2727

28-
static uint8_t ppi_chan_on_rtc_match;
28+
static nrfx_gppi_handle_t ppi_on_rtc_match;
2929
static volatile uint32_t num_rtc_overflows;
3030

3131
static void rtc_isr_handler(nrfx_rtc_int_type_t int_type)
@@ -44,7 +44,7 @@ static void unused_timer_isr_handler(nrf_timer_event_t event_type, void *ctx)
4444
static int rtc_config(void)
4545
{
4646
int ret;
47-
uint8_t dppi_channel_rtc_start;
47+
nrfx_gppi_handle_t dppi_channel_rtc_start;
4848
const nrfx_rtc_config_t rtc_cfg = NRFX_RTC_DEFAULT_CONFIG;
4949

5050
ret = nrfx_rtc_init(&app_rtc_instance, &rtc_cfg, rtc_isr_handler);
@@ -65,60 +65,48 @@ static int rtc_config(void)
6565
nrfx_rtc_tick_enable(&app_rtc_instance, false);
6666
nrfx_rtc_enable(&app_rtc_instance);
6767

68-
68+
nrf_ipc_receive_config_set(NRF_IPC, 4, NRF_IPC_CHANNEL_4);
6969
/* The application core RTC is started synchronously with the controller
7070
* RTC using PPI over IPC.
7171
*/
72-
ret = nrfx_gppi_channel_alloc(&dppi_channel_rtc_start);
73-
if (ret != NRFX_SUCCESS) {
72+
ret = nrfx_gppi_conn_alloc(nrfx_rtc_task_address_get(&app_rtc_instance, NRF_RTC_TASK_CLEAR),
73+
nrf_ipc_event_address_get(NRF_IPC, NRF_IPC_EVENT_RECEIVE_4),
74+
&dppi_rtc_start);
75+
if (ret < 0) {
7476
printk("nrfx DPPI channel alloc error for starting RTC: %d", ret);
75-
return -ENODEV;
77+
return ret;
7678
}
77-
78-
nrf_ipc_receive_config_set(NRF_IPC, 4, NRF_IPC_CHANNEL_4);
79-
80-
nrfx_gppi_channel_endpoints_setup(dppi_channel_rtc_start,
81-
nrfx_rtc_task_address_get(&app_rtc_instance,
82-
NRF_RTC_TASK_CLEAR),
83-
nrf_ipc_event_address_get(NRF_IPC,
84-
NRF_IPC_EVENT_RECEIVE_4));
85-
86-
nrfx_gppi_channels_enable(BIT(dppi_channel_rtc_start));
79+
nrfx_gppi_conn_enable(dppi_rtc_start);
8780

8881
return 0;
8982
}
9083

9184
static int timer_config(void)
9285
{
9386
int ret;
94-
uint8_t ppi_chan_timer_clear_on_rtc_tick;
87+
nrfx_gppi_handle_t ppi_timer_clear_on_rtc_tick;
9588
const nrfx_timer_config_t timer_cfg = {
9689
.frequency = NRFX_MHZ_TO_HZ(1UL),
9790
.mode = NRF_TIMER_MODE_TIMER,
9891
.bit_width = NRF_TIMER_BIT_WIDTH_8,
9992
.interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY,
10093
.p_context = NULL};
94+
uint32_t eep = nrfx_rtc_event_address_get(&app_rtc_instance, NRF_RTC_EVENT_TICK);
95+
uint32_t tep = nrfx_timer_task_address_get(&app_timer_instance, NRF_TIMER_TASK_CLEAR);
10196

10297
ret = nrfx_timer_init(&app_timer_instance, &timer_cfg, unused_timer_isr_handler);
10398
if (ret != NRFX_SUCCESS) {
10499
printk("Failed initializing timer (ret: %d)\n", ret - NRFX_ERROR_BASE_NUM);
105100
return -ENODEV;
106101
}
107102

108-
/* Clear the TIMER every RTC tick. */
109-
if (nrfx_gppi_channel_alloc(&ppi_chan_timer_clear_on_rtc_tick) != NRFX_SUCCESS) {
103+
ret = nrfx_gppi_conn_alloc(eep, tep, &ppi_timer_clear_on_rtc_tick);
104+
if (ret < 0) {
110105
printk("Failed allocating for clearing TIMER on RTC TICK\n");
111-
return -ENOMEM;
106+
return ret;
112107
}
113108

114-
nrfx_gppi_channel_endpoints_setup(ppi_chan_timer_clear_on_rtc_tick,
115-
nrfx_rtc_event_address_get(&app_rtc_instance,
116-
NRF_RTC_EVENT_TICK),
117-
nrfx_timer_task_address_get(&app_timer_instance,
118-
NRF_TIMER_TASK_CLEAR));
119-
120-
nrfx_gppi_channels_enable(BIT(ppi_chan_timer_clear_on_rtc_tick));
121-
109+
nrfx_gppi_conn_enable(ppi_timer_clear_on_rtc_tick);
122110
nrfx_timer_enable(&app_timer_instance);
123111

124112
return 0;
@@ -135,34 +123,31 @@ static int timer_config(void)
135123
*/
136124
int config_egu_trigger_on_rtc_and_timer_match(void)
137125
{
138-
uint8_t ppi_chan_on_timer_match;
126+
nrfx_gppi_handle_t ppi_on_timer_match;
127+
nrfx_gppi_group_handle_t group;
128+
uint32_t eep0 = nrfx_rtc_event_address_get(&app_rtc_instance, NRF_RTC_EVENT_COMPARE_0);
129+
uint32_t eep1 = nrfx_timer_event_address_get(&app_timer_instance, NRF_TIMER_EVENT_COMPARE0),
130+
uint32_t tep1 = nrf_egu_task_address_get(NRF_EGU0, NRF_EGU_TASK_TRIGGER0);
131+
int ret;
139132

140-
if (nrfx_gppi_channel_alloc(&ppi_chan_on_rtc_match) != NRFX_SUCCESS) {
141-
printk("Failed allocating for RTC match\n");
142-
return -ENOMEM;
133+
ret = nrfx_gppi_group_alloc(&eep0, 1, &group);
134+
if (ret < 0) {
135+
printk("Failed allocating group\n");
136+
return ret;
143137
}
144138

145-
if (nrfx_gppi_channel_alloc(&ppi_chan_on_timer_match) != NRFX_SUCCESS) {
146-
printk("Failed allocating for TIMER match\n");
147-
return -ENOMEM;
139+
ret = nrfx_gppi_conn_alloc(eep0, nrfx_gppi_group_task_en_addr(group), &ppi_on_rtc_match);
140+
if (ret < 0) {
141+
printk("Failed allocating for RTC match\n");
142+
return ret;
148143
}
149144

150-
nrfx_gppi_group_clear(NRFX_GPPI_CHANNEL_GROUP0);
151-
nrfx_gppi_group_disable(NRFX_GPPI_CHANNEL_GROUP0);
152-
nrfx_gppi_channels_include_in_group(
153-
BIT(ppi_chan_on_timer_match) | BIT(ppi_chan_on_rtc_match),
154-
NRFX_GPPI_CHANNEL_GROUP0);
155-
156-
nrfx_gppi_channel_endpoints_setup(ppi_chan_on_rtc_match,
157-
nrfx_rtc_event_address_get(&app_rtc_instance,
158-
NRF_RTC_EVENT_COMPARE_0),
159-
nrfx_gppi_task_address_get(NRFX_GPPI_TASK_CHG0_EN));
160-
nrfx_gppi_channel_endpoints_setup(ppi_chan_on_timer_match,
161-
nrfx_timer_event_address_get(&app_timer_instance,
162-
NRF_TIMER_EVENT_COMPARE0),
163-
nrfx_gppi_task_address_get(NRFX_GPPI_TASK_CHG0_DIS));
164-
nrfx_gppi_fork_endpoint_setup(ppi_chan_on_timer_match,
165-
nrf_egu_task_address_get(NRF_EGU0, NRF_EGU_TASK_TRIGGER0));
145+
ret = nrfx_gppi_conn_alloc(eep1, tep1, &ppi_on_timer_match);
146+
if (ret < 0) {
147+
printk("Failed allocating for RTC match\n");
148+
return ret;
149+
}
150+
(void)nrfx_gppi_ep_attach(ppi_on_timer_match, nrfx_gppi_group_task_dis_addr(group));
166151

167152
return 0;
168153
}
@@ -253,7 +238,7 @@ void controller_time_trigger_set(uint64_t timestamp_us)
253238
}
254239

255240
nrfx_timer_compare(&app_timer_instance, 0, timer_val, false);
256-
nrfx_gppi_channels_enable(BIT(ppi_chan_on_rtc_match));
241+
nrfx_gppi_conn_enable(ppi_on_rtc_match);
257242
}
258243

259244
uint32_t controller_time_trigger_event_addr_get(void)

samples/bluetooth/conn_time_sync/src/timed_led_toggle.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static uint8_t previous_led_value;
3333
int timed_led_toggle_init(void)
3434
{
3535
int err;
36-
uint8_t ppi_chan_led_toggle;
36+
nrfx_gppi_handle_t ppi_led_toggle;
3737
uint8_t gpiote_chan_led_toggle;
3838

3939
const nrfx_gpiote_output_config_t gpiote_output_cfg = NRFX_GPIOTE_DEFAULT_OUTPUT_CONFIG;
@@ -63,16 +63,15 @@ int timed_led_toggle_init(void)
6363
return -ENOMEM;
6464
}
6565

66-
if (nrfx_gppi_channel_alloc(&ppi_chan_led_toggle) != NRFX_SUCCESS) {
66+
err = nrfx_gppi_conn_alloc(controller_time_trigger_event_addr_get(),
67+
nrfx_gpiote_out_task_address_get(&gpiote, LED_PIN),
68+
&ppi_led_toggle);
69+
if (err < 0) {
6770
printk("Failed allocating PPI chan for toggling led\n");
6871
return -ENOMEM;
6972
}
7073

71-
nrfx_gppi_channel_endpoints_setup(ppi_chan_led_toggle,
72-
controller_time_trigger_event_addr_get(),
73-
nrfx_gpiote_out_task_address_get(&gpiote, LED_PIN));
74-
75-
nrfx_gppi_channels_enable(BIT(ppi_chan_led_toggle));
74+
nrfx_gppi_conn_enable(ppi_led_toggle);
7675
nrfx_gpiote_out_task_enable(&gpiote, LED_PIN);
7776

7877
return 0;

0 commit comments

Comments
 (0)