source: rtems/c/src/lib/libbsp/sparc/erc32/timer/timer.c @ 292f01c

4.104.114.9
Last change on this file since 292f01c was 292f01c, checked in by Ralf Corsepius <ralf.corsepius@…>, on Aug 18, 2008 at 11:27:37 AM

Add missing prototypes.

  • Property mode set to 100644
File size: 2.3 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 the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
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 <bsp.h>
24
25rtems_boolean Timer_driver_Find_average_overhead;
26
27rtems_boolean Timer_driver_Is_initialized = FALSE;
28
29void Timer_initialize(void)
30{
31  /*
32   *  Timer runs long and accurate enough not to require an interrupt.
33   */
34
35  if ( Timer_driver_Is_initialized == FALSE ) {
36
37    /* approximately 1 us per countdown */
38    ERC32_MEC.General_Purpose_Timer_Scalar  = CLOCK_SPEED - 1;
39    ERC32_MEC.General_Purpose_Timer_Counter = 0xffffffff;
40
41  } else {
42    Timer_driver_Is_initialized = TRUE;
43  }
44
45  ERC32_MEC_Set_General_Purpose_Timer_Control(
46    ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING |
47      ERC32_MEC_TIMER_COUNTER_LOAD_COUNTER
48  );
49
50  ERC32_MEC_Set_General_Purpose_Timer_Control(
51    ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING
52  );
53
54}
55
56#if ENABLE_SIS_QUIRKS
57#define AVG_OVERHEAD      8  /* It typically takes 3.0 microseconds */
58                             /*     to start/stop the timer. */
59#define LEAST_VALID       9  /* Don't trust a value lower than this */
60#else
61#define AVG_OVERHEAD     12  /* It typically takes 3.0 microseconds */
62                             /*     to start/stop the timer. */
63#define LEAST_VALID      13  /* Don't trust a value lower than this */
64#endif
65
66int Read_timer(void)
67{
68  uint32_t          total;
69
70  total = ERC32_MEC.General_Purpose_Timer_Counter;
71
72  total = 0xffffffff - total;
73
74  if ( Timer_driver_Find_average_overhead == 1 )
75    return total;          /* in one microsecond units */
76
77  if ( total < LEAST_VALID )
78    return 0;            /* below timer resolution */
79
80  return total - AVG_OVERHEAD;
81}
82
83rtems_status_code Empty_function( void )
84{
85  return RTEMS_SUCCESSFUL;
86}
87
88void Set_find_average_overhead(
89  rtems_boolean find_flag
90)
91{
92  Timer_driver_Find_average_overhead = find_flag;
93}
Note: See TracBrowser for help on using the repository browser.