source: rtems/c/src/lib/libbsp/powerpc/psim/timer/timer.c @ 6128a4a

4.104.114.84.95
Last change on this file since 6128a4a was 6128a4a, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/21/04 at 10:43:04

Remove stray white spaces.

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/*
2 *  This file implements a benchmark timer using the PPC decrement register.
3 *
4 *  COPYRIGHT (c) 1989-2000.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *
8 *  $Id$
9 */
10
11#include <assert.h>
12
13#include <bsp.h>
14
15uint64_t         Timer_driver_Start_time;
16
17rtems_boolean Timer_driver_Find_average_overhead;
18
19void Timer_initialize()
20{
21  /*
22   *  Timer runs long and accurate enough not to require an interrupt.
23   */
24
25  Timer_driver_Start_time = PPC_Get_timebase_register();
26}
27
28#define AVG_OVERHEAD     24  /* It typically takes 24 instructions */
29                             /*     to start/stop the timer. */
30#define LEAST_VALID       1  /* Don't trust a value lower than this */
31                             /* psim can count instructions. :) */
32
33int Read_timer()
34{
35  uint64_t          clicks;
36  uint64_t          total64;
37  uint32_t          total;
38
39  /* approximately CLOCK_SPEED clicks per microsecond */
40
41  clicks = PPC_Get_timebase_register();
42
43  assert( clicks > Timer_driver_Start_time );
44
45  total64 = clicks - Timer_driver_Start_time;
46
47  assert( total64 <= 0xffffffff );  /* fits into a uint32_t   */
48
49  total = (uint32_t) total64;
50
51  if ( Timer_driver_Find_average_overhead == 1 )
52    return total;          /* in one microsecond units */
53
54  if ( total < LEAST_VALID )
55    return 0;            /* below timer resolution */
56
57  return total - AVG_OVERHEAD;
58}
59
60rtems_status_code Empty_function( void )
61{
62  return RTEMS_SUCCESSFUL;
63}
64
65void Set_find_average_overhead(
66  rtems_boolean find_flag
67)
68{
69  Timer_driver_Find_average_overhead = find_flag;
70}
Note: See TracBrowser for help on using the repository browser.