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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [mips/] [upd985xx/] [current/] [src/] [var_misc.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      var_misc.c
4
//
5
//      HAL CPU variant miscellaneous functions
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, nickg
43
// Contributors: nickg, jlarmour
44
// Date:         2001-05-24
45
// Purpose:      HAL miscellaneous functions
46
// Description:  This file contains miscellaneous functions provided by the
47
//               HAL.
48
//
49
//####DESCRIPTIONEND####
50
//
51
//========================================================================*/
52
 
53
#include <pkgconf/hal.h>
54
 
55
#include <cyg/infra/cyg_type.h>         // Base types
56
#include <cyg/infra/cyg_trac.h>         // tracing macros
57
#include <cyg/infra/cyg_ass.h>          // assertion macros
58
 
59
#include <cyg/hal/hal_arch.h>           // everything...
60
#include <cyg/hal/hal_cache.h>          // HAL_ICACHE_ENABLE();
61
#include <cyg/hal/hal_if.h>             // hal_if_init();
62
#include <cyg/hal/hal_intr.h>           // HAL_INTERRUPT_UNMASK()
63
#include <cyg/hal/hal_arbiter.h>        // hal_call_isr()
64
 
65
/*------------------------------------------------------------------------*/
66
/* Variant specific initialization routine.                               */
67
 
68
volatile CYG_ADDRESS    hal_interrupt_handlers[CYGNUM_HAL_ISR_COUNT];
69
volatile CYG_ADDRWORD   hal_interrupt_data[CYGNUM_HAL_ISR_COUNT];
70
volatile CYG_ADDRESS    hal_interrupt_objects[CYGNUM_HAL_ISR_COUNT];
71
 
72
// ------------------------------------------------------------------------
73
// An ISR for decoding and calling the additional S_ISR external interrupt
74
// sources; this has to be an external routine because the S_ISR register
75
// is read-clear, and the interrupt sources are edge-triggered so they do
76
// not re-assert themselves - so we must address multiple sources per
77
// actual interrupt.
78
 
79
static cyg_uint32 _arbitration_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data);
80
 
81
#ifndef CYGOPT_HAL_MIPS_UPD985XX_HARDWARE_BUGS_S2
82
static cyg_uint32 _arbitration_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
83
{
84
    cyg_uint32 s_isr;
85
    int bit, vecnum;
86
    cyg_uint32 isr_ret = 0;
87
    // decode interrupt source and for each active source call the ISR
88
 
89
    s_isr = *S_ISR;                     // Read once only
90
    s_isr &= *S_IMR;                    // Keep unmasked bits
91
 
92
    for ( bit = 1, vecnum = CYGNUM_HAL_INTERRUPT_SYSCTL_LOW;
93
          vecnum <=  CYGNUM_HAL_INTERRUPT_SYSCTL_HI;
94
          bit <<= 1, vecnum++ )
95
        if ( bit & s_isr )
96
            isr_ret |= hal_call_isr( vecnum );
97
 
98
    return isr_ret & ~CYG_ISR_CALL_DSR; // Since we have no DSR.
99
}
100
#endif // NOT defined CYGOPT_HAL_MIPS_UPD985XX_HARDWARE_BUGS_S2
101
 
102
// ------------------------------------------------------------------------
103
 
104
void hal_variant_init(void)
105
{
106
    int i;
107
    for ( i = 0; i < CYGNUM_HAL_ISR_COUNT; i++ ) {
108
        hal_interrupt_handlers [i] = (CYG_ADDRESS)&hal_default_isr;
109
        hal_interrupt_data     [i] = 0;
110
        hal_interrupt_objects  [i] = 0;
111
    }
112
 
113
    // Interrupt mask shadow variable initialization
114
    hal_interrupt_sr_mask_shadow = 0;
115
 
116
    // Enable the IBUS arbiter so that internal devices can work
117
    // (Ie. USB and ether)
118
    *S_GMR |= S_GMR_IAEN;
119
 
120
    // Enable writing to the flash device per se (ie. no SEGV)
121
    *RMMDR |= RMMDR_FLASH_WRITE_ENABLE;
122
 
123
    // Mask off external interrupt sources and clear any pending.
124
    *S_IMR = 0;
125
    i = *S_ISR;
126
    // Enable sysctl interrupt (in status reg) for those external sources.
127
    // "True" enable is in the external control reg, handled generically
128
    // by HAL_INTERRUPT_UNMASK for those vector numbers.
129
    HAL_INTERRUPT_ATTACH( CYGNUM_HAL_INTERRUPT_SYSCTL, &_arbitration_isr, 0, 0);
130
    HAL_INTERRUPT_UNMASK( CYGNUM_HAL_INTERRUPT_SYSCTL );
131
 
132
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
133
    hal_if_init();
134
#endif
135
 
136
    // The uPD985xx only has an enable that works on both caches. So we
137
    // only need to enable one of them for both to work.
138
    HAL_DCACHE_ENABLE();
139
    // HAL_ICACHE_ENABLE();
140
}
141
 
