source: rtems/testsuites/samples/nsecs/init.c @ 5f0cd34

4.11
Last change on this file since 5f0cd34 was 5f0cd34, checked in by Joel Sherrill <joel.sherrill@…>, on May 12, 2012 at 4:12:57 PM

samples - Eliminate missing prototype warnings

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