source: rtems/c/src/exec/rtems/src/clockget.c @ df49c60

4.104.114.84.95
Last change on this file since df49c60 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 2.3 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.OARcorp.com/rtems/license.html.
10 *
11 *  $Id$
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
40rtems_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}
Note: See TracBrowser for help on using the repository browser.