source: rtems/c/src/lib/libbsp/i386/force386/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.5 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
36void Timer_initialize()
37{
38
39  (void) set_vector( timerisr, 0x38, 0 );   /* install ISR */
40
41  Ttimer_val = 0;                           /* clear timer ISR count */
42
43  outport_byte( IERA, 0x40 );               /* disable interrupt */
44  outport_byte( TBCR, 0x40 );               /* stop the timer */
45  outport_byte( TBDR, 250 );                /* 250 units */
46
47  outport_byte( TBCR, 0x11 );               /* reset it, delay mode, 4X */
48#if 0
49  outport_byte( TBCR, 0x13 );               /* reset it, delay mode, 16X */
50#endif
51
52  outport_byte( IERA, 0x41 );               /* enable interrupt */
53
54}
55
56#define AVG_OVERHEAD      3  /* It typically takes 3.0 microseconds */
57                             /* (3 ticks) to start/stop the timer. */
58#define LEAST_VALID       4  /* Don't trust a value lower than this */
59
60int Read_timer()
61{
62  register rtems_unsigned32 clicks;
63  register rtems_unsigned32 total;
64
65  outport_byte( TBCR, 0x00 );        /* stop the timer */
66
67  inport_byte( TBDR, clicks );
68
69  total = Ttimer_val + 250 - clicks;
70
71  outport_byte( TBCR, 0x00 );  /* initial value */
72  outport_byte( IERA, 0x40 );  /* disable interrupt */
73
74  /* ??? Is "do not restore old vector" causing problems? */
75
76  if ( Timer_driver_Find_average_overhead == 1 )
77    return total;          /* in one microsecond units */
78
79  else {
80    if ( total < LEAST_VALID )
81      return 0;            /* below timer resolution */
82    return (total - AVG_OVERHEAD);
83  }
84}
85
86rtems_status_code Empty_function( void )
87{
88  return RTEMS_SUCCESSFUL;
89}
90
91void Set_find_average_overhead(
92  rtems_boolean find_flag
93)
94{
95  Timer_driver_Find_average_overhead = find_flag;
96}
Note: See TracBrowser for help on using the repository browser.