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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [sparclite/] [sleb/] [current/] [src/] [hal_priv.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//=============================================================================
2
//
3
//      hal_priv.c
4
//
5
//      SPARClite Architecture sim-specific private variables
6
//
7
//=============================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 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):   hmt
43
// Contributors:hmt
44
// Date:        1998-12-10
45
// Purpose:     private vars for SPARClite sim.
46
//              
47
//####DESCRIPTIONEND####
48
//
49
//=============================================================================
50
 
51
 
52
#include <pkgconf/system.h>
53
#include <pkgconf/hal.h>
54
#include <pkgconf/hal_sparclite.h>
55
#include <pkgconf/hal_sparclite_sleb.h>
56
 
57
#include <cyg/infra/cyg_type.h>
58
#include <cyg/hal/hal_intr.h>
59
#include <cyg/hal/hal_arch.h>
60
 
61
#ifdef CYGPKG_KERNEL
62
#include <pkgconf/kernel.h> // CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT
63
#endif
64
 
65
#include <cyg/hal/hal_clock.h>
66
 
67
// ------------------------------------------------------------------------
68
// Clock static to keep period recorded.
69
cyg_int32 cyg_hal_sparclite_clock_period = 0;
70
 
71
/* Address of clock switch */
72
#define CLKSW_ADDR  0x01000003
73
 
74
#define HAL_SPARC_86940_TIMER1_CONTROL_INIT ( \
75
 
76
                HAL_SPARC_86940_TCR_CLKPRS |  \
77
                HAL_SPARC_86940_TCR_OUTLOW   )
78
                // Disable, CLKSEL=prescale(2), periodic interrupts, gate 0
79
                // and lower the output: OUTCTL = 2
80
 
81
#define HAL_SPARC_86940_TIMER1_CONTROL_ENABLE ( \
82
                HAL_SPARC_86940_TCR_CE |        \
83
                HAL_SPARC_86940_TCR_CLKPRS |    \
84
                HAL_SPARC_86940_TCR_OUTSAME   )
85
                // Enable + .... and no change to the output: OUTCTL = 0
86
 
87
void hal_clock_initialize( cyg_uint32 p )
88
{
89
    cyg_uint32 ints;
90
    cyg_uint32 clk;
91
    HAL_DISABLE_INTERRUPTS( ints );
92
 
93
    HAL_SPARC_86940_TIMER1_CONTROL_WRITE(
94
       HAL_SPARC_86940_TIMER1_CONTROL_INIT ); // Make sure it's disabled
95
 
96
    // Clear any pending interrupts:
97
    HAL_INTERRUPT_ACKNOWLEDGE( CYGNUM_HAL_INTERRUPT_RTC );
98
 
99
    clk = *(unsigned char *)CLKSW_ADDR;
100
    if (clk & 0x80)
101
        clk = 10;
102
 
103
    /* could be 10 - 62 MHz */
104
    clk = (clk & 0x3f);  /* in MHz */
105
    // BUT the 86940 is internally clocked at half that speed (page 20 RHS)
106
    clk >>= 1;
107
    // so the clock is now the number of system ticks we want per counter
108
    // tick...
109
    HAL_SPARC_86940_TIMER1_PRESCALER_WRITE(
110
 
111
        HAL_SPARC_86940_PRS_ODIV1 |
112
        clk );
113
    // should give 1MHz on the externally visible counter...
114
    HAL_SPARC_86940_TIMER1_CONTROL_WRITE(
115
                             HAL_SPARC_86940_TIMER1_CONTROL_INIT );
116
    HAL_SPARC_86940_TIMER1_RELOAD_WRITE( p );
117
    HAL_SPARC_86940_TIMER1_CONTROL_WRITE(
118
                             HAL_SPARC_86940_TIMER1_CONTROL_ENABLE );
119
    HAL_SPARC_86940_TIMER1_RELOAD_WRITE( p );
120
    cyg_hal_sparclite_clock_period = p;
121
    HAL_RESTORE_INTERRUPTS( ints );
122
}
123
 
124
// ------------------------------------------------------------------------
125
 
126
#ifdef CYG_HAL_USE_ROM_MONITOR_CYGMON
127
#include <cyg/hal/hal_cygm.h>           // CygMon vector table & layout
128
 
