diff options
Diffstat (limited to 'cpukit/score/src/timespectoticks.c')
-rw-r--r-- | cpukit/score/src/timespectoticks.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/cpukit/score/src/timespectoticks.c b/cpukit/score/src/timespectoticks.c index ddd82e67a7..10d462976b 100644 --- a/cpukit/score/src/timespectoticks.c +++ b/cpukit/score/src/timespectoticks.c @@ -35,16 +35,22 @@ uint32_t _Timespec_To_ticks( ) { uint32_t ticks; + uint32_t nanoseconds_per_tick; if ( (time->tv_sec == 0) && (time->tv_nsec == 0) ) return 0; - ticks = time->tv_sec * TOD_TICKS_PER_SECOND; + /** + * We should ensure the ticks not be truncated by integer division. We + * need to have it be greater than or equal to the requested time. It + * should not be shorter. + */ + ticks = time->tv_sec * TOD_TICKS_PER_SECOND; + nanoseconds_per_tick = rtems_configuration_get_nanoseconds_per_tick(); + ticks += time->tv_nsec / nanoseconds_per_tick; - ticks += time->tv_nsec / rtems_configuration_get_nanoseconds_per_tick(); + if ( (time->tv_nsec % nanoseconds_per_tick) != 0 ) + ticks += 1; - if (ticks) - return ticks; - - return 1; + return ticks; } |