Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:49

0001 /*
0002  * Cirrus EP7312 Timer driver
0003  *
0004  * Copyright (c) 2002 by Jay Monkman <jtm@smoothsmoothie.com>
0005  *
0006  *  The license and distribution terms for this file may be
0007  *  found in the file LICENSE in this distribution or at
0008  *  http://www.rtems.org/license/LICENSE.
0009  *
0010  * Notes:
0011  *  This file manages the benchmark timer used by the RTEMS Timing Test
0012  *  Suite.  Each measured time period is demarcated by calls to
0013  *  benchmark_timer_initialize() and benchmark_timer_read().  benchmark_timer_read() usually returns
0014  *  the number of microseconds since benchmark_timer_initialize() exitted.
0015  *
0016  *  It is important that the timer start/stop overhead be determined
0017  *  when porting or modifying this code.
0018 */
0019 
0020 #include <rtems.h>
0021 #include <bsp.h>
0022 #include <rtems/btimer.h>
0023 #include <ep7312.h>
0024 
0025 uint16_t         tstart;
0026 bool benchmark_timer_find_average_overhead;
0027 
0028 void benchmark_timer_initialize( void )
0029 {
0030     *EP7312_SYSCON1 |= EP7312_SYSCON1_TC2_512KHZ;
0031     *EP7312_TC2D = 0xffff;
0032 }
0033 
0034 /*
0035  *  The following controls the behavior of benchmark_timer_read().
0036  *
0037  *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
0038  *  is usually deducted from the number returned.
0039  *
0040  *  LEAST_VALID is the lowest number this routine should trust.  Numbers
0041  *  below this are "noise" and zero is returned.
0042  */
0043 
0044 #define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
0045                              /* (Y countdowns) to start/stop the timer. */
0046                              /* This value is in microseconds. */
0047 #define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
0048 
0049 benchmark_timer_t benchmark_timer_read( void )
0050 {
0051   uint16_t         t;
0052   uint32_t         total;
0053   t = *EP7312_TC2D;
0054 
0055   /*
0056    *  Total is calculated by taking into account the number of timer overflow
0057    *  interrupts since the timer was initialized and clicks since the last
0058    *  interrupts.
0059    */
0060 
0061   total = (uint32_t)0x0000ffff - t;  /* result is 1/512000 = ~2 uS */
0062   total = (total * 1953) / 1000;   /* convert to uS */
0063   if ( benchmark_timer_find_average_overhead == true )
0064     return total;          /* in XXX microsecond units */
0065   else {
0066     if ( total < LEAST_VALID )
0067       return 0;            /* below timer resolution */
0068   /*
0069    *  Somehow convert total into microseconds
0070    */
0071       return (total - AVG_OVERHEAD);
0072     }
0073 }
0074 
0075 void benchmark_timer_disable_subtracting_average_overhead(
0076   bool find_flag
0077 )
0078 {
0079   benchmark_timer_find_average_overhead = find_flag;
0080 }