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

4.104.114.84.95
Last change on this file since ccd81b60 was 493fa93, checked in by Joel Sherrill <joel.sherrill@…>, on 12/19/00 at 16:55:35

2000-12-19 Joel Sherrill <joel@…>

  • timer/timer.c: Removed incorrect comments about ERC32.
  • 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
15rtems_unsigned64 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  rtems_unsigned64  clicks;
36  rtems_unsigned64  total64;
37  rtems_unsigned32  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 unsigned32 */
48
49  total = (rtems_unsigned32) 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.