source: rtems/c/src/lib/libcpu/m68k/mcf5272/clock/ckinit.c @ 5039d92

4.115
Last change on this file since 5039d92 was 5105833c, checked in by Joel Sherrill <joel.sherrill@…>, on 10/12/14 at 19:00:00

libcpu/m68k/mcf5272/clock/ckinit.c: Fix warnings

  • 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
32/*
33 * Clock_driver_ticks is a monotonically increasing counter of the
34 * number of clock ticks since the driver was initialized.
35 */
36volatile uint32_t Clock_driver_ticks;
37
38rtems_isr (*rtems_clock_hook)(rtems_vector_number) = NULL;
39
40static rtems_isr
41Clock_isr (rtems_vector_number vector)
42{
43  /* Clear pending interrupt... */
44  g_timer_regs->ter1 = MCF5272_TER_REF | MCF5272_TER_CAP;
45
46  /* Announce the clock tick */
47  Clock_driver_ticks++;
48  rtems_clock_tick();
49  if (rtems_clock_hook != NULL) {
50      rtems_clock_hook(vector);
51  }
52}
53
54void
55Clock_exit(void)
56{
57  uint32_t icr;
58
59  /* disable all timer1 interrupts */
60  icr = g_intctrl_regs->icr1;
61  icr = icr & ~(MCF5272_ICR1_TMR1_MASK | MCF5272_ICR1_TMR1_PI);
62  icr |= (MCF5272_ICR1_TMR1_IPL(0) | MCF5272_ICR1_TMR1_PI);
63  g_intctrl_regs->icr1 = icr;
64
65  /* reset timer1 */
66  g_timer_regs->tmr1 = MCF5272_TMR_CLK_STOP;
67
68  /* clear pending */
69  g_timer_regs->ter1 = MCF5272_TER_REF | MCF5272_TER_CAP;
70}
71
72static void
73Install_clock(rtems_isr_entry clock_isr)
74{
75  uint32_t icr;
76
77  Clock_driver_ticks = 0;
78
79  /* Register the interrupt handler */
80  set_vector(clock_isr, BSP_INTVEC_TMR1, 1);
81
82  /* Reset timer 1 */
83  g_timer_regs->tmr1 = MCF5272_TMR_RST;
84  g_timer_regs->tmr1 = MCF5272_TMR_CLK_STOP;
85  g_timer_regs->tmr1 = MCF5272_TMR_RST;
86  g_timer_regs->tcn1 = 0;  /* reset counter */
87  g_timer_regs->ter1 = MCF5272_TER_REF | MCF5272_TER_CAP;
88
89  /* Set Timer 1 prescaler so that it counts in microseconds */
90  g_timer_regs->tmr1 = (
91      ((((BSP_SYSTEM_FREQUENCY / 1000000) - 1) << MCF5272_TMR_PS_SHIFT) |
92       MCF5272_TMR_CE_DISABLE                                      |
93       MCF5272_TMR_ORI                                             |
94       MCF5272_TMR_FRR                                             |
95       MCF5272_TMR_CLK_MSTR                                        |
96       MCF5272_TMR_RST));
97
98  /* Set the timer timeout value from the BSP config */
99  g_timer_regs->trr1 = rtems_configuration_get_microseconds_per_tick() - 1;
100
101  /* Feed system frequency to the timer */
102  g_timer_regs->tmr1 |= MCF5272_TMR_CLK_MSTR;
103
104  /* Configure timer1 interrupts */
105  icr = g_intctrl_regs->icr1;
106  icr = icr & ~(MCF5272_ICR1_TMR1_MASK | MCF5272_ICR1_TMR1_PI);
107  icr |= (MCF5272_ICR1_TMR1_IPL(BSP_INTLVL_TMR1) | MCF5272_ICR1_TMR1_PI);
108  g_intctrl_regs->icr1 = icr;
109
110  /* Register the driver exit procedure so we can shutdown */
111  atexit(Clock_exit);
112}
113
114rtems_device_driver
115Clock_initialize(
116  rtems_device_major_number major,
117  rtems_device_minor_number minor,
118  void *pargp
119)
120{
121  Install_clock (Clock_isr);
122
123  return RTEMS_SUCCESSFUL;
124}
Note: See TracBrowser for help on using the repository browser.