Back to home page

LXR

 
 

    


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

0001 /**
0002  * @file
0003  * @brief PXA255 timer
0004  */
0005 
0006 /*
0007  * PXA255 timer by Yang Xi <hiyangxi@gmail.com>
0008  * Copyright (c) 2004 by Jay Monkman <jtm@lopingdog.com>
0009  *
0010  * The license and distribution terms for this file may be
0011  * found in the file LICENSE in this distribution or at
0012  * http://www.rtems.org/license/LICENSE.
0013  */
0014 
0015 #include <bsp.h>
0016 #include <rtems.h>
0017 #include <rtems/btimer.h>
0018 #include <pxa255.h>
0019 
0020 uint32_t tstart;
0021 static uint32_t tick_time;
0022 bool benchmark_timer_find_average_overhead;
0023 
0024 bool benchmark_timer_is_initialized = false;
0025 
0026 /*
0027  * Use the timer count register to measure.
0028  * The frequency of it is 3.4864MHZ
0029  * The longest period we are able to capture is 4G/3.4864MHZ
0030  */
0031 void benchmark_timer_initialize(void)
0032 {
0033   tick_time = XSCALE_OS_TIMER_TCR;
0034 }
0035 
0036 /*
0037  *  The following controls the behavior of Read_timer().
0038  *
0039  *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
0040  *  is usually deducted from the number returned.
0041  *
0042  *  LEAST_VALID is the lowest number this routine should trust.  Numbers
0043  *  below this are "noise" and zero is returned.
0044  */
0045 
0046 #define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
0047                              /* (Y countdowns) to start/stop the timer. */
0048                              /* This value is in microseconds. */
0049 #define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
0050 
0051 benchmark_timer_t benchmark_timer_read(void)
0052 {
0053 
0054   uint32_t total;
0055   total = XSCALE_OS_TIMER_TCR;
0056   if(total>=tick_time)
0057     total -= tick_time;
0058   else
0059     total += 0xffffffff - tick_time; /*Round up but not overflow*/
0060 
0061   if ( benchmark_timer_find_average_overhead == true )
0062     return total;          /*Counter cycles*/
0063 
0064   if ( total < LEAST_VALID )
0065     return 0;            /* below timer resolution */
0066 
0067   return total;
0068 }
0069 
0070 void benchmark_timer_disable_subtracting_average_overhead(
0071   bool find_flag
0072 )
0073 {
0074   benchmark_timer_find_average_overhead = find_flag;
0075 }