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

4.104.114.84.95
Last change on this file since 479c86dd was 479c86dd, checked in by Joel Sherrill <joel.sherrill@…>, on 09/23/98 at 13:22:43

Patch from Erik Ivanenko <erik.ivanenko@…>:

Please find attached the two files that have been changed relative to
980921 . The changes here are in the handling of the counter-timer used
as the basis for the rtems executive clock. For the most part, these
are housekeeping changes.

The PSCLK frequency change in start.s... was a part of several
bug-fixes. The fix improves executive clock and timer accuracy.

changes :

start.s -- All timers are disabled by the initialization routine

-- PSCLK ( used by clock and timers ) frequency changed to 1MHz

The clock_initialize routine now assumes that the PSCLK frequency is
exactly 1 MHz.

ckinit.c

Clock_isr -- removed division by 1000. Now use 'static'
variable -- clock_intial_isr_value -- to reset Clock_isrs variable.
clock_initialize -- moved counter timer initialization here. Values
used to configure the timer are totally dependent on
BSP_configuration.microseconds_per_tick ( and the PSCLK assumption).
Initializes clock_initial_isr_value used by th Clock_isr to reset
Clock_isrs.

clock_on -- no longer configures the timer, just enables it.

Since altering the number of sections in the BSP, I decided to give it a
good "once over" . The clock handling is now cleaner.

  • Property mode set to 100644
File size: 4.1 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 */
36static rtems_unsigned32 Clock_initial_isr_value;
37
38volatile rtems_unsigned32 Clock_driver_ticks;
39
40void Clock_exit( void );
41
42/*
43 * These are set by clock driver during its init
44 */
45 
46rtems_device_major_number rtems_clock_major = ~0;
47rtems_device_major_number rtems_clock_minor = 0;
48
49/*
50 *  This is the ISR handler.
51 */
52
53void Clock_isr()
54{
55  /* enable_tracing(); */
56  Clock_driver_ticks += 1;
57  if ( Clock_isrs == 1 ) {
58    rtems_clock_tick();
59    Clock_isrs = Clock_initial_isr_value; /* BSP_Configuration.microseconds_per_tick / 1000;*/
60  }
61  else
62    Clock_isrs -= 1;
63}
64
65void ClockOff(const rtems_irq_connect_data* unused)
66{
67  outport_byte  ( TMRCFG , 0x80 ); /* disable the counter timer */
68}
69
70void ClockOn(const rtems_irq_connect_data* unused)
71{
72  outport_byte    ( TMRCFG , 0x00 ); /* enable the counter timer */
73}
74
75int ClockIsOn(const rtems_irq_connect_data* unused)
76{
77  return ((i8259s_cache & 0x1) == 0);
78}
79
80static rtems_irq_connect_data clockIrqData = {PC_386_PERIODIC_TIMER,
81                                              Clock_isr,
82                                              ClockOn,
83                                              ClockOff,
84                                              ClockIsOn};
85
86rtems_device_driver Clock_initialize(
87  rtems_device_major_number major,
88  rtems_device_minor_number minor,
89  void *pargp
90)
91{
92  unsigned timer_counter_init_value;
93  unsigned char clock_lsb, clock_msb;
94 
95  Clock_driver_ticks = 0;
96
97  Clock_isrs = Clock_initial_isr_value = BSP_Configuration.microseconds_per_tick / 1000; /* ticks per clock_isr */
98 
99  /*
100   * configure the counter timer ( should be based on microsecs/tick )
101   * NB. The divisor(Clock_isrs) resolves the  is the same number that appears in confdefs.h
102   * when setting the microseconds_per_tick value.
103   */
104  ClockOff      ( &clockIrqData );
105 
106  timer_counter_init_value  =  BSP_Configuration.microseconds_per_tick / Clock_isrs;
107  clock_lsb = (unsigned char)timer_counter_init_value;
108  clock_msb = timer_counter_init_value >> 8;
109
110  printk("timer_counter_init_value = 0x%x, lsb = 0x%x, msb = 0x%x, Clock_isrs = %d\n",timer_counter_init_value,
111         clock_lsb, clock_msb, Clock_isrs);
112 
113  outport_byte  ( TMRCON , 0x34 );
114  outport_byte  ( TMR0   , clock_lsb );       /* load LSB first */
115  outport_byte  ( TMR0   , clock_msb );  /* then MSB       */
116 
117  if (!pc386_install_rtems_irq_handler (&clockIrqData)) {
118    printk("Unable to initialize system clock\n");
119    rtems_fatal_error_occurred(1);
120  }
121
122  /*
123   * make major/minor avail to others such as shared memory driver
124   */
125 
126  rtems_clock_major = major;
127  rtems_clock_minor = minor;
128 
129  return RTEMS_SUCCESSFUL;
130}
131
132rtems_device_driver Clock_control(
133  rtems_device_major_number major,
134  rtems_device_minor_number minor,
135  void *pargp
136)
137{
138    rtems_libio_ioctl_args_t *args = pargp;
139 
140    if (args == 0)
141        goto done;
142 
143    /*
144     * This is hokey, but until we get a defined interface
145     * to do this, it will just be this simple...
146     */
147 
148    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
149    {
150        Clock_isr();
151    }
152    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
153    {
154      if (!pc386_install_rtems_irq_handler (&clockIrqData)) {
155        printk("Error installing clock interrupt handler!\n");
156        rtems_fatal_error_occurred(1);
157      }
158#ifdef DEBUG
159      else
160        printk("Clock installed AGAIN\n");
161#endif
162    }
163 
164done:
165    return RTEMS_SUCCESSFUL;
166}
167
168void Clock_exit()
169{
170  ClockOff(&clockIrqData); 
171  pc386_remove_rtems_irq_handler (&clockIrqData);
172}
Note: See TracBrowser for help on using the repository browser.