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

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • 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 on
4 *  the MEC.
5 *
6 *  COPYRIGHT (c) 1989-1999.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  Ported to ERC32 implementation of the SPARC by On-Line Applications
14 *  Research Corporation (OAR) under contract to the European Space
15 *  Agency (ESA).
16 *
17 *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
18 *  European Space Agency.
19 *
20 *  $Id$
21 */
22
23#include <assert.h>
24
25#include <bsp.h>
26
27rtems_unsigned64 Timer_driver_Start_time;
28
29rtems_boolean Timer_driver_Find_average_overhead;
30
31void Timer_initialize()
32{
33  /*
34   *  Timer runs long and accurate enough not to require an interrupt.
35   */
36
37
38  Timer_driver_Start_time = PPC_Get_timebase_register();
39 
40
41}
42
43#define AVG_OVERHEAD     24  /* It typically takes 24 instructions */
44                             /*     to start/stop the timer. */
45#define LEAST_VALID       1  /* Don't trust a value lower than this */
46                             /* psim can count instructions. :) */
47
48int Read_timer()
49{
50  rtems_unsigned64  clicks;
51  rtems_unsigned64  total64;
52  rtems_unsigned32  total;
53
54  /* approximately CLOCK_SPEED clicks per microsecond */
55
56  clicks = PPC_Get_timebase_register();
57
58  assert( clicks > Timer_driver_Start_time );
59
60  total64 = clicks - Timer_driver_Start_time;
61
62  assert( total64 <= 0xffffffff );  /* fits into a unsigned32 */
63
64  total = (rtems_unsigned32) total64;
65
66  if ( Timer_driver_Find_average_overhead == 1 )
67    return total;          /* in one microsecond units */
68
69  if ( total < LEAST_VALID )
70    return 0;            /* below timer resolution */
71
72  return total - AVG_OVERHEAD;
73}
74
75rtems_status_code Empty_function( void )
76{
77  return RTEMS_SUCCESSFUL;
78}
79
80void Set_find_average_overhead(
81  rtems_boolean find_flag
82)
83{
84  Timer_driver_Find_average_overhead = find_flag;
85}
Note: See TracBrowser for help on using the repository browser.