source: rtems/c/src/lib/libbsp/i386/i386ex/timer/timer.c @ 1d4048b2

4.104.114.84.95
Last change on this file since 1d4048b2 was 0ebbf66, checked in by Joel Sherrill <joel.sherrill@…>, on 10/05/98 at 22:36:06

Large patch from Erik Ivanenko <erik.ivanenko@…> which
moves pieces of the pc386 bsp up to a shared level for all i386 BSPs
and modifies the i386ex BSP to use those shared pieces. Serial remote
debugging is included for both targets. Erik's notes:

There are several workarounds in it:

1) #define NEXT_GAS is hardcoded in pc386/start/start.s
2) #define NEXT_GAS is hardcoded in i386ex/start/start.s
3) #define NEW_GAS is hardcoded in pc386/start16.s
4) #undef assert and redeclare _assert hardcoded in console.c for

both pc386 and i386ex due to my egcs1.1b ~ newlib problem. Should have
modified t-rtems.cfg ( no time )

I've tested pc386 with both video and serial consoles and GDB remote.
All work fine, except that GDB acts weird. ( re: other posting)

I hope this will work for you. It took quite some time to locate the
autoconf error. The remainder was just grunt work.
Unfortunately, I think I've unwound the removal of the IBMPCInitVideo
stuff. Sorry. I REALLY can't spend more time... I've been at this
conversion to 4.0 locally and updating the release since Sept. 8th, and
have yet to compile my network driver.... This is as much as I can do
right now.

I look forward to the next patch to really test i368ex. I did make sure
that the sample tests worked for pc386.

  • Property mode set to 100644
File size: 3.8 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-1998.
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#include <stdlib.h>
31
32int Ttimer_val;
33rtems_boolean Timer_driver_Find_average_overhead;
34
35extern void timerisr();
36extern int ClockIsOn(const rtems_raw_irq_connect_data*);
37
38#define TMR0      0xF040
39#define TMR1      0xF041
40#define TMR2      0xF042
41#define TMRCON    0xF043
42#define TMRCFG    0xF834
43
44void TimerOn(const rtems_raw_irq_connect_data* used)
45{
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   , 0xfa ); /* 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   * enable interrrupt at i8259 level
57   */
58  BSP_irq_enable_at_i8259s(used->idtIndex - BSP_IRQ_VECTOR_BASE);
59}
60
61void TimerOff(const rtems_raw_irq_connect_data* used)
62{
63    /*
64     * disable interrrupt at i8259 level
65     */
66     BSP_irq_disable_at_i8259s(used->idtIndex - BSP_IRQ_VECTOR_BASE);
67     /* reset timer mode to standard (DOS) value */
68}
69
70static rtems_raw_irq_connect_data timer_raw_irq_data = {
71  BSP_RT_TIMER3 + BSP_IRQ_VECTOR_BASE,
72  timerisr,
73  TimerOn,
74  TimerOff,
75  ClockIsOn
76};
77
78void Timer_exit()
79{
80 if (!i386_delete_idt_entry(&timer_raw_irq_data)) {
81      printk("Timer_exit:Timer raw handler removal failed\n");
82      rtems_fatal_error_occurred(1);
83 }
84}
85
86void Timer_initialize()
87{
88
89  static rtems_boolean First = TRUE;
90
91  if (First)
92  {
93    First = FALSE;
94
95    atexit(Timer_exit); /* Try not to hose the system at exit. */
96    if (!i386_set_idt_entry (&timer_raw_irq_data)) {
97      printk("Timer_initialize: raw handler installation failed\n");
98      rtems_fatal_error_occurred(1);
99    }
100  }
101  /* wait for ISR to be called at least once */
102  Ttimer_val = 0;
103  while (Ttimer_val == 0)
104    continue;
105  Ttimer_val = 0;
106}
107
108#define AVG_OVERHEAD      3  /* It typically takes 3.0 microseconds */
109                             /* (3 ticks) to start/stop the timer. */
110#define LEAST_VALID       4  /* Don't trust a value lower than this */
111
112int Read_timer()
113{
114  register rtems_unsigned32 clicks;
115  register rtems_unsigned32 total;
116
117/*  outport_byte( TBCR, 0x00 );  stop the timer -- not needed on intel */
118
119  outport_byte ( TMRCON, 0x40 );   /* latch the count */
120  inport_byte  ( TMR1,   clicks ); /* read the count */
121
122  total = Ttimer_val + 250 - clicks;
123
124/*  outport_byte( TBCR, 0x00 );   initial value */
125/*  outport_byte( IERA, 0x40 );   disable interrupt */
126
127  /* ??? Is "do not restore old vector" causing problems? */
128
129  if ( Timer_driver_Find_average_overhead == 1 )
130    return total;          /* in one microsecond units */
131
132  else {
133    if ( total < LEAST_VALID )
134      return 0;            /* below timer resolution */
135    return (total - AVG_OVERHEAD);
136  }
137}
138
139rtems_status_code Empty_function( void )
140{
141  return RTEMS_SUCCESSFUL;
142}
143
144void Set_find_average_overhead(
145  rtems_boolean find_flag
146)
147{
148  Timer_driver_Find_average_overhead = find_flag;
149}
Note: See TracBrowser for help on using the repository browser.