Skip to content

Commit 2401f2f

Browse files
committed
boards/arm/am67/t3-gem-o1: Improve timer_gettime implementation
- Add DEBUGASSERT to validate timespec parameter - Store timer value in temporary variable for clarity - Calculate tv_nsec and tv_sec from timer count - Return OK instead of raw timer value for proper error handling Signed-off-by: Nazmi Aras <nazmi.aras@t3gemstone.org>
1 parent 77423f9 commit 2401f2f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

arch/arm/src/am67/am67_timer.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ int timer_tick_isr(int irq, void *context, void *arg)
397397
am67_timer_clear_overflow_int(AM67_DMTIMER1_1MS_TIMER0_VADDR);
398398

399399
nxsched_process_timer();
400-
return 0;
400+
return OK;
401401
}
402402

403403
/****************************************************************************
@@ -435,7 +435,16 @@ int timer_tick_isr(int irq, void *context, void *arg)
435435

436436
int up_timer_gettime(struct timespec *ts)
437437
{
438-
return am67_timer_get_count(AM67_DMTIMER1_1MS_TIMER0_VADDR);
438+
uint64_t internal_timer;
439+
440+
DEBUGASSERT(ts != NULL);
441+
442+
internal_timer = am67_timer_get_count(AM67_DMTIMER1_1MS_TIMER0_VADDR);
443+
444+
ts->tv_nsec = (uint32_t)(internal_timer * 1000000);
445+
ts->tv_sec = (uint32_t)(internal_timer / 1000 );
446+
447+
return OK;
439448
}
440449

441450
/****************************************************************************
@@ -448,8 +457,9 @@ int up_timer_gettime(struct timespec *ts)
448457

449458
int up_timer_start(struct timespec const *ts)
450459
{
460+
DEBUGASSERT(ts != NULL);
451461
am67_timer_start(AM67_DMTIMER1_1MS_TIMER0_VADDR);
452-
return 0;
462+
return OK;
453463
}
454464

455465
/****************************************************************************
@@ -462,8 +472,9 @@ int up_timer_start(struct timespec const *ts)
462472

463473
int up_timer_cancel(struct timespec *ts)
464474
{
475+
DEBUGASSERT(ts != NULL);
465476
am67_timer_stop(AM67_DMTIMER1_1MS_TIMER0_VADDR);
466-
return 0;
477+
return OK;
467478
}
468479

469480
/****************************************************************************

0 commit comments

Comments
 (0)