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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [sh/] [sh4/] [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 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):    jskov
43
// Contributors: jskov, jlarmour, nickg
44
// Date:         1999-04-03
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>
56
#include <cyg/infra/cyg_trac.h>         // tracing macros
57
#include <cyg/infra/cyg_ass.h>          // assertion macros
58
#include <cyg/infra/diag.h>             // diag_printf
59
 
60
#include <cyg/hal/hal_arch.h>           // HAL header
61
#include <cyg/hal/hal_cache.h>          // HAL cache
62
#include <cyg/hal/hal_intr.h>           // HAL interrupts/exceptions
63
 
64
//---------------------------------------------------------------------------
65
// Initial cache enabling
66
 
67
#ifdef CYGHWR_HAL_SH_CACHE_MODE_P0_WRITE_BACK
68
# define CACHE_MODE_P0 0
69
#else
70
# define CACHE_MODE_P0 CYGARC_REG_CCR_WT
71
#endif
72
 
73
#ifdef CYGHWR_HAL_SH_CACHE_MODE_P1_WRITE_BACK
74
# define CACHE_MODE_P1 CYGARC_REG_CCR_CB
75
#else
76
# define CACHE_MODE_P1 0
77
#endif
78
 
79
externC void
80
cyg_var_enable_caches(void)
81
{
82
    // If relying on a ROM monitor do not invalidate the caches as the
83
    // ROM monitor may have (non-synced) state in the caches.
84
#if !defined(CYGSEM_HAL_USE_ROM_MONITOR)
85
    // Initialize cache.
86
    HAL_DCACHE_INVALIDATE_ALL();
87
    HAL_ICACHE_INVALIDATE_ALL();
88
 
89
    // Set cache modes
90
    HAL_DCACHE_WRITE_MODE_SH(CACHE_MODE_P0|CACHE_MODE_P1);
91
#endif
92
#ifdef CYGHWR_HAL_SH_CACHE_ENABLE
93
    // Enable cache.
94
    HAL_ICACHE_ENABLE();
95
    HAL_DCACHE_ENABLE();
96
#endif
97
}
98
 
99
//---------------------------------------------------------------------------
100
void
101
hal_variant_init(void)
102
{
103
#ifdef CYGHWR_HAL_SH_FPU
104
    __externC void __set_fpscr(cyg_uint32 __fpscr);
105
    // Call __set_fpscr to allow GCC (in libgcc) to update its internal
106
    // state for the floating point mode.
107
    __set_fpscr(CYG_FPSCR);
108
#endif
109
}
110
 
111
//---------------------------------------------------------------------------
112
 
113
externC cyg_uint8 cyg_hal_ILVL_table[];
114
externC cyg_uint8 cyg_hal_IMASK_table[];
115
 
