source: rtems/cpukit/score/src/coretodset.c @ 25f5730f

4.11
Last change on this file since 25f5730f was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • 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
35  _Thread_Disable_dispatch();
36
37  seconds_now = _TOD_Seconds_since_epoch();
38
39  if ( seconds_next < seconds_now )
40    _Watchdog_Adjust_seconds( WATCHDOG_BACKWARD, seconds_now - seconds_next );
41  else
42    _Watchdog_Adjust_seconds( WATCHDOG_FORWARD, seconds_next - seconds_now );
43
44  _TOD_Acquire( tod, &lock_context );
45  tod->now = *tod_as_timestamp;
46  _TOD_Release( tod, &lock_context );
47
48  tod->seconds_trigger = nanoseconds;
49  tod->is_set = true;
50
51  _Thread_Enable_dispatch();
52}
Note: See TracBrowser for help on using the repository browser.