source: rtems/c/src/lib/libbsp/m68k/idp/clock/ckinit.c @ 3a4ae6c

4.104.114.84.95
Last change on this file since 3a4ae6c was 3a4ae6c, checked in by Joel Sherrill <joel.sherrill@…>, on 09/11/95 at 19:35:39

The word "RTEMS" almost completely removed from the core.

Configuration Table Template file added and all tests
modified to use this. All gvar.h and conftbl.h files
removed from test directories.

Configuration parameter maximum_devices added.

Core semaphore and mutex handlers added and RTEMS API Semaphore
Manager updated to reflect this.

Initialization sequence changed to invoke API specific initialization
routines. Initialization tasks table now owned by RTEMS Tasks Manager.

Added user extension for post-switch.

Utilized user extensions to implement API specific functionality
like signal dispatching.

Added extensions to the System Initialization Thread so that an
API can register a function to be invoked while the system
is being initialized. These are largely equivalent to the
pre-driver and post-driver hooks.

Added the Modules file oar-go32_p5, modified oar-go32, and modified
the file make/custom/go32.cfg to look at an environment varable which
determines what CPU model is being used.

All BSPs updated to reflect named devices and clock driver's IOCTL
used by the Shared Memory Driver. Also merged clock isr into
main file and removed ckisr.c where possible.

Updated spsize to reflect new and moved variables.

Makefiles for the executive source and include files updated to show
break down of files into Core, RTEMS API, and Neither.

