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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [rtems/] [src/] [clockget.c] - Blame information for rev 595

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  Clock Manager
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: clockget.c,v 1.2 2001-09-27 11:59:19 chris Exp $
12
 */
13
 
14
#include <rtems/system.h>
15
#include <rtems/rtems/status.h>
16
#include <rtems/rtems/clock.h>
17
#include <rtems/score/isr.h>
18
#include <rtems/score/thread.h>
19
#include <rtems/score/tod.h>
20
#include <rtems/score/watchdog.h>
21
 
22
/*PAGE
23
 *
24
 *  rtems_clock_get
25
 *
26
 *  This directive returns the current date and time.  If the time has
27
 *  not been set by a tm_set then an error is returned.
28
 *
29
 *  Input parameters:
30
 *    option      - which value to return
31
 *    time_buffer - pointer to output buffer (a time and date structure
32
 *                  or an interval)
33
 *
34
 *  Output parameters:
35
 *    time_buffer      - output filled in
36
 *    RTEMS_SUCCESSFUL - if successful
37
 *    error code       - if unsuccessful
38
 */
39
 
40
rtems_status_code rtems_clock_get(
41
  rtems_clock_get_options  option,
42
  void                    *time_buffer
43
)
44
{
45
  ISR_Level      level;
46
  rtems_interval tmp;
47
 
48
  switch ( option ) {
49
    case RTEMS_CLOCK_GET_TOD:
50
      if ( !_TOD_Is_set )
51
        return RTEMS_NOT_DEFINED;
52
 
53
      *(rtems_time_of_day *)time_buffer = _TOD_Current;
54
      return RTEMS_SUCCESSFUL;
55
 
56
    case RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH:
57
      if ( !_TOD_Is_set )
58
        return RTEMS_NOT_DEFINED;
59
 
60
      *(rtems_interval *)time_buffer = _TOD_Seconds_since_epoch;
61
      return RTEMS_SUCCESSFUL;
62
 
63
    case RTEMS_CLOCK_GET_TICKS_SINCE_BOOT:
64
      *(rtems_interval *)time_buffer = _Watchdog_Ticks_since_boot;
65
      return RTEMS_SUCCESSFUL;
66
 
67
    case RTEMS_CLOCK_GET_TICKS_PER_SECOND:
68
      *(rtems_interval *)time_buffer = _TOD_Ticks_per_second;
69
      return RTEMS_SUCCESSFUL;
70
 
71
    case RTEMS_CLOCK_GET_TIME_VALUE:
72
      if ( !_TOD_Is_set )
73
        return RTEMS_NOT_DEFINED;
74
 
75
      _ISR_Disable( level );
76
        ((rtems_clock_time_value *)time_buffer)->seconds =
77
          _TOD_Seconds_since_epoch;
78
        tmp = _TOD_Current.ticks;
79
      _ISR_Enable( level );
80
 
81
      tmp *= _TOD_Microseconds_per_tick;
82
      ((rtems_clock_time_value *)time_buffer)->microseconds = tmp;
83
 
84
      return RTEMS_SUCCESSFUL;
85
  }
86
 
87
  return RTEMS_INTERNAL_ERROR;   /* should never get here */
88
 
89
}

powered by: WebSVN 2.1.0

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