source: rtems/cpukit/score/src/timespecdivide.c @ f919582d

4.104.114.84.95
Last change on this file since f919582d was f919582d, checked in by Joel Sherrill <joel.sherrill@…>, on 05/16/07 at 15:04:25

2007-05-16 Joel Sherrill <joel.sherrill@…>

  • score/Makefile.am, score/include/rtems/score/timespec.h: Add division and greater than operations for timespecs.
  • score/src/timespecdivide.c, score/src/timespecgreaterthan.c: New files.
  • Property mode set to 100644
File size: 1.0 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 *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 * TOD_NANOSECONDS_PER_SECOND;
38  t += time->tv_nsec;
39
40  /*
41   *  Divide to get nanoseconds per iteration
42   */
43
44  t /= iterations;
45
46  /*
47   *  Put it back in the timespec result
48   */
49
50  result->tv_sec  = t / TOD_NANOSECONDS_PER_SECOND;
51  result->tv_nsec = t % TOD_NANOSECONDS_PER_SECOND;
52}
Note: See TracBrowser for help on using the repository browser.