source: rtems/c/src/lib/libcpu/arm/s3c2400/timer/timer.c @ 18bfc42

4.104.114.95
Last change on this file since 18bfc42 was 18bfc42, checked in by Joel Sherrill <joel.sherrill@…>, on 08/31/08 at 17:19:10

2008-08-31 Joel Sherrill <joel.sherrill@…>

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