source: rtems/c/src/lib/libcpu/m68k/mcf5272/clock/ckinit.c @ 9c7de43

Last change on this file since 9c7de43 was 9c7de43, checked in by Joel Sherrill <joel@…>, on Mar 27, 2016 at 11:37:48 PM

libcpu/m68k/mcf5272/clock/ckinit.c: Fix warning by including <rtems/clockdrv.h>

  • Property mode set to 100644
File size: 3.3 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
8/*
9 *  Copyright 2004 Cogent Computer Systems
10 *  Author: Jay Monkman <jtm@lopingdog.com>
11 *
12 *  Based on MCF5206 clock driver by
13 *    Victor V. Vengerov <vvv@oktet.ru>
14 *
15 *  Based on work:
16 *    David Fiddes, D.J@fiddes.surfaid.org
17 *    http://www.calm.hw.ac.uk/davidf/coldfire/
18 *
19 *  COPYRIGHT (c) 1989-1998.
20 *  On-Line Applications Research Corporation (OAR).
21 *
22 *  The license and distribution terms for this file may be
23 *  found in the file LICENSE in this distribution or at
24 *  http://www.rtems.org/license/LICENSE.
25 */
26
27#include <stdlib.h>
28#include <bsp.h>
29#include <rtems/libio.h>
30#include <mcf5272/mcf5272.h>
31#include <rtems/clockdrv.h>
32
33/*
34 * Clock_driver_ticks is a monotonically increasing counter of the
35 * number of clock ticks since the driver was initialized.
36 */
37volatile uint32_t Clock_driver_ticks;
38
39rtems_isr (*rtems_clock_hook)(rtems_vector_number) = NULL;
40
41static rtems_isr
42Clock_isr (rtems_vector_number vector)
43{
44  /* Clear pending interrupt... */
45  g_timer_regs->ter1 = MCF5272_TER_REF | MCF5272_TER_CAP;
46
47  /* Announce the clock tick */
48  Clock_driver_ticks++;
49  rtems_clock_tick();
50  if (rtems_clock_hook != NULL) {
51      rtems_clock_hook(vector);
52  }
53}
54
55void
56Clock_exit(void)
57{
58  uint32_t icr;
59
60  /* disable all timer1 interrupts */
61  icr = g_intctrl_regs->icr1;
62  icr = icr & ~(MCF5272_ICR1_TMR1_MASK | MCF5272_ICR1_TMR1_PI);
63  icr |= (MCF5272_ICR1_TMR1_IPL(0) | MCF5272_ICR1_TMR1_PI);
64  g_intctrl_regs->icr1 = icr;
65
66  /* reset timer1 */
67  g_timer_regs->tmr1 = MCF5272_TMR_CLK_STOP;
68
69  /* clear pending */
70  g_timer_regs->ter1 = MCF5272_TER_REF | MCF5272_TER_CAP;
71}
72
73static void
74Install_clock(rtems_isr_entry clock_isr)
75{
76  uint32_t icr;
77
78  Clock_driver_ticks = 0;
79
80  /* Register the interrupt handler */
81  set_vector(clock_isr, BSP_INTVEC_TMR1, 1);
82
83  /* Reset timer 1 */
84  g_timer_regs->tmr1 = MCF5272_TMR_RST;
85  g_timer_regs->tmr1 = MCF5272_TMR_CLK_STOP;
86  g_timer_regs->tmr1 = MCF5272_TMR_RST;
87  g_timer_regs->tcn1 = 0;  /* reset counter */
88  g_timer_regs->ter1 = MCF5272_TER_REF | MCF5272_TER_CAP;
89
90  /* Set Timer 1 prescaler so that it counts in microseconds */
91  g_timer_regs->tmr1 = (
92      ((((BSP_SYSTEM_FREQUENCY / 1000000) - 1) << MCF5272_TMR_PS_SHIFT) |
93       MCF5272_TMR_CE_DISABLE                                      |
94       MCF5272_TMR_ORI                                             |
95       MCF5272_TMR_FRR                                             |
96       MCF5272_TMR_CLK_MSTR                                        |
97       MCF5272_TMR_RST));
98
99  /* Set the timer timeout value from the BSP config */
100  g_timer_regs->trr1 = rtems_configuration_get_microseconds_per_tick() - 1;
101
102  /* Feed system frequency to the timer */
103  g_timer_regs->tmr1 |= MCF5272_TMR_CLK_MSTR;
104
105  /* Configure timer1 interrupts */
106  icr = g_intctrl_regs->icr1;
107  icr = icr & ~(MCF5272_ICR1_TMR1_MASK | MCF5272_ICR1_TMR1_PI);
108  icr |= (MCF5272_ICR1_TMR1_IPL(BSP_INTLVL_TMR1) | MCF5272_ICR1_TMR1_PI);
109  g_intctrl_regs->icr1 = icr;
110
111  /* Register the driver exit procedure so we can shutdown */
112  atexit(Clock_exit);
113}
114
115rtems_device_driver
116Clock_initialize(
117  rtems_device_major_number major,
118  rtems_device_minor_number minor,
119  void *pargp
120)
121{
122  Install_clock (Clock_isr);
123
124  return RTEMS_SUCCESSFUL;
125}
Note: See TracBrowser for help on using the repository browser.