116
static void
117
hal_interrupt_update_level(int vector)
118
{
119
    cyg_uint16 iprX;
120
    int level;
121
 
122
    level = cyg_hal_IMASK_table[vector] ? cyg_hal_ILVL_table[vector] : 0;
123
 
124
    switch( (vector) ) {
125
    /* IPRA */
126
    case CYGNUM_HAL_INTERRUPT_TMU0_TUNI0:
127
        HAL_READ_UINT16(CYGARC_REG_IPRA, iprX);
128
        iprX &= ~CYGARC_REG_IPRA_TMU0_MASK;
129
        iprX |= (level)*CYGARC_REG_IPRA_TMU0_PRI1;
130
        HAL_WRITE_UINT16(CYGARC_REG_IPRA, iprX);
131
        break;
132
    case CYGNUM_HAL_INTERRUPT_TMU1_TUNI1:
133
        HAL_READ_UINT16(CYGARC_REG_IPRA, iprX);
134
        iprX &= ~CYGARC_REG_IPRA_TMU1_MASK;
135
        iprX |= (level)*CYGARC_REG_IPRA_TMU1_PRI1;
136
        HAL_WRITE_UINT16(CYGARC_REG_IPRA, iprX);
137
        break;
138
    case CYGNUM_HAL_INTERRUPT_TMU2_TUNI2:
139
    case CYGNUM_HAL_INTERRUPT_TMU2_TICPI2:
140
        HAL_READ_UINT16(CYGARC_REG_IPRA, iprX);
141
        iprX &= ~CYGARC_REG_IPRA_TMU2_MASK;
142
        iprX |= (level)*CYGARC_REG_IPRA_TMU2_PRI1;
143
        HAL_WRITE_UINT16(CYGARC_REG_IPRA, iprX);
144
        break;
145
    case CYGNUM_HAL_INTERRUPT_RTC_ATI:
146
    case CYGNUM_HAL_INTERRUPT_RTC_PRI:
147
    case CYGNUM_HAL_INTERRUPT_RTC_CUI:
148
        HAL_READ_UINT16(CYGARC_REG_IPRA, iprX);
149
        iprX &= ~CYGARC_REG_IPRA_RTC_MASK;
150
        iprX |= (level)*CYGARC_REG_IPRA_RTC_PRI1;
151
        HAL_WRITE_UINT16(CYGARC_REG_IPRA, iprX);
152
        break;
153
 
154
    /* IPRB */
155
    case CYGNUM_HAL_INTERRUPT_SCI_ERI:
156
    case CYGNUM_HAL_INTERRUPT_SCI_RXI:
157
    case CYGNUM_HAL_INTERRUPT_SCI_TXI:
158
    case CYGNUM_HAL_INTERRUPT_SCI_TEI:
159
        HAL_READ_UINT16(CYGARC_REG_IPRB, iprX);
160
        iprX &= ~CYGARC_REG_IPRB_SCI_MASK;
161
        iprX |= (level)*CYGARC_REG_IPRB_SCI_PRI1;
162
        HAL_WRITE_UINT16(CYGARC_REG_IPRB, iprX);
163
        break;
164
    case CYGNUM_HAL_INTERRUPT_WDT_ITI:
165
        HAL_READ_UINT16(CYGARC_REG_IPRB, iprX);
166
        iprX &= ~CYGARC_REG_IPRB_WDT_MASK;
167
        iprX |= (level)*CYGARC_REG_IPRB_WDT_PRI1;
168
        HAL_WRITE_UINT16(CYGARC_REG_IPRB, iprX);
169
        break;
170
    case CYGNUM_HAL_INTERRUPT_REF_RCMI:
171
    case CYGNUM_HAL_INTERRUPT_REF_ROVI:
172
        HAL_READ_UINT16(CYGARC_REG_IPRB, iprX);
173
        iprX &= ~CYGARC_REG_IPRB_REF_MASK;
174
        iprX |= (level)*CYGARC_REG_IPRB_REF_PRI1;
175
        HAL_WRITE_UINT16(CYGARC_REG_IPRB, iprX);
176
        break;
177
 
178
    /* IPRC */
179
    case CYGNUM_HAL_INTERRUPT_HUDI:
180
        HAL_READ_UINT16(CYGARC_REG_IPRC, iprX);
181
        iprX &= ~CYGARC_REG_IPRC_HUDI_MASK;
182
        iprX |= (level)*CYGARC_REG_IPRC_HUDI_PRI1;
183
        HAL_WRITE_UINT16(CYGARC_REG_IPRC, iprX);
184
        break;
185
    case CYGNUM_HAL_INTERRUPT_GPIO:
186
        HAL_READ_UINT16(CYGARC_REG_IPRC, iprX);
187
        iprX &= ~CYGARC_REG_IPRC_GPIO_MASK;
188
        iprX |= (level)*CYGARC_REG_IPRC_GPIO_PRI1;
189
        HAL_WRITE_UINT16(CYGARC_REG_IPRC, iprX);
190
        break;
191
    case CYGNUM_HAL_INTERRUPT_DMAC_DMTE0:
192
    case CYGNUM_HAL_INTERRUPT_DMAC_DMTE1:
193
    case CYGNUM_HAL_INTERRUPT_DMAC_DMTE2:
194
    case CYGNUM_HAL_INTERRUPT_DMAC_DMTE3:
195
    case CYGNUM_HAL_INTERRUPT_DMAC_DMAE:
196
        HAL_READ_UINT16(CYGARC_REG_IPRC, iprX);
197
        iprX &= ~CYGARC_REG_IPRC_DMAC_MASK;
198
        iprX |= (level)*CYGARC_REG_IPRC_DMAC_PRI1;
199
        HAL_WRITE_UINT16(CYGARC_REG_IPRC, iprX);
200
        break;
201
    case CYGNUM_HAL_INTERRUPT_SCIF_ERI:
202
    case CYGNUM_HAL_INTERRUPT_SCIF_RXI:
203
    case CYGNUM_HAL_INTERRUPT_SCIF_BRI:
204
    case CYGNUM_HAL_INTERRUPT_SCIF_TXI:
205
        HAL_READ_UINT16(CYGARC_REG_IPRC, iprX);
206
        iprX &= ~CYGARC_REG_IPRC_SCIF_MASK;
207
        iprX |= (level)*CYGARC_REG_IPRC_SCIF_PRI1;
208
        HAL_WRITE_UINT16(CYGARC_REG_IPRC, iprX);
209
        break;
210
#if (CYGARC_SH_MOD_INTC == 2)
211
#ifndef CYGHWR_HAL_SH_IRQ_USE_IRQLVL
212
    case CYGNUM_HAL_INTERRUPT_IRL0:
213
        HAL_READ_UINT16(CYGARC_REG_IPRD, iprX);
214
        iprX &= ~CYGARC_REG_IPRD_IRL0_MASK;
215
        iprX |= (level)*CYGARC_REG_IPRD_IRL0_PRI1;
216
        HAL_WRITE_UINT16(CYGARC_REG_IPRD, iprX);
217
        break;
218
    case CYGNUM_HAL_INTERRUPT_IRL1:
219
        HAL_READ_UINT16(CYGARC_REG_IPRD, iprX);
220
        iprX &= ~CYGARC_REG_IPRD_IRL1_MASK;
221
        iprX |= (level)*CYGARC_REG_IPRD_IRL1_PRI1;
222
        HAL_WRITE_UINT16(CYGARC_REG_IPRD, iprX);
223
        break;
224
    case CYGNUM_HAL_INTERRUPT_IRL2:
225
        HAL_READ_UINT16(CYGARC_REG_IPRD, iprX);
226
        iprX &= ~CYGARC_REG_IPRD_IRL2_MASK;
227
        iprX |= (level)*CYGARC_REG_IPRD_IRL2_PRI1;
228
        HAL_WRITE_UINT16(CYGARC_REG_IPRD, iprX);
229
        break;
230
    case CYGNUM_HAL_INTERRUPT_IRL3:
231
        HAL_READ_UINT16(CYGARC_REG_IPRD, iprX);
232
        iprX &= ~CYGARC_REG_IPRD_IRL3_MASK;
233
        iprX |= (level)*CYGARC_REG_IPRD_IRL3_PRI1;
234
        HAL_WRITE_UINT16(CYGARC_REG_IPRD, iprX);
235
        break;
236
#endif
237
    case CYGNUM_HAL_INTERRUPT_PCISERR:
238
    {
239
        cyg_uint32 intpri;
240
        HAL_READ_UINT32(CYGARC_REG_INTPRI00, intpri);
241
        intpri &= ~CYGARC_REG_INTPRI00_PCISERR_MASK;
242
        intpri |= (level)*CYGARC_REG_INTPRI00_PCISERR_PRI1;
243
        HAL_WRITE_UINT32(CYGARC_REG_INTPRI00, intpri);
244
        break;
245
    }
246
    case CYGNUM_HAL_INTERRUPT_PCIDMA3 ... CYGNUM_HAL_INTERRUPT_PCIERR:
247
    {
248
        cyg_uint32 intpri;
249
        HAL_READ_UINT32(CYGARC_REG_INTPRI00, intpri);
250
        intpri &= ~CYGARC_REG_INTPRI00_PCIERR_MASK;
251
        intpri |= (level)*CYGARC_REG_INTPRI00_PCIERR_PRI1;
252
        HAL_WRITE_UINT32(CYGARC_REG_INTPRI00, intpri);
253
        break;
254
    }
255
    case CYGNUM_HAL_INTERRUPT_TUNI3:
256
    {
257
        cyg_uint32 intpri;
258
        HAL_READ_UINT32(CYGARC_REG_INTPRI00, intpri);
259
        intpri &= ~CYGARC_REG_INTPRI00_TUNI3_MASK;
260
        intpri |= (level)*CYGARC_REG_INTPRI00_TUNI3_PRI1;
261
        HAL_WRITE_UINT32(CYGARC_REG_INTPRI00, intpri);
262
        break;
263
    }
264
    case CYGNUM_HAL_INTERRUPT_TUNI4:
265
    {
266
        cyg_uint32 intpri;
267
        HAL_READ_UINT32(CYGARC_REG_INTPRI00, intpri);
268
        intpri &= ~CYGARC_REG_INTPRI00_TUNI4_MASK;
269
        intpri |= (level)*CYGARC_REG_INTPRI00_TUNI4_PRI1;
270
        HAL_WRITE_UINT32(CYGARC_REG_INTPRI00, intpri);
271
        break;
272
    }
273
#endif // CYGARC_SH_MOD_INTC
274
    case CYGNUM_HAL_INTERRUPT_RESERVED_1E0:
275
    case CYGNUM_HAL_INTERRUPT_RESERVED_3E0:
276
    case CYGNUM_HAL_INTERRUPT_RESERVED_5C0:
277
    case CYGNUM_HAL_INTERRUPT_RESERVED_5E0:
278
    case CYGNUM_HAL_INTERRUPT_RESERVED_6E0:
279
        /* Do nothing for these reserved vectors. */
280
        break;
281
 
282
    // Platform extensions
283
    CYGPRI_HAL_INTERRUPT_UPDATE_LEVEL_PLF(vector, level)
284
 
285
    default:
286
        CYG_FAIL("Unknown interrupt vector");
287
        break;
288
    }
289
}
290
 