Header and inline files installed into subdirectory based on whether
logically in the Core or a part of the RTEMS API.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*  Clock_init()
2 *
3 *
4 *  This is modified by Doug McBride to get it to work for the MC68EC040
5 *  IDP board.  The below comments are kept to show that some prior work
6 *  was done in the area and the modifications performed was application
7 *  specific for the IDP board to port it to.
8 *
9 *  This routine initializes the mc68230 on the MC68EC040 board.
10 *  The tick frequency is 40 milliseconds.
11 *
12 *  Input parameters:  NONE
13 *
14 *  Output parameters:  NONE
15 *
16 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
17 *  On-Line Applications Research Corporation (OAR).
18 *  All rights assigned to U.S. Government, 1994.
19 *
20 *  This material may be reproduced by or for the U.S. Government pursuant
21 *  to the copyright license under the clause at DFARS 252.227-7013.  This
22 *  notice must appear in all copies of this file and its derivatives.
23 *
24 *  $Id$
25 */
26
27#include <stdlib.h>
28
29#include <bsp.h>
30#include <rtems/libio.h>
31
32rtems_unsigned32 Clock_isrs;        /* ISRs until next tick */
33volatile rtems_unsigned32 Clock_driver_ticks;
34                                    /* ticks since initialization */
35rtems_isr_entry  Old_ticker;
36
37extern rtems_configuration_table Configuration;
38extern void led_putnum();
39void Disable_clock();
40
41#define CLOCK_VECTOR 0x4D
42
43void Clock_exit( void );
44 
45/*
46 * These are set by clock driver during its init
47 */
48 
49rtems_device_major_number rtems_clock_major = ~0;
50rtems_device_minor_number rtems_clock_minor;
51 
52
53/*
54 *  ISR Handler
55 *
56 *
57 * ((1ms * 6.5 MHz) / 2^5) = 203.125) where 6.5 MHz is the clock rate of the
58 * MC68230, 2^5 is the prescaler factor, and 1ms is the common interrupt
59 * interval for the Clock_isr routine.
60 * Therefore, 203 (decimal) is the number to program into the CPRH-L registers
61 * of the MC68230 for countdown.  However, I have found that 193 instead of
62 * 203 provides greater accuracy -- why?  The crystal should be more accurate
63 * than that
64 */
65
66rtems_isr Clock_isr(
67  rtems_vector_number vector
68)
69{
70  Clock_driver_ticks += 1;
71  /* acknowledge interrupt
72        TSR = 1; */
73  MC68230_WRITE (TSR, 1);
74
75  if ( Clock_isrs == 1 ) {
76    rtems_clock_tick();
77        /* Cast to an integer so that 68EC040 IDP which doesn't have an FPU doesn't
78           have a heart attack -- if you use newlib1.6 or greater and get
79           libgcc.a for gcc with software floating point support, this is not
80           a problem */
81    Clock_isrs =
82      (int)(BSP_Configuration.microseconds_per_tick / 1000);
83  }
84  else
85    Clock_isrs -= 1;
86}
87
88void Disable_clock()
89{
90        /* Disable timer */
91        MC68230_WRITE (TCR, 0x00);
92}
93
94void Install_clock( clock_isr )
95rtems_isr_entry clock_isr;
96{
97  Clock_driver_ticks = 0;
98  Clock_isrs = (int)(Configuration.microseconds_per_tick / 1000);
99
100  if ( Configuration.ticks_per_timeslice ) {
101/*    led_putnum('c'); * for debugging purposes */
102    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
103
104        /* Disable timer for initialization */
105        MC68230_WRITE (TCR, 0x00);
106
107        /* some PI/T initialization stuff here -- see comment in the ckisr.c
108           file in this directory to understand why I use the values that I do */
109        /* Set up the interrupt vector on the MC68230 chip:
110                TIVR = CLOCK_VECTOR; */
111        MC68230_WRITE (TIVR, CLOCK_VECTOR);
112
113        /* Set CPRH through CPRL to 193 (not 203) decimal for countdown--see ckisr.c
114                CPRH = 0x00;
115                CPRM = 0x00;
116                CPRL = 0xC1; */
117        MC68230_WRITE (CPRH, 0x00);
118        MC68230_WRITE (CPRM, 0x00);
119        MC68230_WRITE (CPRL, 0xC1);
120
121        /* Enable timer and use it as an external periodic interrupt generator
122                TCR = 0xA1; */
123/*    led_putnum('a'); * for debugging purposes */
124        MC68230_WRITE (TCR, 0xA1);
125
126        /*
127         *  Schedule the clock cleanup routine to execute if the application exits.
128         */
129    atexit( Clock_exit );
130  }
131}
132
133void ReInstall_clock( clock_isr )
134rtems_isr_entry clock_isr;
135{
136  rtems_unsigned32 isrlevel = 0 ;
137
138  rtems_interrupt_disable( isrlevel );
139   (void) set_vector( clock_isr, CLOCK_VECTOR, 1 );
140  rtems_interrupt_enable( isrlevel );
141}
142
143/* The following was added for debugging purposes */
144void Clock_exit( void )
145{
146  rtems_unsigned8 data;
147
148  if ( Configuration.ticks_per_timeslice ) {
149
150        /* disable timer
151                data = TCR;
152                TCR = (data & 0xFE); */
153        MC68230_READ (TCR, data);
154        MC68230_WRITE (TCR, (data & 0xFE));
155
156    /* do not restore old vector */
157  }
158}
159
160rtems_device_driver Clock_initialize(
161  rtems_device_major_number major,
162  rtems_device_minor_number minor,
163  void *pargp
164)
165{
166  Install_clock( Clock_isr );
167 
168  /*
169   * make major/minor avail to others such as shared memory driver
170   */
171 
172  rtems_clock_major = major;
173  rtems_clock_minor = minor;
174 
175  return RTEMS_SUCCESSFUL;
176}
177 
178rtems_device_driver Clock_control(
179  rtems_device_major_number major,
180  rtems_device_minor_number minor,
181  void *pargp
182)
183{
184    rtems_libio_ioctl_args_t *args = pargp;
185 
186    if (args == 0)
187        goto done;
188 
189    /*
190     * This is hokey, but until we get a defined interface
191     * to do this, it will just be this simple...
192     */
193 
194    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
195    {
196        Clock_isr(CLOCK_VECTOR);
197    }
198    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
199    {
200        ReInstall_clock(args->buffer);
201    }
202 
203done:
204    return RTEMS_SUCCESSFUL;
205}
206
Note: See TracBrowser for help on using the repository browser.