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

4.104.114.84.95
Last change on this file since dc104a4 was dc104a4, checked in by Joel Sherrill <joel.sherrill@…>, on 05/30/98 at 11:46:21

Updated to current source and removed warnings.

  • 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 *  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
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                             /* psim can count instructions. :) */
51
52/*  PAGE
53 *
54 *  Read_timer
55 *
56 *  This routine reads the timer.
57 *
58 *  Input parameters:   NONE
59 *
60 *  Output parameters:  NONE
61 *
62 *  Return values:      timer in ms units
63 *
64 */
65
66int Read_timer()
67{
68  rtems_unsigned64  clicks;
69  rtems_unsigned64  total64;
70  rtems_unsigned32  total;
71
72  /* approximately CLOCK_SPEED clicks per microsecond */
73
74  clicks = PPC_Get_timebase_register();
75
76  assert( clicks > Timer_driver_Start_time );
77
78  total64 = clicks - Timer_driver_Start_time;
79
80  assert( total64 <= 0xffffffff );  /* fits into a unsigned32 */
81
82  total = (rtems_unsigned32) total64;
83
84  if ( Timer_driver_Find_average_overhead == 1 )
85    return total;          /* in one microsecond units */
86
87  if ( total < LEAST_VALID )
88    return 0;            /* below timer resolution */
89
90  return total - AVG_OVERHEAD;
91}
92
93/*  PAGE
94 *
95 *  Empty_function
96 *
97 *  This routine is called during the idle loop.
98 *
99 *  Input parameters:   NONE
100 *
101 *  Output parameters: 
102 *    status code of successful
103 *
104 *  Return values:      NONE
105 *
106 */
107
108rtems_status_code Empty_function( void )
109{
110  return RTEMS_SUCCESSFUL;
111}
112
113/*  PAGE
114 *
115 *  Set_find_average_overhead
116 *
117 *  This routine sets a global boolean to the value passed in.
118 *
119 *  Input parameters:
120 *    find_flag  - flag to indicate to find the average overhead.
121 *
122 *  Output parameters:  NONE
123 *
124 *  Return values:      NONE
125 *
126 */
127
128void Set_find_average_overhead(
129  rtems_boolean find_flag
130)
131{
132  Timer_driver_Find_average_overhead = find_flag;
133}
Note: See TracBrowser for help on using the repository browser.