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

4.104.114.84.95
Last change on this file since bd83f47 was bd83f47, checked in by Joel Sherrill <joel.sherrill@…>, on 05/17/99 at 22:42:47

Split Clock Manager into one routine per file.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  Clock Manager
3 *
4 *  COPYRIGHT (c) 1989-1998.
5 *  On-Line Applications Research Corporation (OAR).
6 *  Copyright assigned to U.S. Government, 1994.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#include <rtems/system.h>
16#include <rtems/rtems/status.h>
17#include <rtems/rtems/clock.h>
18#include <rtems/score/isr.h>
19#include <rtems/score/thread.h>
20#include <rtems/score/tod.h>
21#include <rtems/score/watchdog.h>
22
23/*PAGE
24 *
25 *  rtems_clock_get
26 *
27 *  This directive returns the current date and time.  If the time has
28 *  not been set by a tm_set then an error is returned.
29 *
30 *  Input parameters:
31 *    option      - which value to return
32 *    time_buffer - pointer to output buffer (a time and date structure
33 *                  or an interval)
34 *
35 *  Output parameters:
36 *    time_buffer      - output filled in
37 *    RTEMS_SUCCESSFUL - if successful
38 *    error code       - if unsuccessful
39 */
40
41rtems_status_code rtems_clock_get(
42  rtems_clock_get_options  option,
43  void                    *time_buffer
44)
45{
46  ISR_Level      level;
47  rtems_interval tmp;
48
49  switch ( option ) {
50    case RTEMS_CLOCK_GET_TOD:
51      if ( !_TOD_Is_set )
52        return RTEMS_NOT_DEFINED;
53
54      *(rtems_time_of_day *)time_buffer = _TOD_Current;
55      return RTEMS_SUCCESSFUL;
56
57    case RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH:
58      if ( !_TOD_Is_set )
59        return RTEMS_NOT_DEFINED;
60
61      *(rtems_interval *)time_buffer = _TOD_Seconds_since_epoch;
62      return RTEMS_SUCCESSFUL;
63
64    case RTEMS_CLOCK_GET_TICKS_SINCE_BOOT:
65      *(rtems_interval *)time_buffer = _Watchdog_Ticks_since_boot;
66      return RTEMS_SUCCESSFUL;
67
68    case RTEMS_CLOCK_GET_TICKS_PER_SECOND:
69      *(rtems_interval *)time_buffer = _TOD_Ticks_per_second;
70      return RTEMS_SUCCESSFUL;
71
72    case RTEMS_CLOCK_GET_TIME_VALUE:
73      if ( !_TOD_Is_set )
74        return RTEMS_NOT_DEFINED;
75
76      _ISR_Disable( level );
77        ((rtems_clock_time_value *)time_buffer)->seconds =
78          _TOD_Seconds_since_epoch;
79        tmp = _TOD_Current.ticks;
80      _ISR_Enable( level );
81
82      tmp *= _TOD_Microseconds_per_tick;
83      ((rtems_clock_time_value *)time_buffer)->microseconds = tmp;
84
85      return RTEMS_SUCCESSFUL;
86  }
87
88  return RTEMS_INTERNAL_ERROR;   /* should never get here */
89
90}
Note: See TracBrowser for help on using the repository browser.