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
RevLine 
[5d807b5]1/*  timer.c
2 *
3 *  This file implements a benchmark timer using the General Purpose Timer.
4 *
[4fb2a19]5 *  Notes: NONE
[5d807b5]6 *
[4fb2a19]7 *  COPYRIGHT (c) 1989-2000.
[5d807b5]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
[21e1c44]12 *  http://www.rtems.com/license/LICENSE.
[5d807b5]13 *
14 *  $Id$
15 */
16
[a73a977]17#include <rtems/system.h>
[5d807b5]18#include <assert.h>
[8e13ca61]19#include <rtems.h>
[133ddf2e]20#include <bsp.h>
[5d807b5]21
[66c373bf]22uint64_t   Timer_driver_Start_time;
[5d807b5]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{
[66c373bf]33  uint64_t    clicks;
[5d807b5]34
[e208738]35  PPC_Set_timebase_register((uint64_t) 0);
[5d807b5]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();
[e208738]53  PPC_Set_timebase_register((uint64_t) 0);
[5d807b5]54}
55
56
57/*
58 *  Read_timer
59 */
[8e13ca61]60
[5d807b5]61int Read_timer()
62{
[66c373bf]63  uint64_t    total64;
64  uint32_t    total;
[5d807b5]65
66  /* approximately CLOCK_SPEED clicks per microsecond */
67
68  total64 = PPC_Get_timebase_register();
69
[66c373bf]70  assert( total64 <= 0xffffffff );  /* fits into a uint32_t   */
[5d807b5]71
[e208738]72  total = (uint32_t) total64;
[5d807b5]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{
[66c373bf]82  uint64_t    total64;
[5d807b5]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.