source: rtems/c/src/lib/libcpu/arm/s3c2400/timer/timer.c @ 32cf23b1

4.104.114.84.95
Last change on this file since 32cf23b1 was 479ac2d8, checked in by Jay Monkman <jtm@…>, on 03/11/05 at 07:26:45

2005-03-11 Philippe Simons <loki_666@…>

  • Makefile.am, configure.ac: Added gp32 BSP.
  • s3c2400/.cvsignore, s3c2400/Makefile.am, s3c2400/clock/clockdrv.c, s3c2400/include/s3c2400.h, s3c2400/irq/bsp_irq_asm.S, s3c2400/irq/bsp_irq_init.c, s3c2400/irq/irq.c, s3c2400/irq/irq.h, s3c2400/timer/timer.c: New files.
  • Property mode set to 100644
File size: 3.0 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.OARcorp.com/rtems/license.html.
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 *  Timer_initialize() and Read_timer().  Read_timer() usually returns
15 *  the number of microseconds since 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 Timer_driver_Find_average_overhead;
31
32   
33/*
34 * Set up Timer 1
35 */
36void Timer_initialize( void )
37{
38    uint32_t cr;
39    uint32_t m;
40    uint32_t p;
41    uint32_t s;
42
43    /* stop TIMER1*/
44    cr=rTCON & 0xFFFFF0FF;
45    rTCON=(cr | (0x0 << 8));
46
47    /* set MUX for Timer1 to 1/2 */
48    cr=rTCFG1 & 0xFFFFFF0F;
49    rTCFG1=(cr | (0<<4));
50
51    /* compute MPLL freq */
52    m = M_MDIV + 8;
53    p = M_PDIV + 2;
54    s = M_SDIV;
55    g_freq =(BSP_OSC_FREQ * m) / (p << s);
56
57    /* PCLK = MPLL/4 */
58    g_freq = g_freq / 4;
59
60    /* input freq=PLCK/2 Mhz*/
61    g_freq = g_freq / 2000;
62    rTCNTB1 = 0xFFFF;
63
64    /* start TIMER1 with manual reload */
65    cr=rTCON & 0xFFFFF0FF;
66    rTCON=(cr | (0x1 << 9));
67    rTCON=(cr | (0x1 << 8));
68 
69    g_start =  rTCNTO1;
70}
71
72/*
73 *  The following controls the behavior of Read_timer().
74 *
75 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
76 *  is usually deducted from the number returned.
77 *
78 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
79 *  below this are "noise" and zero is returned.
80 */
81
82#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
83                             /* (Y countdowns) to start/stop the timer. */
84                             /* This value is in microseconds. */
85#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
86
87int Read_timer( void )
88{
89    uint32_t t;
90    unsigned long long total;
91
92    t =  rTCNTO1;
93    /*
94     *  Total is calculated by taking into account the number of timer overflow
95     *  interrupts since the timer was initialized and clicks since the last
96     *  interrupts.
97     */
98   
99    total = (g_start - t);
100
101    /* convert to microseconds */
102    total = (total*1000) / g_freq;
103
104    if ( Timer_driver_Find_average_overhead == 1 ) {
105        return (int) total;
106    } else if ( total < LEAST_VALID ) {
107        return 0;       
108    }
109
110    /*
111     *  Somehow convert total into microseconds
112     */
113    return (total - AVG_OVERHEAD);
114}
115
116/*
117 *  Empty function call used in loops to measure basic cost of looping
118 *  in Timing Test Suite.
119 */
120
121rtems_status_code Empty_function( void )
122{
123    return RTEMS_SUCCESSFUL;
124}
125
126void Set_find_average_overhead(
127  rtems_boolean find_flag
128)
129{
130    Timer_driver_Find_average_overhead = find_flag;
131}
132
Note: See TracBrowser for help on using the repository browser.