[PATCH 6/7] score: Always validate ticks in _TOD_Validate()

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Sep 3 13:33:23 UTC 2021


The behaviour with respect to the handling of the ticks member in the *_when()
directives was inconsistent.  In all *_when() directives the ticks member is
not used to calculate the watchdog expiration time.  However, the
rtems_task_wake_when() directive ignores the ticks member of the time of day
completely, unlike the rtems_timer_fire_when() and
rtems_timer_server_fire_when() directives which check that the ticks are valid
and then ignore them.

This commit changes _TOD_Validate() to unconditionally check the ticks value.
Ignoring the value would make it more difficult to support the ticks in the
future.  The watchdog implementation supports a nanoseconds resolution.
Checking the ticks in rtems_task_wake_when() may case problems for existing
applications which could now get an error status due to an invalid ticks value.

Applications should set the ticks value to zero for future compatibility.  This
recommendation needs to be added to the documentation.
---
 bsps/arm/altera-cyclone-v/rtc/rtc.c    |  4 ++--
 bsps/shared/dev/rtc/rtc-support.c      |  2 +-
 cpukit/include/rtems/rtems/clockimpl.h | 28 +-------------------------
 cpukit/rtems/src/clockset.c            |  2 +-
 cpukit/rtems/src/clocktodvalidate.c    | 12 ++---------
 cpukit/rtems/src/taskwakewhen.c        |  2 +-
 cpukit/rtems/src/timercreate.c         |  2 +-
 testsuites/sptests/sp2038/init.c       |  4 ++--
 testsuites/sptests/sptask_err02/init.c |  5 +++--
 9 files changed, 14 insertions(+), 47 deletions(-)

diff --git a/bsps/arm/altera-cyclone-v/rtc/rtc.c b/bsps/arm/altera-cyclone-v/rtc/rtc.c
index 779a093459..d1c12ee874 100644
--- a/bsps/arm/altera-cyclone-v/rtc/rtc.c
+++ b/bsps/arm/altera-cyclone-v/rtc/rtc.c
@@ -353,7 +353,7 @@ static int altera_cyclone_v_ds1339_get_time(int minor, rtems_time_of_day* tod)
     temp_tod.month  = ds1339_get_month(&time);
     temp_tod.year   = ds1339_get_year(&time);
 
-    sc = _TOD_Validate(&temp_tod, TOD_ENABLE_TICKS_VALIDATION);
+    sc = _TOD_Validate(&temp_tod);
     if (sc == RTEMS_SUCCESSFUL)
       memcpy(tod, &temp_tod, sizeof(temp_tod));
   }
@@ -736,7 +736,7 @@ static int  altera_cyclone_v_m41st87_get_time(int minor, rtems_time_of_day* tod)
   temp_tod.month  = m41st87_get_month(&time);
   temp_tod.year   = m41st87_get_year(&time);
 
-  sc = _TOD_Validate(&temp_tod, TOD_ENABLE_TICKS_VALIDATION);
+  sc = _TOD_Validate(&temp_tod);
   if (sc == RTEMS_SUCCESSFUL)
     memcpy(tod, &temp_tod, sizeof(temp_tod));
 
