rtems: Constify rtems_task_wake_when()

Add a parameter to _TOD_Validate() to disable the validation of the
ticks member.

There are two reasons for this change.  Firstly, in
rtems_task_wake_when() was a double check for time_buffer == NULL (one
in rtems_task_wake_when() and one in _TOD_Validate()).  Secondly, the
ticks member is ignored by rtems_task_wake_when().  This was done with a
write of zero to the ticks member and thus a modification of the
user-provided structure.  Now the structure is no longer modified.
Using a mask parameter is quite efficient. You just have to load an
immediate value and there are no additional branches in _TOD_Validate().

Close #4406.
This commit is contained in:
Sebastian Huber
2021-05-11 17:27:20 +02:00
parent 6136918ddf
commit 523867de9d
9 changed files with 32 additions and 20 deletions

View File

@@ -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.month = ds1339_get_month(&time);
temp_tod.year = ds1339_get_year(&time); temp_tod.year = ds1339_get_year(&time);
sc = _TOD_Validate(&temp_tod) sc = _TOD_Validate(&temp_tod, TOD_ENABLE_TICKS_VALIDATION)
if (sc == RTEMS_SUCCESSFUL) if (sc == RTEMS_SUCCESSFUL)
memcpy(tod, &temp_tod, sizeof(temp_tod)); memcpy(tod, &temp_tod, sizeof(temp_tod));
} }

View File

