source: rtems/cpukit/score/src/coretodset.c

Last change on this file was 80cf60e, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 15, 2020 at 7:48:32 AM

Canonicalize config.h include

Use the following variant which was already used by most source files:

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/**
2 * @file
3 *
4 * @brief Set Time of Day Given a Timestamp
5 *
6 * @ingroup RTEMSScoreTOD
7 */
8
9/*  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#ifdef HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/todimpl.h>
22#include <rtems/score/assert.h>
23#include <rtems/score/watchdogimpl.h>
24
25static Status_Control _TOD_Check_time_of_day_and_run_hooks(
26  const struct timespec *tod
27)
28{
29  if ( !_Watchdog_Is_valid_timespec( tod ) ) {
30    return STATUS_INVALID_NUMBER;
31  }
32
33  if ( tod->tv_sec < TOD_SECONDS_1970_THROUGH_1988 ) {
34    return STATUS_INVALID_NUMBER;
35  }
36
37  if ( _Watchdog_Is_far_future_timespec( tod ) ) {
38    return STATUS_INVALID_NUMBER;
39  }
40
41  return _TOD_Hook_Run( TOD_ACTION_SET_CLOCK, tod );
42}
43
44Status_Control _TOD_Set(
45  const struct timespec *tod,
46  ISR_lock_Context      *lock_context
47)
48{
49  struct bintime  tod_as_bintime;
50  uint64_t        tod_as_ticks;
51  uint32_t        cpu_max;
52  uint32_t        cpu_index;
53  Status_Control  status;
54
55  _Assert( _TOD_Is_owner() );
56
57  status = _TOD_Check_time_of_day_and_run_hooks( tod );
58  if ( status != STATUS_SUCCESSFUL ) {
59    _TOD_Release( lock_context );
60    return status;
61  }
62
63  timespec2bintime( tod, &tod_as_bintime );
64  _Timecounter_Set_clock( &tod_as_bintime, lock_context );
65
66  tod_as_ticks = _Watchdog_Ticks_from_timespec( tod );
67  cpu_max = _SMP_Get_processor_maximum();
68
69  for ( cpu_index = 0 ; cpu_index < cpu_max ; ++cpu_index ) {
70    Per_CPU_Control  *cpu;
71    Watchdog_Header  *header;
72    ISR_lock_Context  lock_context;
73    Watchdog_Control *first;
74
75    cpu = _Per_CPU_Get_by_index( cpu_index );
76    header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_REALTIME ];
77
78    _ISR_lock_ISR_disable_and_acquire( &cpu->Watchdog.Lock, &lock_context );
79
80    first = _Watchdog_Header_first( header );
81
82    if ( first != NULL ) {
83      _Watchdog_Tickle(
84        header,
85        first,
86        tod_as_ticks,
87        &cpu->Watchdog.Lock,
88        &lock_context
89      );
90    }
91
92    _ISR_lock_Release_and_ISR_enable( &cpu->Watchdog.Lock, &lock_context );
93  }
94
95  _TOD.is_set = true;
96
97  return STATUS_SUCCESSFUL;
98}
Note: See TracBrowser for help on using the repository browser.