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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [mips/] [upd985xx/] [v2_0/] [src/] [var_misc.c] - Blame information for rev 459

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
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 Red Hat, 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 version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):    hmt, nickg
44
// Contributors: nickg, jlarmour
45
// Date:         2001-05-24
46
// Purpose:      HAL miscellaneous functions
47
// Description:  This file contains miscellaneous functions provided by the
48
//               HAL.
49
//
50
//####DESCRIPTIONEND####
51
//
52
//========================================================================*/
53
 
54
#include <pkgconf/hal.h>
55
 
56
#include <cyg/infra/cyg_type.h>         // Base types
57
#include <cyg/infra/cyg_trac.h>         // tracing macros
58
#include <cyg/infra/cyg_ass.h>          // assertion macros
59
 
60
#include <cyg/hal/hal_arch.h>           // everything...
61
#include <cyg/hal/hal_cache.h>          // HAL_ICACHE_ENABLE();
62
#include <cyg/hal/hal_if.h>             // hal_if_init();
63
#include <cyg/hal/hal_intr.h>           // HAL_INTERRUPT_UNMASK()
64
#include <cyg/hal/hal_arbiter.h>        // hal_call_isr()
65
 
66
/*------------------------------------------------------------------------*/
67
/* Variant specific initialization routine.                               */
68
 
69
volatile CYG_ADDRESS    hal_interrupt_handlers[CYGNUM_HAL_ISR_COUNT];
70
volatile CYG_ADDRWORD   hal_interrupt_data[CYGNUM_HAL_ISR_COUNT];
71
volatile CYG_ADDRESS    hal_interrupt_objects[CYGNUM_HAL_ISR_COUNT];
72
 
73
// ------------------------------------------------------------------------
74
// An ISR for decoding and calling the additional S_ISR external interrupt
75
// sources; this has to be an external routine because the S_ISR register
76
// is read-clear, and the interrupt sources are edge-triggered so they do
77
// not re-assert themselves - so we must address multiple sources per
78
// actual interrupt.
79
 
80
static cyg_uint32 _arbitration_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data);
81
 
82
#ifndef CYGOPT_HAL_MIPS_UPD985XX_HARDWARE_BUGS_S2
83
static cyg_uint32 _arbitration_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
84
{
85
    cyg_uint32 s_isr;
86
    int bit, vecnum;
87
    cyg_uint32 isr_ret = 0;
88
    // decode interrupt source and for each active source call the ISR
89
 
90
    s_isr = *S_ISR;                     // Read once only
91
    s_isr &= *S_IMR;                    // Keep unmasked bits
92
 
93
    for ( bit = 1, vecnum = CYGNUM_HAL_INTERRUPT_SYSCTL_LOW;
94
          vecnum <=  CYGNUM_HAL_INTERRUPT_SYSCTL_HI;
95
          bit <<= 1, vecnum++ )
96
        if ( bit & s_isr )
97
            isr_ret |= hal_call_isr( vecnum );
98
 
99
    return isr_ret & ~CYG_ISR_CALL_DSR; // Since we have no DSR.
100
}
101
#endif // NOT defined CYGOPT_HAL_MIPS_UPD985XX_HARDWARE_BUGS_S2
102
 
103
// ------------------------------------------------------------------------
104
 
105
void hal_variant_init(void)
106
{
107
    int i;
108
    for ( i = 0; i < CYGNUM_HAL_ISR_COUNT; i++ ) {
109
        hal_interrupt_handlers [i] = (CYG_ADDRESS)&hal_default_isr;
110
        hal_interrupt_data     [i] = 0;
111
        hal_interrupt_objects  [i] = 0;
112
    }
113
 
114
    // Interrupt mask shadow variable initialization
115
    hal_interrupt_sr_mask_shadow = 0;
116
 
117
    // Enable the IBUS arbiter so that internal devices can work
118
    // (Ie. USB and ether)
119
    *S_GMR |= S_GMR_IAEN;
120
 
121
    // Enable writing to the flash device per se (ie. no SEGV)
122
    *RMMDR |= RMMDR_FLASH_WRITE_ENABLE;
123
 
124
    // Mask off external interrupt sources and clear any pending.
125
    *S_IMR = 0;
126
    i = *S_ISR;
127
    // Enable sysctl interrupt (in status reg) for those external sources.
128
    // "True" enable is in the external control reg, handled generically
129
    // by HAL_INTERRUPT_UNMASK for those vector numbers.
130
    HAL_INTERRUPT_ATTACH( CYGNUM_HAL_INTERRUPT_SYSCTL, &_arbitration_isr, 0, 0);
131
    HAL_INTERRUPT_UNMASK( CYGNUM_HAL_INTERRUPT_SYSCTL );
132
 
133
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
134
    hal_if_init();
135
#endif
136
 
137
    // The uPD985xx only has an enable that works on both caches. So we
138
    // only need to enable one of them for both to work.
139
    HAL_DCACHE_ENABLE();
140
    // HAL_ICACHE_ENABLE();
141
}
142
 
