source: rtems/cpukit/score/src/timespectoticks.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.2 KB
Line 
1/**
2 *  @file  score/src/timespectoticks.c
3 */
4
5/*
6 *  COPYRIGHT (c) 1989-2007.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.org/license/LICENSE.
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems/score/timespec.h>
19#include <rtems/score/todimpl.h>
20#include <rtems/config.h>
21
22/**
23 *
24 *  This routines converts a timespec to the corresponding number of ticks.
25 */
26
27uint32_t _Timespec_To_ticks(
28  const struct timespec *time
29)
30{
31  uint32_t  ticks;
32  uint32_t  nanoseconds_per_tick;
33
34  if ( (time->tv_sec == 0) && (time->tv_nsec == 0) )
35    return 0;
36
37  /**
38   *  We should ensure the ticks not be truncated by integer division.  We
39   *  need to have it be greater than or equal to the requested time.  It
40   *  should not be shorter.
41   */
42  ticks                 = time->tv_sec * TOD_TICKS_PER_SECOND;
43  nanoseconds_per_tick  = rtems_configuration_get_nanoseconds_per_tick();
44  ticks                += time->tv_nsec / nanoseconds_per_tick;
45
46  if ( (time->tv_nsec % nanoseconds_per_tick) != 0 )
47    ticks += 1;
48
49  return ticks;
50}
Note: See TracBrowser for help on using the repository browser.