source: rtems/c/src/lib/libcpu/powerpc/mpc821/clock/clock.c @ 3084de2

4.104.114.84.95
Last change on this file since 3084de2 was 3084de2, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 7, 1999 at 3:57:05 PM

MPC821 support and PPC patches from Andrew Bray <andy@…>:

In c/src/exec/score/cpu/powerpc/rtems/score/ppc.h:

A lot of hardware interrupts were omitted. Patch enclosed.
I have also added the 821.

In c/src/exec/score/cpu/powerpc/rtems/score/cpu.h:

My patch adds the 821.

In c/src/exec/score/cpu/powerpc/cpu.c:

I have added the MPC821, and also fixed up for the missing hardware
interrupts. It is also inconsistent with
c/src/lib/libcpu/powerpc/mpc860/vectors/vectors.S. This has been fixed.

In c/src/lib/libcpu/powerpc/mpc860/vectors/vectors.S:

Fixed an inconsistency with cpu.c.

I also include some new files to go with the above patches. These are the
cpu library rtems-19990331/c/src/lib/libcpu/powerpc/mpc821/* and
c/src/exec/score/cpu/powerpc/mpc821.h which are minor modifications of
the 860 equivalents.

Other comments:

The various accesses to the DPRAM on the 860 are done with a linktime
symbol. This could be done dynamically at run time by reading the immr
register, and masking off the lower 16 bits. This takes the same amount
of time as loading an address constant, and the same number of
instructions as well (2).

In c/src/lib/libcpu/powerpc/mpc860/console-generic/console-generic.c:

This will silently fail if you attempt to use SCC1. This is only relevant
if you are not using SCC1 for ethernet.

This file also sets one of port B output pins for each port. This is NOT
generic, it should be in the BSP specific console driver.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*  clock.c
2 *
3 *  This routine initializes the PIT on the MPC821.
4 *  The tick frequency is specified by the bsp.
5 *
6 *  Author: Jay Monkman (jmonkman@frasca.com)
7 *  Copyright (C) 1998 by Frasca International, Inc.
8 *
9 *  Derived from c/src/lib/libcpu/ppc/ppc403/clock/clock.c:
10 *
11 *  Author: Andrew Bray <andy@i-cubed.co.uk>
12 *
13 *  COPYRIGHT (c) 1995 by i-cubed ltd.
14 *
15 *  To anyone who acknowledges that this file is provided "AS IS"
16 *  without any express or implied warranty:
17 *      permission to use, copy, modify, and distribute this file
18 *      for any purpose is hereby granted without fee, provided that
19 *      the above copyright notice and this notice appears in all
20 *      copies, and that the name of i-cubed limited not be used in
21 *      advertising or publicity pertaining to distribution of the
22 *      software without specific, written prior permission.
23 *      i-cubed limited makes no representations about the suitability
24 *      of this software for any purpose.
25 *
26 *  Derived from c/src/lib/libcpu/hppa1_1/clock/clock.c:
27 *
28 *  COPYRIGHT (c) 1989-1998.
29 *  On-Line Applications Research Corporation (OAR).
30 *  Copyright assigned to U.S. Government, 1994.
31 *
32 *  The license and distribution terms for this file may be
33 *  found in the file LICENSE in this distribution or at
34 *  http://www.OARcorp.com/rtems/license.html.
35 *
36 *  $Id$
37 */
38
39#include <bsp.h>
40#include <clockdrv.h>
41#include <rtems/libio.h>
42
43#include <stdlib.h>                     /* for atexit() */
44#include <mpc821.h>
45
46extern rtems_cpu_table           Cpu_table;             /* owned by BSP */
47
48volatile rtems_unsigned32 Clock_driver_ticks;
49extern volatile m821_t m821;
50
51void Clock_exit( void );
52 
53/*
54 * These are set by clock driver during its init
55 */
56 
57rtems_device_major_number rtems_clock_major = ~0;
58rtems_device_minor_number rtems_clock_minor;
59 
60/*
61 *  ISR Handler
62 */
63rtems_isr Clock_isr(rtems_vector_number vector)
64{
65  m821.piscr |= M821_PISCR_PS;
66  Clock_driver_ticks++;
67  rtems_clock_tick();
68}
69
70void Install_clock(rtems_isr_entry clock_isr)
71{
72  rtems_isr_entry previous_isr;
73  rtems_unsigned32 pit_value;
74 
75  Clock_driver_ticks = 0;
76 
77  pit_value = BSP_Configuration.microseconds_per_tick *
78               Cpu_table.clicks_per_usec;
79  if (pit_value == 0) {
80    pit_value = 0xffff;
81  } else {
82    pit_value--;
83  }
84 
85  if (pit_value > 0xffff) {           /* pit is only 16 bits long */
86    rtems_fatal_error_occurred(-1);
87  } 
88  if (BSP_Configuration.ticks_per_timeslice) {
89   
90    /*
91     * initialize the interval here
92     * First tick is set to right amount of time in the future
93     * Future ticks will be incremented over last value set
94     * in order to provide consistent clicks in the face of
95     * interrupt overhead
96     */
97   
98    rtems_interrupt_catch(clock_isr, PPC_IRQ_LVL0, &previous_isr);
99   
100    m821.sccr &= ~(1<<24);
101    m821.pitc = pit_value;
102   
103    /* set PIT irq level, enable PIT, PIT interrupts */
104    /*  and clear int. status */
105    m821.piscr = M821_PISCR_PIRQ(0) |
106      M821_PISCR_PTE | M821_PISCR_PS | M821_PISCR_PIE; 
107   
108    m821.simask |= M821_SIMASK_LVM0;
109  }
110  atexit(Clock_exit);
111}
112
113void
114ReInstall_clock(rtems_isr_entry new_clock_isr)
115{
116  rtems_isr_entry previous_isr;
117  rtems_unsigned32 isrlevel = 0;
118 
119  rtems_interrupt_disable(isrlevel);
120 
121  rtems_interrupt_catch(new_clock_isr, PPC_IRQ_LVL0, &previous_isr);
122 
123  rtems_interrupt_enable(isrlevel);
124}
125
126
127/*
128 * Called via atexit()
129 * Remove the clock interrupt handler by setting handler to NULL
130 */
131void
132Clock_exit(void)
133{
134  if ( BSP_Configuration.ticks_per_timeslice ) {
135    /* disable PIT and PIT interrupts */
136    m821.piscr &= ~(M821_PISCR_PTE | M821_PISCR_PIE); 
137   
138    (void) set_vector(0, PPC_IRQ_LVL0, 1);
139  }
140}
141
142rtems_device_driver Clock_initialize(
143  rtems_device_major_number major,
144  rtems_device_minor_number minor,
145  void *pargp
146)
147{
148  Install_clock( Clock_isr );
149 
150  /*
151   * make major/minor avail to others such as shared memory driver
152   */
153 
154  rtems_clock_major = major;
155  rtems_clock_minor = minor;
156 
157  return RTEMS_SUCCESSFUL;
158}
159 
160rtems_device_driver Clock_control(
161  rtems_device_major_number major,
162  rtems_device_minor_number minor,
163  void *pargp
164)
165{
166  rtems_libio_ioctl_args_t *args = pargp;
167 
168  if (args == 0)
169    goto done;
170 
171  /*
172   * This is hokey, but until we get a defined interface
173   * to do this, it will just be this simple...
174   */
175 
176  if (args->command == rtems_build_name('I', 'S', 'R', ' ')) {
177    Clock_isr(PPC_IRQ_LVL0);
178  }
179  else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) {
180    ReInstall_clock(args->buffer);
181  }
182 
183 done:
184  return RTEMS_SUCCESSFUL;
185}
186
Note: See TracBrowser for help on using the repository browser.