source: rtems/cpukit/rtems/src/clockset.c @ 08bd7d3

5
Last change on this file since 08bd7d3 was 08bd7d3, checked in by Joel Sherrill <joel@…>, on 11/12/19 at 15:33:41

Add TOD Hooks to allow BSP to take action when TOD is set

Two use cases were envisioned for this.

1) a BSP or application which desires to update a real-time clock

when the RTEMS TOD is set.

2) a paravirtualized BSP can use this to propagate setting the time

in an RTEMS application to the hosting environment. This enables
the entire set of applications in the virtualized environments
to have a single consistent TOD.

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Set the Current TOD
5 *  @ingroup ClassicClock
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-1999.
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/rtems/clock.h>
22#include <rtems/score/todimpl.h>
23#include <rtems/config.h>
24
25rtems_status_code rtems_clock_set(
26  const rtems_time_of_day *tod
27)
28{
29  bool retval;
30
31  if ( !tod )
32    return RTEMS_INVALID_ADDRESS;
33
34  if ( _TOD_Validate( tod ) ) {
35    struct timespec  tod_as_timespec;
36    ISR_lock_Context lock_context;
37
38    tod_as_timespec.tv_sec = _TOD_To_seconds( tod );
39    tod_as_timespec.tv_nsec = tod->ticks
40      * rtems_configuration_get_nanoseconds_per_tick();
41
42    _TOD_Lock();
43    _TOD_Acquire( &lock_context );
44    retval = _TOD_Set( &tod_as_timespec, &lock_context );
45    _TOD_Unlock();
46
47    if ( retval == true ) {
48      return RTEMS_SUCCESSFUL;
49    }
50    return RTEMS_IO_ERROR;
51  }
52
53  return RTEMS_INVALID_CLOCK;
54}
Note: See TracBrowser for help on using the repository browser.