Skip to content

Commit ab49673

Browse files
nordic-krchcarlescufi
authored andcommitted
drivers: timer: nrf_rtc_timer: Change type of channel argument
There was an inconsistency in the API as z_nrf_rtc_timer_chan_alloc returned int but other function were using uint32_t for channel argument. Updated api to use int32_t everywhere. Update nrf_802154 driver which was using this api to use int32_t. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent b2cc526 commit ab49673

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

drivers/timer/nrf_rtc_timer.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,27 @@ static uint32_t counter_sub(uint32_t a, uint32_t b)
5151
return (a - b) & COUNTER_MAX;
5252
}
5353

54-
static void set_comparator(uint32_t chan, uint32_t cyc)
54+
static void set_comparator(int32_t chan, uint32_t cyc)
5555
{
5656
nrf_rtc_cc_set(RTC, chan, cyc & COUNTER_MAX);
5757
}
5858

59-
static uint32_t get_comparator(uint32_t chan)
59+
static uint32_t get_comparator(int32_t chan)
6060
{
6161
return nrf_rtc_cc_get(RTC, chan);
6262
}
6363

64-
static void event_clear(uint32_t chan)
64+
static void event_clear(int32_t chan)
6565
{
6666
nrf_rtc_event_clear(RTC, RTC_CHANNEL_EVENT_ADDR(chan));
6767
}
6868

69-
static void event_enable(uint32_t chan)
69+
static void event_enable(int32_t chan)
7070
{
7171
nrf_rtc_event_enable(RTC, RTC_CHANNEL_INT_MASK(chan));
7272
}
7373

74-
static void event_disable(uint32_t chan)
74+
static void event_disable(int32_t chan)
7575
{
7676
nrf_rtc_event_disable(RTC, RTC_CHANNEL_INT_MASK(chan));
7777
}
@@ -86,13 +86,13 @@ uint32_t z_nrf_rtc_timer_read(void)
8686
return nrf_rtc_counter_get(RTC);
8787
}
8888

89-
uint32_t z_nrf_rtc_timer_compare_evt_address_get(uint32_t chan)
89+
uint32_t z_nrf_rtc_timer_compare_evt_address_get(int32_t chan)
9090
{
9191
__ASSERT_NO_MSG(chan < CHAN_COUNT);
9292
return nrf_rtc_event_address_get(RTC, nrf_rtc_compare_event_get(chan));
9393
}
9494

95-
bool z_nrf_rtc_timer_compare_int_lock(uint32_t chan)
95+
bool z_nrf_rtc_timer_compare_int_lock(int32_t chan)
9696
{
9797
__ASSERT_NO_MSG(chan && chan < CHAN_COUNT);
9898

@@ -103,7 +103,7 @@ bool z_nrf_rtc_timer_compare_int_lock(uint32_t chan)
103103
return prev & BIT(chan);
104104
}
105105

106-
void z_nrf_rtc_timer_compare_int_unlock(uint32_t chan, bool key)
106+
void z_nrf_rtc_timer_compare_int_unlock(int32_t chan, bool key)
107107
{
108108
__ASSERT_NO_MSG(chan && chan < CHAN_COUNT);
109109

@@ -113,7 +113,7 @@ void z_nrf_rtc_timer_compare_int_unlock(uint32_t chan, bool key)
113113
}
114114
}
115115

116-
uint32_t z_nrf_rtc_timer_compare_read(uint32_t chan)
116+
uint32_t z_nrf_rtc_timer_compare_read(int32_t chan)
117117
{
118118
__ASSERT_NO_MSG(chan < CHAN_COUNT);
119119

@@ -154,7 +154,7 @@ int z_nrf_rtc_timer_get_ticks(k_timeout_t t)
154154
* less than COUNTER_HALF_SPAN from now. It detects late setting and also
155155
* handle +1 cycle case.
156156
*/
157-
static void set_absolute_alarm(uint32_t chan, uint32_t abs_val)
157+
static void set_absolute_alarm(int32_t chan, uint32_t abs_val)
158158
{
159159
uint32_t now;
160160
uint32_t now2;
@@ -203,7 +203,7 @@ static void set_absolute_alarm(uint32_t chan, uint32_t abs_val)
203203
(counter_sub(cc_val, now2 + 2) > COUNTER_HALF_SPAN));
204204
}
205205

