source: rtems/c/src/lib/libcpu/arm/s3c24xx/timer/timer.c @ c080c343

4.115
Last change on this file since c080c343 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 * S3C2400 Timer driver
3 *
4 * This uses timer 1 for timing measurments.
5 *
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *  http://www.rtems.org/license/LICENSE.
9 *
10 * Notes:
11 *  This file manages the benchmark timer used by the RTEMS Timing Test
12 *  Suite.  Each measured time period is demarcated by calls to
13 *  benchmark_timer_initialize() and benchmark_timer_read().  benchmark_timer_read() usually returns
14 *  the number of microseconds since benchmark_timer_initialize() exitted.
15 *
16 *  It is important that the timer start/stop overhead be determined
17 *  when porting or modifying this code.
18*/
19
20#include <rtems.h>
21#include <bsp.h>
22#include <s3c24xx.h>
23
24uint32_t g_start;
25uint32_t g_freq;
26
27bool benchmark_timer_find_average_overhead;
28
29
30/*
31 * Set up Timer 1
32 */
33void benchmark_timer_initialize( void )
34{
35    uint32_t cr;
36
37    /* stop TIMER1*/
38    cr=rTCON & 0xFFFFF0FF;
39    rTCON=(cr | (0x0 << 8));
40
41    /* set MUX for Timer1 to 1/2 */
42    cr=rTCFG1 & 0xFFFFFF0F;
43    rTCFG1=(cr | (0<<4));
44
45    /* input freq=PLCK/2 Mhz*/
46    g_freq = get_PCLK() / 2000;
47    rTCNTB1 = 0xFFFF;
48
49    /* start TIMER1 with manual reload */
50    cr=rTCON & 0xFFFFF0FF;
51    rTCON=(cr | (0x1 << 9));
52    rTCON=(cr | (0x1 << 8));
53
54    g_start =  rTCNTO1;
55}
56
57/*
58 *  The following controls the behavior of benchmark_timer_read().
59 *
60 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
61 *  is usually deducted from the number returned.
62 *
63 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
64 *  below this are "noise" and zero is returned.
65 */
66
67#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
68                             /* (Y countdowns) to start/stop the timer. */
69                             /* This value is in microseconds. */
70#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
71
72int benchmark_timer_read( void )
73{
74    uint32_t t;
75    unsigned long long total;
76
77    t =  rTCNTO1;
78    /*
79     *  Total is calculated by taking into account the number of timer overflow
80     *  interrupts since the timer was initialized and clicks since the last
81     *  interrupts.
82     */
83
84    total = (g_start - t);
85
86    /* convert to microseconds */
87    total = (total*1000) / g_freq;
88
89    if ( benchmark_timer_find_average_overhead == 1 ) {
90        return (int) total;
91    } else if ( total < LEAST_VALID ) {
92        return 0;
93    }
94
95    /*
96     *  Somehow convert total into microseconds
97     */
98    return (total - AVG_OVERHEAD);
99}
100
101void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
102{
103    benchmark_timer_find_average_overhead = find_flag;
104}
105
Note: See TracBrowser for help on using the repository browser.