OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [sparc/] [erc32/] [timer/] [timer.c] - Blame information for rev 562

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  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.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: timer.c,v 1.2 2001-09-27 12:01:14 chris Exp $
21
 */
22
 
23
 
24
#include <bsp.h>
25
 
26
rtems_boolean Timer_driver_Find_average_overhead;
27
 
28
rtems_boolean Timer_driver_Is_initialized = FALSE;
29
 
30
void Timer_initialize()
31
{
32
  /*
33
   *  Timer runs long and accurate enough not to require an interrupt.
34
   */
35
 
36
  if ( Timer_driver_Is_initialized == FALSE ) {
37
 
38
    /* approximately 1 us per countdown */
39
    ERC32_MEC.General_Purpose_Timer_Scalar  = CLOCK_SPEED - 1;
40
    ERC32_MEC.General_Purpose_Timer_Counter = 0xffffffff;
41
 
42
  } else {
43
    Timer_driver_Is_initialized = TRUE;
44
  }
45
 
46
  ERC32_MEC_Set_General_Purpose_Timer_Control(
47
    ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING |
48
      ERC32_MEC_TIMER_COUNTER_LOAD_COUNTER
49
  );
50
 
51
  ERC32_MEC_Set_General_Purpose_Timer_Control(
52
    ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING
53
  );
54
 
55
}
56
 
57
#define AVG_OVERHEAD      3  /* It typically takes 3.0 microseconds */
58
                             /*     to start/stop the timer. */
59
#define LEAST_VALID       2  /* Don't trust a value lower than this */
60
 
61
int Read_timer()
62
{
63
  rtems_unsigned32  total;
64
 
65
  total = ERC32_MEC.General_Purpose_Timer_Counter;
66
 
67
  total = 0xffffffff - total;
68
 
69
  if ( Timer_driver_Find_average_overhead == 1 )
70
    return total;          /* in one microsecond units */
71
 
72
  if ( total < LEAST_VALID )
73
    return 0;            /* below timer resolution */
74
 
75
  return total - AVG_OVERHEAD;
76
}
77
 
78
rtems_status_code Empty_function( void )
79
{
80
  return RTEMS_SUCCESSFUL;
81
}
82
 
83
void Set_find_average_overhead(
84
  rtems_boolean find_flag
85
)
86
{
87
  Timer_driver_Find_average_overhead = find_flag;
88
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.