source: rtems/c/src/lib/libcpu/powerpc/mpc8260/clock/clock.c @ dad34779

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

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

  • mpc5xx/clock/clock.c, mpc6xx/clock/c_clock.c, mpc8260/clock/clock.c, mpc8xx/clock/clock.c, ppc403/clock/clock.c, ppc403/clock/clock_4xx.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.9 KB
Line 
1/*  clock.c
2 *
3 *  This routine initializes the PIT on the MPC8xx.
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-2007.
29 *  On-Line Applications Research Corporation (OAR).
30 *
31 *  The license and distribution terms for this file may be
32 *  found in the file LICENSE in this distribution or at
33 *  http://www.rtems.com/license/LICENSE.
34 *
35 *  $Id$
36 */
37
38#include <rtems.h>
39#include <rtems/clockdrv.h>
40#include <rtems/libio.h>
41
42#include <stdlib.h>                     /* for atexit() */
43#include <mpc8260.h>
44#include <bsp/irq.h>
45
46volatile uint32_t   Clock_driver_ticks;
47extern int BSP_get_clock_irq_level(void);
48extern int BSP_connect_clock_handler(rtems_isr_entry);
49extern int BSP_disconnect_clock_handler(void);
50
51void Clock_exit( void );
52
53uint32_t   decrementer_value;
54
55volatile int ClockInitialised = 0;
56
57
58/*
59 * These are set by clock driver during its init
60 */
61 
62rtems_device_major_number rtems_clock_major = ~0;
63rtems_device_minor_number rtems_clock_minor;
64 
65/*
66 *  ISR Handler
67 */
68rtems_isr Clock_isr(rtems_vector_number vector)
69{
70  int clicks;
71
72  if( ClockInitialised ) {
73    PPC_Get_decrementer( clicks );
74    do {
75      clicks += decrementer_value;
76      PPC_Set_decrementer( clicks );
77
78      Clock_driver_ticks++;
79      rtems_clock_tick();
80    } while( clicks < 100 );
81  }
82#if 0
83  m8260.piscr |= M8260_PISCR_PS;
84  Clock_driver_ticks++;
85  rtems_clock_tick();
86#endif
87
88
89}
90
91void clockOn(void* unused)
92{
93  extern uint32_t bsp_clicks_per_usec;
94
95  decrementer_value = rtems_configuration_get_microseconds_per_tick() *
96                      bsp_clicks_per_usec - 1;
97
98  PPC_Set_decrementer( decrementer_value );
99  Clock_driver_ticks = 0;
100
101  ClockInitialised = 1;
102}
103
104/*
105 * Called via atexit()
106 * Remove the clock interrupt handler by setting handler to NULL
107 */
108void
109clockOff(void* unused)
110{
111#if 0
112  /* disable PIT and PIT interrupts */
113  m8260.piscr &= ~(M8260_PISCR_PTE | M8260_PISCR_PIE);
114#endif
115  ClockInitialised = 0;
116}
117
118int clockIsOn(void* unused)
119{
120  return ClockInitialised;
121#if 0
122  if (m8260.piscr & M8260_PISCR_PIE) return 1;
123  return 0;
124#endif
125
126}
127
128/*
129 * Called via atexit()
130 * Remove the clock interrupt handler by setting handler to NULL
131 */
132void
133Clock_exit(void)
134{
135  (void) BSP_disconnect_clock_handler ();
136}
137
138void Install_clock(rtems_isr_entry clock_isr)
139{
140  extern uint32_t bsp_clicks_per_usec;
141
142  Clock_driver_ticks = 0;
143
144  decrementer_value = rtems_configuration_get_microseconds_per_tick() *
145                      bsp_clicks_per_usec - 1;
146
147  PPC_Set_decrementer( decrementer_value );
148
149  BSP_connect_clock_handler (clock_isr);
150
151
152  ClockInitialised = 1;
153
154  atexit(Clock_exit);
155
156}
157
158void
159ReInstall_clock(rtems_isr_entry new_clock_isr)
160{
161  BSP_connect_clock_handler (new_clock_isr);
162}
163
164
165rtems_device_driver Clock_initialize(
166  rtems_device_major_number major,
167  rtems_device_minor_number minor,
168  void *pargp
169)
170{
171  Install_clock( Clock_isr );
172 
173  /*
174   * make major/minor avail to others such as shared memory driver
175   */
176 
177  rtems_clock_major = major;
178  rtems_clock_minor = minor;
179 
180  return RTEMS_SUCCESSFUL;
181}
Note: See TracBrowser for help on using the repository browser.