Back to home page

LXR

 
 

    


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

0001 /**
0002  * @file
0003  * @brief S3C2400 Timer driver
0004  *
0005  * This uses timer 1 for timing measurments.
0006  */
0007 
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 
0014 #include <bsp.h>
0015 #include <rtems.h>
0016 #include <rtems/btimer.h>
0017 #include <s3c24xx.h>
0018 
0019 uint32_t g_start;
0020 uint32_t g_freq;
0021 
0022 bool benchmark_timer_find_average_overhead;
0023 
0024 
0025 /*
0026  * Set up Timer 1
0027  */
0028 void benchmark_timer_initialize( void )
0029 {
0030     uint32_t cr;
0031 
0032     /* stop TIMER1*/
0033     cr=rTCON & 0xFFFFF0FF;
0034     rTCON=(cr | (0x0 << 8));
0035 
0036     /* set MUX for Timer1 to 1/2 */
0037     cr=rTCFG1 & 0xFFFFFF0F;
0038     rTCFG1=(cr | (0<<4));
0039 
0040     /* input freq=PLCK/2 Mhz*/
0041     g_freq = get_PCLK() / 2000;
0042     rTCNTB1 = 0xFFFF;
0043 
0044     /* start TIMER1 with manual reload */
0045     cr=rTCON & 0xFFFFF0FF;
0046     rTCON=(cr | (0x1 << 9));
0047     rTCON=(cr | (0x1 << 8));
0048 
0049     g_start =  rTCNTO1;
0050 }
0051 
0052 /*
0053  *  The following controls the behavior of benchmark_timer_read().
0054  *
0055  *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
0056  *  is usually deducted from the number returned.
0057  *
0058  *  LEAST_VALID is the lowest number this routine should trust.  Numbers
0059  *  below this are "noise" and zero is returned.
0060  */
0061 
0062 #define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
0063                              /* (Y countdowns) to start/stop the timer. */
0064                              /* This value is in microseconds. */
0065 #define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
0066 
0067 benchmark_timer_t benchmark_timer_read( void )
0068 {
0069     uint32_t t;
0070     unsigned long long total;
0071 
0072     t =  rTCNTO1;
0073     /*
0074      *  Total is calculated by taking into account the number of timer overflow
0075      *  interrupts since the timer was initialized and clicks since the last
0076      *  interrupts.
0077      */
0078 
0079     total = (g_start - t);
0080 
0081     /* convert to microseconds */
0082     total = (total*1000) / g_freq;
0083 
0084     if ( benchmark_timer_find_average_overhead == 1 ) {
0085         return (int) total;
0086     } else if ( total < LEAST_VALID ) {
0087         return 0;
0088     }
0089 
0090     /*
0091      *  Somehow convert total into microseconds
0092      */
0093     return (total - AVG_OVERHEAD);
0094 }
0095 
0096 void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
0097 {
0098     benchmark_timer_find_average_overhead = find_flag;
0099 }
0100