diff --git a/drivers/timer/nrf_rtc_timer.c b/drivers/timer/nrf_rtc_timer.c index 35946154cd9..38b31671e44 100644 --- a/drivers/timer/nrf_rtc_timer.c +++ b/drivers/timer/nrf_rtc_timer.c @@ -51,27 +51,27 @@ static uint32_t counter_sub(uint32_t a, uint32_t b) return (a - b) & COUNTER_MAX; } -static void set_comparator(uint32_t chan, uint32_t cyc) +static void set_comparator(int32_t chan, uint32_t cyc) { nrf_rtc_cc_set(RTC, chan, cyc & COUNTER_MAX); } -static uint32_t get_comparator(uint32_t chan) +static uint32_t get_comparator(int32_t chan) { return nrf_rtc_cc_get(RTC, chan); } -static void event_clear(uint32_t chan) +static void event_clear(int32_t chan) { nrf_rtc_event_clear(RTC, RTC_CHANNEL_EVENT_ADDR(chan)); } -static void event_enable(uint32_t chan) +static void event_enable(int32_t chan) { nrf_rtc_event_enable(RTC, RTC_CHANNEL_INT_MASK(chan)); } -static void event_disable(uint32_t chan) +static void event_disable(int32_t chan) { nrf_rtc_event_disable(RTC, RTC_CHANNEL_INT_MASK(chan)); } @@ -86,13 +86,13 @@ uint32_t z_nrf_rtc_timer_read(void) return nrf_rtc_counter_get(RTC); } -uint32_t z_nrf_rtc_timer_compare_evt_address_get(uint32_t chan) +uint32_t z_nrf_rtc_timer_compare_evt_address_get(int32_t chan) { __ASSERT_NO_MSG(chan < CHAN_COUNT); return nrf_rtc_event_address_get(RTC, nrf_rtc_compare_event_get(chan)); } -bool z_nrf_rtc_timer_compare_int_lock(uint32_t chan) +bool z_nrf_rtc_timer_compare_int_lock(int32_t chan) { __ASSERT_NO_MSG(chan && chan < CHAN_COUNT); @@ -103,7 +103,7 @@ bool z_nrf_rtc_timer_compare_int_lock(uint32_t chan) return prev & BIT(chan); } -void z_nrf_rtc_timer_compare_int_unlock(uint32_t chan, bool key) +void z_nrf_rtc_timer_compare_int_unlock(int32_t chan, bool key) { __ASSERT_NO_MSG(chan && chan < CHAN_COUNT); @@ -113,7 +113,7 @@ void z_nrf_rtc_timer_compare_int_unlock(uint32_t chan, bool key) } } -uint32_t z_nrf_rtc_timer_compare_read(uint32_t chan) +uint32_t z_nrf_rtc_timer_compare_read(int32_t chan) { __ASSERT_NO_MSG(chan < CHAN_COUNT); @@ -154,7 +154,7 @@ int z_nrf_rtc_timer_get_ticks(k_timeout_t t) * less than COUNTER_HALF_SPAN from now. It detects late setting and also * handle +1 cycle case. */ -static void set_absolute_alarm(uint32_t chan, uint32_t abs_val) +static void set_absolute_alarm(int32_t chan, uint32_t abs_val) { uint32_t now; uint32_t now2; @@ -203,7 +203,7 @@ static void set_absolute_alarm(uint32_t chan, uint32_t abs_val) (counter_sub(cc_val, now2 + 2) > COUNTER_HALF_SPAN)); } -static void compare_set(uint32_t chan, uint32_t cc_value, +static void compare_set(int32_t chan, uint32_t cc_value, z_nrf_rtc_timer_compare_handler_t handler, void *user_data) { @@ -213,7 +213,7 @@ static void compare_set(uint32_t chan, uint32_t cc_value, set_absolute_alarm(chan, cc_value); } -void z_nrf_rtc_timer_compare_set(uint32_t chan, uint32_t cc_value, +void z_nrf_rtc_timer_compare_set(int32_t chan, uint32_t cc_value, z_nrf_rtc_timer_compare_handler_t handler, void *user_data) { @@ -226,7 +226,7 @@ void z_nrf_rtc_timer_compare_set(uint32_t chan, uint32_t cc_value, z_nrf_rtc_timer_compare_int_unlock(chan, key); } -static void sys_clock_timeout_handler(uint32_t chan, +static void sys_clock_timeout_handler(int32_t chan, uint32_t cc_value, void *user_data) { @@ -258,7 +258,7 @@ void rtc_nrf_isr(const void *arg) { ARG_UNUSED(arg); - for (uint32_t chan = 0; chan < CHAN_COUNT; chan++) { + for (int32_t chan = 0; chan < CHAN_COUNT; chan++) { if (nrf_rtc_int_enable_check(RTC, RTC_CHANNEL_INT_MASK(chan)) && nrf_rtc_event_check(RTC, RTC_CHANNEL_EVENT_ADDR(chan))) { uint32_t cc_val; @@ -277,9 +277,9 @@ void rtc_nrf_isr(const void *arg) } } -int z_nrf_rtc_timer_chan_alloc(void) +int32_t z_nrf_rtc_timer_chan_alloc(void) { - int chan; + int32_t chan; atomic_val_t prev; do { chan = alloc_mask ? 31 - __builtin_clz(alloc_mask) : -1; @@ -292,7 +292,7 @@ int z_nrf_rtc_timer_chan_alloc(void) return chan; } -void z_nrf_rtc_timer_chan_free(uint32_t chan) +void z_nrf_rtc_timer_chan_free(int32_t chan) { __ASSERT_NO_MSG(chan && chan < CHAN_COUNT); @@ -311,7 +311,7 @@ int sys_clock_driver_init(const struct device *dev) /* TODO: replace with counter driver to access RTC */ nrf_rtc_prescaler_set(RTC, 0); - for (uint32_t chan = 0; chan < CHAN_COUNT; chan++) { + for (int32_t chan = 0; chan < CHAN_COUNT; chan++) { nrf_rtc_int_enable(RTC, RTC_CHANNEL_INT_MASK(chan)); } diff --git a/include/drivers/timer/nrf_rtc_timer.h b/include/drivers/timer/nrf_rtc_timer.h index 321289c4907..f4b502edffc 100644 --- a/include/drivers/timer/nrf_rtc_timer.h +++ b/include/drivers/timer/nrf_rtc_timer.h @@ -11,7 +11,7 @@ extern "C" { #endif -typedef void (*z_nrf_rtc_timer_compare_handler_t)(uint32_t id, +typedef void (*z_nrf_rtc_timer_compare_handler_t)(int32_t id, uint32_t cc_value, void *user_data); @@ -22,13 +22,13 @@ typedef void (*z_nrf_rtc_timer_compare_handler_t)(uint32_t id, * @retval Non-negative indicates allocated channel ID. * @retval -ENOMEM if channel cannot be allocated. */ -int z_nrf_rtc_timer_chan_alloc(void); +int32_t z_nrf_rtc_timer_chan_alloc(void); /** @brief Free RTC compare channel. * * @param chan Previously allocated channel ID. */ -void z_nrf_rtc_timer_chan_free(uint32_t chan); +void z_nrf_rtc_timer_chan_free(int32_t chan); /** @brief Read current RTC counter value. * @@ -44,7 +44,7 @@ uint32_t z_nrf_rtc_timer_read(void); * * @return Register address. */ -uint32_t z_nrf_rtc_timer_compare_evt_address_get(uint32_t chan); +uint32_t z_nrf_rtc_timer_compare_evt_address_get(int32_t chan); /** @brief Safely disable compare event interrupt. * @@ -54,7 +54,7 @@ uint32_t z_nrf_rtc_timer_compare_evt_address_get(uint32_t chan); * * @return key passed to @ref z_nrf_rtc_timer_compare_int_unlock. */ -bool z_nrf_rtc_timer_compare_int_lock(uint32_t chan); +bool z_nrf_rtc_timer_compare_int_lock(int32_t chan); /** @brief Safely enable compare event interrupt. * @@ -64,7 +64,7 @@ bool z_nrf_rtc_timer_compare_int_lock(uint32_t chan); * * @param key Key returned by @ref z_nrf_rtc_timer_compare_int_lock. */ -void z_nrf_rtc_timer_compare_int_unlock(uint32_t chan, bool key); +void z_nrf_rtc_timer_compare_int_unlock(int32_t chan, bool key); /** @brief Read compare register value. * @@ -72,7 +72,7 @@ void z_nrf_rtc_timer_compare_int_unlock(uint32_t chan, bool key); * * @return Value set in the compare register. */ -uint32_t z_nrf_rtc_timer_compare_read(uint32_t chan); +uint32_t z_nrf_rtc_timer_compare_read(int32_t chan); /** @brief Try to set compare channel to given value. * @@ -95,7 +95,7 @@ uint32_t z_nrf_rtc_timer_compare_read(uint32_t chan); * * @param user_data Data passed to the handler. */ -void z_nrf_rtc_timer_compare_set(uint32_t chan, uint32_t cc_value, +void z_nrf_rtc_timer_compare_set(int32_t chan, uint32_t cc_value, z_nrf_rtc_timer_compare_handler_t handler, void *user_data); diff --git a/modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_lp_timer_zephyr.c b/modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_lp_timer_zephyr.c index 2d862d63bfb..11d430a1195 100644 --- a/modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_lp_timer_zephyr.c +++ b/modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_lp_timer_zephyr.c @@ -17,10 +17,10 @@ static volatile bool m_clock_ready; static bool m_is_running; -static uint32_t m_rtc_channel; +static int32_t m_rtc_channel; static bool m_in_critical_section; -void rtc_irq_handler(uint32_t id, uint32_t cc_value, void *user_data) +void rtc_irq_handler(int32_t id, uint32_t cc_value, void *user_data) { (void)cc_value; (void)user_data; @@ -81,11 +81,8 @@ void nrf_802154_lp_timer_init(void) /* Intentionally empty */ } - int32_t chan = z_nrf_rtc_timer_chan_alloc(); - - if (chan >= 0) { - m_rtc_channel = (uint32_t)chan; - } else { + m_rtc_channel = z_nrf_rtc_timer_chan_alloc(); + if (m_rtc_channel < 0) { assert(false); return; }