source: rtems/c/src/lib/libbsp/i386/go32/timer/timer.c @ 637df35

4.104.114.84.95
Last change on this file since 637df35 was 637df35, checked in by Joel Sherrill <joel.sherrill@…>, on 07/12/95 at 19:47:25

Ada95, gnat, go32

  • 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 <cpu.h>
26#include <bsp.h>
27
28volatile rtems_unsigned32 Ttimer_val;
29rtems_boolean Timer_driver_Find_average_overhead;
30
31#if defined(pentium)
32static inline unsigned long long rdtsc( void )
33{
34    /* Return the value of the on-chip cycle counter. */
35    unsigned long long result;
36    __asm __volatile( ".byte 0x0F, 0x31" : "=A" (result) );
37    return result;
38}
39#else /* pentium */
40rtems_isr timerisr();
41#endif /* pentium */
42
43void Timer_initialize()
44{
45#if defined(pentium)
46    Ttimer_val = rdtsc();
47#else /* pentium */
48    static int First = 1;
49    if ( First )  {
50        /* install ISR */
51        set_vector( timerisr, 0x8, 0 );
52
53        /* Wait for ISR to be called at least once */
54        Ttimer_val = 0;
55        while ( Ttimer_val == 0 )
56            continue;
57
58        /* load timer for 250 microsecond period */
59        outport_byte( TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN );
60        outport_byte( TIMER_CNTR0, US_TO_TICK(250) >> 0 & 0xff);
61        outport_byte( TIMER_CNTR0, US_TO_TICK(250) >> 8 & 0xff);
62
63        First = 0;
64    }
65    Ttimer_val = 0;                           /* clear timer ISR count */
66#endif /* PENTIUM */
67}
68
69#define AVG_OVERHEAD       0  /* 0.1 microseconds to start/stop timer. */
70#define LEAST_VALID        1  /* Don't trust a value lower than this */
71
72
73int Read_timer()
74{
75    register rtems_unsigned32 total;
76#if defined(pentium)
77    total = rdtsc() - Ttimer_val;
78#else /* pentium */
79    register rtems_unsigned8 lsb, msb;
80    register rtems_unsigned32 clicks;
81    outport_byte( TIMER_MODE, TIMER_SEL0|TIMER_LATCH );
82    inport_byte( TIMER_CNTR0, lsb );
83    inport_byte( TIMER_CNTR0, msb );
84    clicks = msb << 8 | lsb;
85    total = Ttimer_val + 250 - TICK_TO_US( clicks );
86#endif /* pentium */
87
88    if ( Timer_driver_Find_average_overhead == 1 )
89        return total;
90    else if ( total < LEAST_VALID )
91        return 0;               /* below timer resolution */
92    else
93        return total - AVG_OVERHEAD;
94}
95
96rtems_status_code Empty_function( void )
97{
98    return RTEMS_SUCCESSFUL;
99}
100
101
102void Set_find_average_overhead(
103  rtems_boolean find_flag
104)
105{
106  Timer_driver_Find_average_overhead = find_flag;
107}
Note: See TracBrowser for help on using the repository browser.