OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [libcsupport/] [src/] [__gettod.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  gettimeofday() - SVR4 and BSD4.3 extension required by Newlib
3
 *
4
 *  COPYRIGHT (c) 1989-1999.
5
 *  On-Line Applications Research Corporation (OAR).
6
 *
7
 *  The license and distribution terms for this file may be
8
 *  found in the file LICENSE in this distribution or at
9
 *  http://www.OARcorp.com/rtems/license.html.
10
 *
11
 *  __gettod.c,v 1.15 2001/01/08 18:26:44 joel Exp
12
 */
13
 
14
#if HAVE_CONFIG_H
15
#include "config.h"
16
#endif
17
 
18
#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
19
 
20
#include <rtems.h>
21
 
22
#if !defined(RTEMS_UNIX)
23
#ifdef RTEMS_NEWLIB
24
#include <sys/reent.h>
25
#endif
26
 
27
#include <sys/time.h>
28
#include <time.h>
29
 
30
#include <errno.h>
31
#include <assert.h>
32
 
33
/*
34
 *  Seconds from January 1, 1970 to January 1, 1988.  Used to account for
35
 *  differences between POSIX API and RTEMS core.
36
 */
37
 
38
#define POSIX_TIME_SECONDS_1970_THROUGH_1988 \
39
  (((1987 - 1970 + 1)  * TOD_SECONDS_PER_NON_LEAP_YEAR) + \
40
  (4 * TOD_SECONDS_PER_DAY))
41
 
42
/*
43
 *  NOTE:  The solaris gettimeofday does not have a second parameter.
44
 */
45
 
46
int gettimeofday(
47
  struct timeval  *tp,
48
  struct timezone *tzp
49
)
50
{
51
  rtems_interrupt_level level;
52
  rtems_unsigned32      seconds;
53
  rtems_unsigned32      microseconds;
54
 
55
  if ( !tp ) {
56
    errno = EFAULT;
57
    return -1;
58
  }
59
 
60
  /*
61
   *  POSIX does not seem to allow for not having a TOD so we just
62
   *  grab the time of day.
63
   *
64
   *  NOTE: XXX this routine should really be in the executive proper.
65
   */
66
 
67
  rtems_interrupt_disable(level);
68
    seconds      = _TOD_Seconds_since_epoch;
69
    microseconds = _TOD_Current.ticks;
70
  rtems_interrupt_enable(level);
71
 
72
  tp->tv_sec  = seconds + POSIX_TIME_SECONDS_1970_THROUGH_1988;
73
  tp->tv_usec = microseconds * _TOD_Microseconds_per_tick;
74
 
75
  /*
76
   * newlib does not have timezone and daylight savings time
77
   * yet.  When it does this needs to be fixed.
78
   */
79
 
80
#if 0
81
  if ( tzp ) {
82
    tzp->tz_minuteswest = 0;  /* at UTC */
83
    tzp->tz_dsttime = 0;      /* no daylight savings */
84
  tzp->minuteswest = timezone / 60; /* from seconds to minutes */
85
  tzp->dsttime = daylight;
86
  }
87
#endif
88
  return 0;
89
}
90
 
91
#if defined(RTEMS_NEWLIB)
92
 
93
/*
94
 *  "Reentrant" version
95
 */
96
 
97
int _gettimeofday_r(
98
  struct _reent   *ignored_reentrancy_stuff,
99
  struct timeval  *tp,
100
  struct timezone *tzp
101
)
102
{
103
  return gettimeofday( tp, tzp );
104
}
105
 
106
/*
107
 *  "System call" version
108
 */
109
 
110
int _gettimeofday(
111
  struct timeval  *tp,
112
  struct timezone *tzp
113
)
114
{
115
  return gettimeofday( tp, tzp );
116
}
117
 
118
#endif /* defined(RTEMS_NEWLIB) */
119
 
120
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.