source: rtems/cpukit/rtems/src/clockget.c @ a29d2e7

4.104.114.84.95
Last change on this file since a29d2e7 was 1095ec1, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/18/05 at 09:03:45

Include config.h.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
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.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems/system.h>
19#include <rtems/rtems/status.h>
20#include <rtems/rtems/clock.h>
21#include <rtems/score/isr.h>
22#include <rtems/score/thread.h>
23#include <rtems/score/tod.h>
24#include <rtems/score/watchdog.h>
25
26/*PAGE
27 *
28 *  rtems_clock_get
29 *
30 *  This directive returns the current date and time.  If the time has
31 *  not been set by a tm_set then an error is returned.
32 *
33 *  Input parameters:
34 *    option      - which value to return
35 *    time_buffer - pointer to output buffer (a time and date structure
36 *                  or an interval)
37 *
38 *  Output parameters:
39 *    time_buffer      - output filled in
40 *    RTEMS_SUCCESSFUL - if successful
41 *    error code       - if unsuccessful
42 */
43
44rtems_status_code rtems_clock_get(
45  rtems_clock_get_options  option,
46  void                    *time_buffer
47)
48{
49  ISR_Level      level;
50  rtems_interval tmp;
51
52   if ( !time_buffer )
53     return RTEMS_INVALID_ADDRESS;
54
55  switch ( option ) {
56    case RTEMS_CLOCK_GET_TOD:
57      if ( !_TOD_Is_set )
58        return RTEMS_NOT_DEFINED;
59
60      *(rtems_time_of_day *)time_buffer = _TOD_Current;
61      return RTEMS_SUCCESSFUL;
62
63    case RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH:
64      if ( !_TOD_Is_set )
65        return RTEMS_NOT_DEFINED;
66
67      *(rtems_interval *)time_buffer = _TOD_Seconds_since_epoch;
68      return RTEMS_SUCCESSFUL;
69
70    case RTEMS_CLOCK_GET_TICKS_SINCE_BOOT:
71      *(rtems_interval *)time_buffer = _Watchdog_Ticks_since_boot;
72      return RTEMS_SUCCESSFUL;
73
74    case RTEMS_CLOCK_GET_TICKS_PER_SECOND:
75      *(rtems_interval *)time_buffer = _TOD_Ticks_per_second;
76      return RTEMS_SUCCESSFUL;
77
78    case RTEMS_CLOCK_GET_TIME_VALUE:
79      if ( !_TOD_Is_set )
80        return RTEMS_NOT_DEFINED;
81
82      _ISR_Disable( level );
83        ((rtems_clock_time_value *)time_buffer)->seconds =
84          _TOD_Seconds_since_epoch;
85        tmp = _TOD_Current.ticks;
86      _ISR_Enable( level );
87
88      tmp *= _TOD_Microseconds_per_tick;
89      ((rtems_clock_time_value *)time_buffer)->microseconds = tmp;
90
91      return RTEMS_SUCCESSFUL;
92  }
93
94  return RTEMS_INTERNAL_ERROR;   /* should never get here */
95
96}
Note: See TracBrowser for help on using the repository browser.