source: rtems/c/src/lib/libbsp/i386/pc386/clock/ckinit.c @ 12bd47e

4.104.114.95
Last change on this file since 12bd47e was 12bd47e, checked in by Joel Sherrill <joel.sherrill@…>, on 12/11/07 at 15:49:53

2007-12-11 Joel Sherrill <joel.sherrill@…>

  • clock/ckinit.c, include/bsp.h, startup/bspstart.c: Eliminate copies of the Configuration Table. Use the RTEMS provided accessor macros to obtain configuration fields.
  • Property mode set to 100644
File size: 8.1 KB
Line 
1/*-------------------------------------------------------------------------+
2| ckinit.c v1.1 - PC386 BSP - 1997/08/07
3+--------------------------------------------------------------------------+
4| This file contains the PC386 clock package.
5+--------------------------------------------------------------------------+
6| (C) Copyright 1997 -
7| - NavIST Group - Real-Time Distributed Systems and Industrial Automation
8|
9| http://pandora.ist.utl.pt
10|
11| Instituto Superior Tecnico * Lisboa * PORTUGAL
12+--------------------------------------------------------------------------+
13| Disclaimer:
14|
15| This file is provided "AS IS" without warranty of any kind, either
16| expressed or implied.
17+--------------------------------------------------------------------------+
18| This code is based on:
19|   ckinit.c,v 1.4 1995/12/19 20:07:13 joel Exp - go32 BSP
20| With the following copyright notice:
21| **************************************************************************
22| *  COPYRIGHT (c) 1989-1999.
23| *  On-Line Applications Research Corporation (OAR).
24| *
25| *  The license and distribution terms for this file may be
26| *  found in found in the file LICENSE in this distribution or at
27| *  http://www.rtems.com/license/LICENSE.
28| **************************************************************************
29|
30|  $Id$
31+--------------------------------------------------------------------------*/
32
33#include <stdlib.h>
34
35#include <bsp.h>
36#include <bsp/irq.h>
37#include <rtems/libio.h>
38
39/*-------------------------------------------------------------------------+
40| Macros
41+--------------------------------------------------------------------------*/
42#if 0
43/* This was dropped in the last revision.  Its a nice thing to know. */
44#define TICKS_PER_SECOND() \
45          (1000000 / (Clock_isrs_per_tick * microseconds_per_isr))
46#endif /* 0 */
47
48/*-------------------------------------------------------------------------+
49| Global Variables
50+--------------------------------------------------------------------------*/
51
52volatile uint32_t         Clock_driver_ticks;   /* Tick (interrupt) counter. */
53         uint32_t         Clock_isrs_per_tick;  /* ISRs per tick.            */
54         uint32_t         Clock_isrs;           /* ISRs until next tick.     */
55
56/* The following variables are set by the clock driver during its init */
57
58rtems_device_major_number rtems_clock_major = ~0;
59rtems_device_minor_number rtems_clock_minor;
60
61/*-------------------------------------------------------------------------+
62|         Function: clockIsr
63|      Description: Interrupt Service Routine for clock (0h) interruption.
64| Global Variables: Clock_driver_ticks, Clock_isrs.
65|        Arguments: vector - standard RTEMS argument - see documentation.
66|          Returns: standard return value - see documentation.
67+--------------------------------------------------------------------------*/
68static void clockIsr()
69{
70  /*-------------------------------------------------------------------------+
71  | PLEASE NOTE: The following is directly transcribed from the go32 BSP for
72  |              those who wish to use it with PENTIUM based machine. It needs
73  |              to be correctly integrated with the rest of the code!!!
74  +--------------------------------------------------------------------------*/
75
76#if 0 && defined(pentium) /* more accurate clock for PENTIUMs (not supported) */
77  {
78    extern long long Last_RDTSC;
79    __asm __volatile(".byte 0x0F, 0x31" : "=A" (Last_RDTSC));
80  }
81#endif /* 0 && pentium */
82
83  Clock_driver_ticks++;
84
85  if ( Clock_isrs == 1 )
86  {
87    rtems_clock_tick();
88    Clock_isrs = Clock_isrs_per_tick;
89  }
90  else
91    Clock_isrs--;
92
93} /* clockIsr */
94
95/*-------------------------------------------------------------------------+
96|         Function: Clock_exit
97|      Description: Clock cleanup routine at RTEMS exit. NOTE: This routine is
98|                   not really necessary, since there will be a reset at exit.
99| Global Variables: None.
100|        Arguments: None.
101|          Returns: Nothing.
102+--------------------------------------------------------------------------*/
103void clockOff(const rtems_irq_connect_data* unused)
104{
105  /* reset timer mode to standard (BIOS) value */
106  outport_byte(TIMER_MODE, TIMER_SEL0 | TIMER_16BIT | TIMER_RATEGEN);
107  outport_byte(TIMER_CNTR0, 0);
108  outport_byte(TIMER_CNTR0, 0);
109} /* Clock_exit */
110
111/*-------------------------------------------------------------------------+
112|         Function: Install_clock
113|      Description: Initialize and install clock interrupt handler.
114| Global Variables: None.
115|        Arguments: None.
116|          Returns: Nothing.
117+--------------------------------------------------------------------------*/
118static void clockOn(const rtems_irq_connect_data* unused)
119{
120  uint32_t          microseconds_per_isr;
121
122#if 0
123  /* Initialize clock from on-board real time clock.  This breaks the  */
124  /* test code which assumes which assumes the application will do it. */
125  {
126    rtems_time_of_day now;
127
128    /* External Prototypes */
129    extern void init_rtc(void);                /* defined in 'rtc.c' */
130    extern long rtc_read(rtems_time_of_day *); /* defined in 'rtc.c' */
131
132    init_rtc();
133    if (rtc_read(&now) >= 0)
134      clock_set(&now);
135  }
136#endif /* 0 */
137
138  /* Start by assuming hardware counter is large enough, then  scale it until
139     it actually fits. */
140
141  Clock_driver_ticks  = 0;
142  Clock_isrs_per_tick = 1;
143
144  if (rtems_configuration_get_microseconds_per_tick() == 0)
145    microseconds_per_isr = 10000; /* default 10 ms */
146  else
147    microseconds_per_isr = rtems_configuration_get_microseconds_per_tick();
148  while (US_TO_TICK(microseconds_per_isr) > 65535)
149  {
150    Clock_isrs_per_tick  *= 10;
151    microseconds_per_isr /= 10;
152  }
153
154  Clock_isrs = Clock_isrs_per_tick; /* Initialize Clock_isrs */
155
156  {
157    /* 105/88 approximates TIMER_TICK * 1e-6 */
158    uint32_t         count = US_TO_TICK(microseconds_per_isr);
159
160    outport_byte(TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN);
161    outport_byte(TIMER_CNTR0, count >> 0 & 0xff);
162    outport_byte(TIMER_CNTR0, count >> 8 & 0xff);
163  }
164
165}
166
167int clockIsOn(const rtems_irq_connect_data* unused)
168{
169  return ((i8259s_cache & 0x1) == 0);
170}
171
172static rtems_irq_connect_data clockIrqData = {BSP_PERIODIC_TIMER,
173                                              clockIsr,
174                                              0,
175                                              clockOn,
176                                              clockOff,
177                                              clockIsOn};
178
179/*-------------------------------------------------------------------------+
180| Clock device driver INITIALIZE entry point.
181+--------------------------------------------------------------------------+
182| Initilizes the clock driver.
183+--------------------------------------------------------------------------*/
184rtems_device_driver
185Clock_initialize(rtems_device_major_number major,
186                 rtems_device_minor_number minor,
187                 void                      *pargp)
188{
189
190  if (!BSP_install_rtems_irq_handler (&clockIrqData)) {
191    printk("Unable to initialize system clock\n");
192    rtems_fatal_error_occurred(1);
193  }
194  /* make major/minor avail to others such as shared memory driver */
195
196  rtems_clock_major = major;
197  rtems_clock_minor = minor;
198
199  return RTEMS_SUCCESSFUL;
200} /* Clock_initialize */
201
202/*-------------------------------------------------------------------------+
203| Console device driver CONTROL entry point
204+--------------------------------------------------------------------------*/
205rtems_device_driver
206Clock_control(rtems_device_major_number major,
207              rtems_device_minor_number minor,
208              void                      *pargp)
209{
210  if (pargp != NULL)
211  {
212    rtems_libio_ioctl_args_t *args = pargp;
213
214    /*-------------------------------------------------------------------------+
215    | This is hokey, but until we get a defined interface to do this, it will
216    | just be this simple...
217    +-------------------------------------------------------------------------*/
218
219    if      (args->command == rtems_build_name('I', 'S', 'R', ' '))
220      clockIsr();
221    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
222    {
223      if (!BSP_install_rtems_irq_handler (&clockIrqData)) {
224        printk("Error installing clock interrupt handler!\n");
225        rtems_fatal_error_occurred(1);
226      }
227    }
228  }
229
230  return RTEMS_SUCCESSFUL;
231} /* Clock_control */
232
233void Clock_exit()
234{
235  BSP_remove_rtems_irq_handler (&clockIrqData);
236}
237
Note: See TracBrowser for help on using the repository browser.