[23a0105a] | 1 | /* |
---|
| 2 | * Nanoseconds accuracy timestamp test |
---|
[8ff5e59d] | 3 | */ |
---|
| 4 | |
---|
| 5 | /* COPYRIGHT (c) 1989-2007. |
---|
[23a0105a] | 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> |
---|
[587da8b8] | 23 | #include <rtems/score/timespec.h> /* _Timespec_Substract */ |
---|
[23a0105a] | 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; |
---|
[8ff5e59d] | 41 | _Timespec_Subtract( start, stop, t ); |
---|
[23a0105a] | 42 | } |
---|
| 43 | |
---|
[8bfffd9b] | 44 | /* body below .. hoping it isn't inlined */ |
---|
| 45 | void Empty_function(); |
---|
| 46 | |
---|
[23a0105a] | 47 | rtems_task Init( |
---|
| 48 | rtems_task_argument argument |
---|
| 49 | ) |
---|
| 50 | { |
---|
| 51 | rtems_status_code status; |
---|
| 52 | rtems_time_of_day time; |
---|
| 53 | int index; |
---|
| 54 | |
---|
| 55 | puts( "\n\n*** NANOSECOND CLOCK TEST ***" ); |
---|
| 56 | |
---|
| 57 | time.year = 2007; |
---|
| 58 | time.month = 03; |
---|
| 59 | time.day = 24; |
---|
| 60 | time.hour = 11; |
---|
| 61 | time.minute = 15; |
---|
| 62 | time.second = 0; |
---|
| 63 | time.ticks = 0; |
---|
| 64 | |
---|
| 65 | status = rtems_clock_set( &time ); |
---|
| 66 | |
---|
| 67 | /* |
---|
| 68 | * Iterate 10 times showing difference in TOD |
---|
| 69 | */ |
---|
| 70 | printf( "10 iterations of getting TOD\n" ); |
---|
| 71 | for (index=0 ; index <10 ; index++ ) { |
---|
| 72 | struct timespec start, stop; |
---|
| 73 | struct timespec diff; |
---|
[dd61160] | 74 | #if 0 |
---|
[23a0105a] | 75 | clock_gettime( CLOCK_REALTIME, &start ); |
---|
| 76 | clock_gettime( CLOCK_REALTIME, &stop ); |
---|
[dd61160] | 77 | #else |
---|
| 78 | _TOD_Get( &start ); |
---|
| 79 | _TOD_Get( &stop ); |
---|
| 80 | #endif |
---|
[23a0105a] | 81 | |
---|
| 82 | subtract_em( &start, &stop, &diff ); |
---|
| 83 | printf( "Start: %s:%d\nStop : %s:%d", |
---|
| 84 | my_ctime(start.tv_sec), start.tv_nsec, |
---|
| 85 | my_ctime(stop.tv_sec), stop.tv_nsec |
---|
| 86 | ); |
---|
| 87 | |
---|
| 88 | printf( " --> %d:%d\n", diff.tv_sec, diff.tv_nsec ); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | /* |
---|
| 92 | * Iterate 10 times showing difference in Uptime |
---|
| 93 | */ |
---|
| 94 | printf( "\n10 iterations of getting Uptime\n" ); |
---|
| 95 | for (index=0 ; index <10 ; index++ ) { |
---|
| 96 | struct timespec start, stop; |
---|
| 97 | struct timespec diff; |
---|
| 98 | rtems_clock_get_uptime( &start ); |
---|
| 99 | rtems_clock_get_uptime( &stop ); |
---|
| 100 | |
---|
| 101 | subtract_em( &start, &stop, &diff ); |
---|
| 102 | printf( "%d:%d %d:%d --> %d:%d\n", |
---|
| 103 | start.tv_sec, start.tv_nsec, |
---|
| 104 | stop.tv_sec, stop.tv_nsec, |
---|
| 105 | diff.tv_sec, diff.tv_nsec |
---|
| 106 | ); |
---|
| 107 | } |
---|
| 108 | |
---|
[d3b05790] | 109 | /* |
---|
| 110 | * Iterate 10 times showing difference in Uptime with different counts |
---|
| 111 | */ |
---|
| 112 | printf( "\n10 iterations of getting Uptime with different loop values\n" ); |
---|
| 113 | for (index=1 ; index <=10 ; index++ ) { |
---|
| 114 | struct timespec start, stop; |
---|
| 115 | struct timespec diff; |
---|
| 116 | int j, max = (index * 10000); |
---|
| 117 | rtems_clock_get_uptime( &start ); |
---|
| 118 | for (j=0 ; j<max ; j++ ) |
---|
| 119 | Empty_function(); |
---|
| 120 | rtems_clock_get_uptime( &stop ); |
---|
| 121 | |
---|
| 122 | subtract_em( &start, &stop, &diff ); |
---|
| 123 | printf( "loop of %d %d:%d %d:%d --> %d:%d\n", |
---|
| 124 | max, |
---|
| 125 | start.tv_sec, start.tv_nsec, |
---|
| 126 | stop.tv_sec, stop.tv_nsec, |
---|
| 127 | diff.tv_sec, diff.tv_nsec |
---|
| 128 | ); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | sleep(1); |
---|
| 132 | |
---|
[23a0105a] | 133 | puts( "*** END OF NANOSECOND CLOCK TEST ***" ); |
---|
| 134 | exit(0); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | #include <bsp.h> /* for device driver prototypes */ |
---|
| 139 | |
---|
| 140 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 141 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 142 | |
---|
| 143 | #define CONFIGURE_MICROSECONDS_PER_TICK 1000 |
---|
| 144 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
| 145 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 146 | |
---|
| 147 | #include <rtems/confdefs.h> |
---|
[8bfffd9b] | 148 | |
---|
| 149 | /* put here hoping it won't get inlined */ |
---|
| 150 | void Empty_function() {} |
---|