source: rtems/c/src/lib/libbsp/i386/i386ex/clock/ckinit.c @ 04bc5d9

4.104.114.84.95
Last change on this file since 04bc5d9 was 04bc5d9, checked in by Joel Sherrill <joel.sherrill@…>, on 09/21/98 at 00:23:02

Update from Erik Ivanenko <erik.ivanenko@…> to bring the
i386ex bsp up to date.

1) A 'hlt' instruction is coded in case of a return from boot_card in

start.s.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*  Clock_initialize
2 *
3 *  This routine initializes the Timer/Counter on the Intel
4 *  386ex evaluation board.
5 *
6 *  The tick frequency is 1 millisecond.
7 *
8 *  Input parameters:  NONE
9 *
10 *  Output parameters:  NONE
11 *
12 *  COPYRIGHT (c) 1989-1998.
13 *  On-Line Applications Research Corporation (OAR).
14 *  Copyright assigned to U.S. Government, 1994.
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.OARcorp.com/rtems/license.html.
19 *
20 *  $Id$
21 */
22#define TMR0      0xF040
23#define TMR1      0xF041
24#define TMR2      0xF042
25#define TMRCON    0xF043
26#define TMRCFG    0xF834
27
28#include <bsp.h>
29#include <irq.h>
30
31#include <rtems/libio.h>
32
33#include <stdlib.h>
34
35rtems_unsigned32 Clock_isrs;              /* ISRs until next tick */
36
37volatile rtems_unsigned32 Clock_driver_ticks;
38
39void Clock_exit( void );
40
41/*
42 * These are set by clock driver during its init
43 */
44 
45rtems_device_major_number rtems_clock_major = ~0;
46rtems_device_major_number rtems_clock_minor = 0;
47
48/*
49 *  This is the ISR handler.
50 */
51
52void Clock_isr()
53{
54  /* enable_tracing(); */
55  Clock_driver_ticks += 1;
56  if ( Clock_isrs == 1 ) {
57    rtems_clock_tick();
58    Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
59  }
60  else
61    Clock_isrs -= 1;
62}
63
64void ClockOff(const rtems_irq_connect_data* unused)
65{
66  /* should do something here */;
67  outport_byte  ( TMRCFG , 0x80 );
68}
69
70void ClockOn(const rtems_irq_connect_data* unused)
71{
72  outport_byte  ( TMRCFG , 0x80 );
73
74  outport_byte    ( TMRCON , 0x34 );
75  outport_byte  ( TMR0   , 0xA8 );
76  outport_byte    ( TMR0   , 0x04 );
77
78  outport_byte    ( TMRCFG , 0x00 );
79}
80
81int ClockIsOn(const rtems_irq_connect_data* unused)
82{
83  return ((i8259s_cache & 0x1) == 0);
84}
85
86static rtems_irq_connect_data clockIrqData = {PC_386_PERIODIC_TIMER,
87                                              Clock_isr,
88                                              ClockOn,
89                                              ClockOff,
90                                              ClockIsOn};
91
92rtems_device_driver Clock_initialize(
93  rtems_device_major_number major,
94  rtems_device_minor_number minor,
95  void *pargp
96)
97{
98  Clock_driver_ticks = 0;
99  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
100  if (!pc386_install_rtems_irq_handler (&clockIrqData)) {
101    printk("Unable to initialize system clock\n");
102    rtems_fatal_error_occurred(1);
103  }
104  /*
105   * make major/minor avail to others such as shared memory driver
106   */
107 
108  rtems_clock_major = major;
109  rtems_clock_minor = minor;
110 
111  return RTEMS_SUCCESSFUL;
112}
113
114rtems_device_driver Clock_control(
115  rtems_device_major_number major,
116  rtems_device_minor_number minor,
117  void *pargp
118)
119{
120    rtems_libio_ioctl_args_t *args = pargp;
121 
122    if (args == 0)
123        goto done;
124 
125    /*
126     * This is hokey, but until we get a defined interface
127     * to do this, it will just be this simple...
128     */
129 
130    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
131    {
132        Clock_isr();
133    }
134    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
135    {
136      if (!pc386_install_rtems_irq_handler (&clockIrqData)) {
137        printk("Error installing clock interrupt handler!\n");
138        rtems_fatal_error_occurred(1);
139      }
140#ifdef DEBUG
141      else
142        printk("Clock installed AGAIN\n");
143#endif
144    }
145 
146done:
147    return RTEMS_SUCCESSFUL;
148}
149
150void Clock_exit()
151{
152  ClockOff(&clockIrqData); 
153  pc386_remove_rtems_irq_handler (&clockIrqData);
154}
Note: See TracBrowser for help on using the repository browser.