@@ -91,20 +91,6 @@ static inline uint64_t counter(void)
9191 return nrfx_grtc_syscounter_get ();
9292}
9393
94- static inline int get_comparator (uint32_t chan , uint64_t * cc )
95- {
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 ;
106- }
107-
10894/*
10995 * Program a new callback <value> microseconds in the future
11096 */
@@ -173,15 +159,15 @@ static void sys_clock_timeout_handler(int32_t id, uint64_t cc_val, void *p_conte
173159int32_t z_nrf_grtc_timer_chan_alloc (void )
174160{
175161 uint8_t chan ;
176- nrfx_err_t err_code ;
162+ int ret ;
177163
178164 /* Prevent allocating all available channels - one must be left for system purposes. */
179165 if (ext_channels_allocated >= EXT_CHAN_COUNT ) {
180166 return - ENOMEM ;
181167 }
182- err_code = nrfx_grtc_channel_alloc (& chan );
183- if (err_code != NRFX_SUCCESS ) {
184- return - ENOMEM ;
168+ ret = nrfx_grtc_channel_alloc (& chan );
169+ if (ret != 0 ) {
170+ return ret ;
185171 }
186172 ext_channels_allocated ++ ;
187173 return (int32_t )chan ;
@@ -190,9 +176,9 @@ int32_t z_nrf_grtc_timer_chan_alloc(void)
190176void z_nrf_grtc_timer_chan_free (int32_t chan )
191177{
192178 IS_CHANNEL_ALLOWED_ASSERT (chan );
193- nrfx_err_t err_code = nrfx_grtc_channel_free (chan );
179+ int ret = nrfx_grtc_channel_free (chan );
194180
195- if (err_code == NRFX_SUCCESS ) {
181+ if (ret == 0 ) {
196182 ext_channels_allocated -- ;
197183 }
198184}
@@ -243,25 +229,20 @@ int z_nrf_grtc_timer_compare_read(int32_t chan, uint64_t *val)
243229{
244230 IS_CHANNEL_ALLOWED_ASSERT (chan );
245231
246- return get_comparator (chan , val );
232+ return nrfx_grtc_syscounter_cc_value_read (chan , val );
247233}
248234
249235static int compare_set_nolocks (int32_t chan , uint64_t target_time ,
250236 z_nrf_grtc_timer_compare_handler_t handler , void * user_data )
251237{
252- nrfx_err_t result ;
253-
254238 __ASSERT_NO_MSG (target_time < COUNTER_SPAN );
255239 nrfx_grtc_channel_t user_channel_data = {
256240 .handler = handler ,
257241 .p_context = user_data ,
258242 .channel = chan ,
259243 };
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 ;
244+
245+ return nrfx_grtc_syscounter_cc_absolute_set (& user_channel_data , target_time , true);
265246}
266247
267248static int compare_set (int32_t chan , uint64_t target_time ,
@@ -314,21 +295,14 @@ int z_nrf_grtc_timer_capture_prepare(int32_t chan)
314295 .p_context = NULL ,
315296 .channel = chan ,
316297 };
317- nrfx_err_t result ;
318298
319299 IS_CHANNEL_ALLOWED_ASSERT (chan );
320300
321301 /* Set the CC value to mark channel as not triggered and also to enable it
322302 * (makes CCEN=1). COUNTER_SPAN is used so as not to fire an event unnecessarily
323303 * - it can be assumed that such a large value will never be reached.
324304 */
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 ;
305+ return nrfx_grtc_syscounter_cc_absolute_set (& user_channel_data , COUNTER_SPAN , false);
332306}
333307
334308int z_nrf_grtc_timer_capture_read (int32_t chan , uint64_t * captured_time )
@@ -338,7 +312,7 @@ int z_nrf_grtc_timer_capture_read(int32_t chan, uint64_t *captured_time)
338312 */
339313
340314 uint64_t capt_time ;
341- nrfx_err_t result ;
315+ int result ;
342316
343317 IS_CHANNEL_ALLOWED_ASSERT (chan );
344318
@@ -350,8 +324,8 @@ int z_nrf_grtc_timer_capture_read(int32_t chan, uint64_t *captured_time)
350324 return - EBUSY ;
351325 }
352326 result = nrfx_grtc_syscounter_cc_value_read (chan , & capt_time );
353- if (result != NRFX_SUCCESS ) {
354- return - EPERM ;
327+ if (result != 0 ) {
328+ return result ;
355329 }
356330
357331 __ASSERT_NO_MSG (capt_time < COUNTER_SPAN );
@@ -369,7 +343,6 @@ uint64_t z_nrf_grtc_timer_startup_value_get(void)
369343#if defined(CONFIG_POWEROFF ) && defined(CONFIG_NRF_GRTC_START_SYSCOUNTER )
370344int z_nrf_grtc_wakeup_prepare (uint64_t wake_time_us )
371345{
372- nrfx_err_t err_code ;
373346 static uint8_t systemoff_channel ;
374347 uint64_t now = counter ();
375348 nrfx_grtc_sleep_config_t sleep_cfg ;
@@ -391,10 +364,10 @@ int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us)
391364
392365 k_spinlock_key_t key = k_spin_lock (& lock );
393366
394- err_code = nrfx_grtc_channel_alloc (& systemoff_channel );
395- if (err_code != NRFX_SUCCESS ) {
367+ ret = nrfx_grtc_channel_alloc (& systemoff_channel );
368+ if (ret != 0 ) {
396369 k_spin_unlock (& lock , key );
397- return - ENOMEM ;
370+ return ret ;
398371 }
399372 (void )nrfx_grtc_syscounter_cc_int_disable (systemoff_channel );
400373 ret = compare_set (systemoff_channel ,
@@ -459,7 +432,7 @@ uint32_t sys_clock_elapsed(void)
459432
460433static int sys_clock_driver_init (void )
461434{
462- nrfx_err_t err_code ;
435+ int ret ;
463436
464437 IRQ_CONNECT (DT_IRQN (GRTC_NODE ), DT_IRQ (GRTC_NODE , priority ), nrfx_isr ,
465438 nrfx_grtc_irq_handler , 0 );
@@ -476,20 +449,20 @@ static int sys_clock_driver_init(void)
476449#endif
477450#endif
478451
479- err_code = nrfx_grtc_init (0 );
480- if (err_code != NRFX_SUCCESS ) {
481- return - EPERM ;
452+ ret = nrfx_grtc_init (0 );
453+ if (ret != 0 ) {
454+ return ret ;
482455 }
483456
484457#if defined(CONFIG_NRF_GRTC_START_SYSCOUNTER )
485- 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 ;
458+ ret = nrfx_grtc_syscounter_start (true, & system_clock_channel_data .channel );
459+ if (ret != 0 ) {
460+ return ret ;
488461 }
489462#else
490- err_code = nrfx_grtc_channel_alloc (& system_clock_channel_data .channel );
491- if (err_code != NRFX_SUCCESS ) {
492- return - ENOMEM ;
463+ ret = nrfx_grtc_channel_alloc (& system_clock_channel_data .channel );
464+ if (ret != 0 ) {
465+ return ret ;
493466 }
494467#endif /* CONFIG_NRF_GRTC_START_SYSCOUNTER */
495468
0 commit comments