source: rtems/cpukit/score/inline/rtems/score/tod.inl @ 812da54

4.104.114.84.95
Last change on this file since 812da54 was 812da54, checked in by Joel Sherrill <joel.sherrill@…>, on 04/02/07 at 18:23:59

2007-04-02 Joel Sherrill <joel@…>

  • itron/src/itrontime.c, libcsupport/src/gettod.c, posix/include/rtems/posix/time.h, posix/include/rtems/posix/timer.h, posix/src/clockgettime.c, posix/src/clocksettime.c, posix/src/nanosleep.c, posix/src/posixtimespecsubtract.c, posix/src/posixtimespectointerval.c, posix/src/ptimer1.c, posix/src/sleep.c, rtems/Makefile.am, rtems/include/rtems/rtems/clock.h, rtems/include/rtems/rtems/timer.h, rtems/include/rtems/rtems/types.h, rtems/src/clockget.c, rtems/src/clockset.c, rtems/src/clocktodtoseconds.c, rtems/src/clocktodvalidate.c, rtems/src/taskwakewhen.c, score/Makefile.am, score/include/rtems/score/tod.h, score/inline/rtems/score/tod.inl, score/src/coretod.c, score/src/coretodset.c: Convert from Classic API style TOD_Control as fundamental time structure to POSIX struct timespec. Add clock_get_uptime().
  • rtems/src/clockgetuptime.c, score/src/coretodget.c, score/src/coretodgetuptime.c: New files.
  • score/src/coretodtickle.c, score/src/coretodtoseconds.c, score/src/coretodvalidate.c: Removed.
  • Property mode set to 100644
File size: 2.6 KB
Line 
1/**
2 *  @file  rtems/score/tod.inl
3 *
4 *  This file contains the static inline implementation of the inlined routines
5 *  from the Time of Day Handler.
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 *
16 *  $Id$
17 */
18
19#ifndef _RTEMS_SCORE_TOD_INL
20#define _RTEMS_SCORE_TOD_INL
21
22#include <rtems/score/isr.h>
23
24/**
25 *  @addtogroup ScoreTOD
26 *  @{
27 */
28
29/**
30 *
31 *  This routines adds two timespecs.  The second argument is added
32 *  to the first.
33 */
34
35RTEMS_INLINE_ROUTINE uint32_t _TOD_Add_timespec(
36  struct timespec *time,
37  struct timespec *add
38)
39{
40  uint32_t seconds = 0;
41
42 
43  /* Add the basics */
44  time->tv_sec += add->tv_sec;
45  time->tv_nsec += add->tv_nsec;
46
47  /* Now adjust it so nanoseconds is in range */
48  while ( time->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
49    time->tv_nsec -= TOD_NANOSECONDS_PER_SECOND;
50    time->tv_sec++;
51    seconds++;
52  }
53
54  return seconds;
55}
56
57/**
58 *  This routine increments the ticks field of the current time of
59 *  day at each clock tick.
60 */
61
62RTEMS_INLINE_ROUTINE void _TOD_Tickle_ticks( void )
63{
64  struct timespec tick;
65  uint32_t        seconds;
66
67  /* Convert the tick quantum to a timespec */
68  tick.tv_nsec = _TOD_Microseconds_per_tick * 1000;
69  tick.tv_sec  = 0;
70
71  /* Update the counter of ticks since boot */
72  _Watchdog_Ticks_since_boot += 1;
73
74  /* Update the timespec format uptime */
75  (void) _TOD_Add_timespec( &_TOD_Uptime, &tick );
76  /* we do not care how much the uptime changed */
77
78  /* Update the timespec format TOD */
79  seconds = _TOD_Add_timespec( &_TOD_Now, &tick );
80  while ( seconds ) {
81    _Watchdog_Tickle_seconds();
82    seconds--;
83  }
84}
85
86/**
87 *  This routine deactivates updating of the current time of day.
88 */
89
90RTEMS_INLINE_ROUTINE void _TOD_Deactivate( void )
91{
92  /* XXX do we need something now that we are using timespec for TOD */
93}
94
95/**
96 *  This routine activates updating of the current time of day.
97 */
98
99RTEMS_INLINE_ROUTINE void _TOD_Activate(
100  Watchdog_Interval ticks
101)
102{
103  /* XXX do we need something now that we are using timespec for TOD */
104}
105
106/**
107 *  This routine returns a timeval based upon the internal timespec format TOD.
108 */
109
110RTEMS_INLINE_ROUTINE void _TOD_Get_timeval(
111  struct timeval *time
112)
113{
114  ISR_Level level;
115  struct timespec now;
116
117  _ISR_Disable(level);
118    _TOD_Get( &now );
119  _ISR_Enable(level);
120
121  time->tv_sec  = now.tv_sec;
122  time->tv_usec = now.tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND;
123}
124
125/**@}*/
126
127#endif
128/* end of include file */
Note: See TracBrowser for help on using the repository browser.