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

4.104.114.84.9
Last change on this file since 61ba9763 was 61ba9763, checked in by Joel Sherrill <joel.sherrill@…>, on Feb 22, 2000 at 6:39:52 PM

New port of RTEMS to TI C3x and C4x.

  • 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.OARcorp.com/rtems/license.html.
17 *
18 *  $Id$
19 */
20
21#include <rtems.h>
22#include <bsp.h>
23#include <c4xio.h>
24
25rtems_unsigned32 Timer_interrupts;
26rtems_boolean Timer_driver_Find_average_overhead;
27
28static unsigned32 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 
39  c4x_timer_stop(C4X_TIMER_0);
40  c4x_timer_set_period(C4X_TIMER_0, 0xffffffff); /* so no interupts */
41  c4x_timer_start(C4X_TIMER_0);
42  start = c4x_timer_get_counter(C4X_TIMER_0);
43
44  Timer_interrupts = 0;
45
46  /*
47   *  Somehow start the timer
48   */
49}
50
51/*
52 *  The following controls the behavior of Read_timer().
53 *
54 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
55 *  is usually deducted from the number returned.
56 *
57 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
58 *  below this are "noise" and zero is returned.
59 */
60
61#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
62                             /* (Y countdowns) to start/stop the timer. */
63                             /* This value is in microseconds. */
64#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
65
66int Read_timer( void )
67{
68  rtems_unsigned32 clicks;
69  rtems_unsigned32 total;
70  int            tmp;
71
72  /*
73   *  Read the timer and see how many clicks it has been since we started.
74   */
75
76  clicks = c4x_timer_get_counter(C4X_TIMER_0);
77  clicks -= start;
78
79  /*
80   *  Total is calculated by taking into account the number of timer overflow
81   *  interrupts since the timer was initialized and clicks since the last
82   *  interrupts.
83   */
84
85  total = clicks * 1;
86
87  if ( Timer_driver_Find_average_overhead == 1 ) {
88    return total;          /* in count units where each count is */
89                           /* 1 / (clock frequency/2) */
90  } else {
91    if ( total < LEAST_VALID )
92      return 0;            /* below timer resolution */
93  /*
94   *  Somehow convert total into microseconds
95   */
96      tmp = (int) ((float) total * ((1.0 / 25.0)));
97      return (tmp - AVG_OVERHEAD);
98    }
99}
100
101/*
102 *  Empty function call used in loops to measure basic cost of looping
103 *  in Timing Test Suite.
104 */
105
106rtems_status_code Empty_function( void )
107{
108  return RTEMS_SUCCESSFUL;
109}
110
111void Set_find_average_overhead(
112  rtems_boolean find_flag
113)
114{
115  Timer_driver_Find_average_overhead = find_flag;
116}
117
Note: See TracBrowser for help on using the repository browser.