source: rtems/c/src/lib/libbsp/powerpc/dmv177/timer/timer.c @ c932d85

4.104.114.84.95
Last change on this file since c932d85 was c932d85, checked in by Joel Sherrill <joel.sherrill@…>, on 05/30/98 at 10:09:14

New files -- from rtems-LM-980406 which was based on an RTEMS from 12/97.
This was called the dmv170 BSP in that source tree but since the DMV171
is now obsolete, we have transitioned to the DMV177 and have no intention
of checking compatibility with any other models.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*  timer.c
2 *
3 *  This file implements a benchmark timer using the General Purpose Timer on
4 *  the MEC.
5 *
6 *  The license and distribution terms for this file are in
7 *  the file LICENSE in this distribution or at
8 *  http://www.OARcorp.com/rtems/license.html.
9 *
10 *  $Id$
11 */
12
13#include <assert.h>
14
15#include <bsp.h>
16
17rtems_unsigned64 Timer_driver_Start_time;
18
19rtems_boolean Timer_driver_Find_average_overhead;
20
21static inline rtems_unsigned64 PPC_Get_timebase_register( void )
22{
23  rtems_unsigned32 tbr_low;
24  rtems_unsigned32 tbr_high;
25  rtems_unsigned32 tbr_high_old;
26  rtems_unsigned64 tbr;
27
28  do {
29    asm volatile( "mftbu %0" : "=r" (tbr_high_old));
30    asm volatile( "mftb  %0" : "=r" (tbr_low));
31    asm volatile( "mftbu %0" : "=r" (tbr_high));
32  } while ( tbr_high_old != tbr_high );
33
34  tbr = tbr_high;
35  tbr <<= 32;
36  tbr |= tbr_low;
37  return tbr;
38}
39
40/*  PAGE
41 *
42 *  Timer_initialize
43 * 
44 *  This routine initializes the timer. 
45 *
46 *  Input parameters:   NONE
47 *
48 *  Output parameters:  NONE
49 *
50 *  Return values:      NONE
51 *
52 */
53
54void Timer_initialize()
55{
56  /*
57   *  Timer runs long and accurate enough not to require an interrupt.
58   */
59
60
61  Timer_driver_Start_time = PPC_Get_timebase_register();
62 
63
64}
65
66#define AVG_OVERHEAD     24  /* It typically takes 24 instructions */
67                             /*     to start/stop the timer. */
68#define LEAST_VALID       1  /* Don't trust a value lower than this */
69                             /* psim can count instructions. :) */
70
71/*  PAGE
72 *
73 *  Read_timer
74 *
75 *  This routine reads the timer.
76 *
77 *  Input parameters:   NONE
78 *
79 *  Output parameters:  NONE
80 *
81 *  Return values:      timer in ms units
82 *
83 */
84
85int Read_timer()
86{
87  rtems_unsigned64  clicks;
88  rtems_unsigned64  total64;
89  rtems_unsigned32  total;
90
91  /* approximately CLOCK_SPEED clicks per microsecond */
92
93  clicks = PPC_Get_timebase_register();
94
95  assert( clicks > Timer_driver_Start_time );
96
97  total64 = clicks - Timer_driver_Start_time;
98
99  assert( total64 <= 0xffffffff );  /* fits into a unsigned32 */
100
101  total = (rtems_unsigned32) total64;
102
103  if ( Timer_driver_Find_average_overhead == 1 )
104    return total;          /* in one microsecond units */
105
106  if ( total < LEAST_VALID )
107    return 0;            /* below timer resolution */
108
109  return total - AVG_OVERHEAD;
110}
111
112/*  PAGE
113 *
114 *  Empty_function
115 *
116 *  This routine is called during the idle loop.
117 *
118 *  Input parameters:   NONE
119 *
120 *  Output parameters: 
121 *    status code of successful
122 *
123 *  Return values:      NONE
124 *
125 */
126
127rtems_status_code Empty_function( void )
128{
129  return RTEMS_SUCCESSFUL;
130}
131
132/*  PAGE
133 *
134 *  Set_find_average_overhead
135 *
136 *  This routine sets a global boolean to the value passed in.
137 *
138 *  Input parameters:
139 *    find_flag  - flag to indicate to find the average overhead.
140 *
141 *  Output parameters:  NONE
142 *
143 *  Return values:      NONE
144 *
145 */
146
147void Set_find_average_overhead(
148  rtems_boolean find_flag
149)
150{
151  Timer_driver_Find_average_overhead = find_flag;
152}
Note: See TracBrowser for help on using the repository browser.