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

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

Add missing prototypes.

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[41c9282]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
[7f3c6ce]25#if defined(RTEMS_MULTIPROCESSING)
26  #define LEON3_TIMER_INDEX \
[2088669]27      ((rtems_configuration_get_user_multiprocessing_table()) ? \
[7f3c6ce]28        (rtems_configuration_get_user_multiprocessing_table()->node) - 1 : 1)
29#else
30  #define LEON3_TIMER_INDEX 0
31#endif
[0b83afe9]32
[41c9282]33rtems_boolean Timer_driver_Find_average_overhead;
34
35rtems_boolean Timer_driver_Is_initialized = FALSE;
36
37extern volatile LEON3_Timer_Regs_Map *LEON3_Timer_Regs;
38
[292f01c]39void Timer_initialize(void)
[41c9282]40{
41  /*
42   *  Timer runs long and accurate enough not to require an interrupt.
43   */
44  if (LEON3_Timer_Regs) {
45    if ( Timer_driver_Is_initialized == FALSE ) {
46      /* approximately 1 us per countdown */
[0b83afe9]47      LEON3_Timer_Regs->timer[LEON3_TIMER_INDEX].reload = 0xffffff;
48      LEON3_Timer_Regs->timer[LEON3_TIMER_INDEX].value = 0xffffff;
[41c9282]49    } else {
50      Timer_driver_Is_initialized = TRUE;
51    }
[0b83afe9]52    LEON3_Timer_Regs->timer[LEON3_TIMER_INDEX].conf = LEON3_GPTIMER_EN | LEON3_GPTIMER_LD;
[41c9282]53  }
54}
55
56#define AVG_OVERHEAD      3  /* It typically takes 3.0 microseconds */
57                             /*     to start/stop the timer. */
58#define LEAST_VALID       2  /* Don't trust a value lower than this */
59
[292f01c]60int Read_timer(void)
[41c9282]61{
[1408ea8d]62  uint32_t total;
[41c9282]63
64  if (LEON3_Timer_Regs) {
[0b83afe9]65    total = LEON3_Timer_Regs->timer[LEON3_TIMER_INDEX].value;
[41c9282]66   
67    total = 0xffffff - 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 */
[0b83afe9]74
[41c9282]75    return total - AVG_OVERHEAD;
76  }
77  return 0;
78}
79
80rtems_status_code Empty_function( void )
81{
82  return RTEMS_SUCCESSFUL;
83}
84
85void Set_find_average_overhead(
86  rtems_boolean find_flag
87)
88{
89  Timer_driver_Find_average_overhead = find_flag;
90}
Note: See TracBrowser for help on using the repository browser.