![]() |
|
|||
File indexing completed on 2025-05-11 08:23:46
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /* 0004 * Clock Driver for MCF5206eLITE board 0005 * 0006 * This driver initailizes timer1 on the MCF5206E as the 0007 * main system clock 0008 */ 0009 0010 /* 0011 * Author: Victor V. Vengerov <vvv@oktet.ru> 0012 * 0013 * Based on work: 0014 * David Fiddes, D.J@fiddes.surfaid.org 0015 * http://www.calm.hw.ac.uk/davidf/coldfire/ 0016 * 0017 * COPYRIGHT (c) 1989-1998. 0018 * On-Line Applications Research Corporation (OAR). 0019 * 0020 * Redistribution and use in source and binary forms, with or without 0021 * modification, are permitted provided that the following conditions 0022 * are met: 0023 * 1. Redistributions of source code must retain the above copyright 0024 * notice, this list of conditions and the following disclaimer. 0025 * 2. Redistributions in binary form must reproduce the above copyright 0026 * notice, this list of conditions and the following disclaimer in the 0027 * documentation and/or other materials provided with the distribution. 0028 * 0029 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0030 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0031 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0032 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0033 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0034 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0035 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0036 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0037 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0038 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0039 * POSSIBILITY OF SUCH DAMAGE. 0040 */ 0041 0042 #include <stdlib.h> 0043 #include <bsp.h> 0044 #include <rtems/libio.h> 0045 #include <rtems/clockdrv.h> 0046 #include "mcf5206/mcf5206e.h" 0047 0048 /* 0049 * Clock_driver_ticks is a monotonically increasing counter of the 0050 * number of clock ticks since the driver was initialized. 0051 */ 0052 volatile uint32_t Clock_driver_ticks; 0053 0054 rtems_isr (*rtems_clock_hook)(rtems_vector_number) = NULL; 0055 0056 static rtems_isr 0057 Clock_isr (rtems_vector_number vector) 0058 { 0059 /* Clear pending interrupt... */ 0060 *MCF5206E_TER(MBAR,1) = MCF5206E_TER_REF | MCF5206E_TER_CAP; 0061 0062 /* Announce the clock tick */ 0063 Clock_driver_ticks++; 0064 rtems_clock_tick(); 0065 if (rtems_clock_hook != NULL) 0066 rtems_clock_hook(vector); 0067 } 0068 0069 static void 0070 Clock_exit(void) 0071 { 0072 /* disable all timer1 interrupts */ 0073 *MCF5206E_IMR(MBAR) |= MCF5206E_INTR_BIT(MCF5206E_INTR_TIMER_1); 0074 0075 /* reset timer1 */ 0076 *MCF5206E_TMR(MBAR,1) = MCF5206E_TMR_ICLK_STOP; 0077 0078 /* clear pending */ 0079 *MCF5206E_TER(MBAR,1) = MCF5206E_TER_REF | MCF5206E_TER_CAP; 0080 } 0081 0082 0083 static void 0084 Install_clock(rtems_isr_entry clock_isr) 0085 { 0086 Clock_driver_ticks = 0; 0087 0088 /* Configure timer1 interrupts */ 0089 *MCF5206E_ICR(MBAR,MCF5206E_INTR_TIMER_1) = 0090 MCF5206E_ICR_AVEC | 0091 ((BSP_INTLVL_TIMER1 << MCF5206E_ICR_IL_S) & MCF5206E_ICR_IL) | 0092 ((BSP_INTPRIO_TIMER1 << MCF5206E_ICR_IP_S) & MCF5206E_ICR_IP); 0093 0094 /* Register the interrupt handler */ 0095 set_vector(clock_isr, BSP_INTVEC_TIMER1, 1); 0096 0097 /* Reset timer 1 */ 0098 *MCF5206E_TMR(MBAR, 1) = MCF5206E_TMR_RST; 0099 *MCF5206E_TMR(MBAR, 1) = MCF5206E_TMR_ICLK_STOP; 0100 *MCF5206E_TMR(MBAR, 1) = MCF5206E_TMR_RST; 0101 *MCF5206E_TCN(MBAR, 1) = 0; /* Reset counter */ 0102 *MCF5206E_TER(MBAR, 1) = MCF5206E_TER_REF | MCF5206E_TER_CAP; 0103 0104 /* Set Timer 1 prescaler so that it counts in microseconds */ 0105 *MCF5206E_TMR(MBAR, 1) = 0106 (((BSP_SYSTEM_FREQUENCY/1000000 - 1) << MCF5206E_TMR_PS_S) & 0107 MCF5206E_TMR_PS) | 0108 MCF5206E_TMR_CE_NONE | MCF5206E_TMR_ORI | MCF5206E_TMR_FRR | 0109 MCF5206E_TMR_RST; 0110 0111 /* Set the timer timeout value from the BSP config */ 0112 *MCF5206E_TRR(MBAR, 1) = rtems_configuration_get_microseconds_per_tick() - 1; 0113 0114 /* Feed system frequency to the timer */ 0115 *MCF5206E_TMR(MBAR, 1) |= MCF5206E_TMR_ICLK_MSCLK; 0116 0117 /* Enable timer 1 interrupts */ 0118 *MCF5206E_IMR(MBAR) &= ~MCF5206E_INTR_BIT(MCF5206E_INTR_TIMER_1); 0119 0120 /* Register the driver exit procedure so we can shutdown */ 0121 atexit(Clock_exit); 0122 } 0123 0124 void _Clock_Initialize( void ) 0125 { 0126 Install_clock (Clock_isr); 0127 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |