summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2011-09-29 09:55:54 +0000
committerSebastian Huber <sebastian.huber@embedded-brains.de>2011-09-29 09:55:54 +0000
commit8d7aea0d28cd7504ea406537040d1bbe2f634a29 (patch)
tree5f9247e2d03b415da2ea560334f8f70ed332be0d /cpukit
parent2011-09-29 Sebastian Huber <sebastian.huber@embedded-brains.de> (diff)
downloadrtems-8d7aea0d28cd7504ea406537040d1bbe2f634a29.tar.bz2
2011-09-29 Sebastian Huber <sebastian.huber@embedded-brains.de>
* score/include/rtems/score/tod.h: Declare _TOD_Set_with_timestamp() and _TOD_Get_as_timestamp(). * score/src/coretodset.c: Define _TOD_Set_with_timestamp(). * score/src/coretodget.c: Define _TOD_Get_as_timestamp(). * rtems/src/clockset.c: Use _TOD_Set_with_timestamp(). * score/include/rtems/score/timestamp64.h, score/src/ts64set.c: Changed parameter types of _Timestamp64_Set(). * rtems/src/clocktodtoseconds.c: Year 2100 is not a leap year.
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/ChangeLog11
-rw-r--r--cpukit/rtems/src/clockset.c23
-rw-r--r--cpukit/rtems/src/clocktodtoseconds.c8
-rw-r--r--cpukit/score/include/rtems/score/timestamp64.h17
-rw-r--r--cpukit/score/include/rtems/score/tod.h45
-rw-r--r--cpukit/score/src/coretodget.c18
-rw-r--r--cpukit/score/src/coretodset.c31
-rw-r--r--cpukit/score/src/ts64set.c4
8 files changed, 87 insertions, 70 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index 3d999f10f6..aaa2b6273f 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,14 @@
+2011-09-29 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * score/include/rtems/score/tod.h: Declare _TOD_Set_with_timestamp()
+ and _TOD_Get_as_timestamp().
+ * score/src/coretodset.c: Define _TOD_Set_with_timestamp().
+ * score/src/coretodget.c: Define _TOD_Get_as_timestamp().
+ * rtems/src/clockset.c: Use _TOD_Set_with_timestamp().
+ * score/include/rtems/score/timestamp64.h, score/src/ts64set.c:
+ Changed parameter types of _Timestamp64_Set().
+ * rtems/src/clocktodtoseconds.c: Year 2100 is not a leap year.
+
2011-09-28 Sebastian Huber <sebastian.huber@embedded-brains.de>
* rtems/include/rtems/rtems/clock.h, rtems/src/clockset.c: Added const
diff --git a/cpukit/rtems/src/clockset.c b/cpukit/rtems/src/clockset.c
index b70e42e165..4c055d5b54 100644
--- a/cpukit/rtems/src/clockset.c
+++ b/cpukit/rtems/src/clockset.c
@@ -30,7 +30,7 @@
* This directive sets the date and time for this node.
*
* Input parameters:
- * time_buffer - pointer to the time and date structure
+ * tod - pointer to the time and date structure
*
* Output parameters:
* RTEMS_SUCCESSFUL - if successful
@@ -38,23 +38,26 @@
*/
rtems_status_code rtems_clock_set(
- const rtems_time_of_day *time_buffer
+ const rtems_time_of_day *tod
)
{
- struct timespec newtime;
-
- if ( !time_buffer )
+ if ( !tod )
return RTEMS_INVALID_ADDRESS;
- if ( _TOD_Validate( time_buffer ) ) {
- newtime.tv_sec = _TOD_To_seconds( time_buffer );
- newtime.tv_nsec = time_buffer->ticks *
- rtems_configuration_get_nanoseconds_per_tick();
+ if ( _TOD_Validate( tod ) ) {
+ Timestamp_Control tod_as_timestamp;
+ uint32_t seconds = _TOD_To_seconds( tod );
+ uint32_t nanoseconds = tod->ticks
+ * rtems_configuration_get_nanoseconds_per_tick();
+
+ _Timestamp_Set( &tod_as_timestamp, seconds, nanoseconds );
_Thread_Disable_dispatch();
- _TOD_Set( &newtime );
+ _TOD_Set_with_timestamp( &tod_as_timestamp );
_Thread_Enable_dispatch();
+
return RTEMS_SUCCESSFUL;
}
+
return RTEMS_INVALID_CLOCK;
}
diff --git a/cpukit/rtems/src/clocktodtoseconds.c b/cpukit/rtems/src/clocktodtoseconds.c
index 7de1838b6e..7f867a4857 100644
--- a/cpukit/rtems/src/clocktodtoseconds.c
+++ b/cpukit/rtems/src/clocktodtoseconds.c
@@ -18,6 +18,8 @@
#include <rtems/system.h>
#include <rtems/rtems/clock.h>
+#define TOD_SECONDS_AT_2100_03_01_00_00 4107538800UL
+
/*
* The following array contains the number of days in all months
* up to the month indicated by the index of the second dimension.
@@ -78,6 +80,12 @@ uint32_t _TOD_To_seconds(
time += the_tod->second;
+ /* The year 2100 is not a leap year */
+ if ( time
+ >= (TOD_SECONDS_AT_2100_03_01_00_00 - TOD_SECONDS_1970_THROUGH_1988)) {
+ time -= TOD_SECONDS_PER_DAY;
+ }
+
time += TOD_SECONDS_1970_THROUGH_1988;
return( time );
diff --git a/cpukit/score/include/rtems/score/timestamp64.h b/cpukit/score/include/rtems/score/timestamp64.h
index 2bc408528b..4bba7c9a2d 100644
--- a/cpukit/score/include/rtems/score/timestamp64.h
+++ b/cpukit/score/include/rtems/score/timestamp64.h
@@ -55,14 +55,11 @@ typedef int64_t Timestamp64_Control;
static inline void _Timestamp64_implementation_Set(
Timestamp64_Control *_time,
- long _seconds,
- long _nanoseconds
+ Timestamp64_Control _seconds,
+ Timestamp64_Control _nanoseconds
)
{
- Timestamp64_Control _seconds64 = _seconds;
- Timestamp64_Control _nanoseconds64 = _nanoseconds;
-
- *_time = _seconds64 * 1000000000L + _nanoseconds64;
+ *_time = _seconds * 1000000000L + _nanoseconds;
}
/**
@@ -81,8 +78,8 @@ static inline void _Timestamp64_implementation_Set(
#else
void _Timestamp64_Set(
Timestamp64_Control *_time,
- long _seconds,
- long _nanoseconds
+ Timestamp64_Control _seconds,
+ Timestamp64_Control _nanoseconds
);
#endif
@@ -406,8 +403,8 @@ static inline void _Timestamp64_implementation_To_timespec(
struct timespec *_timespec
)
{
- _timespec->tv_sec = *_timestamp / 1000000000L;
- _timespec->tv_nsec = *_timestamp % 1000000000L;
+ _timespec->tv_sec = (time_t) (*_timestamp / 1000000000L);
+ _timespec->tv_nsec = (long) (*_timestamp % 1000000000L);
}
/**
diff --git a/cpukit/score/include/rtems/score/tod.h b/cpukit/score/include/rtems/score/tod.h
index f92e07000a..c8684ae6cc 100644
--- a/cpukit/score/include/rtems/score/tod.h
+++ b/cpukit/score/include/rtems/score/tod.h
@@ -163,27 +163,48 @@ SCORE_EXTERN Timestamp_Control _TOD_Uptime;
void _TOD_Handler_initialization(void);
/**
- * @brief _TOD_Set
+ * @brief Sets the time of day according to @a tod_as_timestamp.
*
- * This routine sets the current time of day to @a time and
- * the equivalent SECONDS_SINCE_EPOCH.
+ * The @a tod_as_timestamp timestamp represents the time since UNIX epoch. The watchdog
+ * seconds chain will be adjusted.
*/
-void _TOD_Set(
- const struct timespec *time
+void _TOD_Set_with_timestamp(
+ const Timestamp_Control *tod_as_timestamp
);
+static inline void _TOD_Set(
+ const struct timespec *tod_as_timespec
+)
+{
+ Timestamp_Control tod_as_timestamp;
+
+ _Timestamp_Set(
+ &tod_as_timestamp,
+ tod_as_timespec->tv_sec,
+ tod_as_timespec->tv_nsec
+ );
+ _TOD_Set_with_timestamp( &tod_as_timestamp );
+}
+
/**
- * @brief _TOD_Get
- *
- * This routine returns the current time of day with potential accuracy
- * to the nanosecond.
+ * @brief Returns the time of day in @a tod_as_timestamp.
*
- * @param[in] time is a pointer to the time to be returned
+ * The @a tod_as_timestamp timestamp represents the time since UNIX epoch.
*/
-void _TOD_Get(
- struct timespec *time
+void _TOD_Get_as_timestamp(
+ Timestamp_Control *tod_as_timestamp
);
+static inline void _TOD_Get(
+ struct timespec *tod_as_timespec
+)
+{
+ Timestamp_Control tod_as_timestamp;
+
+ _TOD_Get_as_timestamp( &tod_as_timestamp );
+ _Timestamp_To_timespec( &tod_as_timestamp, tod_as_timespec );
+}
+
/**
* @brief _TOD_Get_uptime
*
diff --git a/cpukit/score/src/coretodget.c b/cpukit/score/src/coretodget.c
index 953f3cb753..79e7dfff5e 100644
--- a/cpukit/score/src/coretodget.c
+++ b/cpukit/score/src/coretodget.c
@@ -22,19 +22,8 @@
#include <rtems/score/tod.h>
#include <rtems/score/watchdog.h>
-/*
- * _TOD_Get
- *
- * This routine is used to obtain the current date and time.
- *
- * Input parameters:
- * time - pointer to the time and date structure
- *
- * Output parameters: NONE
- */
-
-void _TOD_Get(
- struct timespec *time
+void _TOD_Get_as_timestamp(
+ Timestamp_Control *tod
)
{
ISR_Level level;
@@ -52,5 +41,6 @@ void _TOD_Get(
_Timestamp_Set( &offset, 0, nanoseconds );
_Timestamp_Add_to( &now, &offset );
- _Timestamp_To_timespec( &now, time );
+
+ *tod = now;
}
diff --git a/cpukit/score/src/coretodset.c b/cpukit/score/src/coretodset.c
index 909e1fee7a..c8fe2ac351 100644
--- a/cpukit/score/src/coretodset.c
+++ b/cpukit/score/src/coretodset.c
@@ -23,39 +23,26 @@
#include <rtems/score/tod.h>
#include <rtems/score/watchdog.h>
-/*
- * _TOD_Set
- *
- * This rountine sets the current date and time with the specified
- * new date and time structure.
- *
- * Input parameters:
- * time - pointer to the time and date structure
- *
- * Output parameters: NONE
- */
-
-void _TOD_Set(
- const struct timespec *time
+void _TOD_Set_with_timestamp(
+ const Timestamp_Control *tod
)
{
- long seconds;
+ Watchdog_Interval seconds_next = _Timestamp_Get_seconds( tod );
+ Watchdog_Interval seconds_now;
_Thread_Disable_dispatch();
_TOD_Deactivate();
- seconds = _TOD_Seconds_since_epoch();
+ seconds_now = _TOD_Seconds_since_epoch();
- if ( time->tv_sec < seconds )
- _Watchdog_Adjust_seconds( WATCHDOG_BACKWARD, seconds - time->tv_sec );
+ if ( seconds_next < seconds_now )
+ _Watchdog_Adjust_seconds( WATCHDOG_BACKWARD, seconds_now - seconds_next );
else
- _Watchdog_Adjust_seconds( WATCHDOG_FORWARD, time->tv_sec - seconds );
+ _Watchdog_Adjust_seconds( WATCHDOG_FORWARD, seconds_next - seconds_now );
- /* POSIX format TOD (timespec) */
- _Timestamp_Set( &_TOD_Now, time->tv_sec, time->tv_nsec );
+ _TOD_Now = *tod;
_TOD_Is_set = true;
_TOD_Activate();
-
_Thread_Enable_dispatch();
}
diff --git a/cpukit/score/src/ts64set.c b/cpukit/score/src/ts64set.c
index 2a3aaca8fe..ab03f13c47 100644
--- a/cpukit/score/src/ts64set.c
+++ b/cpukit/score/src/ts64set.c
@@ -22,8 +22,8 @@
#if CPU_TIMESTAMP_USE_INT64 == TRUE
void _Timestamp64_Set(
Timestamp64_Control *_time,
- long _seconds,
- long _nanoseconds
+ Timestamp64_Control _seconds,
+ Timestamp64_Control _nanoseconds
)
{
_Timestamp64_implementation_Set( _time, _seconds, _nanoseconds );