source: rtems/c/src/lib/libbsp/powerpc/mvme2307/timer/timer.c @ 19ca797

4.104.114.84.95
Last change on this file since 19ca797 was 19ca797, checked in by Joel Sherrill <joel.sherrill@…>, on 10/04/99 at 20:41:28

Motorola MVME2307 BSP submitted by Jay Kulpinski <jskulpin@…>.
No modifications made.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*  timer.c
2 *
3 *  This file manages the benchmark timer used by the RTEMS Timing Test
4 *  Suite.  Each measured time period is demarcated by calls to
5 *  Timer_initialize() and Read_timer().  Read_timer() usually returns
6 *  the number of microseconds since Timer_initialize() exitted.
7 *
8 *  This version returns the number of nanoseconds since Timer_initialize()
9 *  exited, since the '604 is very fast at 300MHz.  Actual resolution is
10 *  60 nsec.
11 *
12 *  NOTE: It is important that the timer start/stop overhead be
13 *        determined when porting or modifying this code.
14 *
15 *  COPYRIGHT (c) 1989-1998.
16 *  On-Line Applications Research Corporation (OAR).
17 *  Copyright assigned to U.S. Government, 1994.
18 *
19 *  The license and distribution terms for this file may be
20 *  found in the file LICENSE in this distribution or at
21 *  http://www.OARcorp.com/rtems/license.html.
22 *
23 *  $Id$
24 */
25
26#include <rtems.h>
27#include <bsp.h>
28
29rtems_unsigned32 Timer_start;
30rtems_boolean Timer_driver_Find_average_overhead;
31
32void Timer_initialize( void )
33{
34    rtems_unsigned32 clicks;
35
36    asm volatile ("mfspr %0,268" : "=r" (clicks) :);
37    Timer_start = clicks;
38}
39
40/*
41 *  The following controls the behavior of Read_timer().
42 *
43 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
44 *  is usually deducted from the number returned.
45 *
46 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
47 *  below this are "noise" and zero is returned.
48 */
49
50#define AVG_OVERHEAD      7  /* On average, it takes 7.4 nanoseconds */
51                             /* (Y countdowns) to start/stop the timer. */
52
53#define NSEC_PER_TICK    60 
54
55int Read_timer( void )
56{
57    rtems_unsigned32 clicks;
58    rtems_unsigned32 total;
59
60    /*
61     *  Read the timer and see how many clicks it has been since we started.
62     *  Timer overflows every 257 seconds, so multiple overflows are deemed
63     *  impossible.
64     */
65
66    asm volatile ("mfspr %0,268" : "=r" (clicks) :);
67    total = (clicks - Timer_start);
68
69    if ( Timer_driver_Find_average_overhead == 1 ) {
70        return total * NSEC_PER_TICK;          /* in nanoseconds */
71    } else {
72        /*
73        *   convert total into nanoseconds
74        */
75        return total * NSEC_PER_TICK - AVG_OVERHEAD;
76    }
77}
78
79/*
80 *  Empty function call used in loops to measure basic cost of looping
81 *  in Timing Test Suite.
82 */
83
84rtems_status_code Empty_function( void ) {
85    return RTEMS_SUCCESSFUL;
86}
87
88void Set_find_average_overhead(rtems_boolean find_flag) {
89    Timer_driver_Find_average_overhead = find_flag;
90}
91
Note: See TracBrowser for help on using the repository browser.