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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [arm9/] [aaed2000/] [v2_0/] [src/] [aaed2000_misc.c] - Blame information for rev 27

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

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

powered by: WebSVN 2.1.0

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