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

4.115
Last change on this file since a211a732 was a211a732, checked in by Sebastian Huber <sebastian.huber@…>, on 04/16/15 at 20:24:59

score: Fix _TOD_Set_with_timestamp()

Update the current time before the watchdog adjust so that timer
routines observe the new time.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Set Time of Day Given a Timestamp
5 *
6 * @ingroup ScoreTOD
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#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/todimpl.h>
22#include <rtems/score/threaddispatch.h>
23#include <rtems/score/watchdogimpl.h>
24
25void _TOD_Set_with_timestamp(
26  const Timestamp_Control *tod_as_timestamp
27)
28{
29  TOD_Control *tod = &_TOD;
30  uint32_t nanoseconds = _Timestamp_Get_nanoseconds( tod_as_timestamp );
31  Watchdog_Interval seconds_next = _Timestamp_Get_seconds( tod_as_timestamp );
32  Watchdog_Interval seconds_now;
33  ISR_lock_Context lock_context;
34  Watchdog_Header *header;
35
36  _Thread_Disable_dispatch();
37
38  seconds_now = _TOD_Seconds_since_epoch();
39
40  _TOD_Acquire( tod, &lock_context );
41  tod->now = *tod_as_timestamp;
42  _TOD_Release( tod, &lock_context );
43
44  header = &_Watchdog_Seconds_header;
45
46  if ( seconds_next < seconds_now )
47    _Watchdog_Adjust_backward( header, seconds_now - seconds_next );
48  else
49    _Watchdog_Adjust_forward( header, seconds_next - seconds_now );
50
51  tod->seconds_trigger = nanoseconds;
52  tod->is_set = true;
53
54  _Thread_Enable_dispatch();
55}
Note: See TracBrowser for help on using the repository browser.