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

4.104.114.84.95
Last change on this file since d3d9ef37 was e208738, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/31/04 at 11:11:53

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

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