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

4.104.114.84.95
Last change on this file since dd61160 was dd61160, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/07 at 19:45:50

2007-05-11 Joel Sherrill <joel.sherrill@…>

  • base_sp/Makefile.am, hello/Makefile.am, iostream/Makefile.am, loopback/Makefile.am, nsecs/Makefile.am, pppd/Makefile.am, ticker/Makefile.am, ticker/system.h, unlimited/Makefile.am: Add optional managers to Makefiles. Clean up test cases so last output line follows END OF pattern. Make sure test case all run. All tests appeared ok on sis.
  • nsecs/init.c: Commit hack so test will compile when POSIX is disabled. Remove hack when clock_gettime() is present even when --disable-posix.
  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[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
25char *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
33void 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
44volatile int i;
45rtems_task Init(
46  rtems_task_argument argument
47)
48{
49  rtems_status_code status;
50  rtems_time_of_day time;
51  int index;
52
53  puts( "\n\n*** NANOSECOND CLOCK TEST ***" );
54
55  time.year   = 2007;
56  time.month  = 03;
57  time.day    = 24;
58  time.hour   = 11;
59  time.minute = 15;
60  time.second = 0;
61  time.ticks  = 0;
62
63  status = rtems_clock_set( &time );
64
65  /*
66   *  Iterate 10 times showing difference in TOD
67   */
68  printf( "10 iterations of getting TOD\n" );
69  for (index=0 ; index <10 ; index++ ) {
70    struct timespec start, stop;
71    struct timespec diff;
[dd61160]72#if 0
[23a0105a]73    clock_gettime( CLOCK_REALTIME, &start );
74    clock_gettime( CLOCK_REALTIME, &stop );
[dd61160]75#else
76    _TOD_Get( &start );
77    _TOD_Get( &stop );
78#endif
[23a0105a]79
80    subtract_em( &start, &stop, &diff );
81    printf( "Start: %s:%d\nStop : %s:%d",
82      my_ctime(start.tv_sec), start.tv_nsec,
83      my_ctime(stop.tv_sec), stop.tv_nsec
84    );
85
86   printf( " --> %d:%d\n", diff.tv_sec, diff.tv_nsec );
87  }
88
89  /*
90   *  Iterate 10 times showing difference in Uptime
91   */
92  printf( "\n10 iterations of getting Uptime\n" );
93  for (index=0 ; index <10 ; index++ ) {
94    struct timespec start, stop;
95    struct timespec diff;
96    rtems_clock_get_uptime( &start );
97    rtems_clock_get_uptime( &stop );
98
99    subtract_em( &start, &stop, &diff );
100    printf( "%d:%d %d:%d --> %d:%d\n",
101      start.tv_sec, start.tv_nsec,
102      stop.tv_sec, stop.tv_nsec,
103      diff.tv_sec, diff.tv_nsec
104   );
105  }
106
107  puts( "*** END OF NANOSECOND CLOCK TEST ***" );
108  exit(0);
109}
110
111
112#include <bsp.h> /* for device driver prototypes */
113
114#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
115#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
116
117#define CONFIGURE_MICROSECONDS_PER_TICK 1000
118#define CONFIGURE_MAXIMUM_TASKS            1
119#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
120
121#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.