291
void
292
hal_interrupt_set_level(int vector, int level)
293
{
294
    CYG_ASSERT((0 <= (level) && 15 >= (level)), "Illegal level");
295
    CYG_ASSERT((CYGNUM_HAL_ISR_MIN <= (vector)
296
                && CYGNUM_HAL_ISR_MAX >= (vector)), "Illegal vector");
297
 
298
    cyg_hal_ILVL_table[vector] = level;
299
 
300
    hal_interrupt_update_level(vector);
301
}
302
 
303
void
304
hal_interrupt_mask(int vector)
305
{
306
#ifdef CYGPKG_HAL_SH_7751
307
    if (vector >= CYGNUM_HAL_INTERRUPT_PCISERR && vector <= CYGNUM_HAL_INTERRUPT_TUNI4) {
308
        HAL_WRITE_UINT32(CYGARC_REG_INTMSK00, 1 << (vector - CYGNUM_HAL_INTERRUPT_PCISERR));
309
        return;
310
    }
311
#endif
312
 
313
    switch( vector ) {
314
    case CYGNUM_HAL_INTERRUPT_NMI:
315
        break;
316
    case CYGNUM_HAL_INTERRUPT_LVL0 ... CYGNUM_HAL_INTERRUPT_LVL14:
317
        /* Normally can only be masked by fiddling Imask in SR,
318
           but some platforms use external interrupt controller,
319
           so allow regular handling. */
320
        // fall through
321
    case CYGNUM_HAL_INTERRUPT_TMU0_TUNI0 ... CYGNUM_HAL_ISR_MAX:
322
        cyg_hal_IMASK_table[vector] = 0;
323
        hal_interrupt_update_level(vector);
324
        break;
325
    case CYGNUM_HAL_INTERRUPT_RESERVED_1E0:
326
    case CYGNUM_HAL_INTERRUPT_RESERVED_3E0:
327
        /* Do nothing for these reserved vectors. */
328
        break;
329
    default:
330
        CYG_FAIL("Unknown interrupt vector");
331
        break;
332
    }
333
}
334
 
