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

4.104.114.95
Last change on this file since e511e126 was e511e126, checked in by Joel Sherrill <joel.sherrill@…>, on 08/31/08 at 17:42:00

2008-08-31 Joel Sherrill <joel.sherrill@…>

  • timer/timer.c: Eliminate empty function from every benchmark timer driver. Fix spelling.
  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[cb585c3]1/*  timer.c
2 *
3 *  This file implements a benchmark timer using the General Purpose Timer on
4 *  the MEC.
5 *
[08311cc3]6 *  COPYRIGHT (c) 1989-1999.
[cb585c3]7 *  On-Line Applications Research Corporation (OAR).
8 *
[98e4ebf5]9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
[7d2a0641]11 *  http://www.rtems.com/license/LICENSE.
[cb585c3]12 *
13 *  Ported to ERC32 implementation of the SPARC by On-Line Applications
[6128a4a]14 *  Research Corporation (OAR) under contract to the European Space
[cb585c3]15 *  Agency (ESA).
16 *
[6128a4a]17 *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
[cb585c3]18 *  European Space Agency.
19 *
20 *  $Id$
21 */
22
23#include <bsp.h>
24
[e511e126]25rtems_boolean benchmark_timer_find_average_overhead;
[cb585c3]26
[e511e126]27rtems_boolean benchmark_timer_is_initialized = FALSE;
[cb585c3]28
[e511e126]29void benchmark_timer_initialize(void)
[cb585c3]30{
31  /*
32   *  Timer runs long and accurate enough not to require an interrupt.
33   */
34
[e511e126]35  if ( benchmark_timer_is_initialized == FALSE ) {
[cb585c3]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 {
[e511e126]42    benchmark_timer_is_initialized = TRUE;
[cb585c3]43  }
44
[6128a4a]45  ERC32_MEC_Set_General_Purpose_Timer_Control(
46    ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING |
[cb585c3]47      ERC32_MEC_TIMER_COUNTER_LOAD_COUNTER
48  );
49
[6128a4a]50  ERC32_MEC_Set_General_Purpose_Timer_Control(
[cb585c3]51    ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING
52  );
53
54}
55
[3ca2768]56#if ENABLE_SIS_QUIRKS
57#define AVG_OVERHEAD      8  /* It typically takes 3.0 microseconds */
[cb585c3]58                             /*     to start/stop the timer. */
[3ca2768]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
[cb585c3]65
[e511e126]66int benchmark_timer_read(void)
[cb585c3]67{
[1be1e913]68  uint32_t          total;
[cb585c3]69
70  total = ERC32_MEC.General_Purpose_Timer_Counter;
71
72  total = 0xffffffff - total;
73
[e511e126]74  if ( benchmark_timer_find_average_overhead == 1 )
[cb585c3]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
[e511e126]83void benchmark_timer_disable_subtracting_average_overhead(
[cb585c3]84  rtems_boolean find_flag
85)
86{
[e511e126]87  benchmark_timer_find_average_overhead = find_flag;
[cb585c3]88}
Note: See TracBrowser for help on using the repository browser.