Skip to content

Commit 8d46d6d

Browse files
committed
drivers: timer: nrf_grtc_timer: Adapt to the new nrfx_grtc API
Adapt to change in return value (nrfx_err_t to errno). Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 3639fc3 commit 8d46d6d

File tree

1 file changed

+20
-50
lines changed

1 file changed

+20
-50
lines changed

drivers/timer/nrf_grtc_timer.c

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,7 @@ static inline uint64_t counter(void)
9393

9494
static inline int get_comparator(uint32_t chan, uint64_t *cc)
9595
{
96-
nrfx_err_t result;
97-
98-
result = nrfx_grtc_syscounter_cc_value_read(chan, cc);
99-
if (result != NRFX_SUCCESS) {
100-
if (result != NRFX_ERROR_INVALID_PARAM) {
101-
return -EAGAIN;
102-
}
103-
return -EPERM;
104-
}
105-
return 0;
96+
return nrfx_grtc_syscounter_cc_value_read(chan, cc);
10697
}
10798

10899
/*
@@ -173,14 +164,14 @@ static void sys_clock_timeout_handler(int32_t id, uint64_t cc_val, void *p_conte
173164
int32_t z_nrf_grtc_timer_chan_alloc(void)
174165
{
175166
uint8_t chan;
176-
nrfx_err_t err_code;
167+
int err_code;
177168

178169
/* Prevent allocating all available channels - one must be left for system purposes. */
179170
if (ext_channels_allocated >= EXT_CHAN_COUNT) {
180171
return -ENOMEM;
181172
}
182173
err_code = nrfx_grtc_channel_alloc(&chan);
183-
if (err_code != NRFX_SUCCESS) {
174+
if (err_code < 0) {
184175
return -ENOMEM;
185176
}
186177
ext_channels_allocated++;
@@ -190,9 +181,9 @@ int32_t z_nrf_grtc_timer_chan_alloc(void)
190181
void z_nrf_grtc_timer_chan_free(int32_t chan)
191182
{
192183
IS_CHANNEL_ALLOWED_ASSERT(chan);
193-
nrfx_err_t err_code = nrfx_grtc_channel_free(chan);
184+
int err_code = nrfx_grtc_channel_free(chan);
194185

195-
if (err_code == NRFX_SUCCESS) {
186+
if (err_code == 0) {
196187
ext_channels_allocated--;
197188
}
198189
}
@@ -249,19 +240,13 @@ int z_nrf_grtc_timer_compare_read(int32_t chan, uint64_t *val)
249240
static int compare_set_nolocks(int32_t chan, uint64_t target_time,
250241
z_nrf_grtc_timer_compare_handler_t handler, void *user_data)
251242
{
252-
nrfx_err_t result;
253-
254243
__ASSERT_NO_MSG(target_time < COUNTER_SPAN);
255244
nrfx_grtc_channel_t user_channel_data = {
256245
.handler = handler,
257246
.p_context = user_data,
258247
.channel = chan,
259248
};
260-
result = nrfx_grtc_syscounter_cc_absolute_set(&user_channel_data, target_time, true);
261-
if (result != NRFX_SUCCESS) {
262-
return -EPERM;
263-
}
264-
return 0;
249+
return nrfx_grtc_syscounter_cc_absolute_set(&user_channel_data, target_time, true);
265250
}
266251

267252
static int compare_set(int32_t chan, uint64_t target_time,
@@ -314,31 +299,22 @@ int z_nrf_grtc_timer_capture_prepare(int32_t chan)
314299
.p_context = NULL,
315300
.channel = chan,
316301
};
317-
nrfx_err_t result;
318302

319303
IS_CHANNEL_ALLOWED_ASSERT(chan);
320304

321305
/* Set the CC value to mark channel as not triggered and also to enable it
322306
* (makes CCEN=1). COUNTER_SPAN is used so as not to fire an event unnecessarily
323307
* - it can be assumed that such a large value will never be reached.
324308
*/
325-
result = nrfx_grtc_syscounter_cc_absolute_set(&user_channel_data, COUNTER_SPAN, false);
326-
327-
if (result != NRFX_SUCCESS) {
328-
return -EPERM;
329-
}
330-
331-
return 0;
309+
return nrfx_grtc_syscounter_cc_absolute_set(&user_channel_data, COUNTER_SPAN, false);
332310
}
333311

334312
int z_nrf_grtc_timer_capture_read(int32_t chan, uint64_t *captured_time)
335313
{
336314
/* TODO: The implementation should probably go to nrfx_grtc and this
337315
* should be just a wrapper for some nrfx_grtc_syscounter_capture_read.
338316
*/
339-
340-
uint64_t capt_time;
341-
nrfx_err_t result;
317+
int result;
342318

343319
IS_CHANNEL_ALLOWED_ASSERT(chan);
344320

@@ -349,14 +325,8 @@ int z_nrf_grtc_timer_capture_read(int32_t chan, uint64_t *captured_time)
349325
*/
350326
return -EBUSY;
351327
}
352-
result = nrfx_grtc_syscounter_cc_value_read(chan, &capt_time);
353-
if (result != NRFX_SUCCESS) {
354-
return -EPERM;
355-
}
356-
357-
__ASSERT_NO_MSG(capt_time < COUNTER_SPAN);
358-
359-
*captured_time = capt_time;
328+
result = nrfx_grtc_syscounter_cc_value_read(chan, captured_time);
329+
__ASSERT_NO_MSG(*captured_time < COUNTER_SPAN);
360330

361331
return 0;
362332
}
@@ -369,7 +339,7 @@ uint64_t z_nrf_grtc_timer_startup_value_get(void)
369339
#if defined(CONFIG_POWEROFF) && defined(CONFIG_NRF_GRTC_START_SYSCOUNTER)
370340
int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us)
371341
{
372-
nrfx_err_t err_code;
342+
int err_code;
373343
static uint8_t systemoff_channel;
374344
uint64_t now = counter();
375345
nrfx_grtc_sleep_config_t sleep_cfg;
@@ -392,9 +362,9 @@ int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us)
392362
k_spinlock_key_t key = k_spin_lock(&lock);
393363

