source: rtems/cpukit/score/src/timespecdividebyinteger.c @ eea7c937

4.115
Last change on this file since eea7c937 was f031df0e, checked in by Sebastian Huber <sebastian.huber@…>, on 07/31/13 at 11:42:07

score: Rename tod.h to todimpl.h

  • 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.com/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.