source: rtems/c/src/lib/libbsp/i386/i386ex/timer/timer.c @ 98e4ebf

4.104.114.84.95
Last change on this file since 98e4ebf was 98e4ebf, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 8, 1997 at 3:45:54 PM

Fixed typo in the pointer to the license terms.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*  Timer_init()
2 *
3 *  This routine initializes the timer on the FORCE CPU-386 board.
4 *
5 *  Input parameters:  NONE
6 *
7 *  Output parameters:  NONE
8 *
9 *  NOTE: This routine will not work if the optimizer is enabled
10 *        for some compilers.  The multiple writes to the Z8036
11 *        may be optimized away.
12 *
13 *        It is important that the timer start/stop overhead be
14 *        determined when porting or modifying this code.
15 *
16 *  COPYRIGHT (c) 1989-1997.
17 *  On-Line Applications Research Corporation (OAR).
18 *  Copyright assigned to U.S. Government, 1994.
19 *
20 *  The license and distribution terms for this file may be
21 *  found in the file LICENSE in this distribution or at
22 *  http://www.OARcorp.com/rtems/license.html.
23 *
24 *  $Id$
25 */
26
27
28#include <rtems.h>
29#include <bsp.h>
30
31int Ttimer_val;
32rtems_boolean Timer_driver_Find_average_overhead;
33
34rtems_isr timerisr();
35
36#define TMR0      0xF040
37#define TMR1      0xF041
38#define TMR2      0xF042
39#define TMRCON    0xF043
40#define TMRCFG    0xF834
41
42void Timer_initialize()
43{
44
45  (void) set_vector( timerisr, 0x2a, 0 );   /* install ISR ( IR2 ) was 0x38*/
46
47  Ttimer_val = 0;                           /* clear timer ISR count */
48
49  outport_byte  ( TMRCON , 0xb0 ); /* select tmr2, stay in mode 0 */
50  outport_byte  ( TMR1   , 0xd2 ); /* set to 250 usec interval */
51  outport_byte  ( TMR1   , 0x00 );
52  outport_byte  ( TMRCON , 0x64 ); /* change to mode 2 ( starts timer ) */ 
53                                   /* interrupts ARE enabled */
54/*  outport_byte( IERA, 0x41 );             enable interrupt */
55
56}
57
58#define AVG_OVERHEAD      3  /* It typically takes 3.0 microseconds */
59                             /* (3 ticks) to start/stop the timer. */
60#define LEAST_VALID       4  /* Don't trust a value lower than this */
61
62int Read_timer()
63{
64  register rtems_unsigned32 clicks;
65  register rtems_unsigned32 total;
66
67/*  outport_byte( TBCR, 0x00 );  stop the timer -- not needed on intel */
68
69  outport_byte ( TMRCON, 0x40 );   /* latch the count */
70  inport_byte  ( TMR1,   clicks ); /* read the count */ 
71
72  total = Ttimer_val + 250 - clicks;
73
74/*  outport_byte( TBCR, 0x00 );   initial value */
75/*  outport_byte( IERA, 0x40 );   disable interrupt */
76
77  /* ??? Is "do not restore old vector" causing problems? */
78
79  if ( Timer_driver_Find_average_overhead == 1 )
80    return total;          /* in one microsecond units */
81
82  else {
83    if ( total < LEAST_VALID )
84      return 0;            /* below timer resolution */
85    return (total - AVG_OVERHEAD);
86  }
87}
88
89rtems_status_code Empty_function( void )
90{
91  return RTEMS_SUCCESSFUL;
92}
93
94void Set_find_average_overhead(
95  rtems_boolean find_flag
96)
97{
98  Timer_driver_Find_average_overhead = find_flag;
99}
Note: See TracBrowser for help on using the repository browser.