source: rtems/c/src/lib/libcpu/powerpc/mpc6xx/timer/timer.c @ 0dd1d44

4.104.114.84.95
Last change on this file since 0dd1d44 was 5d807b5, checked in by Joel Sherrill <joel.sherrill@…>, on 12/21/99 at 17:06:31

New files.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*  timer.c
2 *
3 *  This file implements a benchmark timer using the General Purpose Timer.
4 *
5 *  Notes:
6 *
7 *  BSP_TIMER_AVG_OVERHEAD and BSP_TIMER_LEAST_VALID are required to be
8 *  provided in bsp.h
9 *
10 *  COPYRIGHT (c) 1989-1997.
11 *  On-Line Applications Research Corporation (OAR).
12 *  Copyright assigned to U.S. Government, 1994.
13 *
14 *  The license and distribution terms for this file may in
15 *  the file LICENSE in this distribution or at
16 *  http://www.OARcorp.com/rtems/license.html.
17 *
18 *  $Id$
19 */
20
21#include <assert.h>
22#include <libcpu/cpu.h>
23#include <bsp.h>
24
25rtems_unsigned64 Timer_driver_Start_time;
26
27rtems_boolean Timer_driver_Find_average_overhead = 0;
28unsigned clicks_overhead = 0;
29
30/*
31 * Timer Get overhead
32 */
33
34int Timer_get_clicks_overhead()
35{
36  rtems_unsigned64  clicks;
37
38  PPC_Set_timebase_register((unsigned64) 0);
39  clicks = PPC_Get_timebase_register();
40  assert(clicks <= 0xffffffff);
41  clicks_overhead = (unsigned) clicks;
42  return clicks_overhead;
43}
44
45/*
46 * Timer_initialize
47 */
48void Timer_initialize()
49{
50
51  /*
52   *  Timer runs long and accurate enough not to require an interrupt.
53   */
54
55  if (clicks_overhead == 0) clicks_overhead = Timer_get_clicks_overhead();
56  PPC_Set_timebase_register((unsigned64) 0);
57}
58
59
60/*
61 *  Read_timer
62 */
63int Read_timer()
64{
65  rtems_unsigned64  total64;
66  rtems_unsigned32  total;
67
68  /* approximately CLOCK_SPEED clicks per microsecond */
69
70  total64 = PPC_Get_timebase_register();
71
72  assert( total64 <= 0xffffffff );  /* fits into a unsigned32 */
73
74  total = (rtems_unsigned32) total64;
75
76  if ( Timer_driver_Find_average_overhead == 1 )
77    return total;          /* in "clicks" of the decrementer units */
78
79  return (int) BSP_Convert_decrementer(total - clicks_overhead);
80}
81
82unsigned long long Read_long_timer()
83{
84  rtems_unsigned64  total64;
85
86  total64 = PPC_Get_timebase_register();
87  return BSP_Convert_decrementer(total64 - clicks_overhead);
88}
89
90rtems_status_code Empty_function( void )
91{
92  return RTEMS_SUCCESSFUL;
93}
94
95void Set_find_average_overhead(
96  rtems_boolean find_flag
97)
98{
99  Timer_driver_Find_average_overhead = find_flag;
100}
Note: See TracBrowser for help on using the repository browser.