OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [m68k/] [mcf52xx/] [mcf5272/] [proc/] [current/] [src/] [mcf5272.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      mcf5272.c
4
//
5
//      MCF5272 processor support functions.
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 2003, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):   bartv
43
// Date:        2003-06-04
44
//
45
//####DESCRIPTIONEND####
46
//=============================================================================
47
 
48
#include <pkgconf/system.h>
49
#include <pkgconf/hal.h>
50
#include <pkgconf/hal_m68k.h>
51
#include <pkgconf/hal_m68k_mcfxxxx.h>
52
#include <pkgconf/hal_m68k_mcf5272.h>
53
#include CYGBLD_HAL_PLATFORM_H
54
#include <cyg/hal/hal_intr.h>
55
#include <cyg/infra/cyg_type.h>
56
 
57
#ifdef CYGHWR_HAL_M68K_MCF5272_GPIO
58
# include "gpio.c"
59
#endif
60
 
61
// ----------------------------------------------------------------------------
62
// Processor initialization.
63
void
64
hal_m68k_mcf5272_init(void)
65
{
66
    int i;
67
 
68
    hal_mcf5272_cacr    = CYGNUM_HAL_M68K_MCF5272_CACR;
69
 
70
#ifdef CYGNUM_HAL_M68K_MCF5272_SCR
71
    // SCR. This is configurable since applications may want different
72
    // bus arbitration schemes. The #ifdef is for backwards compatibility.
73
    HAL_WRITE_UINT16(HAL_MCFxxxx_MBAR + HAL_MCF5272_SCR, CYGNUM_HAL_M68K_MCF5272_SCR);
74
#endif
75
 
76
    // Set up the GPIO pins if the platform HAL defines the appropriate settings.
77
#ifdef CYGHWR_HAL_M68K_MCF5272_GPIO
78
    HAL_WRITE_UINT16(HAL_MCFxxxx_MBAR + HAL_MCF5272_PADAT, A_DAT);
79
    HAL_WRITE_UINT16(HAL_MCFxxxx_MBAR + HAL_MCF5272_PADDR, A_DDR);
80
    HAL_WRITE_UINT32(HAL_MCFxxxx_MBAR + HAL_MCF5272_PACNT, A_PAR);
81
    HAL_WRITE_UINT16(HAL_MCFxxxx_MBAR + HAL_MCF5272_PBDAT, B_DAT);
82
    HAL_WRITE_UINT16(HAL_MCFxxxx_MBAR + HAL_MCF5272_PBDDR, B_DDR);
83
    HAL_WRITE_UINT32(HAL_MCFxxxx_MBAR + HAL_MCF5272_PBCNT, B_PAR);
84
    HAL_WRITE_UINT16(HAL_MCFxxxx_MBAR + HAL_MCF5272_PCDAT, C_DAT);
85
    HAL_WRITE_UINT16(HAL_MCFxxxx_MBAR + HAL_MCF5272_PCDDR, C_DDR);
86
    HAL_WRITE_UINT32(HAL_MCFxxxx_MBAR + HAL_MCF5272_PDCNT, D_PAR);
87
#endif    
88
 
89
    // Enable all exceptions.
90
    HAL_WRITE_UINT16(HAL_MCFxxxx_MBAR + HAL_MCF5272_SPR, 0x00FF);
91
 
92
    // If we should enter low power mode when idling, set the PMR here.
93
    // Application programs may tweak it as required.
94
#if   defined(CYGIMP_HAL_M68K_MCF5272_IDLE_run)
95
    // Leave PMR to its default
96
#elif defined(CYGIMP_HAL_M68K_MCF5272_IDLE_sleep)
97
    HAL_WRITE_UINT32(HAL_MCFxxxx_MBAR + HAL_MCF5272_PMR, HAL_MCF5272_PMR_SLPEN);
98
#elif defined(CYGIMP_HAL_M68K_MCF5272_IDLE_stop)
99
    HAL_WRITE_UINT32(HAL_MCFxxxx_MBAR + HAL_MCF5272_PMR, HAL_MCF5272_PMR_MOS);
100
#else
101
# error Unknown low power mode    
102
#endif    
103
 
104
    // Make sure that the interrupt controller matches the proc_intr.h
105
    // vector definitions.
106
    HAL_WRITE_UINT8( HAL_MCFxxxx_MBAR + HAL_MCF5272_PIVR, HAL_MCF5272_INT_VEC_BASE);
107
 
108
    // The interrupt controller. All interrupts are set to priority 0,
109
    // disabled until configured. This cannot be done when running on
110
    // top of RedBoot, it would interfere with any devices in use for
111
    // communication e.g. ethernet.
112
#ifndef CYGSEM_HAL_USE_ROM_MONITOR    
113
    for (i = 0; i < 4; i++) {
114
        hal_mcf5272_icr_pri_mirror[i]   = 0x0;
115
    }
116
#endif    
117
 
118
    // Exception vectors. First the exceptions themselves. If running
119
    // with a ROM monitor then leave these alone, otherwise claim the
120
    // lot.
121
#ifndef CYGSEM_HAL_USE_ROM_MONITOR
122
    HAL_VSR_SET(CYGNUM_HAL_VECTOR_SSP, (void*) 0, (void*) 0);
123
    HAL_VSR_SET(CYGNUM_HAL_VECTOR_RESET, &hal_m68k_exception_reset, (void*) 0);
124
 
125
    for (i = CYGNUM_HAL_VECTOR_BUSERR; i < CYGNUM_HAL_VECTOR_SPURINT; i++) {
126
        HAL_VSR_SET(i, &hal_m68k_exception_vsr, (void*) 0);
127
    }
128
    for (i = CYGNUM_HAL_VECTOR_TRAP0; i <= CYGNUM_HAL_VECTOR_TRAPLAST; i++) {
129
        HAL_VSR_SET(i, &hal_m68k_exception_vsr, (void*) 0);
130
    }
131
#endif
132
 
133
    // All the external interrupts can be handled by the same VSR, the default
134
    // architectural one.
135
    for (i = HAL_MCF5272_INT_VEC_BASE; i < CYGNUM_HAL_VECTOR_RES1; i++) {
136
        HAL_VSR_SET(i, &hal_m68k_interrupt_vsr, (void*) 0);
137
    }
138
}
139
 