142
// ------------------------------------------------------------------------
143
//
144
// Routines to handle soft-masking and calling pent-up interrupts.
145
//
146
 
147
#ifdef CYGOPT_HAL_MIPS_UPD985XX_HARDWARE_BUGS_S2
148
 
149
// Assume all these are called with interrupts disabled globally
150
 
151
// We deal in vector numbers throughout: these contain "true" vector
152
// number shifts, whereas we have to shift hardware regs before use.
153
static int once_mask = 0; // Those unmasked ever
154
static int soft_mask = 0; // Those unmasked right now
155
static int pent_mask = 0; // Those pending right now
156
 
157
void cyg_hal_interrupt_mask( int vec )
158
{
159
    CYG_ASSERT( CYGNUM_HAL_INTERRUPT_SYSCTL_LOW <= vec, "vec underflow" );
160
    CYG_ASSERT( CYGNUM_HAL_INTERRUPT_SYSCTL_HI  >= vec, "vec overflow" );
161
    // We only manipulate the soft mask - NEVER the S_IMR.
162
    soft_mask &=~ (1<<vec);
163
}
164
 
165
void cyg_hal_interrupt_unmask( int vec )
166
{
167
    CYG_ASSERT( CYGNUM_HAL_INTERRUPT_SYSCTL_LOW <= vec, "vec underflow" );
168
    CYG_ASSERT( CYGNUM_HAL_INTERRUPT_SYSCTL_HI  >= vec, "vec overflow" );
169
    // If this is the very first time of unmasking, unmask in the S_IMR &c
170
    // also.
171
    if ( 0 == ( (1<<vec) & once_mask ) ) {
172
        once_mask |= (1<<vec);
173
        *S_IMR |= (1 << ((vec - CYGNUM_HAL_INTERRUPT_SYSCTL_LOW)));
174
    }
175
    // We manipulate the soft mask and call any pent-up interrupt
176
    soft_mask |= (1<<vec);
177
    if ( (1<<vec) & pent_mask ) {
178
        pent_mask &=~ (1<<vec); // "Acknowledge" the pent-up interrupt
179
        hal_call_isr( vec ); // this does it all!
180
    }
181
}
182
 
183
void cyg_hal_interrupt_acknowledge( int vec )
184
{
185
    CYG_ASSERT( CYGNUM_HAL_INTERRUPT_SYSCTL_LOW <= vec ||
186
                CYGNUM_HAL_INTERRUPT_SYSCTL     == vec, "vec underflow" );
187
    CYG_ASSERT( CYGNUM_HAL_INTERRUPT_SYSCTL_HI  >= vec, "vec overflow" );
188
    // (no harm done if this is CYGNUM_HAL_INTERRUPT_SYSCTL)
189
    pent_mask &=~ (1<<vec); // "Acknowledge" the pent-up interrupt
190
}
191
 
192
 
193
static cyg_uint32 _arbitration_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
194
{
195
    cyg_uint32 s_isr;
196
    int vecnum;
197
    cyg_uint32 isr_ret = 0;
198
    // decode interrupt source and for each active source call the ISR
199
 
200
    s_isr = *S_ISR;                     // Read once only
201
 
202
    s_isr <<= CYGNUM_HAL_INTERRUPT_SYSCTL_LOW;
203
    // Ignore the hardware mask; use the soft mask
204
 
205
    // Any that are set in S_ISR and masked out in soft_mask become
206
    // pending:
207
    pent_mask |= (s_isr & ~soft_mask);
208
 
209
    s_isr &= soft_mask;                    // Keep unmasked bits
210
 
211
    for ( vecnum = CYGNUM_HAL_INTERRUPT_SYSCTL_LOW;
212
          vecnum <=  CYGNUM_HAL_INTERRUPT_SYSCTL_HI;
213
          vecnum++ )
214
        if ( (1<<vecnum) & s_isr )
215
            isr_ret |= hal_call_isr( vecnum );
216
 
217
    return isr_ret & ~CYG_ISR_CALL_DSR; // Since we have no DSR.
218
}
219
 
220
#endif // CYGOPT_HAL_MIPS_UPD985XX_HARDWARE_BUGS_S2
221
 
222
/*------------------------------------------------------------------------*/
223
/* End of var_misc.c                                                      */

powered by: WebSVN 2.1.0

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