4.115
Last change
on this file since cae389ba was
cae389ba,
checked in by Joel Sherrill <joel.sherrill@…>, on 09/01/11 at 18:24:47
|
2011-09-01 Joel Sherrill <joel.sherrilL@…>
PR 1895/cpukit
- score/src/coretodmsecstoticks.c, score/src/coretodusectoticks.c,
score/src/timespectoticks.c: Ensure time conversions to ticks do not
ignore partial tick and return 1 less than desired.
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | /** |
---|
2 | * @file score/src/timespectoticks.c |
---|
3 | */ |
---|
4 | |
---|
5 | /* |
---|
6 | * COPYRIGHT (c) 1989-2007. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.rtems.com/license/LICENSE. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #if HAVE_CONFIG_H |
---|
17 | #include "config.h" |
---|
18 | #endif |
---|
19 | |
---|
20 | #include <sys/types.h> |
---|
21 | |
---|
22 | #include <rtems/system.h> |
---|
23 | #include <rtems/config.h> |
---|
24 | #include <rtems/score/timespec.h> |
---|
25 | #include <rtems/score/tod.h> |
---|
26 | #include <rtems/score/watchdog.h> |
---|
27 | |
---|
28 | /** |
---|
29 | * |
---|
30 | * This routines converts a timespec to the corresponding number of ticks. |
---|
31 | */ |
---|
32 | |
---|
33 | uint32_t _Timespec_To_ticks( |
---|
34 | const struct timespec *time |
---|
35 | ) |
---|
36 | { |
---|
37 | uint32_t ticks; |
---|
38 | uint32_t nanoseconds_per_tick; |
---|
39 | |
---|
40 | if ( (time->tv_sec == 0) && (time->tv_nsec == 0) ) |
---|
41 | return 0; |
---|
42 | |
---|
43 | /** |
---|
44 | * We should ensure the ticks not be truncated by integer division. We |
---|
45 | * need to have it be greater than or equal to the requested time. It |
---|
46 | * should not be shorter. |
---|
47 | */ |
---|
48 | ticks = time->tv_sec * TOD_TICKS_PER_SECOND; |
---|
49 | nanoseconds_per_tick = rtems_configuration_get_nanoseconds_per_tick(); |
---|
50 | ticks += time->tv_nsec / nanoseconds_per_tick; |
---|
51 | |
---|
52 | if ( (time->tv_nsec % nanoseconds_per_tick) != 0 ) |
---|
53 | ticks += 1; |
---|
54 | |
---|
55 | return ticks; |
---|
56 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.