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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [arm9/] [aaed2000/] [current/] [src/] [aaed2000_misc.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      aaed2000_misc.c
4
//
5
//      HAL misc board support code for ARM9/AAED2000
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):    gthomas
43
// Contributors: hmt, Travis C. Furrer <furrer@mit.edu>, jskov
44
// Date:         2000-05-21
45
// Purpose:      HAL board support
46
// Description:  Implementations of HAL board interfaces
47
//
48
//####DESCRIPTIONEND####
49
//
50
//========================================================================*/
51
 
52
#include <pkgconf/hal.h>
53
#include <pkgconf/system.h>
54
#include CYGBLD_HAL_PLATFORM_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_io.h>             // IO macros
61
#include <cyg/hal/hal_arch.h>           // Register state info
62
#include <cyg/hal/hal_diag.h>
63
#include <cyg/hal/hal_intr.h>           // Interrupt names
64
#include <cyg/hal/hal_cache.h>
65
#include <cyg/hal/aaed2000.h>           // Platform specifics
66
 
67
#include <cyg/infra/diag.h>             // diag_printf
68
 
69
#include <string.h> // memset
70
 
71
 
72
// -------------------------------------------------------------------------
73
// MMU initialization:
74
// 
75
// These structures are laid down in memory to define the translation
76
// table.
77
// 
78
 
79
/*
80
 * ARM Translation Table Base Bit Masks */
81
#define ARM_TRANSLATION_TABLE_MASK               0xFFFFC000
82
 
83
/*
84
 * ARM Domain Access Control Bit Masks
85
 */
86
#define ARM_ACCESS_TYPE_NO_ACCESS(domain_num)    (0x0 << (domain_num)*2)
87
#define ARM_ACCESS_TYPE_CLIENT(domain_num)       (0x1 << (domain_num)*2)
88
#define ARM_ACCESS_TYPE_MANAGER(domain_num)      (0x3 << (domain_num)*2)
89
 
90
struct ARM_MMU_FIRST_LEVEL_FAULT {
91
    int id : 2;
92
    int sbz : 30;
93
};
94
#define ARM_MMU_FIRST_LEVEL_FAULT_ID 0x0
95
 
96
struct ARM_MMU_FIRST_LEVEL_PAGE_TABLE {
97
    int id : 2;
98
    int imp : 2;
99
    int domain : 4;
100
    int sbz : 1;
101
    int base_address : 23;
102
};
103
#define ARM_MMU_FIRST_LEVEL_PAGE_TABLE_ID 0x1
104
 
105
struct ARM_MMU_FIRST_LEVEL_SECTION {
106
    int id : 2;
107
    int b : 1;
108
    int c : 1;
109
    int imp : 1;
110
    int domain : 4;
111
    int sbz0 : 1;
112
    int ap : 2;
113
    int sbz1 : 8;
114
    int base_address : 12;
115
};
116
#define ARM_MMU_FIRST_LEVEL_SECTION_ID 0x2
117
 
118
struct ARM_MMU_FIRST_LEVEL_RESERVED {
119
    int id : 2;
120
    int sbz : 30;
121
};
122
#define ARM_MMU_FIRST_LEVEL_RESERVED_ID 0x3
123
 
124
#define ARM_MMU_FIRST_LEVEL_DESCRIPTOR_ADDRESS(ttb_base, table_index) \
125
   (unsigned long *)((unsigned long)(ttb_base) + ((table_index) << 2))
126
 
127
#define ARM_FIRST_LEVEL_PAGE_TABLE_SIZE 0x4000
128
 
129
#define ARM_MMU_SECTION(ttb_base, actual_base, virtual_base,              \
130
                        cacheable, bufferable, perm)                      \
131
    CYG_MACRO_START                                                       \
132
        register union ARM_MMU_FIRST_LEVEL_DESCRIPTOR desc;               \
133
                                                                          \
134
        desc.word = 0;                                                    \
135
        desc.section.id = ARM_MMU_FIRST_LEVEL_SECTION_ID;                 \
136
        desc.section.imp = 1;                                             \
137
        desc.section.domain = 0;                                          \
138
        desc.section.c = (cacheable);                                     \
139
        desc.section.b = (bufferable);                                    \
140
        desc.section.ap = (perm);                                         \
