source: rtems/c/src/lib/libcpu/m68k/mcf5206/clock/ckinit.c @ 1e6aed25

4.104.114.95
Last change on this file since 1e6aed25 was 1e6aed25, checked in by Joel Sherrill <joel.sherrill@…>, on 09/05/08 at 22:06:49

2008-09-05 Joel Sherrill <joel.sherrill@…>

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