File indexing completed on 2025-05-11 08:24:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #ifdef HAVE_CONFIG_H
0036 #include "config.h"
0037 #endif
0038
0039 #include <rtems.h>
0040 #include <inttypes.h>
0041 #include <stdio.h>
0042 #include <string.h>
0043 #include <stdlib.h>
0044 #include <unistd.h>
0045 #include <time.h>
0046 #include <sys/time.h>
0047
0048 #define CONFIGURE_INIT
0049 #include "system.h"
0050
0051 #include <rtems/score/timespec.h> /* _Timespec_Substract */
0052
0053 #include "tmacros.h"
0054 #include "pritime.h"
0055
0056 const char rtems_test_name[] = "NANOSECOND CLOCK";
0057
0058 static char *my_ctime( time_t t )
0059 {
0060 static char b[32];
0061 ctime_r(&t, b);
0062 b[ strlen(b) - 1] = '\0';
0063 return b;
0064 }
0065
0066 static void subtract_em(
0067 struct timespec *start,
0068 struct timespec *stop,
0069 struct timespec *t
0070 )
0071 {
0072 t->tv_sec = 0;
0073 t->tv_nsec = 0;
0074 _Timespec_Subtract( start, stop, t );
0075 }
0076
0077
0078 rtems_task Init(
0079 rtems_task_argument argument
0080 )
0081 {
0082 rtems_status_code status;
0083 rtems_time_of_day time;
0084 int index;
0085
0086 TEST_BEGIN();
0087
0088 time.year = 2007;
0089 time.month = 03;
0090 time.day = 24;
0091 time.hour = 11;
0092 time.minute = 15;
0093 time.second = 0;
0094 time.ticks = 0;
0095
0096 status = rtems_clock_set( &time );
0097 directive_failed( status, "clock set" );
0098
0099
0100
0101
0102 printf( "10 iterations of getting TOD\n" );
0103 for (index=0 ; index <10 ; index++ ) {
0104 struct timespec start, stop;
0105 struct timespec diff;
0106
0107 clock_gettime( CLOCK_REALTIME, &start );
0108 clock_gettime( CLOCK_REALTIME, &stop );
0109
0110 subtract_em( &start, &stop, &diff );
0111 printf( "Start: %s:%ld\nStop : %s:%ld",
0112 my_ctime(start.tv_sec), start.tv_nsec,
0113 my_ctime(stop.tv_sec), stop.tv_nsec
0114 );
0115
0116 printf( " --> %" PRIdtime_t ":%ld\n", diff.tv_sec, diff.tv_nsec );
0117 }
0118
0119
0120
0121
0122 printf( "\n10 iterations of getting Uptime\n" );
0123 for (index=0 ; index <10 ; index++ ) {
0124 struct timespec start, stop;
0125 struct timespec diff;
0126 rtems_clock_get_uptime( &start );
0127 rtems_clock_get_uptime( &stop );
0128
0129 subtract_em( &start, &stop, &diff );
0130 printf( "%" PRIdtime_t ":%ld %" PRIdtime_t ":%ld --> %" PRIdtime_t ":%ld\n",
0131 start.tv_sec, start.tv_nsec,
0132 stop.tv_sec, stop.tv_nsec,
0133 diff.tv_sec, diff.tv_nsec
0134 );
0135 }
0136
0137
0138
0139
0140 printf( "\n10 iterations of getting Uptime with different loop values\n" );
0141 for (index=1 ; index <=10 ; index++ ) {
0142 struct timespec start, stop;
0143 struct timespec diff;
0144 long j, max = (index * 10000L);
0145 rtems_clock_get_uptime( &start );
0146 for (j=0 ; j<max ; j++ )
0147 dummy_function_empty_body_to_force_call();
0148 rtems_clock_get_uptime( &stop );
0149
0150 subtract_em( &start, &stop, &diff );
0151 printf( "loop of %ld %" PRIdtime_t
0152 ":%ld %" PRIdtime_t ":%ld --> %" PRIdtime_t ":%ld\n",
0153 max,
0154 start.tv_sec, start.tv_nsec,
0155 stop.tv_sec, stop.tv_nsec,
0156 diff.tv_sec, diff.tv_nsec
0157 );
0158 }
0159
0160 sleep(1);
0161
0162 TEST_END();
0163 exit(0);
0164 }
0165