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

4.104.114.95
Last change on this file since dad34779 was 34ef6c7, checked in by Joel Sherrill <joel.sherrill@…>, on 09/05/08 at 22:06:51

2008-09-05 Joel Sherrill <joel.sherrill@…>

  • clock/ckinit.c: The Shared Memory Driver no longer requires the special IOCTL in Clock_control. This was a hack which has existed since before the Classic API Timer Manager was implemented. All implementations of and references to Clock_control were removed.
  • Property mode set to 100644
File size: 3.7 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(void)
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; /* rtems_configuration_get_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                                              0,
77                                              ClockOn,
78                                              ClockOff,
79                                              ClockIsOn};
80
81rtems_device_driver Clock_initialize(
82  rtems_device_major_number major,
83  rtems_device_minor_number minor,
84  void *pargp
85)
86{
87  unsigned timer_counter_init_value;
88  unsigned char clock_lsb, clock_msb;
89
90#ifdef BSP_DEBUG
91  printk("Initializing clock driver in Clock_initialize().\n");
92#endif
93
94#ifdef LOAD_RTC_AT_START
95  /* Initialize clock from on-board real time clock.  This breaks the  */
96  /* test code which assumes which assumes the application will do it. */
97  {
98    rtems_time_of_day now;
99
100    /* External Prototypes */
101    extern void init_rtc(void);                /* defined in 'rtc.c' */
102    extern long rtc_read(rtems_time_of_day *); /* defined in 'rtc.c' */
103
104#ifdef BSP_DEBUG
105    printk("Loading clock from on-board real-time clock.\n");
106#endif
107
108    init_rtc();
109    if (rtc_read(&now) >= 0)
110      rtems_clock_set(&now);
111  }
112#endif
113
114  Clock_driver_ticks = 0;
115
116  Clock_isrs =
117    Clock_initial_isr_value =
118    rtems_configuration_get_microseconds_per_tick() / 1000; /* ticks per clock_isr */
119
120  /*
121   * configure the counter timer ( should be based on microsecs/tick )
122   * NB. The divisor(Clock_isrs) resolves the  is the same number that appears in confdefs.h
123   * when setting the microseconds_per_tick value.
124   */
125  ClockOff      ( &clockIrqData );
126
127  timer_counter_init_value  =  rtems_configuration_get_microseconds_per_tick() / Clock_isrs;
128  clock_lsb = (unsigned char)timer_counter_init_value;
129  clock_msb = timer_counter_init_value >> 8;
130
131  outport_byte (TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN);
132  outport_byte (TIMER_CNTR0, clock_lsb );   /* load LSB first */
133  outport_byte (TIMER_CNTR0, clock_msb );   /* then MSB       */
134
135  if (!BSP_install_rtems_irq_handler (&clockIrqData)) {
136    printk("Unable to initialize system clock\n");
137    rtems_fatal_error_occurred(1);
138  }
139
140  /*
141   * make major/minor avail to others such as shared memory driver
142   */
143
144  rtems_clock_major = major;
145  rtems_clock_minor = minor;
146
147  return RTEMS_SUCCESSFUL;
148}
149
150void Clock_exit()
151{
152  ClockOff(&clockIrqData);
153  BSP_remove_rtems_irq_handler (&clockIrqData);
154}
Note: See TracBrowser for help on using the repository browser.