Skip to content

Commit 7d663bf

Browse files
nordic-krchjaz1-nordic
authored andcommitted
[nrf fromlist] drivers: timer: nrf_grtc_timer: Adapt to the new nrfx_grtc API
Adapt to change in return value (nrfx_err_t to errno). Upstream PR #: 99084 Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 07fa145 commit 7d663bf

File tree

1 file changed

+20
-49
lines changed

1 file changed

+20
-49
lines changed

drivers/timer/nrf_grtc_timer.c

Lines changed: 20 additions & 49 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,27 +299,19 @@ 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
{
336-
uint64_t capt_time;
337-
nrfx_err_t result;
314+
int result;
338315

339316
IS_CHANNEL_ALLOWED_ASSERT(chan);
340317

@@ -344,14 +321,8 @@ int z_nrf_grtc_timer_capture_read(int32_t chan, uint64_t *captured_time)
344321
*/
345322
return -EBUSY;
346323
}
347-
result = nrfx_grtc_syscounter_cc_value_read(chan, &capt_time);
348-
if (result != NRFX_SUCCESS) {
349-
return -EPERM;
350-
}
351-
352-
__ASSERT_NO_MSG(capt_time < COUNTER_SPAN);
353-
354-
*captured_time = capt_time;
324+
result = nrfx_grtc_syscounter_cc_value_read(chan, captured_time);
325+
__ASSERT_NO_MSG(*captured_time < COUNTER_SPAN);
355326

356327
return 0;
357328
}
@@ -364,7 +335,7 @@ uint64_t z_nrf_grtc_timer_startup_value_get(void)
364335
#if defined(CONFIG_POWEROFF) && defined(CONFIG_NRF_GRTC_START_SYSCOUNTER)
365336
int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us)
366337
{
367-
nrfx_err_t err_code;
338+
int err_code;
368339
static uint8_t systemoff_channel;
369340
uint64_t now = counter();
370341
nrfx_grtc_sleep_config_t sleep_cfg;
@@ -387,9 +358,9 @@ int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us)
387358
k_spinlock_key_t key = k_spin_lock(&lock);
388359

389360
err_code = nrfx_grtc_channel_alloc(&systemoff_channel);
390-
if (err_code != NRFX_SUCCESS) {
361+
if (err_code < 0) {
391362
k_spin_unlock(&lock, key);
392-
return -ENOMEM;
363+
return err_code;
393364
}
394365
(void)nrfx_grtc_syscounter_cc_int_disable(systemoff_channel);
395366
ret = compare_set(systemoff_channel,
@@ -463,7 +434,7 @@ ISR_DIRECT_DECLARE(nrfx_grtc_direct_irq_handler)
463434

464435
static int sys_clock_driver_init(void)
465436
{
466-
nrfx_err_t err_code;
437+
int err_code;
467438

468439
#if defined(CONFIG_GEN_SW_ISR_TABLE)
469440
IRQ_CONNECT(DT_IRQN(GRTC_NODE), DT_IRQ(GRTC_NODE, priority), nrfx_isr,
@@ -488,19 +459,19 @@ static int sys_clock_driver_init(void)
488459
#endif
489460

490461
err_code = nrfx_grtc_init(0);
491-
if (err_code != NRFX_SUCCESS) {
492-
return -EPERM;
462+
if (err_code < 0) {
463+
return err_code;
493464
}
494465

495466
#if defined(CONFIG_NRF_GRTC_START_SYSCOUNTER)
496467
err_code = nrfx_grtc_syscounter_start(true, &system_clock_channel_data.channel);
497-
if (err_code != NRFX_SUCCESS) {
498-
return err_code == NRFX_ERROR_NO_MEM ? -ENOMEM : -EPERM;
468+
if (err_code < 0) {
469+
return err_code;
499470
}
500471
#else
501472
err_code = nrfx_grtc_channel_alloc(&system_clock_channel_data.channel);
502-
if (err_code != NRFX_SUCCESS) {
503-
return -ENOMEM;
473+
if (err_code < 0) {
474+
return err_code;
504475
}
505476
#endif /* CONFIG_NRF_GRTC_START_SYSCOUNTER */
506477

0 commit comments

Comments
 (0)