source: rtems/c/src/lib/libbsp/powerpc/psim/timer/timer.c @ ea57368

4.104.114.84.95
Last change on this file since ea57368 was ea57368, checked in by Joel Sherrill <joel.sherrill@…>, on Jun 3, 1998 at 7:01:21 PM

Removed PPC_Get_timebase_register() as this is now provided by the PowerPC
port itself.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*  timer.c
2 *
3 *  This file implements a benchmark timer using the General Purpose Timer on
4 *  the MEC.
5 *
6 *  COPYRIGHT (c) 1989-1998.
7 *  On-Line Applications Research Corporation (OAR).
8 *  Copyright assigned to U.S. Government, 1994.
9 *
10 *  The license and distribution terms for this file may be
11 *  found in found in the file LICENSE in this distribution or at
12 *  http://www.OARcorp.com/rtems/license.html.
13 *
14 *  Ported to ERC32 implementation of the SPARC by On-Line Applications
15 *  Research Corporation (OAR) under contract to the European Space
16 *  Agency (ESA).
17 *
18 *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
19 *  European Space Agency.
20 *
21 *  $Id$
22 */
23
24#include <assert.h>
25
26#include <bsp.h>
27
28rtems_unsigned64 Timer_driver_Start_time;
29
30rtems_boolean Timer_driver_Find_average_overhead;
31
32void Timer_initialize()
33{
34  /*
35   *  Timer runs long and accurate enough not to require an interrupt.
36   */
37
38
39  Timer_driver_Start_time = PPC_Get_timebase_register();
40 
41
42}
43
44#define AVG_OVERHEAD     24  /* It typically takes 24 instructions */
45                             /*     to start/stop the timer. */
46#define LEAST_VALID       1  /* Don't trust a value lower than this */
47                             /* psim can count instructions. :) */
48
49int Read_timer()
50{
51  rtems_unsigned64  clicks;
52  rtems_unsigned64  total64;
53  rtems_unsigned32  total;
54
55  /* approximately CLOCK_SPEED clicks per microsecond */
56
57  clicks = PPC_Get_timebase_register();
58
59  assert( clicks > Timer_driver_Start_time );
60
61  total64 = clicks - Timer_driver_Start_time;
62
63  assert( total64 <= 0xffffffff );  /* fits into a unsigned32 */
64
65  total = (rtems_unsigned32) total64;
66
67  if ( Timer_driver_Find_average_overhead == 1 )
68    return total;          /* in one microsecond units */
69
70  if ( total < LEAST_VALID )
71    return 0;            /* below timer resolution */
72
73  return total - AVG_OVERHEAD;
74}
75
76rtems_status_code Empty_function( void )
77{
78  return RTEMS_SUCCESSFUL;
79}
80
81void Set_find_average_overhead(
82  rtems_boolean find_flag
83)
84{
85  Timer_driver_Find_average_overhead = find_flag;
86}
Note: See TracBrowser for help on using the repository browser.