OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [i386/] [ts_386ex/] [clock/] [ckinit.c] - Blame information for rev 602

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  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.OARcorp.com/rtems/license.html.
18
 *
19
 *  $Id: ckinit.c,v 1.2 2001-09-27 11:59:50 chris Exp $
20
 */
21
 
22
#include <bsp.h>
23
#include <irq.h>
24
 
25
#include <rtems/libio.h>
26
 
27
#include <stdlib.h>
28
 
29
rtems_unsigned32 Clock_isrs;              /* ISRs until next tick */
30
static rtems_unsigned32 Clock_initial_isr_value;
31
 
32
volatile rtems_unsigned32 Clock_driver_ticks;
33
 
34
void Clock_exit( void );
35
 
36
/*
37
 * These are set by clock driver during its init
38
 */
39
 
40
rtems_device_major_number rtems_clock_major = ~0;
41
rtems_device_major_number rtems_clock_minor = 0;
42
 
43
/*
44
 *  This is the ISR handler.
45
 */
46
 
47
void 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
 
59
void ClockOff(const rtems_irq_connect_data* unused)
60
{
61
  outport_byte (TIMER_CONFIG, 0x80 ); /* disable the counter timer */
62
}
63
 
64
void ClockOn(const rtems_irq_connect_data* unused)
65
{
66
  outport_byte (TIMER_CONFIG, 0x00 ); /* enable the counter timer */
67
}
68
 
69
int ClockIsOn(const rtems_irq_connect_data* unused)
70
{
71
  return ((i8259s_cache & 0x1) == 0);
72
}
73
 
74
static rtems_irq_connect_data clockIrqData = {BSP_PERIODIC_TIMER,
75
                                              Clock_isr,
76
                                              ClockOn,
77
                                              ClockOff,
78
                                              ClockIsOn};
79
 
80
 
81
rtems_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
    BSP_Configuration.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  =  BSP_Configuration.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
 
150
rtems_device_driver Clock_control(
151
  rtems_device_major_number major,
152
  rtems_device_minor_number minor,
153
  void *pargp
154
)
155
{
156
    rtems_libio_ioctl_args_t *args = pargp;
157
 
158
    if (args == 0)
159
        goto done;
160
 
161
    /*
162
     * This is hokey, but until we get a defined interface
163
     * to do this, it will just be this simple...
164
     */
165
 
166
    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
167
    {
168
        Clock_isr();
169
    }
170
    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
171
    {
172
      if (!BSP_install_rtems_irq_handler (&clockIrqData)) {
173
        printk("Error installing clock interrupt handler!\n");
174
        rtems_fatal_error_occurred(1);
175
      }
176
#ifdef BSP_DEBUG
177
      else
178
        printk("Clock installed AGAIN\n");
179
#endif
180
    }
181
 
182
done:
183
    return RTEMS_SUCCESSFUL;
184
}
185
 
186
void Clock_exit()
187
{
188
  ClockOff(&clockIrqData);
189
  BSP_remove_rtems_irq_handler (&clockIrqData);
190
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.