source: rtems/c/src/lib/libcpu/m68k/mcf5272/clock/ckinit.c @ 1c554014

4.115
Last change on this file since 1c554014 was 1c554014, checked in by Ralf Corsépius <ralf.corsepius@…>, on 07/19/12 at 14:14:53

Remove CVS-Ids.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 *  Clock Driver for MCF5272 CPU
3 *
4 *  This driver initailizes timer1 on the MCF5272 as the
5 *  main system clock
6 *
7 *  Copyright 2004 Cogent Computer Systems
8 *  Author: Jay Monkman <jtm@lopingdog.com>
9 *
10 *  Based on MCF5206 clock driver by
11 *    Victor V. Vengerov <vvv@oktet.ru>
12 *
13 *  Based on work:
14 *    David Fiddes, D.J@fiddes.surfaid.org
15 *    http://www.calm.hw.ac.uk/davidf/coldfire/
16 *
17 *  COPYRIGHT (c) 1989-1998.
18 *  On-Line Applications Research Corporation (OAR).
19 *
20 *  The license and distribution terms for this file may be
21 *  found in the file LICENSE in this distribution or at
22 *  http://www.rtems.com/license/LICENSE.
23 */
24
25#include <stdlib.h>
26#include <bsp.h>
27#include <rtems/libio.h>
28#include <mcf5272/mcf5272.h>
29
30/*
31 * Clock_driver_ticks is a monotonically increasing counter of the
32 * number of clock ticks since the driver was initialized.
33 */
34volatile uint32_t Clock_driver_ticks;
35
36
37/*
38 * These are set by clock driver during its init
39 */
40
41rtems_device_major_number rtems_clock_major = ~0;
42rtems_device_minor_number rtems_clock_minor;
43
44rtems_isr (*rtems_clock_hook)(rtems_vector_number) = NULL;
45
46/* Clock_isr --
47 *     This handles the timer interrupt by clearing the timer's interrupt
48 *     flag and announcing the clock tick to the system.
49 *
50 * PARAMETERS:
51 *     vector - timer interrupt vector number
52
53 * RETURNS:
54 *     none
55 */
56rtems_isr
57Clock_isr (rtems_vector_number vector)
58{
59    /* Clear pending interrupt... */
60    g_timer_regs->ter1 = MCF5272_TER_REF | MCF5272_TER_CAP;
61
62    /* Announce the clock tick */
63    Clock_driver_ticks++;
64    rtems_clock_tick();
65    if (rtems_clock_hook != NULL) {
66        rtems_clock_hook(vector);
67    }
68}
69
70
71/* Clock_exit --
72 *     This shuts down the timer if it was enabled and removes it
73 *     from the MCF5206E interrupt mask.
74 *
75 * PARAMETERS:
76 *     none
77 *
78 * RETURNS:
79 *     none
80 */
81void
82Clock_exit(void)
83{
84    if (rtems_configuration_get_ticks_per_timeslice()) {
85        uint32_t icr;
86        /* disable all timer1 interrupts */
87        icr = g_intctrl_regs->icr1;
88        icr = icr & ~(MCF5272_ICR1_TMR1_MASK | MCF5272_ICR1_TMR1_PI);
89        icr |= (MCF5272_ICR1_TMR1_IPL(0) | MCF5272_ICR1_TMR1_PI);
90        g_intctrl_regs->icr1 = icr;
91
92        /* reset timer1 */
93        g_timer_regs->tmr1 = MCF5272_TMR_CLK_STOP;
94
95        /* clear pending */
96        g_timer_regs->ter1 = MCF5272_TER_REF | MCF5272_TER_CAP;
97    }
98}
99
100
101/* Install_clock --
102 *     This initialises timer1 with the BSP timeslice config value
103 *     as a reference and sets up the interrupt handler for clock ticks.
104 *
105 * PARAMETERS:
106 *     clock_isr - clock interrupt handler routine
107 *
108 * RETURNS:
109 *     none.
110 */
111static void
112Install_clock(rtems_isr_entry clock_isr)
113{
114  uint32_t icr;
115  Clock_driver_ticks = 0;
116  if (rtems_configuration_get_ticks_per_timeslice()) {
117
118      /* Register the interrupt handler */
119      set_vector(clock_isr, BSP_INTVEC_TMR1, 1);
120
121      /* Reset timer 1 */
122      g_timer_regs->tmr1 = MCF5272_TMR_RST;
123      g_timer_regs->tmr1 = MCF5272_TMR_CLK_STOP;
124      g_timer_regs->tmr1 = MCF5272_TMR_RST;
125      g_timer_regs->tcn1 = 0;  /* reset counter */
126      g_timer_regs->ter1 = MCF5272_TER_REF | MCF5272_TER_CAP;
127
128      /* Set Timer 1 prescaler so that it counts in microseconds */
129      g_timer_regs->tmr1 = (
130          ((((BSP_SYSTEM_FREQUENCY / 1000000) - 1) << MCF5272_TMR_PS_SHIFT) |
131           MCF5272_TMR_CE_DISABLE                                      |
132           MCF5272_TMR_ORI                                             |
133           MCF5272_TMR_FRR                                             |
134           MCF5272_TMR_CLK_MSTR                                        |
135           MCF5272_TMR_RST));
136
137      /* Set the timer timeout value from the BSP config */
138      g_timer_regs->trr1 = rtems_configuration_get_microseconds_per_tick() - 1;
139
140      /* Feed system frequency to the timer */
141      g_timer_regs->tmr1 |= MCF5272_TMR_CLK_MSTR;
142
143      /* Configure timer1 interrupts */
144      icr = g_intctrl_regs->icr1;
145      icr = icr & ~(MCF5272_ICR1_TMR1_MASK | MCF5272_ICR1_TMR1_PI);
146      icr |= (MCF5272_ICR1_TMR1_IPL(BSP_INTLVL_TMR1) | MCF5272_ICR1_TMR1_PI);
147      g_intctrl_regs->icr1 = icr;
148
149      /* Register the driver exit procedure so we can shutdown */
150      atexit(Clock_exit);
151  }
152}
153
154
155/* Clock_initialize --
156 *     This is called to setup the clock driver. It calls the hardware
157 *     setup function and make the driver major/minor values available
158 *     for other.
159 *
160 * PARAMETERS:
161 *     major - clock device major number
162 *     minor - clock device minor number
163 *     pargp - device driver initialization argument (not used)
164 *
165 * RETURNS:
166 *     RTEMS status code
167 */
168rtems_device_driver
169Clock_initialize(rtems_device_major_number major,
170                 rtems_device_minor_number minor,
171                 void *pargp)
172{
173    Install_clock (Clock_isr);
174
175    /* Make major/minor avail to others such as shared memory driver */
176    rtems_clock_major = major;
177    rtems_clock_minor = minor;
178
179    return RTEMS_SUCCESSFUL;
180}
Note: See TracBrowser for help on using the repository browser.