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

4.104.114.84.95
Last change on this file since ed9e449 was ed9e449, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/31/04 at 03:08:46

2004-03-31 Ralf Corsepius <ralf_corsepius@…>

  • clock/clock.c, console/conscfg.c, console/debugio.c, include/bsp.h, include/dmv170.h, scv64/scv64.c, sonic/dmvsonic.c, startup/bspstart.c, startup/genpvec.c, startup/vmeintr.c, timer/timer.c, tod/todcfg.c: Convert to using c99 fixed size types.
  • Property mode set to 100644
File size: 2.4 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.rtems.com/license/LICENSE.
9 *
10 *  $Id$
11 */
12
13#include <assert.h>
14
15#include <bsp.h>
16
17uint64_t   Timer_driver_Start_time;
18
19rtems_boolean Timer_driver_Find_average_overhead;
20
21/*PAGE
22 *
23 *  Timer_initialize
24 * 
25 *  This routine initializes the timer. 
26 *
27 *  Input parameters:   NONE
28 *
29 *  Output parameters:  NONE
30 *
31 *  Return values:      NONE
32 *
33 */
34
35void Timer_initialize()
36{
37  /*
38   *  Timer runs long and accurate enough not to require an interrupt.
39   */
40
41
42  Timer_driver_Start_time = PPC_Get_timebase_register();
43 
44
45}
46
47#define AVG_OVERHEAD     24  /* It typically takes 24 instructions */
48                             /*     to start/stop the timer. */
49#define LEAST_VALID       1  /* Don't trust a value lower than this */
50
51/*  PAGE
52 *
53 *  Read_timer
54 *
55 *  This routine reads the timer.
56 *
57 *  Input parameters:   NONE
58 *
59 *  Output parameters:  NONE
60 *
61 *  Return values:      timer in ms units
62 *
63 */
64
65int Read_timer()
66{
67  uint64_t    clicks;
68  uint64_t    total64;
69  uint32_t    total;
70
71  /* approximately CLOCK_SPEED clicks per microsecond */
72
73  clicks = PPC_Get_timebase_register();
74
75  assert( clicks > Timer_driver_Start_time );
76
77  total64 = clicks - Timer_driver_Start_time;
78
79  assert( total64 <= 0xffffffff );  /* fits into a uint32_t   */
80
81  total = (uint32_t) total64;
82
83  if ( Timer_driver_Find_average_overhead == 1 )
84    return total;          /* in one microsecond units */
85
86  if ( total < LEAST_VALID )
87    return 0;            /* below timer resolution */
88
89  return total - AVG_OVERHEAD;
90}
91
92/*  PAGE
93 *
94 *  Empty_function
95 *
96 *  This routine is called during the idle loop.
97 *
98 *  Input parameters:   NONE
99 *
100 *  Output parameters: 
101 *    status code of successful
102 *
103 *  Return values:      NONE
104 *
105 */
106
107rtems_status_code Empty_function( void )
108{
109  return RTEMS_SUCCESSFUL;
110}
111
112/*  PAGE
113 *
114 *  Set_find_average_overhead
115 *
116 *  This routine sets a global boolean to the value passed in.
117 *
118 *  Input parameters:
119 *    find_flag  - flag to indicate to find the average overhead.
120 *
121 *  Output parameters:  NONE
122 *
123 *  Return values:      NONE
124 *
125 */
126
127void Set_find_average_overhead(
128  rtems_boolean find_flag
129)
130{
131  Timer_driver_Find_average_overhead = find_flag;
132}
Note: See TracBrowser for help on using the repository browser.