source: rtems/c/src/lib/libbsp/sparc/erc32/timer/timer.c @ 03f2154e

4.104.114.84.95
Last change on this file since 03f2154e was 03f2154e, checked in by Joel Sherrill <joel.sherrill@…>, on 04/22/97 at 17:20:27

headers updated to reflect new style copyright notice as part
of switching to the modified GNU GPL.

  • Property mode set to 100644
File size: 2.1 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-1997.
7 *  On-Line Applications Research Corporation (OAR).
8 *  Copyright assigned to U.S. Government, 1994.
9 *
10 *  The license and distribution terms for this file may in
11 *  the file LICENSE in this distribution or at
12 *  http://www.OARcorp.com/rtems/license.html.
13 *
14 *  Ported to ERC32 implementation of the SPARC by On-Line Applications
15 *  Research Corporation (OAR) under contract to the European Space
16 *  Agency (ESA).
17 *
18 *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
19 *  European Space Agency.
20 *
21 *  $Id$
22 */
23
24
25#include <bsp.h>
26
27rtems_boolean Timer_driver_Find_average_overhead;
28
29rtems_boolean Timer_driver_Is_initialized = FALSE;
30
31void Timer_initialize()
32{
33  /*
34   *  Timer runs long and accurate enough not to require an interrupt.
35   */
36
37  if ( Timer_driver_Is_initialized == FALSE ) {
38
39    /* approximately 1 us per countdown */
40    ERC32_MEC.General_Purpose_Timer_Scalar  = CLOCK_SPEED - 1;
41    ERC32_MEC.General_Purpose_Timer_Counter = 0xffffffff;
42
43  } else {
44    Timer_driver_Is_initialized = TRUE;
45  }
46
47  ERC32_MEC_Set_General_Purpose_Timer_Control(
48    ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING |
49      ERC32_MEC_TIMER_COUNTER_LOAD_COUNTER
50  );
51
52  ERC32_MEC_Set_General_Purpose_Timer_Control(
53    ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING
54  );
55
56}
57
58#define AVG_OVERHEAD      3  /* It typically takes 3.0 microseconds */
59                             /*     to start/stop the timer. */
60#define LEAST_VALID       2  /* Don't trust a value lower than this */
61
62int Read_timer()
63{
64  rtems_unsigned32  total;
65
66  total = ERC32_MEC.General_Purpose_Timer_Counter;
67
68  total = 0xffffffff - total;
69
70  if ( Timer_driver_Find_average_overhead == 1 )
71    return total;          /* in one microsecond units */
72
73  if ( total < LEAST_VALID )
74    return 0;            /* below timer resolution */
75
76  return total - AVG_OVERHEAD;
77}
78
79rtems_status_code Empty_function( void )
80{
81  return RTEMS_SUCCESSFUL;
82}
83
84void Set_find_average_overhead(
85  rtems_boolean find_flag
86)
87{
88  Timer_driver_Find_average_overhead = find_flag;
89}
Note: See TracBrowser for help on using the repository browser.