source: rtems/cpukit/score/include/rtems/score/tod.h @ 63f786e

4.104.114.84.95
Last change on this file since 63f786e was 63f786e, checked in by Joel Sherrill <joel.sherrill@…>, on 04/05/07 at 22:13:08

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

  • itron/src/itrontime.c: Fix typo.
  • score/include/rtems/score/tod.h: Add TOD_TICKS_PER_SECOND macro.
  • score/src/iterateoverthreads.c: Safely take NULL as argument.
  • score/src/threaddispatch.c: Formatting.
  • Property mode set to 100644
File size: 6.1 KB
RevLine 
[baff4da]1/**
[11874561]2 *  @file  rtems/score/tod.h
[ac7d5ef0]3 *
4 *  This include file contains all the constants and structures associated
5 *  with the Time of Day Handler.
[baff4da]6 */
7
8/*
[812da54]9 *  COPYRIGHT (c) 1989-2007.
[ac7d5ef0]10 *  On-Line Applications Research Corporation (OAR).
11 *
[98e4ebf5]12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
[dd687d97]14 *  http://www.rtems.com/license/LICENSE.
[ac7d5ef0]15 *
16 *  $Id$
17 */
18
[092f142a]19#ifndef _RTEMS_SCORE_TOD_H
20#define _RTEMS_SCORE_TOD_H
[ac7d5ef0]21
[baff4da]22/**
23 *  @defgroup ScoreTOD Time Of Day (TOD) Handler
24 *
[6a07436]25 *  This handler encapsulates functionality used to manage time of day.
[baff4da]26 */
27/**@{*/
28
[ac7d5ef0]29#ifdef __cplusplus
30extern "C" {
31#endif
32
[5e9b32b]33#include <rtems/score/object.h>
[812da54]34#include <time.h>
[ac7d5ef0]35
[baff4da]36/** @defgroup ScoreTODConstants TOD Constants
[ac7d5ef0]37 *  The following constants are related to the time of day.
38 */
[baff4da]39/**@{*/
[ac7d5ef0]40
[baff4da]41/**
[6a07436]42 *  This constant represents the number of seconds in a minute.
[baff4da]43 */
[6a07436]44#define TOD_SECONDS_PER_MINUTE (uint32_t)60
[baff4da]45
46/**
[6a07436]47 *  This constant represents the number of minutes per hour.
[baff4da]48 */
[6a07436]49#define TOD_MINUTES_PER_HOUR   (uint32_t)60
[baff4da]50
51/**
[6a07436]52 *  This constant represents the number of months in a year.
[baff4da]53 */
[6a07436]54#define TOD_MONTHS_PER_YEAR    (uint32_t)12
[baff4da]55
56/**
[6a07436]57 *  This constant represents the number of days in a non-leap year.
[baff4da]58 */
[6a07436]59#define TOD_DAYS_PER_YEAR      (uint32_t)365
[baff4da]60
61/**
[6a07436]62 *  This constant represents the number of hours per day.
[baff4da]63 */
[6a07436]64#define TOD_HOURS_PER_DAY      (uint32_t)24
[baff4da]65
66/**
[6a07436]67 *  This constant represents the number of seconds in a day which does
68 *  not include a leap second.
[baff4da]69 */
[6a07436]70#define TOD_SECONDS_PER_DAY    (uint32_t) (TOD_SECONDS_PER_MINUTE * \
[ac7d5ef0]71                                TOD_MINUTES_PER_HOUR   * \
72                                TOD_HOURS_PER_DAY)
73
[baff4da]74/**
[6a07436]75 *  This constant represents the number of seconds in a non-leap year.
[baff4da]76 */
[5e9b32b]77#define TOD_SECONDS_PER_NON_LEAP_YEAR (365 * TOD_SECONDS_PER_DAY)
78
[baff4da]79/**
[6a07436]80 *  This constant represents the number of seconds in a millisecond.
[baff4da]81 */
[6a07436]82#define TOD_MILLISECONDS_PER_SECOND     (uint32_t)1000
[baff4da]83
84/**
[6a07436]85 *  This constant represents the number of microseconds in a second.
[baff4da]86 */
[6a07436]87#define TOD_MICROSECONDS_PER_SECOND     (uint32_t)1000000
[baff4da]88
89/**
[6a07436]90 *  This constant represents the number of nanoseconds in a second.
[baff4da]91 */
[6a07436]92#define TOD_NANOSECONDS_PER_SECOND      (uint32_t)1000000000
[baff4da]93
94/**
[6a07436]95 *  This constant represents the number of nanoseconds in a second.
[baff4da]96 */
[6a07436]97#define TOD_NANOSECONDS_PER_MICROSECOND (uint32_t)1000
[ac7d5ef0]98
[812da54]99/*
100 *  Seconds from January 1, 1970 to January 1, 1988.  Used to account for
101 *  differences between POSIX API and RTEMS core. The timespec format time
102 *  is kept in POSIX compliant form.
103 */
104#define TOD_SECONDS_1970_THROUGH_1988 \
105  (((1987 - 1970 + 1)  * TOD_SECONDS_PER_NON_LEAP_YEAR) + \
106  (4 * TOD_SECONDS_PER_DAY))
107
[baff4da]108/**@}*/
109
[63f786e]110/**  @brief Ticks per Second
111 * 
112 *  This macro calculates the number of ticks per second.
113 */
114
115#define TOD_TICKS_PER_SECOND \
116           (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick)
117
[baff4da]118/** @brief RTEMS Epoch Year
119 *
[ac7d5ef0]120 *  The following constant define the earliest year to which an
[3a4ae6c]121 *  time of day can be initialized.  This is considered the
[ac7d5ef0]122 *  epoch.
123 */
124#define TOD_BASE_YEAR 1988
125
[baff4da]126/** @brief Is the Time Of Day Set
127 *
128 *  This is TRUE if the application has set the current
[7fea679b]129 *  time of day, and FALSE otherwise.
130 */
131SCORE_EXTERN boolean _TOD_Is_set;
132
[812da54]133/** @brief Current Time of Day (Timespec)
[ac7d5ef0]134 *  The following contains the current time of day.
135 */
[812da54]136SCORE_EXTERN struct timespec _TOD_Now;
137
138/** @brief Current Time of Day (Timespec)
139 *  The following contains the running uptime.
140 */
141SCORE_EXTERN struct timespec _TOD_Uptime;
[ac7d5ef0]142
[baff4da]143/** @brief Seconds Since RTEMS Epoch
[ac7d5ef0]144 *  The following contains the number of seconds from 00:00:00
145 *  January 1, TOD_BASE_YEAR until the current time of day.
146 */
[412dbff6]147#define _TOD_Seconds_since_epoch (_TOD_Now.tv_sec)
[ac7d5ef0]148
[baff4da]149/** @brief Microseconds per Clock Tick
150 *
[ac7d5ef0]151 *  The following contains the number of microseconds per tick.
152 */
[d6154c7]153SCORE_EXTERN uint32_t   _TOD_Microseconds_per_tick;
[ac7d5ef0]154
[baff4da]155/** @brief _TOD_Handler_initialization
[ac7d5ef0]156 *
157 *  This routine performs the initialization necessary for this handler.
158 */
159void _TOD_Handler_initialization(
[d6154c7]160  uint32_t   microseconds_per_tick
[ac7d5ef0]161);
162
[baff4da]163/** @brief _TOD_Set
[ac7d5ef0]164 *
[812da54]165 *  This routine sets the current time of day to @a time and
[ac7d5ef0]166 *  the equivalent SECONDS_SINCE_EPOCH.
167 */
168void _TOD_Set(
[812da54]169  const struct timespec *time
[ac7d5ef0]170);
171
[812da54]172/** @brief _TOD_Get
[ac7d5ef0]173 *
[812da54]174 *  This routine returns the current time of day with potential accuracy
175 *  to the nanosecond. 
[ac7d5ef0]176 *
[812da54]177 *  @param[in] time is a pointer to the time to be returned
[ac7d5ef0]178 */
[812da54]179void _TOD_Get(
180  struct timespec *time
[ac7d5ef0]181);
182
[812da54]183/** @brief _TOD_Get_uptime
184 *
185 *  This routine returns the system uptime with potential accuracy
186 *  to the nanosecond. 
[ac7d5ef0]187 *
[812da54]188 *  @param[in] time is a pointer to the uptime to be returned
[ac7d5ef0]189 */
[812da54]190void _TOD_Get_uptime(
191  struct timespec *time
[ac7d5ef0]192);
193
[fc054ca]194/**
195 *  This routine increments the ticks field of the current time of
196 *  day at each clock tick.
197 */
198void _TOD_Tickle_ticks( void );
199
[baff4da]200/** @brief TOD_MILLISECONDS_TO_MICROSECONDS
[ac7d5ef0]201 *
202 *  This routine converts an interval expressed in milliseconds to microseconds.
203 *
[baff4da]204 *  @note This must be a macro so it can be used in "static" tables.
[ac7d5ef0]205 */
[cf04e8ac]206#define TOD_MILLISECONDS_TO_MICROSECONDS(_ms) ((uint32_t)(_ms) * 1000L)
[ac7d5ef0]207
[baff4da]208/** @brief TOD_MICROSECONDS_TO_TICKS
[0a6fb22]209 *
210 *  This routine converts an interval expressed in microseconds to ticks.
211 *
[baff4da]212 *  @note This must be a macro so it can be used in "static" tables.
[0a6fb22]213 */
214#define TOD_MICROSECONDS_TO_TICKS(_us) \
215    ((_us) / _TOD_Microseconds_per_tick)
216
[baff4da]217/** @brief TOD_MILLISECONDS_TO_TICKS
[ac7d5ef0]218 *
219 *  This routine converts an interval expressed in milliseconds to ticks.
220 *
[baff4da]221 *  @note This must be a macro so it can be used in "static" tables.
[ac7d5ef0]222 */
223
[3a4ae6c]224#define TOD_MILLISECONDS_TO_TICKS(_ms) \
225    (TOD_MILLISECONDS_TO_MICROSECONDS(_ms) / _TOD_Microseconds_per_tick)
[ac7d5ef0]226
[412dbff6]227
228/** @brief How many ticks in a second?
229 *
230 *  This macro returns the number of ticks in a second.
231 *
232 *  @note If the clock tick value does not multiply evenly into a second
233 *        then this number of ticks will be slightly shorter than a second.
234 */
235#define TOD_TICKS_PER_SECOND \
236  (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick)
237
[1a8fde6c]238#ifndef __RTEMS_APPLICATION__
[5e9b32b]239#include <rtems/score/tod.inl>
[1a8fde6c]240#endif
[ac7d5ef0]241
242#ifdef __cplusplus
243}
244#endif
245
[baff4da]246/**@}*/
247
[ac7d5ef0]248#endif
249/* end of include file */
Note: See TracBrowser for help on using the repository browser.