129
static struct { int eCosV, CygMonV; } setup[] = {
130
    { CYGNUM_HAL_VECTOR_OTHERS                , BSP_EXC_TRAP               },
131
    { CYGNUM_HAL_VECTOR_FETCH_ABORT           , BSP_EXC_IACCESS            },
132
    { CYGNUM_HAL_VECTOR_ILLEGAL_OP            , BSP_EXC_ILL                },
133
    { CYGNUM_HAL_VECTOR_PRIV_OP               , BSP_EXC_IPRIV              },
134
    { CYGNUM_HAL_VECTOR_UNALIGNED             , BSP_EXC_ALIGN              },
135
    { CYGNUM_HAL_VECTOR_DATA_ABORT            , BSP_EXC_DACCESS            },
136
};
137
 
138
#endif // CYG_HAL_USE_ROM_MONITOR_CYGMON
139
 
140
// ------------------------------------------------------------------------
141
// Board specific startups.
142
 
143
extern void hal_board_prestart( void );
144
extern void hal_board_poststart( void );
145
 
146
#define SLEB_LED (*(volatile char *)(0x02000003))
147
 
148
#define LED( _x_ ) SLEB_LED = (char)(0xff & ~(_x_))
149
 
150
void hal_board_prestart( void )
151
{
152
 
153
    LED( 0xc0 );
154
 
155
    // Disable default clocks &c
156
    HAL_SPARC_86940_TIMER1_PRESCALER_WRITE( 1 ); // as if at reset
157
    HAL_SPARC_86940_TIMER1_CONTROL_WRITE( 0 );   // as if at reset
158
 
159
#ifdef CYG_HAL_USE_ROM_MONITOR_CYGMON
160
    // then initialize our vectors to point to (or bounce to)
161
    // CygMon's equivalent functionality.
162
    {
163
        extern void hal_user_trap_to_cygmon_vsr( void );
164
        extern void hal_nofpcp_trap_to_cygmon_vsr( void );
165
        extern void hal_nmi_handler( void );
166
        int i;
167
 
168
        HAL_VSR_SET( CYGNUM_HAL_VECTOR_USER_TRAP,
169
                     (CYG_ADDRESS)hal_user_trap_to_cygmon_vsr, NULL );
170
 
171
        HAL_VSR_SET( CYGNUM_HAL_VECTOR_NOFPCP,
172
                     (CYG_ADDRESS)hal_nofpcp_trap_to_cygmon_vsr, NULL );
173
 
174
        for ( i = 0; i < sizeof(setup)/sizeof(setup[0]); i++ )
175
            HAL_VSR_SET( setup[i].eCosV,
176
                         CYGMON_VECTOR_TABLE[ setup[i].CygMonV ], NULL );
177
 
178
        // Just point this one straight though, and unmask it.
179
        // That way CygMon looks after ^Cs itself.
180
        HAL_VSR_SET( CYGNUM_HAL_VECTOR_INTERRUPT_10,
181
                     CYGMON_VECTOR_TABLE[ BSP_EXC_INT10 ], NULL );
182
        HAL_INTERRUPT_UNMASK( CYGNUM_HAL_VECTOR_INTERRUPT_10 );
183
 
184
        // Just point this one straight though, and unmask it.
185
        // That way CygMon looks after the Ethernet itself.
186
        HAL_VSR_SET( CYGNUM_HAL_VECTOR_INTERRUPT_14,
187
                     CYGMON_VECTOR_TABLE[ BSP_EXC_INT14 ], NULL );
188
        HAL_INTERRUPT_UNMASK( CYGNUM_HAL_VECTOR_INTERRUPT_14 );
189
 
190
        // Install handler for the NMI button on the board
191
        HAL_VSR_SET( CYGNUM_HAL_VECTOR_INTERRUPT_15,
192
                     (CYG_ADDRESS)hal_nmi_handler, NULL );
193
        HAL_INTERRUPT_UNMASK( CYGNUM_HAL_VECTOR_INTERRUPT_15 );
194
 
195
        LED( 0xc4 );
196
 
197
#ifdef CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT
198
        {
199
            extern void patch_dbg_syscalls(void * vector);
200
            patch_dbg_syscalls( (void *)CYGMON_VECTOR_TABLE );
201
        }
202
#endif // CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT
203
 
204
    }
205
#endif // CYG_HAL_USE_ROM_MONITOR_CYGMON
206
 
207
    LED( 0xc8 );
208
}
209
 
210
void hal_board_poststart( void )
211
{
212
    LED( 0xe0 );
213
    HAL_ENABLE_INTERRUPTS();
214
    LED( 0xf0 );
215
}
216
 
217
 
218
// EOF hal_priv.c

powered by: WebSVN 2.1.0

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