source: rtems/bsps/m68k/mcf5206elite/dev/ckinit.c @ 2190bc6

5
Last change on this file since 2190bc6 was 2190bc6, checked in by Sebastian Huber <sebastian.huber@…>, on Mar 26, 2018 at 10:20:45 AM

bsps/mcf5206elite: Move libcpu content to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 3.0 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
8/*
9 *  Author: Victor V. Vengerov <vvv@oktet.ru>
10 *
11 *  Based on work:
12 *    David Fiddes, D.J@fiddes.surfaid.org
13 *    http://www.calm.hw.ac.uk/davidf/coldfire/
14 *
15 *  COPYRIGHT (c) 1989-1998.
16 *  On-Line Applications Research Corporation (OAR).
17 *
18 *  The license and distribution terms for this file may be
19 *  found in the file LICENSE in this distribution or at
20 *  http://www.rtems.org/license/LICENSE.
21 */
22
23#include <stdlib.h>
24#include <bsp.h>
25#include <rtems/libio.h>
26#include <rtems/clockdrv.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
35rtems_isr (*rtems_clock_hook)(rtems_vector_number) = NULL;
36
37static rtems_isr
38Clock_isr (rtems_vector_number vector)
39{
40  /* Clear pending interrupt... */
41  *MCF5206E_TER(MBAR,1) = MCF5206E_TER_REF | MCF5206E_TER_CAP;
42
43  /* Announce the clock tick */
44  Clock_driver_ticks++;
45  rtems_clock_tick();
46  if (rtems_clock_hook != NULL)
47      rtems_clock_hook(vector);
48}
49
50void
51Clock_exit(void)
52{
53  /* disable all timer1 interrupts */
54  *MCF5206E_IMR(MBAR) |= MCF5206E_INTR_BIT(MCF5206E_INTR_TIMER_1);
55
56  /* reset timer1 */
57  *MCF5206E_TMR(MBAR,1) = MCF5206E_TMR_ICLK_STOP;
58
59  /* clear pending */
60  *MCF5206E_TER(MBAR,1) = MCF5206E_TER_REF | MCF5206E_TER_CAP;
61}
62
63
64static void
65Install_clock(rtems_isr_entry clock_isr)
66{
67  Clock_driver_ticks = 0;
68
69  /* Configure timer1 interrupts */
70  *MCF5206E_ICR(MBAR,MCF5206E_INTR_TIMER_1) =
71      MCF5206E_ICR_AVEC |
72      ((BSP_INTLVL_TIMER1 << MCF5206E_ICR_IL_S) & MCF5206E_ICR_IL) |
73      ((BSP_INTPRIO_TIMER1 << MCF5206E_ICR_IP_S) & MCF5206E_ICR_IP);
74
75  /* Register the interrupt handler */
76  set_vector(clock_isr, BSP_INTVEC_TIMER1, 1);
77
78  /* Reset timer 1 */
79  *MCF5206E_TMR(MBAR, 1) = MCF5206E_TMR_RST;
80  *MCF5206E_TMR(MBAR, 1) = MCF5206E_TMR_ICLK_STOP;
81  *MCF5206E_TMR(MBAR, 1) = MCF5206E_TMR_RST;
82  *MCF5206E_TCN(MBAR, 1) = 0; /* Reset counter */
83  *MCF5206E_TER(MBAR, 1) = MCF5206E_TER_REF | MCF5206E_TER_CAP;
84
85  /* Set Timer 1 prescaler so that it counts in microseconds */
86  *MCF5206E_TMR(MBAR, 1) =
87      (((BSP_SYSTEM_FREQUENCY/1000000 - 1) << MCF5206E_TMR_PS_S) &
88       MCF5206E_TMR_PS) |
89      MCF5206E_TMR_CE_NONE | MCF5206E_TMR_ORI | MCF5206E_TMR_FRR |
90      MCF5206E_TMR_RST;
91
92  /* Set the timer timeout value from the BSP config */
93  *MCF5206E_TRR(MBAR, 1) = rtems_configuration_get_microseconds_per_tick() - 1;
94
95  /* Feed system frequency to the timer */
96  *MCF5206E_TMR(MBAR, 1) |= MCF5206E_TMR_ICLK_MSCLK;
97
98  /* Enable timer 1 interrupts */
99  *MCF5206E_IMR(MBAR) &= ~MCF5206E_INTR_BIT(MCF5206E_INTR_TIMER_1);
100
101  /* Register the driver exit procedure so we can shutdown */
102  atexit(Clock_exit);
103}
104
105rtems_device_driver
106Clock_initialize(rtems_device_major_number major,
107                 rtems_device_minor_number minor,
108                 void *pargp)
109{
110  Install_clock (Clock_isr);
111
112  return RTEMS_SUCCESSFUL;
113}
Note: See TracBrowser for help on using the repository browser.