206-
static void compare_set(uint32_t chan, uint32_t cc_value,
206+
static void compare_set(int32_t chan, uint32_t cc_value,
207207
z_nrf_rtc_timer_compare_handler_t handler,
208208
void *user_data)
209209
{
@@ -213,7 +213,7 @@ static void compare_set(uint32_t chan, uint32_t cc_value,
213213
set_absolute_alarm(chan, cc_value);
214214
}
215215

216-
void z_nrf_rtc_timer_compare_set(uint32_t chan, uint32_t cc_value,
216+
void z_nrf_rtc_timer_compare_set(int32_t chan, uint32_t cc_value,
217217
z_nrf_rtc_timer_compare_handler_t handler,
218218
void *user_data)
219219
{
@@ -226,7 +226,7 @@ void z_nrf_rtc_timer_compare_set(uint32_t chan, uint32_t cc_value,
226226
z_nrf_rtc_timer_compare_int_unlock(chan, key);
227227
}
228228

229-
static void sys_clock_timeout_handler(uint32_t chan,
229+
static void sys_clock_timeout_handler(int32_t chan,
230230
uint32_t cc_value,
231231
void *user_data)
232232
{
@@ -258,7 +258,7 @@ void rtc_nrf_isr(const void *arg)
258258
{
259259
ARG_UNUSED(arg);
260260

261-
for (uint32_t chan = 0; chan < CHAN_COUNT; chan++) {
261+
for (int32_t chan = 0; chan < CHAN_COUNT; chan++) {
262262
if (nrf_rtc_int_enable_check(RTC, RTC_CHANNEL_INT_MASK(chan)) &&
263263
nrf_rtc_event_check(RTC, RTC_CHANNEL_EVENT_ADDR(chan))) {
264264
uint32_t cc_val;
@@ -277,9 +277,9 @@ void rtc_nrf_isr(const void *arg)
277277
}
278278
}
279279

280-
int z_nrf_rtc_timer_chan_alloc(void)
280+
int32_t z_nrf_rtc_timer_chan_alloc(void)
281281
{
282-
int chan;
282+
int32_t chan;
283283
atomic_val_t prev;
284284
do {
285285
chan = alloc_mask ? 31 - __builtin_clz(alloc_mask) : -1;
@@ -292,7 +292,7 @@ int z_nrf_rtc_timer_chan_alloc(void)
292292
return chan;
293293
}
294294

295-
void z_nrf_rtc_timer_chan_free(uint32_t chan)
295+
void z_nrf_rtc_timer_chan_free(int32_t chan)
296296
{
297297
__ASSERT_NO_MSG(chan && chan < CHAN_COUNT);
298298

@@ -311,7 +311,7 @@ int sys_clock_driver_init(const struct device *dev)
311311

312312
/* TODO: replace with counter driver to access RTC */
313313
nrf_rtc_prescaler_set(RTC, 0);
314-
for (uint32_t chan = 0; chan < CHAN_COUNT; chan++) {
314+
for (int32_t chan = 0; chan < CHAN_COUNT; chan++) {
315315
nrf_rtc_int_enable(RTC, RTC_CHANNEL_INT_MASK(chan));
316316
}
317317

include/drivers/timer/nrf_rtc_timer.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
extern "C" {
1212
#endif
1313

14-
typedef void (*z_nrf_rtc_timer_compare_handler_t)(uint32_t id,
14+
typedef void (*z_nrf_rtc_timer_compare_handler_t)(int32_t id,
1515
uint32_t cc_value,
1616
void *user_data);
1717

@@ -22,13 +22,13 @@ typedef void (*z_nrf_rtc_timer_compare_handler_t)(uint32_t id,
2222
* @retval Non-negative indicates allocated channel ID.
2323
* @retval -ENOMEM if channel cannot be allocated.
2424
*/
25-
int z_nrf_rtc_timer_chan_alloc(void);
25+
int32_t z_nrf_rtc_timer_chan_alloc(void);
2626

2727
/** @brief Free RTC compare channel.
2828
*
2929
* @param chan Previously allocated channel ID.
3030
*/
31-
void z_nrf_rtc_timer_chan_free(uint32_t chan);
31+
void z_nrf_rtc_timer_chan_free(int32_t chan);
3232

3333
/** @brief Read current RTC counter value.
3434
*
@@ -44,7 +44,7 @@ uint32_t z_nrf_rtc_timer_read(void);
4444
*
4545
* @return Register address.
4646
*/
47-
uint32_t z_nrf_rtc_timer_compare_evt_address_get(uint32_t chan);
47+
uint32_t z_nrf_rtc_timer_compare_evt_address_get(int32_t chan);
4848

4949
/** @brief Safely disable compare event interrupt.
5050
*
@@ -54,7 +54,7 @@ uint32_t z_nrf_rtc_timer_compare_evt_address_get(uint32_t chan);
5454
*
5555
* @return key passed to @ref z_nrf_rtc_timer_compare_int_unlock.
5656
*/
57-
bool z_nrf_rtc_timer_compare_int_lock(uint32_t chan);
57+
bool z_nrf_rtc_timer_compare_int_lock(int32_t chan);
5858

5959
/** @brief Safely enable compare event interrupt.
6060
*
@@ -64,15 +64,15 @@ bool z_nrf_rtc_timer_compare_int_lock(uint32_t chan);
6464
*
6565
* @param key Key returned by @ref z_nrf_rtc_timer_compare_int_lock.
6666
*/
67-
void z_nrf_rtc_timer_compare_int_unlock(uint32_t chan, bool key);
67+
void z_nrf_rtc_timer_compare_int_unlock(int32_t chan, bool key);
6868

6969
/** @brief Read compare register value.
7070
*
7171
* @param chan Channel ID between 0 and CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT.
7272
*
7373
* @return Value set in the compare register.
7474
*/
75-
uint32_t z_nrf_rtc_timer_compare_read(uint32_t chan);
75+
uint32_t z_nrf_rtc_timer_compare_read(int32_t chan);
7676

7777
/** @brief Try to set compare channel to given value.
7878
*
@@ -95,7 +95,7 @@ uint32_t z_nrf_rtc_timer_compare_read(uint32_t chan);
9595
*
9696
* @param user_data Data passed to the handler.
9797
*/
98-
void z_nrf_rtc_timer_compare_set(uint32_t chan, uint32_t cc_value,
98+
void z_nrf_rtc_timer_compare_set(int32_t chan, uint32_t cc_value,
9999
z_nrf_rtc_timer_compare_handler_t handler,
100100
void *user_data);
101101

modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_lp_timer_zephyr.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
static volatile bool m_clock_ready;
1919
static bool m_is_running;
20-
static uint32_t m_rtc_channel;
20+
static int32_t m_rtc_channel;
2121
static bool m_in_critical_section;
2222

23-
void rtc_irq_handler(uint32_t id, uint32_t cc_value, void *user_data)
23+
void rtc_irq_handler(int32_t id, uint32_t cc_value, void *user_data)
2424
{
2525
(void)cc_value;
2626
(void)user_data;
@@ -81,11 +81,8 @@ void nrf_802154_lp_timer_init(void)
8181
/* Intentionally empty */
8282
}
8383

84-
int32_t chan = z_nrf_rtc_timer_chan_alloc();
85-
86-
if (chan >= 0) {
87-
m_rtc_channel = (uint32_t)chan;
88-
} else {
84+
m_rtc_channel = z_nrf_rtc_timer_chan_alloc();
85+
if (m_rtc_channel < 0) {
8986
assert(false);
9087
return;
9188
}

0 commit comments

Comments
 (0)