source: rtems/c/src/lib/libbsp/i386/go32/timer/timer.c @ 4ca27cf

4.104.114.84.95
Last change on this file since 4ca27cf was 4ca27cf, checked in by Joel Sherrill <joel.sherrill@…>, on 07/18/95 at 21:19:53

committing for rtems-3.2.01 snapshot

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*  Timer_init()
2 *
3 *  This routine initializes the timer on the IBM 386.
4 *
5 *  Input parameters:  NONE
6 *
7 *  Output parameters:  NONE
8 *
9 *  NOTE: It is important that the timer start/stop overhead be
10 *        determined when porting or modifying this code.
11 *
12 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
13 *  On-Line Applications Research Corporation (OAR).
14 *  All rights assigned to U.S. Government, 1994.
15 *
16 *  This material may be reproduced by or for the U.S. Government pursuant
17 *  to the copyright license under the clause at DFARS 252.227-7013.  This
18 *  notice must appear in all copies of this file and its derivatives.
19 *
20 *  $Id$
21 */
22
23
24#include <rtems.h>
25#include <bsp.h>
26
27volatile rtems_unsigned32 Ttimer_val;
28rtems_boolean Timer_driver_Find_average_overhead;
29
30#if defined(pentium)
31static inline unsigned long long rdtsc( void )
32{
33    /* Return the value of the on-chip cycle counter. */
34    unsigned long long result;
35    __asm __volatile( ".byte 0x0F, 0x31" : "=A" (result) );
36    return result;
37}
38#else /* pentium */
39rtems_isr timerisr();
40#endif /* pentium */
41
42void Timer_initialize()
43{
44#if defined(pentium)
45    Ttimer_val = rdtsc();
46#else /* pentium */
47    static int First = 1;
48    if ( First )  {
49        /* install ISR */
50        set_vector( timerisr, 0x8, 0 );
51
52        /* Wait for ISR to be called at least once */
53        Ttimer_val = 0;
54        while ( Ttimer_val == 0 )
55            continue;
56
57        /* load timer for 250 microsecond period */
58        outport_byte( TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN );
59        outport_byte( TIMER_CNTR0, US_TO_TICK(250) >> 0 & 0xff);
60        outport_byte( TIMER_CNTR0, US_TO_TICK(250) >> 8 & 0xff);
61
62        First = 0;
63    }
64    Ttimer_val = 0;                           /* clear timer ISR count */
65#endif /* PENTIUM */
66}
67
68#define AVG_OVERHEAD       0  /* 0.1 microseconds to start/stop timer. */
69#define LEAST_VALID        1  /* Don't trust a value lower than this */
70
71
72int Read_timer()
73{
74    register rtems_unsigned32 total;
75#if defined(pentium)
76    total = rdtsc() - Ttimer_val;
77#else /* pentium */
78    register rtems_unsigned8 lsb, msb;
79    register rtems_unsigned32 clicks;
80    outport_byte( TIMER_MODE, TIMER_SEL0|TIMER_LATCH );
81    inport_byte( TIMER_CNTR0, lsb );
82    inport_byte( TIMER_CNTR0, msb );
83    clicks = msb << 8 | lsb;
84    total = Ttimer_val + 250 - TICK_TO_US( clicks );
85#endif /* pentium */
86
87    if ( Timer_driver_Find_average_overhead == 1 )
88        return total;
89    else if ( total < LEAST_VALID )
90        return 0;               /* below timer resolution */
91    else
92        return total - AVG_OVERHEAD;
93}
94
95rtems_status_code Empty_function( void )
96{
97    return RTEMS_SUCCESSFUL;
98}
99
100
101void Set_find_average_overhead(
102  rtems_boolean find_flag
103)
104{
105  Timer_driver_Find_average_overhead = find_flag;
106}
Note: See TracBrowser for help on using the repository browser.