source: rtems/testsuites/samples/nsecs/init.c @ cf08e7b

4.104.115
Last change on this file since cf08e7b was cf08e7b, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/26/09 at 09:13:53

Include "tmacros.h" instead of "rprintf.h"

  • Property mode set to 100644
File size: 3.4 KB
Line 
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 <unistd.h>
23#include <sys/time.h>
24#include <rtems/score/timespec.h> /* _Timespec_Substract */
25#include "tmacros.h"
26
27char *my_ctime( time_t t )
28{
29  static char b[32];
30  ctime_r(&t, b);
31  b[ strlen(b) - 1] = '\0';
32  return b;
33}
34
35void subtract_em(
36  struct timespec *start,
37  struct timespec *stop,
38  struct timespec *t
39)
40{
41  t->tv_sec = 0;
42  t->tv_nsec = 0;
43  _Timespec_Subtract( start, stop, t );
44}
45
46/* body below .. hoping it isn't inlined */
47extern void dummy_function_empty_body_to_force_call(void);
48
49rtems_task Init(
50  rtems_task_argument argument
51)
52{
53  rtems_status_code status;
54  rtems_time_of_day time;
55  int index;
56
57  puts( "\n\n*** NANOSECOND CLOCK TEST ***" );
58
59  time.year   = 2007;
60  time.month  = 03;
61  time.day    = 24;
62  time.hour   = 11;
63  time.minute = 15;
64  time.second = 0;
65  time.ticks  = 0;
66
67  status = rtems_clock_set( &time );
68
69  /*
70   *  Iterate 10 times showing difference in TOD
71   */
72  printf( "10 iterations of getting TOD\n" );
73  for (index=0 ; index <10 ; index++ ) {
74    struct timespec start, stop;
75    struct timespec diff;
76#if 0
77    clock_gettime( CLOCK_REALTIME, &start );
78    clock_gettime( CLOCK_REALTIME, &stop );
79#else
80    _TOD_Get( &start );
81    _TOD_Get( &stop );
82#endif
83
84    subtract_em( &start, &stop, &diff );
85    printf( "Start: %s:%ld\nStop : %s:%ld",
86      my_ctime(start.tv_sec), start.tv_nsec,
87      my_ctime(stop.tv_sec), stop.tv_nsec
88    );
89
90   printf( " --> %" PRItime_t ":%ld\n", diff.tv_sec, diff.tv_nsec );
91  }
92
93  /*
94   *  Iterate 10 times showing difference in Uptime
95   */
96  printf( "\n10 iterations of getting Uptime\n" );
97  for (index=0 ; index <10 ; index++ ) {
98    struct timespec start, stop;
99    struct timespec diff;
100    rtems_clock_get_uptime( &start );
101    rtems_clock_get_uptime( &stop );
102
103    subtract_em( &start, &stop, &diff );
104    printf( "%" PRItime_t ":%ld %" PRItime_t ":%ld --> %" PRItime_t ":%ld\n",
105      start.tv_sec, start.tv_nsec,
106      stop.tv_sec, stop.tv_nsec,
107      diff.tv_sec, diff.tv_nsec
108   );
109  }
110
111  /*
112   *  Iterate 10 times showing difference in Uptime with different counts
113   */
114  printf( "\n10 iterations of getting Uptime with different loop values\n" );
115  for (index=1 ; index <=10 ; index++ ) {
116    struct timespec start, stop;
117    struct timespec diff;
118    int j, max = (index * 10000);
119    rtems_clock_get_uptime( &start );
120      for (j=0 ; j<max ; j++ )
121        dummy_function_empty_body_to_force_call();
122    rtems_clock_get_uptime( &stop );
123
124    subtract_em( &start, &stop, &diff );
125    printf( "loop of %d %" PRItime_t ":%ld %" PRItime_t ":%ld --> %" PRItime_t ":%ld\n",
126      max,
127      start.tv_sec, start.tv_nsec,
128      stop.tv_sec, stop.tv_nsec,
129      diff.tv_sec, diff.tv_nsec
130   );
131  }
132
133  sleep(1);
134
135  puts( "*** END OF NANOSECOND CLOCK TEST ***" );
136  exit(0);
137}
138
139
140#include <bsp.h> /* for device driver prototypes */
141
142#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
143#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
144
145#define CONFIGURE_MICROSECONDS_PER_TICK 1000
146#define CONFIGURE_MAXIMUM_TASKS            1
147#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
148
149#include <rtems/confdefs.h>
150
Note: See TracBrowser for help on using the repository browser.