source: rtems/c/src/lib/libbsp/sparc/leon2/timer/timer.c @ 37f09415

Last change on this file since 37f09415 was d2a30c77, checked in by Joel Sherrill <joel.sherrill@…>, on 10/05/05 at 19:25:45

2005-10-05 Jiri Gaisler <jiri@…>

Edvin Catovic <edvin@…>
Konrad Eisele <konrad@…>

PR 827/bsps

  • .cvsignore, ChangeLog?, Makefile.am, README, bsp_specs, configure.ac, times, clock/.cvsignore, clock/Makefile.am, clock/ckinit.c, console/.cvsignore, console/Makefile.am, console/console.c, console/consolereserveresources.c, console/debugputs.c, gnatsupp/.cvsignore, gnatsupp/Makefile.am, gnatsupp/gnatsupp.c, include/.cvsignore, include/Makefile.am, include/bsp.h, include/coverhd.h, include/leon.h, leon_open_eth/.cvsignore, leon_open_eth/Makefile.am, leon_open_eth/leon_open_eth.c, leon_smc91111/.cvsignore, leon_smc91111/Makefile.am, leon_smc91111/leon_smc91111.c, start/.cvsignore, start/Makefile.am, startup/.cvsignore, startup/Makefile.am, startup/linkcmds, startup/setvec.c, startup/spurious.c, timer/.cvsignore, timer/Makefile.am, timer/timer.c, tools/.cvsignore, tools/ChangeLog, tools/Makefile.am, tools/configure.ac, tools/runtest.in, wrapup/.cvsignore, wrapup/Makefile.am: New files.
  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*  timer.c
2 *
3 *  This file implements a benchmark timer using timer 2.
4 *
5 *  COPYRIGHT (c) 1989-1998.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  Ported to LEON implementation of the SPARC by On-Line Applications
13 *  Research Corporation (OAR) under contract to the European Space
14 *  Agency (ESA).
15 *
16 *  LEON modifications of respective RTEMS file: COPYRIGHT (c) 1995.
17 *  European Space Agency.
18 *
19 *  $Id$
20 */
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()
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    LEON_REG.Timer_Counter_2 = 0xffffff;
39    LEON_REG.Timer_Reload_2 = 0xffffff;
40
41  } else {
42    Timer_driver_Is_initialized = TRUE;
43  }
44
45  LEON_REG.Timer_Control_2 = (
46    LEON_REG_TIMER_COUNTER_ENABLE_COUNTING |
47      LEON_REG_TIMER_COUNTER_LOAD_COUNTER
48  );
49
50}
51
52#define AVG_OVERHEAD      3  /* It typically takes 3.0 microseconds */
53                             /*     to start/stop the timer. */
54#define LEAST_VALID       2  /* Don't trust a value lower than this */
55
56int Read_timer()
57{
58  rtems_unsigned32  total;
59
60  total = LEON_REG.Timer_Counter_2;
61
62  total = 0xffffff - total;
63
64  if ( Timer_driver_Find_average_overhead == 1 )
65    return total;          /* in one microsecond units */
66
67  if ( total < LEAST_VALID )
68    return 0;            /* below timer resolution */
69
70  return total - AVG_OVERHEAD;
71}
72
73rtems_status_code Empty_function( void )
74{
75  return RTEMS_SUCCESSFUL;
76}
77
78void Set_find_average_overhead(
79  rtems_boolean find_flag
80)
81{
82  Timer_driver_Find_average_overhead = find_flag;
83}
Note: See TracBrowser for help on using the repository browser.