source: rtems/c/src/lib/libbsp/c4x/c4xsim/timer/timer.c @ f05b2ac

4.104.114.84.95
Last change on this file since f05b2ac was f05b2ac, checked in by Ralf Corsepius <ralf.corsepius@…>, on Apr 21, 2004 at 4:01:48 PM

Remove duplicate white lines.

  • Property mode set to 100644
File size: 3.0 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 *  NOTE: It is important that the timer start/stop overhead be
9 *        determined when porting or modifying this code.
10 *
11 *  COPYRIGHT (c) 1989-1999.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.com/license/LICENSE.
17 *
18 *  $Id$
19 */
20
21#include <rtems.h>
22#include <bsp.h>
23#include <rtems/c4x/c4xio.h>
24
25uint32_t         Timer_interrupts;
26rtems_boolean Timer_driver_Find_average_overhead;
27
28static uint32_t   start;
29
30void Timer_initialize( void )
31{
32
33  /*
34   *  Timer has never overflowed.  This may not be necessary on some
35   *  implemenations of timer but ....
36   */
37
38  c4x_timer_stop(C4X_TIMER_0);
39  c4x_timer_set_period(C4X_TIMER_0, 0xffffffff); /* so no interupts */
40  c4x_timer_start(C4X_TIMER_0);
41  start = c4x_timer_get_counter(C4X_TIMER_0);
42
43  Timer_interrupts = 0;
44
45  /*
46   *  Somehow start the timer
47   */
48}
49
50/*
51 *  The following controls the behavior of Read_timer().
52 *
53 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
54 *  is usually deducted from the number returned.
55 *
56 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
57 *  below this are "noise" and zero is returned.
58 */
59
60#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
61                             /* (Y countdowns) to start/stop the timer. */
62                             /* This value is in microseconds. */
63#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
64
65int Read_timer( void )
66{
67  uint32_t         clicks;
68  uint32_t         total;
69  int            tmp;
70
71  /*
72   *  Read the timer and see how many clicks it has been since we started.
73   */
74
75  clicks = c4x_timer_get_counter(C4X_TIMER_0);
76  clicks -= start;
77
78  /*
79   *  Total is calculated by taking into account the number of timer overflow
80   *  interrupts since the timer was initialized and clicks since the last
81   *  interrupts.
82   */
83
84  total = clicks * 1;
85
86  if ( Timer_driver_Find_average_overhead == 1 ) {
87    return total;          /* in count units where each count is */
88                           /* 1 / (clock frequency/2) */
89  } else {
90    if ( total < LEAST_VALID )
91      return 0;            /* below timer resolution */
92  /*
93   *  Somehow convert total into microseconds
94   */
95      tmp = (int) ((float) total * ((1.0 / 25.0)));
96      return (tmp - AVG_OVERHEAD);
97    }
98}
99
100/*
101 *  Empty function call used in loops to measure basic cost of looping
102 *  in Timing Test Suite.
103 */
104
105rtems_status_code Empty_function( void )
106{
107  return RTEMS_SUCCESSFUL;
108}
109
110void Set_find_average_overhead(
111  rtems_boolean find_flag
112)
113{
114  Timer_driver_Find_average_overhead = find_flag;
115}
Note: See TracBrowser for help on using the repository browser.