1 | /* |
---|
2 | * Nanoseconds accuracy timestamp test |
---|
3 | */ |
---|
4 | |
---|
5 | /* COPYRIGHT (c) 1989-2007. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.com/license/LICENSE. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #define CONFIGURE_INIT |
---|
16 | |
---|
17 | #include <rtems.h> |
---|
18 | #include <inttypes.h> |
---|
19 | #include <stdio.h> |
---|
20 | #include <string.h> |
---|
21 | #include <stdlib.h> |
---|
22 | #include <sys/time.h> |
---|
23 | #include <rtems/score/timespec.h> /* _Timespec_Substract */ |
---|
24 | |
---|
25 | char *my_ctime( time_t t ) |
---|
26 | { |
---|
27 | static char b[32]; |
---|
28 | ctime_r(&t, b); |
---|
29 | b[ strlen(b) - 1] = '\0'; |
---|
30 | return b; |
---|
31 | } |
---|
32 | |
---|
33 | void subtract_em( |
---|
34 | struct timespec *start, |
---|
35 | struct timespec *stop, |
---|
36 | struct timespec *t |
---|
37 | ) |
---|
38 | { |
---|
39 | t->tv_sec = 0; |
---|
40 | t->tv_nsec = 0; |
---|
41 | _Timespec_Subtract( start, stop, t ); |
---|
42 | } |
---|
43 | |
---|
44 | rtems_task Init( |
---|
45 | rtems_task_argument argument |
---|
46 | ) |
---|
47 | { |
---|
48 | rtems_status_code status; |
---|
49 | rtems_time_of_day time; |
---|
50 | int index; |
---|
51 | |
---|
52 | puts( "\n\n*** NANOSECOND CLOCK TEST ***" ); |
---|
53 | |
---|
54 | time.year = 2007; |
---|
55 | time.month = 03; |
---|
56 | time.day = 24; |
---|
57 | time.hour = 11; |
---|
58 | time.minute = 15; |
---|
59 | time.second = 0; |
---|
60 | time.ticks = 0; |
---|
61 | |
---|
62 | status = rtems_clock_set( &time ); |
---|
63 | |
---|
64 | /* |
---|
65 | * Iterate 10 times showing difference in TOD |
---|
66 | */ |
---|
67 | printf( "10 iterations of getting TOD\n" ); |
---|
68 | for (index=0 ; index <10 ; index++ ) { |
---|
69 | struct timespec start, stop; |
---|
70 | struct timespec diff; |
---|
71 | #if 0 |
---|
72 | clock_gettime( CLOCK_REALTIME, &start ); |
---|
73 | clock_gettime( CLOCK_REALTIME, &stop ); |
---|
74 | #else |
---|
75 | _TOD_Get( &start ); |
---|
76 | _TOD_Get( &stop ); |
---|
77 | #endif |
---|
78 | |
---|
79 | subtract_em( &start, &stop, &diff ); |
---|
80 | printf( "Start: %s:%d\nStop : %s:%d", |
---|
81 | my_ctime(start.tv_sec), start.tv_nsec, |
---|
82 | my_ctime(stop.tv_sec), stop.tv_nsec |
---|
83 | ); |
---|
84 | |
---|
85 | printf( " --> %d:%d\n", diff.tv_sec, diff.tv_nsec ); |
---|
86 | } |
---|
87 | |
---|
88 | /* |
---|
89 | * Iterate 10 times showing difference in Uptime |
---|
90 | */ |
---|
91 | printf( "\n10 iterations of getting Uptime\n" ); |
---|
92 | for (index=0 ; index <10 ; index++ ) { |
---|
93 | struct timespec start, stop; |
---|
94 | struct timespec diff; |
---|
95 | rtems_clock_get_uptime( &start ); |
---|
96 | rtems_clock_get_uptime( &stop ); |
---|
97 | |
---|
98 | subtract_em( &start, &stop, &diff ); |
---|
99 | printf( "%d:%d %d:%d --> %d:%d\n", |
---|
100 | start.tv_sec, start.tv_nsec, |
---|
101 | stop.tv_sec, stop.tv_nsec, |
---|
102 | diff.tv_sec, diff.tv_nsec |
---|
103 | ); |
---|
104 | } |
---|
105 | |
---|
106 | /* |
---|
107 | * Iterate 10 times showing difference in Uptime with different counts |
---|
108 | */ |
---|
109 | printf( "\n10 iterations of getting Uptime with different loop values\n" ); |
---|
110 | for (index=1 ; index <=10 ; index++ ) { |
---|
111 | struct timespec start, stop; |
---|
112 | struct timespec diff; |
---|
113 | int j, max = (index * 10000); |
---|
114 | rtems_clock_get_uptime( &start ); |
---|
115 | for (j=0 ; j<max ; j++ ) |
---|
116 | Empty_function(); |
---|
117 | rtems_clock_get_uptime( &stop ); |
---|
118 | |
---|
119 | subtract_em( &start, &stop, &diff ); |
---|
120 | printf( "loop of %d %d:%d %d:%d --> %d:%d\n", |
---|
121 | max, |
---|
122 | start.tv_sec, start.tv_nsec, |
---|
123 | stop.tv_sec, stop.tv_nsec, |
---|
124 | diff.tv_sec, diff.tv_nsec |
---|
125 | ); |
---|
126 | } |
---|
127 | |
---|
128 | sleep(1); |
---|
129 | |
---|
130 | puts( "*** END OF NANOSECOND CLOCK TEST ***" ); |
---|
131 | exit(0); |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | #include <bsp.h> /* for device driver prototypes */ |
---|
136 | |
---|
137 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
138 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
139 | |
---|
140 | #define CONFIGURE_MICROSECONDS_PER_TICK 1000 |
---|
141 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
142 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
143 | |
---|
144 | #include <rtems/confdefs.h> |
---|