140
// ----------------------------------------------------------------------------
141
// Profiling support. This requires a hardware timer set to interrupt at
142
// a rate determined by application code. The interrupt handler should
143
// call __profile_hit() with a single argument, the interrupted PC.
144
// Timer 2 is used to implement the profiling timer. Timer 3 is already
145
// allocated for the system clock. Timers 0 and 1 have some extra
146
// functionality so these are left for application code.
147
//
148
// Usually this would involve installing an ISR. However there is no
149
// easy way for an ISR to get hold of the interrupted PC. In some
150
// configurations the save state will be stored in hal_saved_interrupt_state,
151
// but not always. It might be possible to extract the PC from the stack,
152
// but that gets messy if a separate interrupt stack is used and would be
153
// vulnerable to changes in the architectural VSR. Instead a custom VSR
154
// is installed.
155
 
156
#ifdef CYGFUN_HAL_M68K_MCF5272_PROFILE_TIMER
157
 
158
extern void hal_mcf5272_profile_vsr(void);
159
 
160
# include <cyg/profile/profile.h>
161
 
162
int
163
hal_enable_profile_timer(int resolution)
164
{
165
    // Reset the timer
166
    HAL_WRITE_UINT16(HAL_MCFxxxx_MBAR + HAL_MCF5272_TIMER2_BASE + HAL_MCF5272_TIMER_TMR, 0);
167
 
168
    // The resolution is a time interval in microseconds. The clock is
169
    // set to tick in microseconds by dividing by the system clock
170
    // value.
171
    HAL_WRITE_UINT16(HAL_MCFxxxx_MBAR + HAL_MCF5272_TIMER2_BASE + HAL_MCF5272_TIMER_TRR,
172
                     resolution - 1);
173
 
174
    // Timer captures are of no interest, but reset them just in case.
175
    HAL_WRITE_UINT16(HAL_MCFxxxx_MBAR + HAL_MCF5272_TIMER2_BASE + HAL_MCF5272_TIMER_TCN, 0);
176
    HAL_WRITE_UINT16(HAL_MCFxxxx_MBAR + HAL_MCF5272_TIMER2_BASE + HAL_MCF5272_TIMER_TER,
177
                     HAL_MCF5272_TIMER_TER_REF | HAL_MCF5272_TIMER_TER_CAP);
178
 
179
    // Set up the interrupt handler. This is a high-priority interrupt
180
    // so that we can get profiling information for other interrupt
181
    // sources.
182
    HAL_VSR_SET(CYGNUM_HAL_VECTOR_TMR2, &hal_mcf5272_profile_vsr, (cyg_uint32)0);
183
    HAL_INTERRUPT_SET_LEVEL(CYGNUM_HAL_ISR_TMR2, 6);
184
    HAL_INTERRUPT_UNMASK(CYGNUM_HAL_ISR_TMR2);
185
 
186
    // Now start the timer running.
187
    HAL_WRITE_UINT16(HAL_MCFxxxx_MBAR + HAL_MCF5272_TIMER2_BASE + HAL_MCF5272_TIMER_TMR,
188
                     ((CYGHWR_HAL_SYSTEM_CLOCK_MHZ - 1) << HAL_MCF5272_TIMER_TMR_PS_SHIFT) |
189
                     HAL_MCF5272_TIMER_TMR_ORI | HAL_MCF5272_TIMER_TMR_FRR |
190
                     HAL_MCF5272_TIMER_TMR_CLK_MASTER | HAL_MCF5272_TIMER_TMR_RST);
191
 
192
    // The desired resolution is always supported
193
    return resolution;
194
}
195
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.