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

4.115
Last change on this file since c86da31c was 28352fae, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/29/09 at 13:51:53

Whitespace removal.

  • Property mode set to 100644
File size: 1.0 KB
Line 
1/**
2 *  @file  score/src/timespecdividebyinteger.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.com/license/LICENSE.
12 *
13 *  $Id$
14 */
15
16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <rtems/system.h>
21#include <sys/types.h>
22#include <rtems/score/timespec.h>
23#include <rtems/score/tod.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.