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

4.104.114.84.95
Last change on this file since 16a384cf was 16a384cf, checked in by Joel Sherrill <joel.sherrill@…>, on 04/23/99 at 16:35:11

New BSP from Tony R. Ambardar <tonya@…> from the
University of British Columbia. The BSP is for:

Yes, this is the "entry model" of a series of boards from Technologic
Systems. Costs <$200 I believe. They have a WWW page at www.t-systems.com.
I am letting them know about the availability of this BSP too.

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