Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:08

0001 /**
0002  * @file
0003  * @ingroup RTEMSBSPsSPARCLEON2
0004  * @brief Implement a benchmark timer using timer 2
0005  */
0006 
0007 /*  timer.c
0008  *
0009  *  This file implements a benchmark timer using timer 2.
0010  *
0011  *  COPYRIGHT (c) 1989-1998.
0012  *  On-Line Applications Research Corporation (OAR).
0013  *
0014  *  The license and distribution terms for this file may be
0015  *  found in the file LICENSE in this distribution or at
0016  *  http://www.rtems.org/license/LICENSE.
0017  *
0018  *  Ported to LEON implementation of the SPARC by On-Line Applications
0019  *  Research Corporation (OAR) under contract to the European Space
0020  *  Agency (ESA).
0021  *
0022  *  LEON modifications of respective RTEMS file: COPYRIGHT (c) 1995.
0023  *  European Space Agency.
0024  */
0025 
0026 
0027 #include <bsp.h>
0028 #include <rtems/btimer.h>
0029 
0030 bool benchmark_timer_find_average_overhead;
0031 
0032 bool benchmark_timer_is_initialized = false;
0033 
0034 void benchmark_timer_initialize(void)
0035 {
0036   /*
0037    *  Timer runs long and accurate enough not to require an interrupt.
0038    */
0039 
0040   if ( benchmark_timer_is_initialized == false ) {
0041 
0042     /* approximately 1 us per countdown */
0043     LEON_REG.Timer_Counter_2 = 0xffffff;
0044     LEON_REG.Timer_Reload_2 = 0xffffff;
0045 
0046   } else {
0047     benchmark_timer_is_initialized = true;
0048   }
0049 
0050   LEON_REG.Timer_Control_2 = (
0051     LEON_REG_TIMER_COUNTER_ENABLE_COUNTING |
0052       LEON_REG_TIMER_COUNTER_LOAD_COUNTER
0053   );
0054 
0055 }
0056 
0057 #define AVG_OVERHEAD      3  /* It typically takes 3.0 microseconds */
0058                              /*     to start/stop the timer. */
0059 #define LEAST_VALID       2  /* Don't trust a value lower than this */
0060 
0061 benchmark_timer_t benchmark_timer_read(void)
0062 {
0063   uint32_t total;
0064 
0065   total = LEON_REG.Timer_Counter_2;
0066 
0067   total = 0xffffff - total;
0068 
0069   if ( benchmark_timer_find_average_overhead == true )
0070     return total;          /* in one microsecond units */
0071 
0072   if ( total < LEAST_VALID )
0073     return 0;            /* below timer resolution */
0074 
0075   return total - AVG_OVERHEAD;
0076 }
0077 
0078 void benchmark_timer_disable_subtracting_average_overhead(
0079   bool find_flag
0080 )
0081 {
0082   benchmark_timer_find_average_overhead = find_flag;
0083 }