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

4.104.114.84.95
Last change on this file since bd8c8b2a was bd8c8b2a, checked in by Joel Sherrill <joel.sherrill@…>, on 08/05/98 at 16:51:39

Patch from Eric Valette <valette@…> which brings the i386ex BSP
inline with the new IRQ structure.

  • Property mode set to 100644
File size: 3.3 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
23#include <bsp.h>
24#include <irq.h>
25
26#include <rtems/libio.h>
27
28#include <stdlib.h>
29
30rtems_unsigned32 Clock_isrs;              /* ISRs until next tick */
31
32volatile rtems_unsigned32 Clock_driver_ticks;
33
34void Clock_exit( void );
35
36/*
37 * These are set by clock driver during its init
38 */
39 
40rtems_device_major_number rtems_clock_major = ~0;
41rtems_device_major_number rtems_clock_minor = 0;
42
43/*
44 *  This is the ISR handler.
45 */
46
47void Clock_isr()
48{
49  /* enable_tracing(); */
50  Clock_driver_ticks += 1;
51  if ( Clock_isrs == 1 ) {
52    rtems_clock_tick();
53    Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
54  }
55  else
56    Clock_isrs -= 1;
57}
58
59void ClockOff(const rtems_irq_connect_data* unused)
60{
61     /* should do something here */;
62}
63
64void ClockOn(const rtems_irq_connect_data* unused)
65{
66/*  The following is already set up in interns.s ->
67    ( This is test code only... production code will move the
68      TMRCFG stuff here )
69*/
70#define TMR0      0xF040
71#define TMR1      0xF041
72#define TMR2      0xF042
73#define TMRCON    0xF043
74#define TMRCFG    0xF834
75       
76  outport_byte  ( TMRCFG , 0x80 );
77
78  outport_byte    ( TMRCON , 0x34 );
79  outport_byte  ( TMR0   , 0xA8 );
80  outport_byte    ( TMR0   , 0x04 );
81
82  outport_byte    ( TMRCFG , 0x00 );
83}
84
85int ClockIsOn(const rtems_irq_connect_data* unused)
86{
87  return ((i8259s_cache & 0x1) == 0);
88}
89
90static rtems_irq_connect_data clockIrqData = {PC_386_PERIODIC_TIMER,
91                                              Clock_isr,
92                                              ClockOn,
93                                              ClockOff,
94                                              ClockIsOn};
95
96rtems_device_driver Clock_initialize(
97  rtems_device_major_number major,
98  rtems_device_minor_number minor,
99  void *pargp
100)
101{
102  Clock_driver_ticks = 0;
103  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
104  if (!pc386_install_rtems_irq_handler (&clockIrqData)) {
105    printk("Unable to initialize system clock\n");
106    rtems_fatal_error_occurred(1);
107  }
108  /*
109   * make major/minor avail to others such as shared memory driver
110   */
111 
112  rtems_clock_major = major;
113  rtems_clock_minor = minor;
114 
115  return RTEMS_SUCCESSFUL;
116}
117
118rtems_device_driver Clock_control(
119  rtems_device_major_number major,
120  rtems_device_minor_number minor,
121  void *pargp
122)
123{
124    rtems_libio_ioctl_args_t *args = pargp;
125 
126    if (args == 0)
127        goto done;
128 
129    /*
130     * This is hokey, but until we get a defined interface
131     * to do this, it will just be this simple...
132     */
133 
134    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
135    {
136        Clock_isr();
137    }
138    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
139    {
140      if (!pc386_install_rtems_irq_handler (&clockIrqData)) {
141        printk("Error installing clock interrupt handler!\n");
142        rtems_fatal_error_occurred(1);
143      }
144    }
145 
146done:
147    return RTEMS_SUCCESSFUL;
148}
149
150void Clock_exit()
151{
152  pc386_remove_rtems_irq_handler (&clockIrqData);
153}
Note: See TracBrowser for help on using the repository browser.