diff --git a/bsps/shared/dev/rtc/rtc-support.c b/bsps/shared/dev/rtc/rtc-support.c
index c0b639ec7c..04b8f0c847 100644
--- a/bsps/shared/dev/rtc/rtc-support.c
+++ b/bsps/shared/dev/rtc/rtc-support.c
@@ -255,7 +255,7 @@ int setRealTime(
   if (!RTC_Is_present())
     return -1;
 
-  if (_TOD_Validate(tod, TOD_ENABLE_TICKS_VALIDATION) != RTEMS_SUCCESSFUL)
+  if (_TOD_Validate(tod) != RTEMS_SUCCESSFUL)
     return -1;
 
   RTC_Table[RTC_Minor].pDeviceFns->deviceSetTime(RTC_Minor, tod);
diff --git a/cpukit/include/rtems/rtems/clockimpl.h b/cpukit/include/rtems/rtems/clockimpl.h
index c8334afaf3..85d7341c9a 100644
--- a/cpukit/include/rtems/rtems/clockimpl.h
+++ b/cpukit/include/rtems/rtems/clockimpl.h
@@ -34,43 +34,17 @@ extern "C" {
  * @{
  */
 
-/**
- * @brief The enumerators of this type determine if the ticks member is
- *   validated in _TOD_Validate().
- */
-typedef enum {
-  /**
-   * @brief Use this option to disable the validation of the ticks member in
-   *   _TOD_Validate().
-   */
-  TOD_DISABLE_TICKS_VALIDATION = 0,
-
-  /**
-   * @brief Use this option to enable the validation of the ticks member in
-   *   _TOD_Validate().
-   */
-  TOD_ENABLE_TICKS_VALIDATION = -1
-} TOD_Ticks_validation;
-
 /**
  * @brief Validates the time of day.
  *
  * @param the_tod is the reference to the time of day structure to validate or
  *   NULL.
  *
- * @param ticks_validation indicates if the ticks member of the time of day
- *   should be validated.  Use #TOD_ENABLE_TICKS_VALIDATION to validate the
- *   ticks member.  Use #TOD_DISABLE_TICKS_VALIDATION to skip the validation of
- *   the ticks member.
- *
  * @retval RTEMS_SUCCESSFUL @a the_tod references a valid time of day.
  * @retval RTEMS_INVALID_CLOCK @a the_tod references an invalid time of day.
  * @retval RTEMS_INVALID_ADDRESS @a the_tod reference is @c NULL.
  */
-rtems_status_code _TOD_Validate(
-  const rtems_time_of_day *the_tod,
-  TOD_Ticks_validation     ticks_validation
-);
+rtems_status_code _TOD_Validate( const rtems_time_of_day *the_tod );
 
 /**
  * @brief TOD to Seconds
diff --git a/cpukit/rtems/src/clockset.c b/cpukit/rtems/src/clockset.c
index 07384290b8..df163531a7 100644
--- a/cpukit/rtems/src/clockset.c
+++ b/cpukit/rtems/src/clockset.c
@@ -34,7 +34,7 @@ rtems_status_code rtems_clock_set(
   struct timespec   tod_as_timespec;
   ISR_lock_Context  lock_context;
 
-  status = _TOD_Validate( tod, TOD_ENABLE_TICKS_VALIDATION );
+  status = _TOD_Validate( tod );
 
   if ( status != RTEMS_SUCCESSFUL ) {
     return status;
diff --git a/cpukit/rtems/src/clocktodvalidate.c b/cpukit/rtems/src/clocktodvalidate.c
index 0e3b5772b5..ddf310c3c0 100644
--- a/cpukit/rtems/src/clocktodvalidate.c
+++ b/cpukit/rtems/src/clocktodvalidate.c
@@ -35,23 +35,15 @@ const uint32_t   _TOD_Days_per_month[ 2 ][ 13 ] = {
   { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
 };
 
-rtems_status_code _TOD_Validate(
-  const rtems_time_of_day *the_tod,
-  TOD_Ticks_validation     ticks_validation
-)
+rtems_status_code _TOD_Validate( const rtems_time_of_day *the_tod )
 {
   uint32_t days_in_month;
-  uint32_t ticks_per_second;
-  uint32_t ticks_mask;
 
   if ( the_tod == NULL ) {
     return RTEMS_INVALID_ADDRESS;
   }
 
-  ticks_per_second = rtems_clock_get_ticks_per_second();
-  ticks_mask = (uint32_t) ticks_validation;
-
-  if ( ( the_tod->ticks & ticks_mask ) >= ticks_per_second ) {
+  if ( the_tod->ticks >= rtems_clock_get_ticks_per_second() ) {
     return RTEMS_INVALID_CLOCK;
   }
 
diff --git a/cpukit/rtems/src/taskwakewhen.c b/cpukit/rtems/src/taskwakewhen.c
index 4dfa6dfef2..3bd0db1246 100644
--- a/cpukit/rtems/src/taskwakewhen.c
+++ b/cpukit/rtems/src/taskwakewhen.c
@@ -38,7 +38,7 @@ rtems_status_code rtems_task_wake_when(
   if ( !_TOD_Is_set() )
     return RTEMS_NOT_DEFINED;
 
-  status = _TOD_Validate( time_buffer, TOD_DISABLE_TICKS_VALIDATION );
+  status = _TOD_Validate( time_buffer );
 
   if ( status != RTEMS_SUCCESSFUL ) {
     return status;
diff --git a/cpukit/rtems/src/timercreate.c b/cpukit/rtems/src/timercreate.c
index 59fa353b22..bd9421c440 100644
--- a/cpukit/rtems/src/timercreate.c
+++ b/cpukit/rtems/src/timercreate.c
@@ -141,7 +141,7 @@ rtems_status_code _Timer_Fire_when(
   if ( !routine )
     return RTEMS_INVALID_ADDRESS;
 
-  status = _TOD_Validate( wall_time, TOD_ENABLE_TICKS_VALIDATION );
+  status = _TOD_Validate( wall_time );
 
   if ( status != RTEMS_SUCCESSFUL ) {
     return status;
diff --git a/testsuites/sptests/sp2038/init.c b/testsuites/sptests/sp2038/init.c
index dedd66d2c3..035b9a9b9b 100644
--- a/testsuites/sptests/sp2038/init.c
+++ b/testsuites/sptests/sp2038/init.c
@@ -281,9 +281,9 @@ static void test_leap_year(void)
     const rtems_time_of_day *problem = &problem_2100;
     const rtems_time_of_day *problem2 = &problem_2100_2;
     // 2100 is not a leap year, so it should have 28 days
-    test_status = _TOD_Validate(problem, TOD_ENABLE_TICKS_VALIDATION);
+    test_status = _TOD_Validate(problem);
     rtems_test_assert(test_status == RTEMS_SUCCESSFUL);
-    test_status = _TOD_Validate(problem2, TOD_ENABLE_TICKS_VALIDATION);
+    test_status = _TOD_Validate(problem2);
     rtems_test_assert(test_status == RTEMS_INVALID_CLOCK);
 }
 
diff --git a/testsuites/sptests/sptask_err02/init.c b/testsuites/sptests/sptask_err02/init.c
index dfdaf396d0..2cf796d26e 100644
--- a/testsuites/sptests/sptask_err02/init.c
+++ b/testsuites/sptests/sptask_err02/init.c
@@ -76,11 +76,12 @@ rtems_task Init(
 
   /* invalid ticks */
   status = rtems_task_wake_when( &time );
-  directive_failed(
+  fatal_directive_status(
     status,
+    RTEMS_INVALID_CLOCK,
     "rtems_task_wake_when with invalid ticks per second"
   );
-  puts( "TA1 - rtems_task_wake_when - TICKINVALID - woke up RTEMS_SUCCESSFUL" );
+  puts( "TA1 - rtems_task_wake_when - RTEMS_INVALID_CLOCK" );
 
   build_time( &time, 2, 5, 1961, 8, 30, 48, 0 );
   print_time( "TA1 - rtems_task_wake_when - ", &time, "" );
-- 
2.26.2



More information about the devel mailing list