[rtems commit] score: Statically initialize TOD handler

Sebastian Huber sebh at rtems.org
Tue Jan 12 11:04:10 UTC 2016


Module:    rtems
Branch:    master
Commit:    599d71f7ffdde091108b4bd516bf990ae5c3a082
Changeset: http://git.rtems.org/rtems/commit/?id=599d71f7ffdde091108b4bd516bf990ae5c3a082

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Jan 11 13:02:06 2016 +0100

score: Statically initialize TOD handler

---

 cpukit/sapi/src/exinit.c                           |  1 -
 cpukit/score/include/rtems/score/timecounterimpl.h |  2 -
 cpukit/score/include/rtems/score/todimpl.h         |  9 +---
 cpukit/score/src/coretod.c                         | 14 +-----
 cpukit/score/src/kern_tc.c                         | 27 ++++++----
 testsuites/sptests/sptimecounter01/init.c          | 58 ++++++++++++++++++++--
 6 files changed, 73 insertions(+), 38 deletions(-)

diff --git a/cpukit/sapi/src/exinit.c b/cpukit/sapi/src/exinit.c
index 1f482f0..1eaf24f 100644
--- a/cpukit/sapi/src/exinit.c
+++ b/cpukit/sapi/src/exinit.c
@@ -114,7 +114,6 @@ static void rtems_initialize_data_structures(void)
   _API_Mutex_Allocate( &_Once_Mutex );
 
   _Watchdog_Handler_initialization();
-  _TOD_Handler_initialization();
 
   _Thread_Handler_initialization();
 
