diff --git a/drivers/timer/nrf_grtc_timer.c b/drivers/timer/nrf_grtc_timer.c index b0593e3bd135e..d72b4f3a2c1c7 100644 --- a/drivers/timer/nrf_grtc_timer.c +++ b/drivers/timer/nrf_grtc_timer.c @@ -95,16 +95,7 @@ static inline uint64_t counter(void) static inline int get_comparator(uint32_t chan, uint64_t *cc) { - nrfx_err_t result; - - result = nrfx_grtc_syscounter_cc_value_read(chan, cc); - if (result != NRFX_SUCCESS) { - if (result != NRFX_ERROR_INVALID_PARAM) { - return -EAGAIN; - } - return -EPERM; - } - return 0; + return nrfx_grtc_syscounter_cc_value_read(chan, cc); } /* @@ -175,14 +166,14 @@ static void sys_clock_timeout_handler(int32_t id, uint64_t cc_val, void *p_conte int32_t z_nrf_grtc_timer_chan_alloc(void) { uint8_t chan; - nrfx_err_t err_code; + int err_code; /* Prevent allocating all available channels - one must be left for system purposes. */ if (ext_channels_allocated >= EXT_CHAN_COUNT) { return -ENOMEM; } err_code = nrfx_grtc_channel_alloc(&chan); - if (err_code != NRFX_SUCCESS) { + if (err_code < 0) { return -ENOMEM; } ext_channels_allocated++; @@ -192,9 +183,9 @@ int32_t z_nrf_grtc_timer_chan_alloc(void) void z_nrf_grtc_timer_chan_free(int32_t chan) { IS_CHANNEL_ALLOWED_ASSERT(chan); - nrfx_err_t err_code = nrfx_grtc_channel_free(chan); + int err_code = nrfx_grtc_channel_free(chan); - if (err_code == NRFX_SUCCESS) { + if (err_code == 0) { ext_channels_allocated--; } } @@ -251,19 +242,13 @@ int z_nrf_grtc_timer_compare_read(int32_t chan, uint64_t *val) static int compare_set_nolocks(int32_t chan, uint64_t target_time, z_nrf_grtc_timer_compare_handler_t handler, void *user_data) { - nrfx_err_t result; - __ASSERT_NO_MSG(target_time < COUNTER_SPAN); nrfx_grtc_channel_t user_channel_data = { .handler = handler, .p_context = user_data, .channel = chan, }; - result = nrfx_grtc_syscounter_cc_absolute_set(&user_channel_data, target_time, true); - if (result != NRFX_SUCCESS) { - return -EPERM; - } - return 0; + return nrfx_grtc_syscounter_cc_absolute_set(&user_channel_data, target_time, true); } static int compare_set(int32_t chan, uint64_t target_time, @@ -316,7 +301,6 @@ int z_nrf_grtc_timer_capture_prepare(int32_t chan) .p_context = NULL, .channel = chan, }; - nrfx_err_t result; IS_CHANNEL_ALLOWED_ASSERT(chan); @@ -324,19 +308,12 @@ int z_nrf_grtc_timer_capture_prepare(int32_t chan) * (makes CCEN=1). COUNTER_SPAN is used so as not to fire an event unnecessarily * - it can be assumed that such a large value will never be reached. */ - result = nrfx_grtc_syscounter_cc_absolute_set(&user_channel_data, COUNTER_SPAN, false); - - if (result != NRFX_SUCCESS) { - return -EPERM; - } - - return 0; + return nrfx_grtc_syscounter_cc_absolute_set(&user_channel_data, COUNTER_SPAN, false); } int z_nrf_grtc_timer_capture_read(int32_t chan, uint64_t *captured_time) { - uint64_t capt_time; - nrfx_err_t result; + int result; IS_CHANNEL_ALLOWED_ASSERT(chan); @@ -346,15 +323,13 @@ int z_nrf_grtc_timer_capture_read(int32_t chan, uint64_t *captured_time) */ return -EBUSY; } - result = nrfx_grtc_syscounter_cc_value_read(chan, &capt_time); - if (result != NRFX_SUCCESS) { - return -EPERM; - } - __ASSERT_NO_MSG(capt_time < COUNTER_SPAN); - - *captured_time = capt_time; + result = nrfx_grtc_syscounter_cc_value_read(chan, captured_time); + if (result < 0) { + return result; + } + __ASSERT_NO_MSG(*captured_time < COUNTER_SPAN); return 0; } @@ -366,7 +341,7 @@ uint64_t z_nrf_grtc_timer_startup_value_get(void) #if defined(CONFIG_POWEROFF) && defined(CONFIG_NRF_GRTC_START_SYSCOUNTER) int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us) { - nrfx_err_t err_code; + int err_code; static uint8_t systemoff_channel; uint64_t now = counter(); nrfx_grtc_sleep_config_t sleep_cfg; @@ -389,9 +364,9 @@ int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us) k_spinlock_key_t key = k_spin_lock(&lock); err_code = nrfx_grtc_channel_alloc(&systemoff_channel); - if (err_code != NRFX_SUCCESS) { + if (err_code < 0) { k_spin_unlock(&lock, key); - return -ENOMEM; + return err_code; } (void)nrfx_grtc_syscounter_cc_int_disable(systemoff_channel); ret = compare_set(systemoff_channel, @@ -465,7 +440,7 @@ ISR_DIRECT_DECLARE(nrfx_grtc_direct_irq_handler) static int sys_clock_driver_init(void) { - nrfx_err_t err_code; + int err_code; #if defined(CONFIG_GEN_SW_ISR_TABLE) IRQ_CONNECT(DT_IRQN(GRTC_NODE), DT_IRQ(GRTC_NODE, priority), nrfx_isr, @@ -489,19 +464,19 @@ static int sys_clock_driver_init(void) #endif err_code = nrfx_grtc_init(0); - if (err_code != NRFX_SUCCESS) { - return -EPERM; + if (err_code < 0) { + return err_code; } #if defined(CONFIG_NRF_GRTC_START_SYSCOUNTER) err_code = nrfx_grtc_syscounter_start(true, &system_clock_channel_data.channel); - if (err_code != NRFX_SUCCESS) { - return err_code == NRFX_ERROR_NO_MEM ? -ENOMEM : -EPERM; + if (err_code < 0) { + return err_code; } #else err_code = nrfx_grtc_channel_alloc(&system_clock_channel_data.channel); - if (err_code != NRFX_SUCCESS) { - return -ENOMEM; + if (err_code < 0) { + return err_code; } #endif /* CONFIG_NRF_GRTC_START_SYSCOUNTER */