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

4.104.114.84.95
Last change on this file since b6394ae was b6394ae, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 15, 1998 at 3:13:01 PM

Transitioned to shared bsp_libc_init() and cleaned up comments.

  • Property mode set to 100644
File size: 2.5 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
32static inline rtems_unsigned64 PPC_Get_timebase_register( void )
33{
34  rtems_unsigned32 tbr_low;
35  rtems_unsigned32 tbr_high;
36  rtems_unsigned32 tbr_high_old;
37  rtems_unsigned64 tbr;
38
39  do {
40    asm volatile( "mftbu %0" : "=r" (tbr_high_old));
41    asm volatile( "mftb  %0" : "=r" (tbr_low));
42    asm volatile( "mftbu %0" : "=r" (tbr_high));
43  } while ( tbr_high_old != tbr_high );
44
45  tbr = tbr_high;
46  tbr <<= 32;
47  tbr |= tbr_low;
48  return tbr;
49}
50
51void Timer_initialize()
52{
53  /*
54   *  Timer runs long and accurate enough not to require an interrupt.
55   */
56
57
58  Timer_driver_Start_time = PPC_Get_timebase_register();
59 
60
61}
62
63#define AVG_OVERHEAD     24  /* It typically takes 24 instructions */
64                             /*     to start/stop the timer. */
65#define LEAST_VALID       1  /* Don't trust a value lower than this */
66                             /* psim can count instructions. :) */
67
68int Read_timer()
69{
70  rtems_unsigned64  clicks;
71  rtems_unsigned64  total64;
72  rtems_unsigned32  total;
73
74  /* approximately CLOCK_SPEED clicks per microsecond */
75
76  clicks = PPC_Get_timebase_register();
77
78  assert( clicks > Timer_driver_Start_time );
79
80  total64 = clicks - Timer_driver_Start_time;
81
82  assert( total64 <= 0xffffffff );  /* fits into a unsigned32 */
83
84  total = (rtems_unsigned32) total64;
85
86  if ( Timer_driver_Find_average_overhead == 1 )
87    return total;          /* in one microsecond units */
88
89  if ( total < LEAST_VALID )
90    return 0;            /* below timer resolution */
91
92  return total - AVG_OVERHEAD;
93}
94
95rtems_status_code Empty_function( void )
96{
97  return RTEMS_SUCCESSFUL;
98}
99
100void Set_find_average_overhead(
101  rtems_boolean find_flag
102)
103{
104  Timer_driver_Find_average_overhead = find_flag;
105}
Note: See TracBrowser for help on using the repository browser.