source: rtems/bsps/powerpc/ss555/clock/clock.c @ bb99cd0d

5
Last change on this file since bb99cd0d was bb99cd0d, checked in by Sebastian Huber <sebastian.huber@…>, on Dec 5, 2019 at 6:22:33 PM

clock: Simplify driver initialization

Use a system initialization handler instead of a legacy IO driver.

Update #3834.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 *  This routine initializes the PIT on the MPC5xx.
3 *  The tick frequency is specified by the BSP.
4 */
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.org/license/LICENSE.
40 */
41
42#include <rtems.h>
43#include <rtems/clockdrv.h>
44#include <rtems/libio.h>
45#include <libcpu/irq.h>
46
47#include <stdlib.h>                     /* for atexit() */
48#include <mpc5xx.h>
49
50volatile uint32_t Clock_driver_ticks;
51extern int BSP_connect_clock_handler(rtems_isr_entry);
52extern int BSP_disconnect_clock_handler(void);
53extern uint32_t bsp_clicks_per_usec;
54
55/*
56 *  ISR Handler
57 */
58rtems_isr Clock_isr(rtems_vector_number vector)
59{
60  usiu.piscrk = USIU_UNLOCK_KEY;
61  usiu.piscr |= USIU_PISCR_PS;                  /* acknowledge interrupt */
62  usiu.piscrk = 0;
63
64  Clock_driver_ticks++;
65  rtems_clock_tick();
66}
67
68void clockOn(void* unused)
69{
70  unsigned desiredLevel;
71  uint32_t pit_value;
72
73  /* calculate and set modulus */
74  pit_value = (rtems_configuration_get_microseconds_per_tick() *
75               bsp_clicks_per_usec) - 1 ;
76
77  if (pit_value > 0xffff) {           /* pit is only 16 bits long */
78    rtems_fatal_error_occurred(-1);
79  }
80  usiu.sccrk = USIU_UNLOCK_KEY;
81  usiu.sccr &= ~USIU_SCCR_RTDIV;        /* RTC and PIT clock is divided by 4 */
82  usiu.sccrk = 0;
83
84  usiu.pitck = USIU_UNLOCK_KEY;
85  usiu.pitc = pit_value;
86  usiu.pitck = 0;
87
88  /* set PIT irq level, enable PIT, PIT interrupts */
89  /*  and clear int. status */
90  desiredLevel = CPU_irq_level_from_symbolic_name(CPU_PERIODIC_TIMER);
91
92  usiu.piscrk = USIU_UNLOCK_KEY;
93  usiu.piscr = USIU_PISCR_PIRQ(desiredLevel)    /* set interrupt priority */
94             | USIU_PISCR_PS                    /* acknowledge interrupt */
95             | USIU_PISCR_PIE                   /* enable interrupt */
96             | USIU_PISCR_PITF                  /* freeze during debug */
97             | USIU_PISCR_PTE;                  /* enable timer */
98  usiu.piscrk = 0;
99}
100
101void clockOff(void* unused)
102{
103  /* disable PIT and PIT interrupts */
104  usiu.piscrk = USIU_UNLOCK_KEY;
105  usiu.piscr &= ~(USIU_PISCR_PTE | USIU_PISCR_PIE);
106  usiu.piscrk = 0;
107}
108
109int clockIsOn(void* unused)
110{
111  if (usiu.piscr & USIU_PISCR_PIE)
112    return 1;
113  return 0;
114}
115
116/*
117 * Called via atexit()
118 * Remove the clock interrupt handler by setting handler to NULL
119 */
120static void Clock_exit(void)
121{
122  (void) BSP_disconnect_clock_handler ();
123}
124
125static void Install_clock(rtems_isr_entry clock_isr)
126{
127  Clock_driver_ticks = 0;
128
129  BSP_connect_clock_handler (clock_isr);
130  atexit(Clock_exit);
131}
132
133void _Clock_Initialize( void )
134{
135  Install_clock( Clock_isr );
136}
Note: See TracBrowser for help on using the repository browser.