summaryrefslogtreecommitdiffstats
path: root/cpukit/rtems
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2007-04-02 18:23:59 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2007-04-02 18:23:59 +0000
commit812da546889eea0b6dea7eb2954f46a4c43d1314 (patch)
tree22fc95d921c3544de770454a2f9c604d5d0a27a2 /cpukit/rtems
parent2007-04-02 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-812da546889eea0b6dea7eb2954f46a4c43d1314.tar.bz2
2007-04-02 Joel Sherrill <joel@OARcorp.com>
* 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.
Diffstat (limited to 'cpukit/rtems')
-rw-r--r--cpukit/rtems/Makefile.am3
-rw-r--r--cpukit/rtems/include/rtems/rtems/clock.h37
-rw-r--r--cpukit/rtems/include/rtems/rtems/timer.h2
-rw-r--r--cpukit/rtems/include/rtems/rtems/types.h25
-rw-r--r--cpukit/rtems/src/clockget.c44
-rw-r--r--cpukit/rtems/src/clockgetuptime.c50
-rw-r--r--cpukit/rtems/src/clockset.c9
-rw-r--r--cpukit/rtems/src/clocktodtoseconds.c31
-rw-r--r--cpukit/rtems/src/clocktodvalidate.c22
-rw-r--r--cpukit/rtems/src/taskwakewhen.c1
10 files changed, 187 insertions, 37 deletions
diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am
index a12eef398f..b4bd102927 100644
--- a/cpukit/rtems/Makefile.am
+++ b/cpukit/rtems/Makefile.am
@@ -77,7 +77,8 @@ librtems_a_SOURCES += src/barrier.c src/barriercreate.c src/barrierdelete.c \
## CLOCK_C_FILES
librtems_a_SOURCES += src/rtclock.c src/clockget.c src/clockset.c \
- src/clocktick.c src/clocksetnsecshandler.c
+ src/clocktick.c src/clocksetnsecshandler.c src/clockgetuptime.c \
+ src/clocktodtoseconds.c src/clocktodvalidate.c
## TIMER_C_FILES
librtems_a_SOURCES += src/rtemstimer.c src/timercancel.c src/timercreate.c \
diff --git a/cpukit/rtems/include/rtems/rtems/clock.h b/cpukit/rtems/include/rtems/rtems/clock.h
index 67fa8ab4cd..8c20780ad1 100644
--- a/cpukit/rtems/include/rtems/rtems/clock.h
+++ b/cpukit/rtems/include/rtems/rtems/clock.h
@@ -32,6 +32,8 @@ extern "C" {
#endif
#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/rtems/status.h>
#include <rtems/rtems/types.h>
/*
@@ -122,6 +124,41 @@ rtems_status_code rtems_clock_set_nanoseconds_extension(
rtems_nanoseconds_extension_routine routine
);
+/*
+ * rtems_clock_get_uptime
+ *
+ * DESCRIPTION:
+ *
+ * This directive returns the system uptime.
+ *
+ * Input parameters:
+ * routine - pointer to the time structure
+ *
+ * Output parameters:
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+rtems_status_code rtems_clock_get_uptime(
+ struct timespec *uptime
+);
+
+/** @brief _TOD_Validate
+ *
+ * This function returns TRUE if THE_TOD contains
+ * a valid time of day, and FALSE otherwise.
+ */
+boolean _TOD_Validate(
+ rtems_time_of_day *the_tod
+);
+
+/** @brief _TOD_To_seconds
+ *
+ * This function returns the number seconds between the epoch and THE_TOD.
+ */
+Watchdog_Interval _TOD_To_seconds(
+ rtems_time_of_day *the_tod
+);
+
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/rtems/include/rtems/rtems/timer.h b/cpukit/rtems/include/rtems/rtems/timer.h
index 8048754fd4..a246678480 100644
--- a/cpukit/rtems/include/rtems/rtems/timer.h
+++ b/cpukit/rtems/include/rtems/rtems/timer.h
@@ -41,8 +41,8 @@ extern "C" {
#endif
#include <rtems/score/object.h>
-#include <rtems/score/tod.h>
#include <rtems/score/watchdog.h>
+#include <rtems/rtems/clock.h>
#include <rtems/rtems/attr.h>
/*
diff --git a/cpukit/rtems/include/rtems/rtems/types.h b/cpukit/rtems/include/rtems/rtems/types.h
index 71af603de0..310c979ef9 100644
--- a/cpukit/rtems/include/rtems/rtems/types.h
+++ b/cpukit/rtems/include/rtems/rtems/types.h
@@ -61,7 +61,30 @@ typedef Heap_Information_block region_information_block;
*/
typedef Watchdog_Interval rtems_interval;
-typedef TOD_Control rtems_time_of_day;
+
+
+/**
+ * The following record defines the time of control block. This
+ * control block is used to maintain the current time of day.
+ *
+ * @note This is an RTEID style time/date.
+ */
+typedef struct {
+ /** This field is the year, A.D. */
+ uint32_t year;
+ /** This field is the month, 1 -> 12 */
+ uint32_t month;
+ /** This field is the day, 1 -> 31 */
+ uint32_t day;
+ /** This field is the hour, 0 -> 23 */
+ uint32_t hour;
+ /** This field is the minute, 0 -> 59 */
+ uint32_t minute;
+ /** This field is the second, 0 -> 59 */
+ uint32_t second;
+ /** This field is the elapsed ticks between secs */
+ uint32_t ticks;
+} rtems_time_of_day;
/*
* Define the type for an RTEMS API task mode.
diff --git a/cpukit/rtems/src/clockget.c b/cpukit/rtems/src/clockget.c
index d8f808ce8e..f5948bcffd 100644
--- a/cpukit/rtems/src/clockget.c
+++ b/cpukit/rtems/src/clockget.c
@@ -46,20 +46,35 @@ rtems_status_code rtems_clock_get(
void *time_buffer
)
{
- ISR_Level level;
- rtems_interval tmp;
-
- if ( !time_buffer )
- return RTEMS_INVALID_ADDRESS;
+ if ( !time_buffer )
+ return RTEMS_INVALID_ADDRESS;
switch ( option ) {
- case RTEMS_CLOCK_GET_TOD:
+ case RTEMS_CLOCK_GET_TOD: {
+ struct tm time;
+ struct timeval now;
+ rtems_time_of_day *tmbuf = (rtems_time_of_day *)time_buffer;
+
if ( !_TOD_Is_set )
return RTEMS_NOT_DEFINED;
- *(rtems_time_of_day *)time_buffer = _TOD_Current;
+ /* Obtain the current time */
+ _TOD_Get_timeval( &now );
+
+ /* Split it into a closer format */
+ gmtime_r( &now.tv_sec, &time );
+
+ /* Now adjust it to the RTEMS format */
+ tmbuf->year = time.tm_year + 1900;
+ tmbuf->month = time.tm_mon + 1;
+ tmbuf->day = time.tm_mday;
+ tmbuf->hour = time.tm_hour;
+ tmbuf->minute = time.tm_min;
+ tmbuf->second = time.tm_sec;
+ tmbuf->ticks = now.tv_usec / _TOD_Microseconds_per_tick;
+
return RTEMS_SUCCESSFUL;
-
+ }
case RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH:
if ( !_TOD_Is_set )
return RTEMS_NOT_DEFINED;
@@ -75,20 +90,15 @@ rtems_status_code rtems_clock_get(
*(rtems_interval *)time_buffer = _TOD_Ticks_per_second;
return RTEMS_SUCCESSFUL;
- case RTEMS_CLOCK_GET_TIME_VALUE:
+ case RTEMS_CLOCK_GET_TIME_VALUE: {
+ struct timeval *time = (struct timeval *)time_buffer;
if ( !_TOD_Is_set )
return RTEMS_NOT_DEFINED;
- _ISR_Disable( level );
- ((rtems_clock_time_value *)time_buffer)->seconds =
- _TOD_Seconds_since_epoch;
- tmp = _TOD_Current.ticks;
- _ISR_Enable( level );
-
- tmp *= _TOD_Microseconds_per_tick;
- ((rtems_clock_time_value *)time_buffer)->microseconds = tmp;
+ _TOD_Get_timeval( time );
return RTEMS_SUCCESSFUL;
+ }
}
return RTEMS_INTERNAL_ERROR; /* should never get here */
diff --git a/cpukit/rtems/src/clockgetuptime.c b/cpukit/rtems/src/clockgetuptime.c
new file mode 100644
index 0000000000..9fa88ef74b
--- /dev/null
+++ b/cpukit/rtems/src/clockgetuptime.c
@@ -0,0 +1,50 @@
+/*
+ * Clock Manager - get uptime
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/clock.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/*PAGE
+ *
+ * rtems_clock_get_uptime
+ *
+ * This directive obtains the system uptime. A timestamp is the seconds
+ * and nanoseconds since boot.
+ *
+ * Input parameters:
+ * timestamp - pointer to the timestamp
+ *
+ * Output parameters:
+ * *uptime - filled in
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+rtems_status_code rtems_clock_get_uptime(
+ struct timespec *uptime
+)
+{
+ if ( !uptime )
+ return RTEMS_INVALID_ADDRESS;
+
+ _TOD_Get_uptime( uptime );
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/rtems/src/clockset.c b/cpukit/rtems/src/clockset.c
index befdc5339b..1b1bbe8b04 100644
--- a/cpukit/rtems/src/clockset.c
+++ b/cpukit/rtems/src/clockset.c
@@ -41,15 +41,18 @@ rtems_status_code rtems_clock_set(
rtems_time_of_day *time_buffer
)
{
- rtems_interval seconds;
+ struct timespec newtime;
if ( !time_buffer )
return RTEMS_INVALID_ADDRESS;
if ( _TOD_Validate( time_buffer ) ) {
- seconds = _TOD_To_seconds( time_buffer );
+ newtime.tv_sec = _TOD_To_seconds( time_buffer );
+ newtime.tv_nsec = time_buffer->ticks *
+ (_TOD_Microseconds_per_tick * TOD_NANOSECONDS_PER_MICROSECOND);
+
_Thread_Disable_dispatch();
- _TOD_Set( time_buffer, seconds );
+ _TOD_Set( &newtime );
_Thread_Enable_dispatch();
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/rtems/src/clocktodtoseconds.c b/cpukit/rtems/src/clocktodtoseconds.c
index 5bea09cc25..0caac50214 100644
--- a/cpukit/rtems/src/clocktodtoseconds.c
+++ b/cpukit/rtems/src/clocktodtoseconds.c
@@ -1,8 +1,8 @@
/*
- * Time of Day (TOD) Handler
+ * Time of Day (TOD) Handler - Classic TOD to Seconds
*
*
- * COPYRIGHT (c) 1989-1999.
+ * COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -17,10 +17,27 @@
#endif
#include <rtems/system.h>
-#include <rtems/score/object.h>
-#include <rtems/score/thread.h>
-#include <rtems/score/tod.h>
-#include <rtems/score/watchdog.h>
+#include <rtems/rtems/clock.h>
+
+/*
+ * The following array contains the number of days in all months
+ * up to the month indicated by the index of the second dimension.
+ * The first dimension should be 1 for leap years, and 0 otherwise.
+ */
+const uint16_t _TOD_Days_to_date[2][13] = {
+ { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
+ { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
+};
+
+/*
+ * The following array contains the number of days in the years
+ * since the last leap year. The index should be 0 for leap
+ * years, and the number of years since the beginning of a leap
+ * year otherwise.
+ */
+const uint16_t _TOD_Days_since_last_leap_year[4] = { 0, 366, 731, 1096 };
+
+
/*PAGE
*
@@ -37,7 +54,7 @@
*/
uint32_t _TOD_To_seconds(
- TOD_Control *the_tod
+ rtems_time_of_day *the_tod
)
{
uint32_t time;
diff --git a/cpukit/rtems/src/clocktodvalidate.c b/cpukit/rtems/src/clocktodvalidate.c
index 6db0c9eb67..09cb5b4092 100644
--- a/cpukit/rtems/src/clocktodvalidate.c
+++ b/cpukit/rtems/src/clocktodvalidate.c
@@ -1,8 +1,8 @@
/*
- * Time of Day (TOD) Handler
+ * Time of Day (TOD) Handler -- Validate Classic TOD
*
*
- * COPYRIGHT (c) 1989-1999.
+ * COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -17,10 +17,18 @@
#endif
#include <rtems/system.h>
-#include <rtems/score/object.h>
-#include <rtems/score/thread.h>
-#include <rtems/score/tod.h>
-#include <rtems/score/watchdog.h>
+#include <rtems/rtems/clock.h>
+
+/*
+ * The following array contains the number of days in all months.
+ * The first dimension should be 1 for leap years, and 0 otherwise.
+ * The second dimension should range from 1 to 12 for January to
+ * February, respectively.
+ */
+const uint32_t _TOD_Days_per_month[ 2 ][ 13 ] = {
+ { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+};
/*PAGE
*
@@ -39,7 +47,7 @@
*/
boolean _TOD_Validate(
- TOD_Control *the_tod
+ rtems_time_of_day *the_tod
)
{
uint32_t days_in_month;
diff --git a/cpukit/rtems/src/taskwakewhen.c b/cpukit/rtems/src/taskwakewhen.c
index 363234fa08..96f7db2618 100644
--- a/cpukit/rtems/src/taskwakewhen.c
+++ b/cpukit/rtems/src/taskwakewhen.c
@@ -20,6 +20,7 @@
#include <rtems/rtems/status.h>
#include <rtems/rtems/support.h>
#include <rtems/rtems/modes.h>
+#include <rtems/rtems/clock.h>
#include <rtems/score/object.h>
#include <rtems/score/stack.h>
#include <rtems/score/states.h>