141
        desc.section.base_address = (actual_base);                        \
142
        *ARM_MMU_FIRST_LEVEL_DESCRIPTOR_ADDRESS(ttb_base, (virtual_base)) \
143
                            = desc.word;                                  \
144
    CYG_MACRO_END
145
 
146
#define X_ARM_MMU_SECTION(abase,vbase,size,cache,buff,access)      \
147
    { int i; int j = abase; int k = vbase;                         \
148
      for (i = size; i > 0 ; i--,j++,k++)                          \
149
      {                                                            \
150
        ARM_MMU_SECTION(ttb_base, j, k, cache, buff, access);      \
151
      }                                                            \
152
    }
153
 
154
union ARM_MMU_FIRST_LEVEL_DESCRIPTOR {
155
    unsigned long word;
156
    struct ARM_MMU_FIRST_LEVEL_FAULT fault;
157
    struct ARM_MMU_FIRST_LEVEL_PAGE_TABLE page_table;
158
    struct ARM_MMU_FIRST_LEVEL_SECTION section;
159
    struct ARM_MMU_FIRST_LEVEL_RESERVED reserved;
160
};
161
 
162
#define ARM_UNCACHEABLE                         0
163
#define ARM_CACHEABLE                           1
164
#define ARM_UNBUFFERABLE                        0
165
#define ARM_BUFFERABLE                          1
166
 
167
#define ARM_ACCESS_PERM_NONE_NONE               0
168
#define ARM_ACCESS_PERM_RO_NONE                 0
169
#define ARM_ACCESS_PERM_RO_RO                   0
170
#define ARM_ACCESS_PERM_RW_NONE                 1
171
#define ARM_ACCESS_PERM_RW_RO                   2
172
#define ARM_ACCESS_PERM_RW_RW                   3
173
 