143
// ------------------------------------------------------------------------
144
//
145
// Routines to handle soft-masking and calling pent-up interrupts.
146
//
147
 
148
#ifdef CYGOPT_HAL_MIPS_UPD985XX_HARDWARE_BUGS_S2
149
 
150
// Assume all these are called with interrupts disabled globally
151
 
152
// We deal in vector numbers throughout: these contain "true" vector
153
// number shifts, whereas we have to shift hardware regs before use.
154
static int once_mask = 0; // Those unmasked ever
155
static int soft_mask = 0; // Those unmasked right now
156
static int pent_mask = 0; // Those pending right now
157
 
158
void cyg_hal_interrupt_mask( int vec )
159
{
160
    CYG_ASSERT( CYGNUM_HAL_INTERRUPT_SYSCTL_LOW <= vec, "vec underflow" );
161
    CYG_ASSERT( CYGNUM_HAL_INTERRUPT_SYSCTL_HI  >= vec, "vec overflow" );
162
    // We only manipulate the soft mask - NEVER the S_IMR.
163
    soft_mask &=~ (1<<vec);
164
}
165
 
166
void cyg_hal_interrupt_unmask( int vec )
167
{
168
    CYG_ASSERT( CYGNUM_HAL_INTERRUPT_SYSCTL_LOW <= vec, "vec underflow" );
169
    CYG_ASSERT( CYGNUM_HAL_INTERRUPT_SYSCTL_HI  >= vec, "vec overflow" );
170
    // If this is the very first time of unmasking, unmask in the S_IMR &c
171
    // also.
172
    if ( 0 == ( (1<<vec) & once_mask ) ) {
173
        once_mask |= (1<<vec);
174
        *S_IMR |= (1 << ((vec - CYGNUM_HAL_INTERRUPT_SYSCTL_LOW)));
175
    }
176
    // We manipulate the soft mask and call any pent-up interrupt
177
    soft_mask |= (1<<vec);
178
    if ( (1<<vec) & pent_mask ) {
179
        pent_mask &=~ (1<<vec); // "Acknowledge" the pent-up interrupt
180
        hal_call_isr( vec ); // this does it all!
181
    }
182
}
183
 
184
void cyg_hal_interrupt_acknowledge( int vec )
185
{
186
    CYG_ASSERT( CYGNUM_HAL_INTERRUPT_SYSCTL_LOW <= vec ||
187
                CYGNUM_HAL_INTERRUPT_SYSCTL     == vec, "vec underflow" );
188
    CYG_ASSERT( CYGNUM_HAL_INTERRUPT_SYSCTL_HI  >= vec, "vec overflow" );
189
    // (no harm done if this is CYGNUM_HAL_INTERRUPT_SYSCTL)
190
    pent_mask &=~ (1<<vec); // "Acknowledge" the pent-up interrupt
191
}
192
 
193
 
194
static cyg_uint32 _arbitration_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
195
{
196
    cyg_uint32 s_isr;
197
    int vecnum;
198
    cyg_uint32 isr_ret = 0;
199
    // decode interrupt source and for each active source call the ISR
200
 
201
    s_isr = *S_ISR;                     // Read once only
202
 
203
    s_isr <<= CYGNUM_HAL_INTERRUPT_SYSCTL_LOW;
204
    // Ignore the hardware mask; use the soft mask
205
 
206
    // Any that are set in S_ISR and masked out in soft_mask become
207
    // pending:
208
    pent_mask |= (s_isr & ~soft_mask);
209
 
210
    s_isr &= soft_mask;                    // Keep unmasked bits
211
 
212
    for ( vecnum = CYGNUM_HAL_INTERRUPT_SYSCTL_LOW;
213
          vecnum <=  CYGNUM_HAL_INTERRUPT_SYSCTL_HI;
214
          vecnum++ )
215
        if ( (1<<vecnum) & s_isr )
216
            isr_ret |= hal_call_isr( vecnum );
217
 
218
    return isr_ret & ~CYG_ISR_CALL_DSR; // Since we have no DSR.
219
}
220
 
221
#endif // CYGOPT_HAL_MIPS_UPD985XX_HARDWARE_BUGS_S2
222
 
223
/*------------------------------------------------------------------------*/
224
/* 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.