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

4.104.114.84.95
Last change on this file since b2a4e861 was b2a4e861, checked in by Joel Sherrill <joel.sherrill@…>, on 06/02/05 at 13:45:53

2005-06-01 Philippe Simons <loki_666@…>

  • Makefile.am: Add s3c2400/lcd/lcd.c, s3c2400/clock/support.c
  • s3c2400/clock/clockdrv.c: Update to use get_PCLK()
  • s3c2400/timer/timer.c: Update to use get_PCLK()
  • Property mode set to 100644
File size: 2.8 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
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 Read_timer().
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 Read_timer( 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 ( Timer_driver_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
104/*
105 *  Empty function call used in loops to measure basic cost of looping
106 *  in Timing Test Suite.
107 */
108
109rtems_status_code Empty_function( void )
110{
111    return RTEMS_SUCCESSFUL;
112}
113
114void Set_find_average_overhead(
115  rtems_boolean find_flag
116)
117{
118    Timer_driver_Find_average_overhead = find_flag;
119}
120
Note: See TracBrowser for help on using the repository browser.