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

4.115
Last change on this file since b6c3e3e was b6c3e3e, checked in by Joel Sherrill <joel.sherrill@…>, on 10/12/14 at 20:37:33

libcpu/powerpc/mpc5xx/clock/clock.c: Fix warnings

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