394364
err_code = nrfx_grtc_channel_alloc(&systemoff_channel);
395-
if (err_code != NRFX_SUCCESS) {
365+
if (err_code < 0) {
396366
k_spin_unlock(&lock, key);
397-
return -ENOMEM;
367+
return err_code;
398368
}
399369
(void)nrfx_grtc_syscounter_cc_int_disable(systemoff_channel);
400370
ret = compare_set(systemoff_channel,
@@ -459,7 +429,7 @@ uint32_t sys_clock_elapsed(void)
459429

460430
static int sys_clock_driver_init(void)
461431
{
462-
nrfx_err_t err_code;
432+
int err_code;
463433

464434
IRQ_CONNECT(DT_IRQN(GRTC_NODE), DT_IRQ(GRTC_NODE, priority), nrfx_isr,
465435
nrfx_grtc_irq_handler, 0);
@@ -477,19 +447,19 @@ static int sys_clock_driver_init(void)
477447
#endif
478448

479449
err_code = nrfx_grtc_init(0);
480-
if (err_code != NRFX_SUCCESS) {
481-
return -EPERM;
450+
if (err_code < 0) {
451+
return err_code;
482452
}
483453

484454
#if defined(CONFIG_NRF_GRTC_START_SYSCOUNTER)
485455
err_code = nrfx_grtc_syscounter_start(true, &system_clock_channel_data.channel);
486-
if (err_code != NRFX_SUCCESS) {
487-
return err_code == NRFX_ERROR_NO_MEM ? -ENOMEM : -EPERM;
456+
if (err_code < 0) {
457+
return err_code;
488458
}
489459
#else
490460
err_code = nrfx_grtc_channel_alloc(&system_clock_channel_data.channel);
491-
if (err_code != NRFX_SUCCESS) {
492-
return -ENOMEM;
461+
if (err_code < 0) {
462+
return err_code;
493463
}
494464
#endif /* CONFIG_NRF_GRTC_START_SYSCOUNTER */
495465

0 commit comments

Comments
 (0)