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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libc/] [__gettod.c] - Blame information for rev 173

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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