rtems: Add TOD_Ticks_validation

Replace defines with an enum.

Update #4406.
This commit is contained in:
Sebastian Huber
2021-05-14 08:09:34 +02:00
parent 523867de9d
commit 45a3495325
2 changed files with 24 additions and 15 deletions

View File

@@ -35,16 +35,22 @@ extern "C" {
*/ */
/** /**
* @brief Using this constant for the ticks mask disables the validation of the * @brief The enumerators of this type determine if the ticks member is
* ticks member in _TOD_Validate(). * validated in _TOD_Validate().
*/ */
#define TOD_DISABLE_TICKS_VALIDATION 0 typedef enum {
/**
* @brief Use this option to disable the validation of the ticks member in
* _TOD_Validate().
*/
TOD_DISABLE_TICKS_VALIDATION = 0,
/** /**
* @brief Using this constant for the ticks mask enables the validation of the * @brief Use this option to enable the validation of the ticks member in
* ticks member in _TOD_Validate(). * _TOD_Validate().
*/ */
#define TOD_ENABLE_TICKS_VALIDATION UINT32_MAX TOD_ENABLE_TICKS_VALIDATION = -1
} TOD_Ticks_validation;
/** /**
* @brief Validates the time of day. * @brief Validates the time of day.
@@ -52,9 +58,10 @@ extern "C" {
* @param the_tod is the reference to the time of day structure to validate or * @param the_tod is the reference to the time of day structure to validate or
* NULL. * NULL.
* *
* @param ticks_mask is the mask for the ticks member of the time of day. Use * @param ticks_validation indicates if the ticks member of the time of day
* #TOD_ENABLE_TICKS_VALIDATION to validate the ticks member. Use * should be validated. Use #TOD_ENABLE_TICKS_VALIDATION to validate the
* #TOD_DISABLE_TICKS_VALIDATION to skip the validation of the ticks member. * 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.
@@ -62,7 +69,7 @@ extern "C" {
*/ */
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 TOD_Ticks_validation ticks_validation
); );
/** /**

View File

@@ -37,17 +37,19 @@ 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 TOD_Ticks_validation ticks_validation
) )
{ {
uint32_t days_in_month; uint32_t days_in_month;
uint32_t ticks_per_second; uint32_t ticks_per_second;
uint32_t ticks_mask;
if ( the_tod == NULL ) { if ( the_tod == NULL ) {
return RTEMS_INVALID_ADDRESS; return RTEMS_INVALID_ADDRESS;
} }
ticks_per_second = rtems_clock_get_ticks_per_second(); 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 & ticks_mask ) >= ticks_per_second ) ||
(the_tod->second >= TOD_SECONDS_PER_MINUTE) || (the_tod->second >= TOD_SECONDS_PER_MINUTE) ||