source: rtems/bsps/powerpc/ss555/clock/clock.c @ 511dc4b

5
Last change on this file since 511dc4b was 7632906, checked in by Sebastian Huber <sebastian.huber@…>, on 04/19/18 at 04:35:52

bsps: Move clock drivers to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 3.9 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
55void Clock_exit( void );
56
57/*
58 *  ISR Handler
59 */
60rtems_isr Clock_isr(rtems_vector_number vector)
61{
62  usiu.piscrk = USIU_UNLOCK_KEY;
63  usiu.piscr |= USIU_PISCR_PS;                  /* acknowledge interrupt */
64  usiu.piscrk = 0;
65
66  Clock_driver_ticks++;
67  rtems_clock_tick();
68}
69
70void clockOn(void* unused)
71{
72  unsigned desiredLevel;
73  uint32_t pit_value;
74
75  /* calculate and set modulus */
76  pit_value = (rtems_configuration_get_microseconds_per_tick() *
77               bsp_clicks_per_usec) - 1 ;
78
79  if (pit_value > 0xffff) {           /* pit is only 16 bits long */
80    rtems_fatal_error_occurred(-1);
81  }
82  usiu.sccrk = USIU_UNLOCK_KEY;
83  usiu.sccr &= ~USIU_SCCR_RTDIV;        /* RTC and PIT clock is divided by 4 */
84  usiu.sccrk = 0;
85
86  usiu.pitck = USIU_UNLOCK_KEY;
87  usiu.pitc = pit_value;
88  usiu.pitck = 0;
89
90  /* set PIT irq level, enable PIT, PIT interrupts */
91  /*  and clear int. status */
92  desiredLevel = CPU_irq_level_from_symbolic_name(CPU_PERIODIC_TIMER);
93
94  usiu.piscrk = USIU_UNLOCK_KEY;
95  usiu.piscr = USIU_PISCR_PIRQ(desiredLevel)    /* set interrupt priority */
96             | USIU_PISCR_PS                    /* acknowledge interrupt */
97             | USIU_PISCR_PIE                   /* enable interrupt */
98             | USIU_PISCR_PITF                  /* freeze during debug */
99             | USIU_PISCR_PTE;                  /* enable timer */
100  usiu.piscrk = 0;
101}
102
103void clockOff(void* unused)
104{
105  /* disable PIT and PIT interrupts */
106  usiu.piscrk = USIU_UNLOCK_KEY;
107  usiu.piscr &= ~(USIU_PISCR_PTE | USIU_PISCR_PIE);
108  usiu.piscrk = 0;
109}
110
111int clockIsOn(void* unused)
112{
113  if (usiu.piscr & USIU_PISCR_PIE)
114    return 1;
115  return 0;
116}
117
118/*
119 * Called via atexit()
120 * Remove the clock interrupt handler by setting handler to NULL
121 */
122void Clock_exit(void)
123{
124  (void) BSP_disconnect_clock_handler ();
125}
126
127static void Install_clock(rtems_isr_entry clock_isr)
128{
129  Clock_driver_ticks = 0;
130
131  BSP_connect_clock_handler (clock_isr);
132  atexit(Clock_exit);
133}
134
135rtems_device_driver Clock_initialize(
136  rtems_device_major_number major,
137  rtems_device_minor_number minor,
138  void *pargp
139)
140{
141  Install_clock( Clock_isr );
142
143  return RTEMS_SUCCESSFUL;
144}
Note: See TracBrowser for help on using the repository browser.