source: rtems/cpukit/score/src/timespecdividebyinteger.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: 1022 bytes
Line 
1/**
2 * @file
3 *
4 * @brief Divide Timespec By Integer
5 *
6 * @ingroup Timespec
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2007.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/timespec.h>
23#include <rtems/score/todimpl.h>
24
25void _Timespec_Divide_by_integer(
26  const struct timespec *time,
27  uint32_t               iterations,
28  struct timespec       *result
29)
30{
31  uint64_t t;
32
33  /*
34   *  For math simplicity just convert the timespec to nanoseconds
35   *  in a 64-bit integer.
36   */
37  t  = time->tv_sec;
38  t *= TOD_NANOSECONDS_PER_SECOND;
39  t += time->tv_nsec;
40
41  /*
42   *  Divide to get nanoseconds per iteration
43   */
44
45  t /= iterations;
46
47  /*
48   *  Put it back in the timespec result
49   */
50
51  result->tv_sec  = t / TOD_NANOSECONDS_PER_SECOND;
52  result->tv_nsec = t % TOD_NANOSECONDS_PER_SECOND;
53}
Note: See TracBrowser for help on using the repository browser.