source: rtems/cpukit/score/src/timespecdivide.c @ 4fc370e

4.115
Last change on this file since 4fc370e was f7f1d77, checked in by Alex Ivanov <alexivanov97@…>, on 11/28/12 at 14:11:31

score misc: Clean up Doxygen (GCI 2012)

This patch is a task from GCI 2012 which improves the Doxygen
comments in the RTEMS source.
https://google-melange.appspot.com/gci/task/view/google/gci2012/7978208

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Divide Timespec By Integer
5 * @ingroup Timespec
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#include <sys/types.h>
23#include <rtems/score/timespec.h>
24#include <rtems/score/tod.h>
25
26void _Timespec_Divide(
27  const struct timespec *lhs,
28  const struct timespec *rhs,
29  uint32_t              *ival_percentage,
30  uint32_t              *fval_percentage
31)
32{
33  uint64_t left, right, answer;
34
35  /*
36   *  For math simplicity just convert the timespec to nanoseconds
37   *  in a 64-bit integer.
38   */
39  left   = lhs->tv_sec * (uint64_t)TOD_NANOSECONDS_PER_SECOND;
40  left  += lhs->tv_nsec;
41  right  = rhs->tv_sec * (uint64_t)TOD_NANOSECONDS_PER_SECOND;
42  right += rhs->tv_nsec;
43
44  if ( right == 0 ) {
45    *ival_percentage = 0;
46    *fval_percentage = 0;
47    return;
48  }
49
50  /*
51   *  Put it back in the timespec result.
52   *
53   *  TODO: Rounding on the last digit of the fval.
54   */
55
56  answer = (left * 100000) / right;
57
58  *ival_percentage = answer / 1000;
59  *fval_percentage = answer % 1000;
60}
Note: See TracBrowser for help on using the repository browser.