@@ -255,7 +255,7 @@ int setRealTime(
if (!RTC_Is_present()) if (!RTC_Is_present())
return -1; return -1;
if (_TOD_Validate(tod) != RTEMS_SUCCESSFUL) if (_TOD_Validate(tod, TOD_ENABLE_TICKS_VALIDATION) != RTEMS_SUCCESSFUL)
return -1; return -1;
RTC_Table[RTC_Minor].pDeviceFns->deviceSetTime(RTC_Minor, tod); RTC_Table[RTC_Minor].pDeviceFns->deviceSetTime(RTC_Minor, tod);

View File

@@ -35,19 +35,34 @@ extern "C" {
*/ */
/** /**
* @brief TOD Validate * @brief Using this constant for the ticks mask disables the validation of the
* ticks member in _TOD_Validate().
*/
#define TOD_DISABLE_TICKS_VALIDATION 0
/**
* @brief Using this constant for the ticks mask enables the validation of the
* ticks member in _TOD_Validate().
*/
#define TOD_ENABLE_TICKS_VALIDATION UINT32_MAX
/**
* @brief Validates the time of day.
* *
* This support function tests whether @a the_tod references * @param the_tod is the reference to the time of day structure to validate or
* a valid time of day. * NULL.
* *
* @param the_tod A reference to the time of day structure to validate. * @param ticks_mask is the mask for the ticks member of the time of day. 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_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_CLOCK @a the_tod references an invalid time of day.
* @retval RTEMS_INVALID_ADDRESS @a the_tod reference is @c NULL. * @retval RTEMS_INVALID_ADDRESS @a the_tod reference is @c NULL.
*/ */
rtems_status_code _TOD_Validate( rtems_status_code _TOD_Validate(
const rtems_time_of_day *the_tod const rtems_time_of_day *the_tod,
uint32_t ticks_mask
); );
/** /**

View File

@@ -2071,7 +2071,7 @@ rtems_status_code rtems_task_wake_after( rtems_interval ticks );
* occur. * occur.
* @endparblock * @endparblock
*/ */
rtems_status_code rtems_task_wake_when( rtems_time_of_day *time_buffer ); rtems_status_code rtems_task_wake_when( const rtems_time_of_day *time_buffer );
/* Generated from spec:/rtems/task/if/get-scheduler */ /* Generated from spec:/rtems/task/if/get-scheduler */

View File

@@ -34,7 +34,7 @@ rtems_status_code rtems_clock_set(
struct timespec tod_as_timespec; struct timespec tod_as_timespec;
ISR_lock_Context lock_context; ISR_lock_Context lock_context;
status = _TOD_Validate( tod ); status = _TOD_Validate( tod, TOD_ENABLE_TICKS_VALIDATION );
if ( status != RTEMS_SUCCESSFUL ) { if ( status != RTEMS_SUCCESSFUL ) {
return status; return status;

View File

@@ -36,7 +36,8 @@ const uint32_t _TOD_Days_per_month[ 2 ][ 13 ] = {
}; };
rtems_status_code _TOD_Validate( rtems_status_code _TOD_Validate(
const rtems_time_of_day *the_tod const rtems_time_of_day *the_tod,
uint32_t ticks_mask
) )
{ {
uint32_t days_in_month; uint32_t days_in_month;
@@ -48,7 +49,7 @@ rtems_status_code _TOD_Validate(
ticks_per_second = rtems_clock_get_ticks_per_second(); ticks_per_second = rtems_clock_get_ticks_per_second();
if ((the_tod->ticks >= ticks_per_second) || if ( ( ( the_tod->ticks & ticks_mask ) >= ticks_per_second ) ||
(the_tod->second >= TOD_SECONDS_PER_MINUTE) || (the_tod->second >= TOD_SECONDS_PER_MINUTE) ||
(the_tod->minute >= TOD_MINUTES_PER_HOUR) || (the_tod->minute >= TOD_MINUTES_PER_HOUR) ||
(the_tod->hour >= TOD_HOURS_PER_DAY) || (the_tod->hour >= TOD_HOURS_PER_DAY) ||

View File

@@ -27,7 +27,7 @@
#include <rtems/score/watchdogimpl.h> #include <rtems/score/watchdogimpl.h>
rtems_status_code rtems_task_wake_when( rtems_status_code rtems_task_wake_when(
rtems_time_of_day *time_buffer const rtems_time_of_day *time_buffer
) )
{ {
uint32_t seconds; uint32_t seconds;
@@ -38,11 +38,7 @@ rtems_status_code rtems_task_wake_when(
if ( !_TOD_Is_set() ) if ( !_TOD_Is_set() )
return RTEMS_NOT_DEFINED; return RTEMS_NOT_DEFINED;
if ( !time_buffer ) status = _TOD_Validate( time_buffer, TOD_DISABLE_TICKS_VALIDATION );
return RTEMS_INVALID_ADDRESS;
time_buffer->ticks = 0;
status = _TOD_Validate( time_buffer );
if ( status != RTEMS_SUCCESSFUL ) { if ( status != RTEMS_SUCCESSFUL ) {
return status; return status;

View File

@@ -141,7 +141,7 @@ rtems_status_code _Timer_Fire_when(
if ( !routine ) if ( !routine )
return RTEMS_INVALID_ADDRESS; return RTEMS_INVALID_ADDRESS;
status = _TOD_Validate( wall_time ); status = _TOD_Validate( wall_time, TOD_ENABLE_TICKS_VALIDATION );
if ( status != RTEMS_SUCCESSFUL ) { if ( status != RTEMS_SUCCESSFUL ) {
return status; return status;

View File

@@ -281,9 +281,9 @@ static void test_leap_year(void)
const rtems_time_of_day *problem = &problem_2100; const rtems_time_of_day *problem = &problem_2100;
const rtems_time_of_day *problem2 = &problem_2100_2; const rtems_time_of_day *problem2 = &problem_2100_2;
// 2100 is not a leap year, so it should have 28 days // 2100 is not a leap year, so it should have 28 days
test_status = _TOD_Validate(problem); test_status = _TOD_Validate(problem, TOD_ENABLE_TICKS_VALIDATION);
rtems_test_assert(test_status == RTEMS_SUCCESSFUL); rtems_test_assert(test_status == RTEMS_SUCCESSFUL);
test_status = _TOD_Validate(problem2); test_status = _TOD_Validate(problem2, TOD_ENABLE_TICKS_VALIDATION);
rtems_test_assert(test_status == RTEMS_INVALID_CLOCK); rtems_test_assert(test_status == RTEMS_INVALID_CLOCK);
} }