335
void
336
hal_interrupt_unmask(int vector)
337
{
338
#ifdef CYGPKG_HAL_SH_7751
339
    if (vector >= CYGNUM_HAL_INTERRUPT_PCISERR && vector <= CYGNUM_HAL_INTERRUPT_TUNI4) {
340
        HAL_WRITE_UINT32(CYGARC_REG_INTMSKCLR00, 1 << (vector - CYGNUM_HAL_INTERRUPT_PCISERR));
341
        return;
342
    }
343
#endif
344
 
345
    switch( (vector) ) {
346
    case CYGNUM_HAL_INTERRUPT_NMI:
347
        break;
348
    case CYGNUM_HAL_INTERRUPT_LVL0 ... CYGNUM_HAL_INTERRUPT_LVL14:
349
        /* Normally can only be masked by fiddling Imask in SR,
350
           but some platforms use external interrupt controller,
351
           so allow regular handling. */
352
        // fall through
353
    case CYGNUM_HAL_INTERRUPT_TMU0_TUNI0 ... CYGNUM_HAL_ISR_MAX:
354
        cyg_hal_IMASK_table[vector] = 1;
355
        hal_interrupt_update_level(vector);
356
        break;
357
    case CYGNUM_HAL_INTERRUPT_RESERVED_1E0:
358
    case CYGNUM_HAL_INTERRUPT_RESERVED_3E0:
359
        /* Do nothing for these reserved vectors. */
360
        break;
361
    default:
362
        CYG_FAIL("Unknown interrupt vector");
363
        break;
364
    }
365
}
366
 
367
void
368
hal_interrupt_acknowledge(int vector)
369
{
370
    CYGPRI_HAL_INTERRUPT_ACKNOWLEDGE_PLF(vector);
371
}
372
 
373
void
374
hal_interrupt_configure(int vector, int level, int up)
375
{
376
    CYGPRI_HAL_INTERRUPT_CONFIGURE_PLF(vector, level, up);
377
}

powered by: WebSVN 2.1.0

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