174
void
175
hal_mmu_init(void)
176
{
177
    unsigned long ttb_base = AAED2000_SDRAM_PHYS_BASE + 0x4000;
178
    unsigned long i;
179
 
180
    /*
181
     * Set the TTB register
182
     */
183
    asm volatile ("mcr  p15,0,%0,c2,c0,0" : : "r"(ttb_base) /*:*/);
184
 
185
    /*
186
     * Set the Domain Access Control Register
187
     */
188
    i = ARM_ACCESS_TYPE_MANAGER(0)    |
189
        ARM_ACCESS_TYPE_NO_ACCESS(1)  |
190
        ARM_ACCESS_TYPE_NO_ACCESS(2)  |
191
        ARM_ACCESS_TYPE_NO_ACCESS(3)  |
192
        ARM_ACCESS_TYPE_NO_ACCESS(4)  |
193
        ARM_ACCESS_TYPE_NO_ACCESS(5)  |
194
        ARM_ACCESS_TYPE_NO_ACCESS(6)  |
195
        ARM_ACCESS_TYPE_NO_ACCESS(7)  |
196
        ARM_ACCESS_TYPE_NO_ACCESS(8)  |
197
        ARM_ACCESS_TYPE_NO_ACCESS(9)  |
198
        ARM_ACCESS_TYPE_NO_ACCESS(10) |
199
        ARM_ACCESS_TYPE_NO_ACCESS(11) |
200
        ARM_ACCESS_TYPE_NO_ACCESS(12) |
201
        ARM_ACCESS_TYPE_NO_ACCESS(13) |
202
        ARM_ACCESS_TYPE_NO_ACCESS(14) |
203
        ARM_ACCESS_TYPE_NO_ACCESS(15);
204
    asm volatile ("mcr  p15,0,%0,c3,c0,0" : : "r"(i) /*:*/);
205
 
206
    /*
207
     * First clear all TT entries - ie Set them to Faulting
208
     */
209
    memset((void *)ttb_base, 0, ARM_FIRST_LEVEL_PAGE_TABLE_SIZE);
210
 
211
    /*               Actual  Virtual  Size   Attributes                                                    Function  */
212
    /*               Base     Base     MB      cached?           buffered?        access permissions                 */
213
    /*             xxx00000  xxx00000                                                                                */
214
    X_ARM_MMU_SECTION(0x000,  0x600,    32,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* Boot flash ROMspace CS0 */
215
    X_ARM_MMU_SECTION(0x100,  0x100,     1,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* Ethernet */
216
    X_ARM_MMU_SECTION(0x300,  0x300,     1,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* AAED2000 board registers */
217
    X_ARM_MMU_SECTION(0x400,  0x400,     1,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* PCMCIA slot - I/O */
218
    X_ARM_MMU_SECTION(0x440,  0x440,     1,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* PCMCIA slot - stat*/
219
    X_ARM_MMU_SECTION(0x480,  0x480,     1,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* PCMCIA slot - attribute */
220
    X_ARM_MMU_SECTION(0x4C0,  0x4C0,     1,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* PCMCIA slot - common */
221
    X_ARM_MMU_SECTION(0x500,  0x500,     1,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* CF slot - I/O */
222
    X_ARM_MMU_SECTION(0x540,  0x540,     1,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* CF slot - stat*/
223
    X_ARM_MMU_SECTION(0x580,  0x580,     1,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* CF slot - attribute */
224
    X_ARM_MMU_SECTION(0x5C0,  0x5C0,     1,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* CF slot - common */
225
    X_ARM_MMU_SECTION(0x800,  0x800,     1,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* AAEC2000 registers */
226
    // DRAM is non-contiguous, laid out in weird and wonderful ways...
227
    X_ARM_MMU_SECTION(0xF00,  0x000,     4,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM */
228
    X_ARM_MMU_SECTION(0xF10,  0x004,     4,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM */
229
    X_ARM_MMU_SECTION(0xF40,  0x008,     4,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM */
230
    X_ARM_MMU_SECTION(0xF50,  0x00C,     4,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM */
231
    X_ARM_MMU_SECTION(0xF80,  0x010,     4,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM */
232
    X_ARM_MMU_SECTION(0xF90,  0x014,     4,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM */
233
    X_ARM_MMU_SECTION(0xFC0,  0x018,     4,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM */
234
    X_ARM_MMU_SECTION(0xFD0,  0x01C,     4,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM */
235
    // Map in DRAM raw as well
236
    X_ARM_MMU_SECTION(0xF00,  0xF00,   256,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* Raw SDRAM */
237
}
238
 
239
//
240
// Platform specific initialization
241
//
242
void
243
plf_hardware_init(void)
244
{
245
    HAL_WRITE_UINT8(AAEC_PCDR, 0x22);
246
    HAL_WRITE_UINT8(AAEC_PCCDR, 0);
247
    HAL_WRITE_UINT8(AAEC_PBDDR, 0x83);
248
    HAL_WRITE_UINT8(AAEC_PINMUX,
249
                    AAEC_PINMUX_UART3CON | AAEC_PINMUX_PD0CON | AAEC_PINMUX_PE0CON);
250
 
251
    // FIXME - all platform interrupt sources should be configured here
252
    HAL_INTERRUPT_CONFIGURE(CYGNUM_HAL_INTERRUPT_TS,  0, 0 );  // Low pulse
253
    HAL_INTERRUPT_CONFIGURE(CYGNUM_HAL_INTERRUPT_ETH, 0, 1 );  // High pulse
254
}
255
 
256
//
257
// Support for platform specific I/O channels
258
//
259
 
260
externC void lcd_comm_init(void);
261
 
262
void
263
plf_if_init(void)
264
{
265
    aaed2000_KeyboardInit();
266
#ifdef CYGSEM_AAED2000_LCD_COMM
267
    // Initialize I/O channel
268
    lcd_comm_init();
269
#endif
270
}
271
 
272
// -------------------------------------------------------------------------
273
void hal_clock_initialize(cyg_uint32 period)
274
{
275
    // Use timer1 for the kernel clock
276
    HAL_WRITE_UINT32(AAEC_TMR_T1LOAD, period);
277
    HAL_WRITE_UINT32(AAEC_TMR_T1CONTROL,
278
                     AAEC_TMR_TxCONTROL_ENABLE
279
                     | AAEC_TMR_TxCONTROL_MODE_PERIODIC
280
                     | AAEC_TMR_TxCONTROL_508KHZ);
281
 
282
    // Unmask timer 0 interrupt
283
    HAL_INTERRUPT_CONFIGURE( CYGNUM_HAL_INTERRUPT_RTC, 1, 1 );
284
    HAL_INTERRUPT_UNMASK( CYGNUM_HAL_INTERRUPT_RTC );
285
}
286
 
287
// This routine is called during a clock interrupt.
288
void hal_clock_reset(cyg_uint32 vector, cyg_uint32 period)
289
{
290
    // Clear pending interrupt bit
291
    HAL_INTERRUPT_ACKNOWLEDGE(vector);
292
}
293
 
294
// Read the current value of the clock, returning the number of hardware
295
// "ticks" that have occurred (i.e. how far away the current value is from
296
// the start)
297
 
298
// Note: The "contract" for this function is that the value is the number
299
// of hardware clocks that have happened since the last interrupt (i.e.
300
// when it was reset).
301
 
302
void hal_clock_read(cyg_uint32 *pvalue)
303
{
304
    cyg_uint32 ctr;
305
 
306
    HAL_READ_UINT32(AAEC_TMR_T1VALUE, ctr);
307
    ctr = CYGNUM_HAL_RTC_PERIOD - ctr;
308
    *pvalue = ctr;
309
}
310
 
311
//
312
// Delay for some number of micro-seconds
313
//   Use timer #3 which runs at [fixed] 7.3728 MHz
314
//   Since this is only a 16 bit counter, it may be necessary
315
//   to run a loop to achieve sufficiently large delay values.
316
//
317
// Note: The 7.3728MHz value does not seem to work in practice
318
// It seems to be off by about a factor of 2.
319
//
320
void hal_delay_us(cyg_int32 usecs)
321
{
322
    static struct _tmr_vals {
323
        int us_val, tmr_val;
324
    } tmr_vals[] = {
325
        { 2*1000, 7372 },
326
        {  2*100,  737 },
327
        {   2*10,   74 },
328
        {    2*1,    7 },
329
        {      0,    0 }
330
    };
331
    struct _tmr_vals *vals = tmr_vals;
332
    cyg_uint32 state;
333
 
334
    while (vals->tmr_val) {
335
        while (usecs >= vals->us_val) {
336
            // disable timer #3
337
            HAL_WRITE_UINT32(AAEC_TMR_T3CONTROL, 0);
338
            HAL_WRITE_UINT32(AAEC_TMR_T3EOI, 0);
339
            // configure for tmr_val
340
            HAL_WRITE_UINT32(AAEC_TMR_T3LOAD, vals->tmr_val);
341
            // enable
342
            HAL_WRITE_UINT32(AAEC_TMR_T3CONTROL,
343
                             AAEC_TMR_TxCONTROL_ENABLE | AAEC_TMR_TxCONTROL_MODE_FREE);
344
            // wait for overflow
345
            do {
346
                HAL_READ_UINT32(AAEC_INT_RSR, state);
347
            } while ((state & (1<<AAEC_INTS_T3OI)) == 0);
348
            usecs -= vals->us_val;
349
        }
350
        vals++;
351
    }
352
}
353
 
354
// -------------------------------------------------------------------------
355
 
356
// This routine is called to respond to a hardware interrupt (IRQ).  It
357
// should interrogate the hardware and return the IRQ vector number.
358
int hal_IRQ_handler(void)
359
{
360
    int irq = CYGNUM_HAL_INTERRUPT_NONE;
361
    int vec;
362
    cyg_uint32 sr;
363
 
364
    HAL_READ_UINT32(AAEC_INT_SR, sr);
365
    for (vec = 0; vec <= CYGNUM_HAL_INTERRUPT_BMIINTR; vec++) {
366
        if (sr & (1<<vec)) {
367
            irq = vec;
368
            break;
369
        }
370
    }
371
 
372
    return irq;
373
}
374
 
375
//
376
// Interrupt control
377
//
378
 
379
struct {
380
    int   gpio_int;   // GPIO (F) interrupt source
381
    cyg_haladdress eoi;        // Acknowledge location
382
} AAED2000_INTMAP[] = {
383
    { 0, 0}, // CYGNUM_HAL_INTERRUPT_TS            CYGNUM_HAL_INTERRUPT_GPIO0FIQ
384
    {-1, AAEC_CSC_BLEOI}, // CYGNUM_HAL_INTERRUPT_BLINT         1
385
    {-1, AAEC_CSC_TEOI},  // CYGNUM_HAL_INTERRUPT_WEINT         2
386
    {-1, AAEC_CSC_MCEOI}, // CYGNUM_HAL_INTERRUPT_MCINT         3
387
    {-1, AAEC_COD_CDEOI}, // CYGNUM_HAL_INTERRUPT_CSINT         4
388
    { 1, 0}, // CYGNUM_HAL_INTERRUPT_ETH           CYGNUM_HAL_INTERRUPT_GPIO1INTR
389
    { 2, 0}, // CYGNUM_HAL_INTERRUPT_PCMCIA_CD2    CYGNUM_HAL_INTERRUPT_GPIO2INTR
390
    { 3, 0}, // CYGNUM_HAL_INTERRUPT_PCMCIA_CD1    CYGNUM_HAL_INTERRUPT_GPIO3INTR
391
    {-1, AAEC_TMR_T1EOI}, // CYGNUM_HAL_INTERRUPT_TC1OI         8
392
    {-1, AAEC_TMR_T2EOI}, // CYGNUM_HAL_INTERRUPT_TC2OI         9
393
    {-1, AAEC_RTC_RTCEOI},// CYGNUM_HAL_INTERRUPT_RTCMI        10
394
    {-1, AAEC_CSC_TEOI},  // CYGNUM_HAL_INTERRUPT_TINTR        11
395
    {-1, 0}, // CYGNUM_HAL_INTERRUPT_UART1INTR    12
396
    {-1, AAEC_UART2_UMS2EOI}, // CYGNUM_HAL_INTERRUPT_UART2INTR    13
397
    {-1, 0}, // CYGNUM_HAL_INTERRUPT_LCDINTR      14
398
    {-1, 0}, // CYGNUM_HAL_INTERRUPT_SSEOTI       15
399
    {-1, AAEC_UART2_UMS3EOI}, // CYGNUM_HAL_INTERRUPT_UART3INTR    16
400
    {-1, 0}, // CYGNUM_HAL_INTERRUPT_SCIINTR      17
401
    {-1, 0}, // CYGNUM_HAL_INTERRUPT_AACINTR      18
402
    {-1, 0}, // CYGNUM_HAL_INTERRUPT_MMCINTR      19
403
    {-1, 0}, // CYGNUM_HAL_INTERRUPT_USBINTR      20
404
    {-1, 0}, // CYGNUM_HAL_INTERRUPT_DMAINTR      21
405
    {-1, AAEC_TMR_T3EOI}, // CYGNUM_HAL_INTERRUPT_TC3OI        22
406
    { 4, 0}, // CYGNUM_HAL_INTERRUPT_SCI_VCCEN    CYGNUM_HAL_INTERRUPT_GPIO4INTR
407
    { 5, 0}, // CYGNUM_HAL_INTERRUPT_SCI_DETECT   CYGNUM_HAL_INTERRUPT_GPIO5INTR
408
    { 6, 0}, // CYGNUM_HAL_INTERRUPT_PCMCIA_RDY1  CYGNUM_HAL_INTERRUPT_GPIO6INTR
409
    { 7, 0}, // CYGNUM_HAL_INTERRUPT_PCMCIA_RDY2  CYGNUM_HAL_INTERRUPT_GPIO7INTR
410
    {-1, 0}, // CYGNUM_HAL_INTERRUPT_BMIINTR      27
411
};
412
 
413
void hal_interrupt_mask(int vector)
414
{
415
    CYG_ASSERT(vector <= CYGNUM_HAL_ISR_MAX &&
416
               vector >= CYGNUM_HAL_ISR_MIN , "Invalid vector");
417
 
418
    if (vector <= CYGNUM_HAL_INTERRUPT_BMIINTR) {
419
        HAL_WRITE_UINT32(AAEC_INT_ENC, (1 << vector));
420
    }
421
}
422
 
423
void hal_interrupt_unmask(int vector)
424
{
425
    CYG_ASSERT(vector <= CYGNUM_HAL_ISR_MAX &&
426
               vector >= CYGNUM_HAL_ISR_MIN , "Invalid vector");
427
 
428
    if (vector <= CYGNUM_HAL_INTERRUPT_BMIINTR) {
429
        HAL_WRITE_UINT32(AAEC_INT_ENS, (1 << vector));
430
    }
431
}
432
 
433
void hal_interrupt_acknowledge(int vector)
434
{
435
    cyg_haladdress eoi;
436
    int gpio;
437
    CYG_ASSERT(vector <= CYGNUM_HAL_ISR_MAX &&
438
               vector >= CYGNUM_HAL_ISR_MIN , "Invalid vector");
439
 
440
    if (vector <= CYGNUM_HAL_INTERRUPT_BMIINTR) {
441
        // Must be cleared at the source
442
        if ((eoi = AAED2000_INTMAP[vector].eoi) != 0) {
443
            HAL_WRITE_UINT32(eoi, 0);  // Any write clears interrupt
444
        } else if ((gpio = AAED2000_INTMAP[vector].gpio_int) >= 0) {
445
            // GPIO interrupts require special care
446
            HAL_WRITE_UINT32(AAEC_GPIO_FEOI, (1<<gpio));
447
        }
448
    }
449
}
450
 
451
void hal_interrupt_configure(int vector, int level, int up)
452
{
453
    int gpio;
454
    CYG_ASSERT(vector <= CYGNUM_HAL_ISR_MAX &&
455
               vector >= CYGNUM_HAL_ISR_MIN , "Invalid vector");
456
    if (vector <= CYGNUM_HAL_INTERRUPT_BMIINTR) {
457
        if ((gpio = AAED2000_INTMAP[vector].gpio_int) >= 0) {
458
            // Only GPIO interrupts can be configured
459
            int mask = (1<<gpio);
460
            cyg_uint32 cur;
461
            // Set type (level or edge)
462
            HAL_READ_UINT32(AAEC_GPIO_INT_TYPE1, cur);
463
            if (level) {
464
                // Level driven
465
                cur &= ~mask;
466
            } else {
467
                // Edge driven
468
                cur |= mask;
469
            }
470
            HAL_WRITE_UINT32(AAEC_GPIO_INT_TYPE1, cur);
471
            // Set level (high/rising or low/falling)
472
            HAL_READ_UINT32(AAEC_GPIO_INT_TYPE2, cur);
473
            if (up) {
474
                // Trigger on high/rising
475
                cur |= mask;
476
            } else {
477
                // Trigger on low/falling
478
                cur &= ~mask;
479
            }
480
            HAL_WRITE_UINT32(AAEC_GPIO_INT_TYPE2, cur);
481
            // Enable as interrupt
482
            HAL_READ_UINT32(AAEC_GPIO_INTEN, cur);
483
            cur |= mask;
484
            HAL_WRITE_UINT32(AAEC_GPIO_INTEN, cur);
485
        }
486
    }
487
}
488
 
489
void hal_interrupt_set_level(int vector, int level)
490
{
491
}
492
 
493
cyg_uint32
494
hal_virt_to_phys_address(cyg_uint32 virt)
495
{
496
    cyg_uint32 phys = 0xFFFFFFFF, dram_page;
497
    static cyg_uint32 _dram_map[] = {
498
        0xF0000000, 0xF1000000, 0xF4000000, 0xF5000000,
499
        0xF8000000, 0xF9000000, 0xFC000000, 0xFD000000
500
    };
501
 
502
    // Hard-wired, rather than walk the tables
503
    switch ((virt & 0xF0000000) >> 28) {
504
    case 0x0: // DRAM
505
        if ((virt & 0x0E000000) == 0) {
506
            dram_page = _dram_map[((virt & 0x01C00000) >> 22)];
507
            phys = dram_page | virt;
508
        } else {
509
            phys = 0xFFFFFFFF;
510
        }
511
        break;
512
    case 0x6: // FLASH
513
        phys = (virt & 0x0FFFFFFF);
514
        break;
515
    case 0x1:
516
    case 0x2:
517
    case 0x7:
518
    case 0x9:
519
    case 0xA:
520
    case 0xB:
521
    case 0xC:
522
    case 0xD:
523
    case 0xE:
524
        // Not mapped
525
        phys = 0xFFFFFFFF;
526
        break;
527
    case 0x3:
528
    case 0x4:
529
    case 0x5:
530
    case 0x8:
531
    case 0xF:
532
        // Mapped 1-1
533
        phys = virt;
534
        break;
535
    }
536
    return phys;
537
}

powered by: WebSVN 2.1.0

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