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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  clockgettime.c,v 1.4 2002/01/04 18:28:24 joel Exp
3
 */
4
 
5
#if HAVE_CONFIG_H
6
#include "config.h"
7
#endif
8
 
9
#include <assert.h>
10
#include <time.h>
11
#include <errno.h>
12
 
13
#include <rtems/system.h>
14
#include <rtems/score/isr.h>
15
#include <rtems/score/thread.h>
16
#include <rtems/score/tod.h>
17
 
18
#include <rtems/seterr.h>
19
#include <rtems/posix/time.h>
20
 
21
/*PAGE
22
 *
23
 *  14.2.1 Clocks, P1003.1b-1993, p. 263
24
 */
25
 
26
int clock_gettime(
27
  clockid_t        clock_id,
28
  struct timespec *tp
29
)
30
{
31
  ISR_Level      level;
32
  time_t         seconds;
33
  long           ticks;
34
 
35
  if ( !tp )
36
    rtems_set_errno_and_return_minus_one( EINVAL );
37
 
38
  switch ( clock_id ) {
39
 
40
    case CLOCK_REALTIME:
41
 
42
      _ISR_Disable( level );
43
        seconds = _TOD_Seconds_since_epoch;
44
        ticks   = _TOD_Current.ticks;
45
      _ISR_Enable( level );
46
 
47
      tp->tv_sec  = seconds + POSIX_TIME_SECONDS_1970_THROUGH_1988;
48
      tp->tv_nsec = ticks * _TOD_Microseconds_per_tick *
49
                      TOD_NANOSECONDS_PER_MICROSECOND;
50
      break;
51
 
52
#ifdef _POSIX_CPUTIME
53
    case CLOCK_PROCESS_CPUTIME:
54
      /* don't base this on _Watchdog_Ticks_since_boot--duration is too short*/
55
      return POSIX_NOT_IMPLEMENTED();
56
      break;
57
#endif
58
 
59
#ifdef _POSIX_THREAD_CPUTIME
60
    case CLOCK_THREAD_CPUTIME:
61
      return POSIX_NOT_IMPLEMENTED();
62
      break;
63
#endif
64
    default:
65
      rtems_set_errno_and_return_minus_one( EINVAL );
66
 
67
  }
68
  return 0;
69
}

powered by: WebSVN 2.1.0

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