source: rtems/c/src/lib/libcpu/powerpc/mpc5xx/clock/clock.c @ 14a78df

4.104.115
Last change on this file since 14a78df was 14a78df, checked in by Joel Sherrill <joel.sherrill@…>, on 04/28/10 at 17:17:59

2010-04-28 Joel Sherrill <joel.sherrilL@…>

  • mpc5xx/clock/clock.c, mpc5xx/console-generic/console-generic.c, mpc5xx/irq/irq_init.c, mpc5xx/timer/timer.c: Remove warnings.
  • Property mode set to 100644
File size: 4.2 KB
Line 
1/* clock.c
2 *
3 *  This routine initializes the PIT on the MPC5xx.
4 *  The tick frequency is specified by the bsp.
5 *
6 *
7 *  MPC5xx port sponsored by Defence Research and Development Canada - Suffield
8 *  Copyright (C) 2004, Real-Time Systems Inc. (querbach@realtime.bc.ca)
9 *
10 *  Derived from c/src/lib/libcpu/powerpc/mpc8xx/clock/clock.c:
11 *
12 *  Author: Jay Monkman (jmonkman@frasca.com)
13 *  Copyright (C) 1998 by Frasca International, Inc.
14 *
15 *  Derived from c/src/lib/libcpu/ppc/ppc403/clock/clock.c:
16 *
17 *  Author: Andrew Bray <andy@i-cubed.co.uk>
18 *
19 *  COPYRIGHT (c) 1995 by i-cubed ltd.
20 *
21 *  To anyone who acknowledges that this file is provided "AS IS"
22 *  without any express or implied warranty:
23 *      permission to use, copy, modify, and distribute this file
24 *      for any purpose is hereby granted without fee, provided that
25 *      the above copyright notice and this notice appears in all
26 *      copies, and that the name of i-cubed limited not be used in
27 *      advertising or publicity pertaining to distribution of the
28 *      software without specific, written prior permission.
29 *      i-cubed limited makes no representations about the suitability
30 *      of this software for any purpose.
31 *
32 *  Derived from c/src/lib/libcpu/hppa1_1/clock/clock.c:
33 *
34 *  COPYRIGHT (c) 1989-2007.
35 *  On-Line Applications Research Corporation (OAR).
36 *
37 *  The license and distribution terms for this file may be
38 *  found in the file LICENSE in this distribution or at
39 *  http://www.rtems.com/license/LICENSE.
40 *
41 *  $Id$
42 */
43
44#include <rtems.h>
45#include <rtems/clockdrv.h>
46#include <rtems/libio.h>
47#include <libcpu/irq.h>
48
49#include <stdlib.h>                     /* for atexit() */
50#include <mpc5xx.h>
51
52volatile uint32_t Clock_driver_ticks;
53extern int BSP_connect_clock_handler(rtems_isr_entry);
54extern int BSP_disconnect_clock_handler();
55extern uint32_t bsp_clicks_per_usec;
56
57void Clock_exit( void );
58
59/*
60 * These are set by clock driver during its init
61 */
62
63rtems_device_major_number rtems_clock_major = ~0;
64rtems_device_minor_number rtems_clock_minor;
65
66/*
67 *  ISR Handler
68 */
69rtems_isr Clock_isr(rtems_vector_number vector)
70{
71  usiu.piscrk = USIU_UNLOCK_KEY;
72  usiu.piscr |= USIU_PISCR_PS;                  /* acknowledge interrupt */
73  usiu.piscrk = 0;
74
75  Clock_driver_ticks++;
76  rtems_clock_tick();
77}
78
79void clockOn(void* unused)
80{
81  unsigned desiredLevel;
82  uint32_t pit_value;
83
84  /* calculate and set modulus */
85  pit_value = (rtems_configuration_get_microseconds_per_tick() *
86               bsp_clicks_per_usec) - 1 ;
87
88  if (pit_value > 0xffff) {           /* pit is only 16 bits long */
89    rtems_fatal_error_occurred(-1);
90  }
91  usiu.sccrk = USIU_UNLOCK_KEY;
92  usiu.sccr &= ~USIU_SCCR_RTDIV;        /* RTC and PIT clock is divided by 4 */
93  usiu.sccrk = 0;
94
95  usiu.pitck = USIU_UNLOCK_KEY;
96  usiu.pitc = pit_value;
97  usiu.pitck = 0;
98
99  /* set PIT irq level, enable PIT, PIT interrupts */
100  /*  and clear int. status */
101  desiredLevel = CPU_irq_level_from_symbolic_name(CPU_PERIODIC_TIMER);
102
103  usiu.piscrk = USIU_UNLOCK_KEY;
104  usiu.piscr = USIU_PISCR_PIRQ(desiredLevel)    /* set interrupt priority */
105             | USIU_PISCR_PS                    /* acknowledge interrupt */
106             | USIU_PISCR_PIE                   /* enable interrupt */
107             | USIU_PISCR_PITF                  /* freeze during debug */
108             | USIU_PISCR_PTE;                  /* enable timer */
109  usiu.piscrk = 0;
110}
111
112void
113clockOff(void* unused)
114{
115  /* disable PIT and PIT interrupts */
116  usiu.piscrk = USIU_UNLOCK_KEY;
117  usiu.piscr &= ~(USIU_PISCR_PTE | USIU_PISCR_PIE);
118  usiu.piscrk = 0;
119}
120
121int clockIsOn(void* unused)
122{
123  if (usiu.piscr & USIU_PISCR_PIE)
124    return 1;
125  return 0;
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  Clock_driver_ticks = 0;
141
142  BSP_connect_clock_handler (clock_isr);
143  atexit(Clock_exit);
144}
145
146void
147ReInstall_clock(rtems_isr_entry new_clock_isr)
148{
149  BSP_connect_clock_handler (new_clock_isr);
150}
151
152
153rtems_device_driver Clock_initialize(
154  rtems_device_major_number major,
155  rtems_device_minor_number minor,
156  void *pargp
157)
158{
159  Install_clock( Clock_isr );
160
161  /*
162   * make major/minor avail to others such as shared memory driver
163   */
164
165  rtems_clock_major = major;
166  rtems_clock_minor = minor;
167
168  return RTEMS_SUCCESSFUL;
169}
Note: See TracBrowser for help on using the repository browser.