Back to home page

LXR

 
 

    


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

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