diff --git a/cpukit/score/include/rtems/score/timecounterimpl.h b/cpukit/score/include/rtems/score/timecounterimpl.h
index dd47aac..82ade23 100644
--- a/cpukit/score/include/rtems/score/timecounterimpl.h
+++ b/cpukit/score/include/rtems/score/timecounterimpl.h
@@ -36,8 +36,6 @@ extern "C" {
  * @{
  */
 
-void _Timecounter_Initialize( void );
-
 void _Timecounter_Set_clock( const struct timespec *ts );
 
 /** @} */
diff --git a/cpukit/score/include/rtems/score/todimpl.h b/cpukit/score/include/rtems/score/todimpl.h
index a94b140..b61651c 100644
--- a/cpukit/score/include/rtems/score/todimpl.h
+++ b/cpukit/score/include/rtems/score/todimpl.h
@@ -149,14 +149,7 @@ typedef struct {
   bool is_set;
 } TOD_Control;
 
-SCORE_EXTERN TOD_Control _TOD;
-
-/**
- *  @brief Initializes the time of day handler.
- *
- *  Performs the initialization necessary for the Time Of Day handler.
- */
-void _TOD_Handler_initialization(void);
+extern TOD_Control _TOD;
 
 /**
  *  @brief Sets the time of day from timestamp.
diff --git a/cpukit/score/src/coretod.c b/cpukit/score/src/coretod.c
index 975ffef..1df1b4e 100644
--- a/cpukit/score/src/coretod.c
+++ b/cpukit/score/src/coretod.c
@@ -20,16 +20,4 @@
 
 #include <rtems/score/todimpl.h>
 
-void _TOD_Handler_initialization(void)
-{
-  struct timespec ts;
-
-  _Timecounter_Initialize();
-
-  ts.tv_sec = TOD_SECONDS_1970_THROUGH_1988;
-  ts.tv_nsec = 0;
-  _Timecounter_Set_clock( &ts );
-
-  /* TOD has not been set */
-  _TOD.is_set = false;
-}
+TOD_Control _TOD;
diff --git a/cpukit/score/src/kern_tc.c b/cpukit/score/src/kern_tc.c
index d8f086d..9533e77 100644
--- a/cpukit/score/src/kern_tc.c
+++ b/cpukit/score/src/kern_tc.c
@@ -33,6 +33,7 @@
 #define time_second _Timecounter_Time_second
 #define time_uptime _Timecounter_Time_uptime
 #include <rtems/score/timecounterimpl.h>
+#include <rtems/score/todimpl.h>
 #include <rtems/score/watchdogimpl.h>
 #endif /* __rtems__ */
 #include <sys/cdefs.h>
@@ -144,8 +145,13 @@ static struct timehands th0 = {
 	(uint64_t)-1 / 1000000,
 	0,
 	{1, 0},
+#ifndef __rtems__
 	{0, 0},
 	{0, 0},
+#else /* __rtems__ */
+	{TOD_SECONDS_1970_THROUGH_1988, 0},
+	{TOD_SECONDS_1970_THROUGH_1988, 0},
+#endif /* __rtems__ */
 	1,
 #if defined(RTEMS_SMP)
 	&th1
@@ -162,10 +168,20 @@ static struct timecounter *timecounters = &dummy_timecounter;
 int tc_min_ticktock_freq = 1;
 #endif /* __rtems__ */
 
+#ifndef __rtems__
 volatile time_t time_second = 1;
+#else /* __rtems__ */
+volatile time_t time_second = TOD_SECONDS_1970_THROUGH_1988;
+#endif /* __rtems__ */
 volatile time_t time_uptime = 1;
 
+#ifndef __rtems__
 struct bintime boottimebin;
+#else /* __rtems__ */
+struct bintime boottimebin = {
+  .sec = TOD_SECONDS_1970_THROUGH_1988 - 1
+};
+#endif /* __rtems__ */
 #ifndef __rtems__
 struct timeval boottime;
 static int sysctl_kern_boottime(SYSCTL_HANDLER_ARGS);
@@ -2045,17 +2061,10 @@ sysctl_kern_timecounter_adjprecision(SYSCTL_HANDLER_ARGS)
 done:
 	return (0);
 }
-#endif /* __rtems__ */
 
-#ifndef __rtems__
 static void
 inittimecounter(void *dummy)
-#else /* __rtems__ */
-void
-_Timecounter_Initialize(void)
-#endif /* __rtems__ */
 {
-#ifndef __rtems__
 	u_int p;
 	int tick_rate;
 
@@ -2079,7 +2088,6 @@ _Timecounter_Initialize(void)
 	tc_tick_sbt = bttosbt(tc_tick_bt);
 	p = (tc_tick * 1000000) / hz;
 	printf("Timecounters tick every %d.%03u msec\n", p / 1000, p % 1000);
-#endif /* __rtems__ */
 
 #ifdef FFCLOCK
 	ffclock_init();
@@ -2090,11 +2098,8 @@ _Timecounter_Initialize(void)
 	tc_windup();
 }
 
-#ifndef __rtems__
 SYSINIT(timecounter, SI_SUB_CLOCKS, SI_ORDER_SECOND, inittimecounter, NULL);
-#endif /* __rtems__ */
 
-#ifndef __rtems__
 /* Cpu tick handling -------------------------------------------------*/
 
 static int cpu_tick_variable;
diff --git a/testsuites/sptests/sptimecounter01/init.c b/testsuites/sptests/sptimecounter01/init.c
index 47ebb27..7b31064 100644
--- a/testsuites/sptests/sptimecounter01/init.c
+++ b/testsuites/sptests/sptimecounter01/init.c
@@ -23,11 +23,12 @@
 #include <rtems/test.h>
 
 #include <rtems/score/timecounterimpl.h>
+#include <rtems/score/todimpl.h>
 #include <rtems/score/watchdogimpl.h>
 #include <rtems/timecounter.h>
 #include <rtems/bsd.h>
 
-const char rtems_test_name[] = "SPTIMECOUNTER_1";
+const char rtems_test_name[] = "SPTIMECOUNTER 1";
 
 typedef struct {
   struct timecounter tc_soft;
@@ -51,16 +52,67 @@ void boot_card(const char *cmdline)
   struct timecounter *tc_soft = &ctx->tc_soft;
   uint64_t soft_freq = 1000000;
   struct bintime bt;
+  struct timeval tv;
+  struct timespec ts;
 
   rtems_test_begink();
 
-  _Timecounter_Initialize();
   _Watchdog_Handler_initialization();
 
+  assert(time(NULL) == TOD_SECONDS_1970_THROUGH_1988);
+
+  rtems_bsd_bintime(&bt);
+  assert(bt.sec == TOD_SECONDS_1970_THROUGH_1988);
+  assert(bt.frac == 0);
+
+  rtems_bsd_getbintime(&bt);
+  assert(bt.sec == TOD_SECONDS_1970_THROUGH_1988);
+  assert(bt.frac == 0);
+
+  rtems_bsd_microtime(&tv);
+  assert(tv.tv_sec == TOD_SECONDS_1970_THROUGH_1988);
+  assert(tv.tv_usec == 0);
+
+  rtems_bsd_getmicrotime(&tv);
+  assert(tv.tv_sec == TOD_SECONDS_1970_THROUGH_1988);
+  assert(tv.tv_usec == 0);
+
+  rtems_bsd_nanotime(&ts);
+  assert(ts.tv_sec == TOD_SECONDS_1970_THROUGH_1988);
+  assert(ts.tv_nsec == 0);
+
+  rtems_bsd_getnanotime(&ts);
+  assert(ts.tv_sec == TOD_SECONDS_1970_THROUGH_1988);
+  assert(ts.tv_nsec == 0);
+
+  assert(rtems_clock_get_uptime_seconds() == 0);
+  assert(rtems_clock_get_uptime_nanoseconds() == 0);
+
   rtems_bsd_binuptime(&bt);
   assert(bt.sec == 1);
-  assert(bt.frac== 0);
+  assert(bt.frac == 0);
+
+  rtems_bsd_getbinuptime(&bt);
+  assert(bt.sec == 1);
+  assert(bt.frac == 0);
+
+  rtems_bsd_microuptime(&tv);
+  assert(tv.tv_sec == 1);
+  assert(tv.tv_usec == 0);
+
+  rtems_bsd_getmicrouptime(&tv);
+  assert(tv.tv_sec == 1);
+  assert(tv.tv_usec == 0);
+
+  rtems_bsd_nanouptime(&ts);
+  assert(ts.tv_sec == 1);
+  assert(ts.tv_nsec == 0);
+
+  rtems_bsd_getnanouptime(&ts);
+  assert(ts.tv_sec == 1);
+  assert(ts.tv_nsec == 0);
 
+  /* On RTEMS time does not advance using the dummy timecounter */
   rtems_bsd_binuptime(&bt);
   assert(bt.sec == 1);
   assert(bt.frac == 0);




More information about the vc mailing list