OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [powerpc/] [dmv177/] [timer/] [timer.c] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  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: timer.c,v 1.2 2001-09-27 12:00:35 chris Exp $
11
 */
12
 
13
#include <assert.h>
14
 
15
#include <bsp.h>
16
 
17
rtems_unsigned64 Timer_driver_Start_time;
18
 
19
rtems_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
 
35
void 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
 
65
int Read_timer()
66
{
67
  rtems_unsigned64  clicks;
68
  rtems_unsigned64  total64;
69
  rtems_unsigned32  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 unsigned32 */
80
 
81
  total = (rtems_unsigned32) 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
 
107
rtems_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
 
127
void Set_find_average_overhead(
128
  rtems_boolean find_flag
129
)
130
{
131
  Timer_driver_Find_average_overhead = find_flag;
132
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.