source: rtems/c/src/lib/libbsp/i386/ts_386ex/clock/ckinit.c @ 5c7f274

4.104.114.84.95
Last change on this file since 5c7f274 was 48ad38db, checked in by Jennifer Averett <Jennifer.Averett@…>, on 05/06/05 at 19:57:27

2005-05-06 Jennifer Averett <jennifer.averett@…>

  • clock/ckinit.c, console/console.c, include/bsp.h, network/ne2000.c: Moved irq.h to bsp subdirectory.
  • Property mode set to 100644
File size: 4.4 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-1999.
13 *  On-Line Applications Research Corporation (OAR).
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.com/license/LICENSE.
18 *
19 *  $Id$
20 */
21
22#include <bsp.h>
23#include <bsp/irq.h>
24
25#include <rtems/libio.h>
26
27#include <stdlib.h>
28
29uint32_t         Clock_isrs;              /* ISRs until next tick */
30static uint32_t         Clock_initial_isr_value;
31
32volatile uint32_t         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 = Clock_initial_isr_value; /* 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  outport_byte (TIMER_CONFIG, 0x80 ); /* disable the counter timer */
62}
63
64void ClockOn(const rtems_irq_connect_data* unused)
65{
66  outport_byte (TIMER_CONFIG, 0x00 ); /* enable the counter timer */
67}
68
69int ClockIsOn(const rtems_irq_connect_data* unused)
70{
71  return ((i8259s_cache & 0x1) == 0);
72}
73
74static rtems_irq_connect_data clockIrqData = {BSP_PERIODIC_TIMER,
75                                              Clock_isr,
76                                              ClockOn,
77                                              ClockOff,
78                                              ClockIsOn};
79
80rtems_device_driver Clock_initialize(
81  rtems_device_major_number major,
82  rtems_device_minor_number minor,
83  void *pargp
84)
85{
86  unsigned timer_counter_init_value;
87  unsigned char clock_lsb, clock_msb;
88
89#ifdef BSP_DEBUG
90  printk("Initializing clock driver in Clock_initialize().\n");
91#endif
92
93#ifdef LOAD_RTC_AT_START
94  /* Initialize clock from on-board real time clock.  This breaks the  */
95  /* test code which assumes which assumes the application will do it. */
96  {
97    rtems_time_of_day now;
98
99    /* External Prototypes */
100    extern void init_rtc(void);                /* defined in 'rtc.c' */
101    extern long rtc_read(rtems_time_of_day *); /* defined in 'rtc.c' */
102
103#ifdef BSP_DEBUG
104    printk("Loading clock from on-board real-time clock.\n");
105#endif
106
107    init_rtc();
108    if (rtc_read(&now) >= 0)
109      rtems_clock_set(&now);
110  }
111#endif
112
113  Clock_driver_ticks = 0;
114
115  Clock_isrs =
116    Clock_initial_isr_value =
117    BSP_Configuration.microseconds_per_tick / 1000; /* ticks per clock_isr */
118
119  /*
120   * configure the counter timer ( should be based on microsecs/tick )
121   * NB. The divisor(Clock_isrs) resolves the  is the same number that appears in confdefs.h
122   * when setting the microseconds_per_tick value.
123   */
124  ClockOff      ( &clockIrqData );
125
126  timer_counter_init_value  =  BSP_Configuration.microseconds_per_tick / Clock_isrs;
127  clock_lsb = (unsigned char)timer_counter_init_value;
128  clock_msb = timer_counter_init_value >> 8;
129
130  outport_byte (TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN);
131  outport_byte (TIMER_CNTR0, clock_lsb );   /* load LSB first */
132  outport_byte (TIMER_CNTR0, clock_msb );   /* then MSB       */
133
134  if (!BSP_install_rtems_irq_handler (&clockIrqData)) {
135    printk("Unable to initialize system clock\n");
136    rtems_fatal_error_occurred(1);
137  }
138
139  /*
140   * make major/minor avail to others such as shared memory driver
141   */
142
143  rtems_clock_major = major;
144  rtems_clock_minor = minor;
145
146  return RTEMS_SUCCESSFUL;
147}
148
149rtems_device_driver Clock_control(
150  rtems_device_major_number major,
151  rtems_device_minor_number minor,
152  void *pargp
153)
154{
155    rtems_libio_ioctl_args_t *args = pargp;
156
157    if (args == 0)
158        goto done;
159
160    /*
161     * This is hokey, but until we get a defined interface
162     * to do this, it will just be this simple...
163     */
164
165    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
166    {
167        Clock_isr();
168    }
169    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
170    {
171      if (!BSP_install_rtems_irq_handler (&clockIrqData)) {
172        printk("Error installing clock interrupt handler!\n");
173        rtems_fatal_error_occurred(1);
174      }
175#ifdef BSP_DEBUG
176      else
177        printk("Clock installed AGAIN\n");
178#endif
179    }
180
181done:
182    return RTEMS_SUCCESSFUL;
183}
184
185void Clock_exit()
186{
187  ClockOff(&clockIrqData);
188  BSP_remove_rtems_irq_handler (&clockIrqData);
189}
Note: See TracBrowser for help on using the repository browser.