source: rtems/cpukit/score/src/timespecdivide.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.2 KB
Line 
1/**
2 *  @file  score/src/timespecdivide.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(
26  const struct timespec *lhs,
27  const struct timespec *rhs,
28  uint32_t              *ival_percentage,
29  uint32_t              *fval_percentage
30)
31{
32  uint64_t left, right, answer;
33
34  /*
35   *  For math simplicity just convert the timespec to nanoseconds
36   *  in a 64-bit integer.
37   */
38  left   = lhs->tv_sec * (uint64_t)TOD_NANOSECONDS_PER_SECOND;
39  left  += lhs->tv_nsec;
40  right  = rhs->tv_sec * (uint64_t)TOD_NANOSECONDS_PER_SECOND;
41  right += rhs->tv_nsec;
42
43  if ( right == 0 ) {
44    *ival_percentage = 0;
45    *fval_percentage = 0;
46    return;
47  }
48
49  /*
50   *  Put it back in the timespec result.
51   *
52   *  TODO: Rounding on the last digit of the fval.
53   */
54
55  answer = (left * 100000) / right;
56
57  *ival_percentage = answer / 1000;
58  *fval_percentage = answer % 1000;
59}
Note: See TracBrowser for help on using the repository browser.