source: rtems/cpukit/rtems/src/clocktodvalidate.c @ 523867d

Last change on this file since 523867d was 523867d, checked in by Sebastian Huber <sebastian.huber@…>, on 05/11/21 at 15:27:20

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.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup RTEMSImplClassicClock
5 *
6 * @brief This source file contains the implementation of
7 *   _TOD_Validate().
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2007.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <rtems/rtems/clockimpl.h>
24#include <rtems/score/todimpl.h>
25#include <rtems/config.h>
26
27/*
28 *  The following array contains the number of days in all months.
29 *  The first dimension should be 1 for leap years, and 0 otherwise.
30 *  The second dimension should range from 1 to 12 for January to
31 *  February, respectively.
32 */
33const uint32_t   _TOD_Days_per_month[ 2 ][ 13 ] = {
34  { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
35  { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
36};
37
38rtems_status_code _TOD_Validate(
39  const rtems_time_of_day *the_tod,
40  uint32_t                 ticks_mask
41)
42{
43  uint32_t   days_in_month;
44  uint32_t   ticks_per_second;
45
46  if ( the_tod == NULL ) {
47    return RTEMS_INVALID_ADDRESS;
48  }
49
50  ticks_per_second = rtems_clock_get_ticks_per_second();
51
52  if ( ( ( the_tod->ticks & ticks_mask ) >= ticks_per_second ) ||
53      (the_tod->second >= TOD_SECONDS_PER_MINUTE) ||
54      (the_tod->minute >= TOD_MINUTES_PER_HOUR)   ||
55      (the_tod->hour   >= TOD_HOURS_PER_DAY)      ||
56      (the_tod->month  == 0)                      ||
57      (the_tod->month  >  TOD_MONTHS_PER_YEAR)    ||
58      (the_tod->year   <  TOD_BASE_YEAR)          ||
59      (the_tod->year   >  TOD_LATEST_YEAR)        ||
60      (the_tod->day    == 0) ) {
61    return RTEMS_INVALID_CLOCK;
62  }
63
64  if (((the_tod->year % 4) == 0 && (the_tod->year % 100 != 0)) ||
65     (the_tod->year % 400 == 0))
66    days_in_month = _TOD_Days_per_month[ 1 ][ the_tod->month ];
67  else
68    days_in_month = _TOD_Days_per_month[ 0 ][ the_tod->month ];
69
70  if ( the_tod->day > days_in_month ) {
71    return RTEMS_INVALID_CLOCK;
72  }
73
74  return RTEMS_SUCCESSFUL;
75}
Note: See TracBrowser for help on using the repository browser.