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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [edb7xxx/] [current/] [src/] [edb7xxx_misc.c] - Blame information for rev 856

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      edb7xxx_misc.c
4
//
5
//      HAL misc board support code for ARM EDB7XXX-1
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, 2003 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: gthomas
44
// Date:         1999-02-20
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/hal_edb7xxx.h>         // Hardware definitions
66
#include <cyg/hal/hal_if.h>             // calling interface API
67
 
68
// #define CYGHWR_HAL_ARM_EDB7XXX_BATLOW
69
#ifdef CYGHWR_HAL_ARM_EDB7XXX_BATLOW
70
#include <cyg/hal/hal_intr.h>           // HAL interrupt macros
71
#include <cyg/hal/drv_api.h>            // HAL ISR support
72
static cyg_interrupt batlow_interrupt;
73
static cyg_handle_t  batlow_interrupt_handle;
74
#endif
75
 
76
#if (CYGHWR_HAL_ARM_EDB7XXX_PROCESSOR_CLOCK == 18432)
77
#define CPU_CLOCK 0
78
#elif (CYGHWR_HAL_ARM_EDB7XXX_PROCESSOR_CLOCK == 36864)
79
#define CPU_CLOCK 1
80
#elif (CYGHWR_HAL_ARM_EDB7XXX_PROCESSOR_CLOCK == 49152)
81
#define CPU_CLOCK 2
82
#elif (CYGHWR_HAL_ARM_EDB7XXX_PROCESSOR_CLOCK == 73728)
83
#define CPU_CLOCK 3
84
#elif (CYGHWR_HAL_ARM_EDB7XXX_PROCESSOR_CLOCK == 90317)
85
#define CPU_CLOCK 3 // Yes, the same
86
#define CPU_CLOCK_90MHZ
87
#else
88
#error Invalid CPU clock frequency
89
#endif
90
 
91
static cyg_uint32 _period;
92
void dram_delay_loop(void);
93
 
94
// Use Timer/Counter #2 for system clock
95
 
96
void hal_clock_initialize(cyg_uint32 period)
97
{
98
    volatile cyg_uint32 *syscon1 = (volatile cyg_uint32 *)SYSCON1;
99
    volatile cyg_uint32 *tc2d = (volatile cyg_uint32 *)TC2D;
100
    // Set timer to 512KHz, prescale mode
101
    *syscon1 = (*syscon1 & ~(SYSCON1_TC2M|SYSCON1_TC2S)) | SYSCON1_TC2S | SYSCON1_TC2M;
102
    // Initialize counter
103
    *tc2d = period;
104
    _period = period;
105
}
106
 
107
// This routine is called during a clock interrupt.
108
 
109
static void __inline__
110
enable_FIQ(void)
111
{
112
    asm volatile ("mrs r0,cpsr;"
113
                  "bic r0,r0,#0x40;"
114
                  "msr cpsr,r0");
115
}
116
 
117
#ifdef CYGHWR_HAL_ARM_EDB7XXX_SOFTWARE_DRAM_REFRESH
118
#define DRAM_START    0x00000000
119
#define DRAM_END      0x01000000
120
#define DRAM_ROW_SIZE 0x00000400
121
#define DRAM_REFRESH  (((DRAM_END-DRAM_START)/DRAM_ROW_SIZE)+99)/100
122
 
123
static void
124
do_DRAM_refresh(void)
125
{
126
    static cyg_uint32 *row_ptr;
127
    volatile cyg_uint32 val;
128
    int i;
129
    for (i = 0;  i < DRAM_REFRESH;  i++) {
130
        val = *row_ptr;
131
        row_ptr += DRAM_ROW_SIZE / sizeof(*row_ptr);
132
        if (row_ptr >= (cyg_uint32 *)DRAM_END) row_ptr = (cyg_uint32 *)DRAM_START;
133
    }
134
}
135
#endif // CYGHWR_HAL_ARM_EDB7XXX_SOFTWARE_DRAM_REFRESH
136
 
137
void hal_clock_reset(cyg_uint32 vector, cyg_uint32 period)
138
{
139
    volatile cyg_uint32 *tc2d = (volatile cyg_uint32 *)TC2D;
140
    if (period != _period) {
141
        *tc2d = period;
142
        _period = period;
143
    }
144
#if !defined(__EDB7312)
145
#ifndef CYGPKG_HAL_ARM_EDB7209
146
// EP7209 has no DRAM/controller, thus no problem
147
    enable_FIQ();  // Should be safe here
148
#ifdef CYGHWR_HAL_ARM_EDB7XXX_SOFTWARE_DRAM_REFRESH
149
    do_DRAM_refresh();
150
#else
151
    dram_delay_loop();
152
#endif 
153
#endif
154
#endif // !defined(__EDB7312)
155
}
156
 
157
// Read the current value of the clock, returning the number of hardware "ticks"
158
// that have occurred (i.e. how far away the current value is from the start)
159
 
160
void hal_clock_read(cyg_uint32 *pvalue)
161
{
162
    volatile cyg_int32 *tc2d = (volatile cyg_int32 *)TC2D;
163
    static cyg_int32 clock_val;
164
    clock_val = *tc2d & 0x0000FFFF;                 // Register has only 16 bits
165
    if (clock_val & 0x00008000) clock_val |= 0xFFFF8000;  // Extend sign bit
166
    *pvalue = (cyg_uint32)(_period - clock_val);    // 'clock_val' counts down and wraps
167
}
168
 
169
// Delay for some number of useconds.  Assume that the system clock
170
// has been set up to run at 512KHz (default).
171
void hal_delay_us(int us)
172
{
173
    volatile cyg_int32 *tc2d = (volatile cyg_int32 *)TC2D;
174
    cyg_int32 val, prev;
175
    while (us >= 2) {
176
        prev = *tc2d & 0x0000FFFF;                 // Register has only 16 bits
177
        if (prev & 0x00008000) prev |= 0xFFFF8000;  // Extend sign bit
178
        while (true) {
179
            val = *tc2d & 0x0000FFFF;                 // Register has only 16 bits
180
            if (val & 0x00008000) {
181
                val |= 0xFFFF8000;  // Extend sign bit
182
                *tc2d = _period;  // Need to reset counter
183
            }
184
            if (val != prev) {
185
                break;  // At least 2us have passed
186
            }
187
        }
188
        us -= 2;
189
    }
190
}
191
 
192
void
193
dram_delay_loop(void)
194
{
195
    // Temporary fix for DRAM starvation problem
196
    if (CYGHWR_HAL_ARM_EDB7XXX_PROCESSOR_CLOCK > 37000) {
197
        int i;
198
        for (i = 0;  i < (CYGHWR_HAL_ARM_EDB7XXX_PROCESSOR_CLOCK*2)/24;  i++) ;  // approx 300 us
199
    }
200
}
201
 
202
// These tables map the various [soft] interrupt numbers onto the hardware
203
 
204
static cyg_uint32 hal_interrupt_bitmap[] = {
205
    0,              // CYGNUM_HAL_INTERRUPT_unused     0
206
    INTSR1_EXTFIQ,  // CYGNUM_HAL_INTERRUPT_EXTFIQ     1
207
    INTSR1_BLINT,   // CYGNUM_HAL_INTERRUPT_BLINT      2
208
    INTSR1_WEINT,   // CYGNUM_HAL_INTERRUPT_WEINT      3
209
    INTSR1_MCINT,   // CYGNUM_HAL_INTERRUPT_MCINT      4
210
    INTSR1_CSINT,   // CYGNUM_HAL_INTERRUPT_CSINT      5
211
    INTSR1_EINT1,   // CYGNUM_HAL_INTERRUPT_EINT1      6    
212
    INTSR1_EINT2,   // CYGNUM_HAL_INTERRUPT_EINT2      7
213
    INTSR1_EINT3,   // CYGNUM_HAL_INTERRUPT_EINT3      8
214
    INTSR1_TC1OI,   // CYGNUM_HAL_INTERRUPT_TC1OI      9
215
    INTSR1_TC2OI,   // CYGNUM_HAL_INTERRUPT_TC2OI      10
216
    INTSR1_RTCMI,   // CYGNUM_HAL_INTERRUPT_RTCMI      11
217
    INTSR1_TINT,    // CYGNUM_HAL_INTERRUPT_TINT       12
218
    INTSR1_UTXINT1, // CYGNUM_HAL_INTERRUPT_UTXINT1    13
219
    INTSR1_URXINT1, // CYGNUM_HAL_INTERRUPT_URXINT1    14
220
    INTSR1_UMSINT,  // CYGNUM_HAL_INTERRUPT_UMSINT     15
221
    INTSR1_SSEOTI,  // CYGNUM_HAL_INTERRUPT_SSEOTI     16
222
    INTSR2_KBDINT,  // CYGNUM_HAL_INTERRUPT_KBDINT     17
223
    INTSR2_SS2RX,   // CYGNUM_HAL_INTERRUPT_SS2RX      18
224
    INTSR2_SS2TX,   // CYGNUM_HAL_INTERRUPT_SS2TX      19
225
    INTSR2_UTXINT2, // CYGNUM_HAL_INTERRUPT_UTXINT2    20
226
    INTSR2_URXINT2, // CYGNUM_HAL_INTERRUPT_URXINT2    21
227
#if defined(__EDB7211)
228
    INTSR3_MCPINT   // CYGNUM_HAL_INTERRUPT_MCPINT     22
229
#endif
230
#if defined(__EDB7209)
231
    INTSR3_I2SINT   // CYGNUM_HAL_INTERRUPT_I2SINT     22
232
#endif
233
#if defined(__EDB7312)
234
    INTSR3_DAIINT   // CYGNUM_HAL_INTERRUPT_DAIINT     22
235
#endif
236
};
237
 
238
static cyg_uint32 hal_interrupt_mask_regmap[] = {
239
    0,      // CYGNUM_HAL_INTERRUPT_unused     0
240
    INTMR1, // CYGNUM_HAL_INTERRUPT_EXTFIQ     1
241
    INTMR1, // CYGNUM_HAL_INTERRUPT_BLINT      2
242
    INTMR1, // CYGNUM_HAL_INTERRUPT_WEINT      3
243
    INTMR1, // CYGNUM_HAL_INTERRUPT_MCINT      4
244
    INTMR1, // CYGNUM_HAL_INTERRUPT_CSINT      5
245
    INTMR1, // CYGNUM_HAL_INTERRUPT_EINT1      6    
246
    INTMR1, // CYGNUM_HAL_INTERRUPT_EINT2      7
247
    INTMR1, // CYGNUM_HAL_INTERRUPT_EINT3      8
248
    INTMR1, // CYGNUM_HAL_INTERRUPT_TC1OI      9
249
    INTMR1, // CYGNUM_HAL_INTERRUPT_TC2OI      10
250
    INTMR1, // CYGNUM_HAL_INTERRUPT_RTCMI      11
251
    INTMR1, // CYGNUM_HAL_INTERRUPT_TINT       12
252
    INTMR1, // CYGNUM_HAL_INTERRUPT_UTXINT1    13
253
    INTMR1, // CYGNUM_HAL_INTERRUPT_URXINT1    14
254
    INTMR1, // CYGNUM_HAL_INTERRUPT_UMSINT     15
255
    INTMR1, // CYGNUM_HAL_INTERRUPT_SSEOTI     16
256
    INTMR2, // CYGNUM_HAL_INTERRUPT_KBDINT     17
257
    INTMR2, // CYGNUM_HAL_INTERRUPT_SS2RX      18
258
    INTMR2, // CYGNUM_HAL_INTERRUPT_SS2TX      19
259
    INTMR2, // CYGNUM_HAL_INTERRUPT_UTXINT2    20
260
    INTMR2, // CYGNUM_HAL_INTERRUPT_URXINT2    21
261
#if defined(__EDB7211)
262
    INTMR3, // CYGNUM_HAL_INTERRUPT_MCPINT     22
263
#endif
264
#if defined(__EDB7209)
265
    INTMR3, // CYGNUM_HAL_INTERRUPT_I2SINT     22
266
#endif
267
#if defined(__EDB7312)
268
    INTMR3, // CYGNUM_HAL_INTERRUPT_DAIINT     22
269
#endif
270
};
271
 
272
static cyg_uint32 hal_interrupt_clear_map[] = {
273
    0,      // CYGNUM_HAL_INTERRUPT_unused     0
274
    0,      // CYGNUM_HAL_INTERRUPT_EXTFIQ     1
275
    BLEOI,  // CYGNUM_HAL_INTERRUPT_BLINT      2
276
    TEOI,   // CYGNUM_HAL_INTERRUPT_WEINT      3
277
    MCEOI,  // CYGNUM_HAL_INTERRUPT_MCINT      4
278
    COEOI,  // CYGNUM_HAL_INTERRUPT_CSINT      5
279
    0,      // CYGNUM_HAL_INTERRUPT_EINT1      6    
280
    0,      // CYGNUM_HAL_INTERRUPT_EINT2      7
281
    0,      // CYGNUM_HAL_INTERRUPT_EINT3      8
282
    TC1EOI, // CYGNUM_HAL_INTERRUPT_TC1OI      9
283
    TC2EOI, // CYGNUM_HAL_INTERRUPT_TC2OI      10
284
    RTCEOI, // CYGNUM_HAL_INTERRUPT_RTCMI      11
285
    TEOI,   // CYGNUM_HAL_INTERRUPT_TINT       12
286
    0,      // CYGNUM_HAL_INTERRUPT_UTXINT1    13
287
    0,      // CYGNUM_HAL_INTERRUPT_URXINT1    14
288
    UMSEOI, // CYGNUM_HAL_INTERRUPT_UMSINT     15
289
    0,      // CYGNUM_HAL_INTERRUPT_SSEOTI     16
290
    KBDEOI, // CYGNUM_HAL_INTERRUPT_KBDINT     17
291
    0,      // CYGNUM_HAL_INTERRUPT_SS2RX      18
292
    0,      // CYGNUM_HAL_INTERRUPT_SS2TX      19
293
    0,      // CYGNUM_HAL_INTERRUPT_UTXINT2    20
294
    0,      // CYGNUM_HAL_INTERRUPT_URXINT2    21
295
#if defined(__EDB7211)
296
    0,      // CYGNUM_HAL_INTERRUPT_MCPINT     22
297
#endif
298
#if defined(__EDB7209)
299
    0,      // CYGNUM_HAL_INTERRUPT_I2SINT     22
300
#endif
301
#if defined(__EDB7312)
302
    0,      // CYGNUM_HAL_INTERRUPT_DAIINT     22
303
#endif
304
};
305
 
306
static struct regmap {
307
    int        first_int, last_int;
308
    cyg_uint32 stat_reg, mask_reg;
309
} hal_interrupt_status_regmap[] = {
310
    { CYGNUM_HAL_INTERRUPT_EXTFIQ, CYGNUM_HAL_INTERRUPT_MCINT,   INTSR1, INTMR1},
311
#if defined(__EDB7211)
312
    { CYGNUM_HAL_INTERRUPT_MCPINT, CYGNUM_HAL_INTERRUPT_MCPINT,  INTSR3, INTMR3},
313
#endif
314
#if defined(__EDB7209)
315
    { CYGNUM_HAL_INTERRUPT_I2SINT, CYGNUM_HAL_INTERRUPT_I2SINT,  INTSR3, INTMR3},
316
#endif
317
#if defined(__EDB7312)
318
    { CYGNUM_HAL_INTERRUPT_DAIINT, CYGNUM_HAL_INTERRUPT_DAIINT,  INTSR3, INTMR3},
319
#endif
320
    { CYGNUM_HAL_INTERRUPT_CSINT,  CYGNUM_HAL_INTERRUPT_SSEOTI,  INTSR1, INTMR1},
321
    { CYGNUM_HAL_INTERRUPT_KBDINT, CYGNUM_HAL_INTERRUPT_URXINT2, INTSR2, INTMR2},
322
    { 0, 0, 0, 0 }
323
};
324
 
325
#ifdef CYGHWR_HAL_ARM_EDB7XXX_BATLOW
326
// This ISR is called when the battery low interrupt occurs
327
int
328
cyg_hal_batlow_isr(cyg_vector_t vector, cyg_addrword_t data, HAL_SavedRegisters *regs)
329
{
330
    diag_printf("Battery low\n");
331
    cyg_drv_interrupt_mask(CYGNUM_HAL_INTERRUPT_BLINT);
332
    // Presumably, one would leave this masked until the battery changed
333
    cyg_drv_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_BLINT);
334
    return 0;  // No need to run DSR
335
}
336
#endif
337
 
338
//
339
// Early stage hardware initialization
340
//   Some initialization has already been done before we get here.  For now
341
// just set up the interrupt environment.
342
 
343
void hal_hardware_init(void)
344
{
345
    volatile cyg_uint32 *icr;
346
    int vector;
347
 
348
    // Clear and initialize instruction cache
349
    HAL_ICACHE_INVALIDATE_ALL();
350
    HAL_ICACHE_ENABLE();
351
 
352
    // Any hardware/platform initialization that needs to be done.
353
    *(volatile cyg_uint32 *)INTMR1 = 0;
354
    *(volatile cyg_uint32 *)INTMR2 = 0;
355
#if !defined(__CL7111)
356
    *(volatile cyg_uint32 *)INTMR3 = 0;
357
#endif
358
#if !defined(__CL7111) && !defined(__EDB7312)
359
    *(volatile cyg_uint8 *)SYSCON3 = SYSCON3_CLKCTL(CPU_CLOCK);
360
#endif
361
 
362
#if 0
363
    diag_printf("IMR1: %04x, IMR2: %04x\n",
364
                *(volatile cyg_uint32 *)INTMR1,
365
                *(volatile cyg_uint32 *)INTMR2);
366
    diag_printf("Memcfg1: %08x, Memcfg2: %08x, DRAM refresh: %08x\n",
367
                *(volatile cyg_uint32 *)MEMCFG1,
368
                *(volatile cyg_uint32 *)MEMCFG2,
369
                *(volatile cyg_uint8 *)DRFPR);
370
#endif
371
#define MEMCFG_BUS_WIDTH(n)   (n<<0)
372
#define MEMCFG_BUS_WIDTH_32   (0<<0)
373
#define MEMCFG_BUS_WIDTH_16   (1<<0)
374
#define MEMCFG_BUS_WIDTH_8    (2<<0)
375
#define MEMCFG_WAIT_STATES(n) (n<<2)     // 0 is max, 15 min
376
#define MEMCFG_SQAEN          (1<<6)
377
#define MEMCFG_CLKENB         (1<<7)
378
 
379
// These need to be checked/improved
380
#define CS0_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(3) | MEMCFG_SQAEN
381
#define CS1_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(4)
382
#define CS2_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(0)
383
#define CS3_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(0)
384
#define CS4_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(0)
385
#define CS5_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(0)
386
#define CS6_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(0)
387
#define CS7_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(0)
388
 
389
#if defined(__EDB7209)
390
    *(volatile cyg_uint32 *)MEMCFG1 =
391
        (CS0_CONFIG << 0) |       // FLASH rom
392
        (CS1_CONFIG << 8) |       // NAND flash
393
        (CS2_CONFIG << 16) |      // Ethernet
394
        (CS3_CONFIG << 24);       // Parallel printer, keyboard, touch panel
395
    *(volatile cyg_uint32 *)MEMCFG2 =
396
        (CS4_CONFIG << 0) |       // USB
397
        (CS5_CONFIG << 8) |       // Expansion
398
        (CS6_CONFIG << 16) |      // Local SRAM
399
        (CS7_CONFIG << 24);       // Boot ROM
400
    // This value came from Cirrus, but doesn't match the recommendations above?
401
    *(volatile cyg_uint32 *)MEMCFG1 = 0x3C001814;
402
    // Set up GPIO lines
403
    *(volatile cyg_uint8 *)PADDR   = 0x00;  // Keyboard data 0-7 input
404
    *(volatile cyg_uint8 *)PBDDR   = 0xFA;  // 0 - I/O on J22
405
                                            // 1 - RTS on UART1
406
                                            // 2 - Ring on UART1
407
                                            // 3 - SSI header, Pin 13
408
                                            // 4 - NAND Command Latch Enable
409
                                            // 5 - NAND Address Latch Enable
410
                                            // 6 - On-board NAND Select (active low)
411
                                            // 7 - SmartMedia Card Enable (active low)
412
    *(volatile cyg_uint8 *)PBDR    = 0xC0;  // Everything off
413
    *(volatile cyg_uint8 *)PDDDR   = 0x40;  // 0 - Diagnostic LED control
414
                                            // 1 - Enable DC-DC converter for LCD
415
                                            // 2 - Enable LCD
416
                                            // 3 - ENable LCD Backlight
417
                                            // 4 - CS4342 I2C Data
418
                                            // 5 - CS4342 I2C Clock
419
                                            // 6 - SmartMedia Presence indicator
420
                                            // 7 - I/O on J22
421
    *(volatile cyg_uint8 *)PDDR    = 0x00;  // Everything off
422
    *(volatile cyg_uint8 *)PEDDR   = 0x05;  // 0 - Codec or ADC/DAC
423
                                            // 1 - I/O on JP38 (0 when inserted)
424
                                            // 2 - Enable touch panel
425
    *(volatile cyg_uint8 *)PEDR    = 0x01;  // Enable audio (not CODEC)
426
    // Initialize system control
427
    *(volatile cyg_uint32 *)SYSCON2 = SYSCON2_KBWEN;
428
#endif
429
 
430
#if defined(__EDB7312)
431
    *(volatile cyg_uint32 *)MEMCFG1 = 0x1F101710;
432
    *(volatile cyg_uint32 *)MEMCFG2 = 0x00001F93;
433
    // Set up GPIO lines
434
    *(volatile cyg_uint8 *)PADDR   = 0x00;  // Keyboard data 0-7 input
435
    *(volatile cyg_uint8 *)PBDDR   = 0xF2;
436
    *(volatile cyg_uint8 *)PDDDR   = 0x2F;
437
    *(volatile cyg_uint8 *)PDDDR   = 0x10;  // Directions are inverted!
438
    *(volatile cyg_uint8 *)PDDR    = 0x00;  // Everything off
439
    *(volatile cyg_uint8 *)PEDDR   = 0x01;
440
    // Initialize system control
441
    *(volatile cyg_uint32 *)SYSCON1 = 0x00040100;
442
    *(volatile cyg_uint32 *)SYSCON2 = 0x00000102;
443
 
444
#ifdef CPU_CLOCK_90MHZ
445
    // We must slow down the RAM timings compared to default by adding
446
    // wait states or it does not work.
447
    // Slow them all down to Random=5, Seq=3 waitstates by replacing
448
    // that field throughout the default value copied from above:
449
    *(volatile cyg_uint32 *)MEMCFG1 = (0x1F101710 & ~0x3c3c3c3c) | 0x0c0c0c0c;
450
    *(volatile cyg_uint32 *)MEMCFG2 = (0x00001F93 & ~0x00003c3c) | 0x00000c0c;
451
#endif // CPU_CLOCK_90MHZ
452
 
453
    *(volatile cyg_uint32 *)SYSCON3 = 0x00000208 | SYSCON3_CLKCTL(CPU_CLOCK);
454
 
455
#ifdef CPU_CLOCK_90MHZ
456
    // Let the clock change settle before hitting the PLL multiplier
457
    // register to change up by a further 22.5%
458
    asm volatile( "nop;nop;nop;nop;nop;nop;nop;nop;");
459
    *(volatile cyg_uint32 *)EP7312_PLL_MR = EP7312_PLL_MR_FOR_90MHz;
460
    asm volatile( "nop;nop;nop;nop;nop;nop;nop;nop;");
461
#endif // CPU_CLOCK_90MHZ
462
 
463
#endif
464
    // Reset all interrupt masks (disable all interrupt sources)
465
    for (vector = CYGNUM_HAL_ISR_MIN;  vector < CYGNUM_HAL_ISR_COUNT;  vector++) {
466
        icr = (volatile cyg_uint32 *)hal_interrupt_clear_map[vector];
467
        if (icr) *icr = 0;  // Just a write clears the latch
468
    }
469
#ifndef __EDB7312
470
    // Turn on the DIAG LED to let the world know the board is alive
471
    *(volatile unsigned char *)LEDFLSH = LEDFLSH_ENABLE|LEDFLSH_DUTY(16)|LEDFLSH_PERIOD(1);
472
#endif
473
#ifdef CYGHWR_HAL_ARM_EDB7XXX_BATLOW
474
    cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_BLINT,
475
                             99,                     // Priority - what goes here?
476
                             0,                      //  Data item passed to interrupt handler
477
                             cyg_hal_batlow_isr,
478
                             0,
479
                             &batlow_interrupt_handle,
480
                             &batlow_interrupt);
481
    cyg_drv_interrupt_attach(batlow_interrupt_handle);
482
    cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_BLINT);
483
#endif
484
 
485
    // Initialize real-time clock (for delays, etc, even if kernel doesn't use it)
486
    hal_clock_initialize(CYGNUM_HAL_RTC_PERIOD);
487
 
488
    // Set up eCos/ROM interfaces
489
    hal_if_init();
490
 
491
#ifdef CYGSEM_EDB7XXX_LCD_COMM
492
    // Initialize I/O channel
493
    lcd_comm_init();
494
#endif
495
}
496
 
497
//
498
// This routine is called to respond to a hardware interrupt (IRQ).  It
499
// should interrogate the hardware and return the IRQ vector number.
500
 
501
// This code is a little convoluted to keep it general while still avoiding
502
// reading the hardware a lot, since the interrupt status is split across
503
// three separate registers.
504
 
505
int hal_spurious_ints;
506
 
507
int hal_IRQ_handler(void)
508
{
509
    struct regmap *map = hal_interrupt_status_regmap;
510
    cyg_uint32 stat;
511
    int vector;
512
    while (map->first_int) {
513
        stat = *(volatile cyg_uint32 *)map->stat_reg & *(volatile cyg_uint32 *)map->mask_reg;
514
        for (vector = map->first_int;  vector <= map->last_int;  vector++) {
515
            if (stat & hal_interrupt_bitmap[vector]) return vector;
516
        }
517
        map++;  // Next interrupt status register
518
    }
519
    hal_spurious_ints++;
520
    return CYGNUM_HAL_INTERRUPT_NONE; // This shouldn't happen!
521
}
522
 
523
//
524
// Interrupt control
525
//
526
 
527
void hal_interrupt_mask(int vector)
528
{
529
    volatile cyg_uint32 *imr;
530
    imr = (volatile cyg_uint32 *)hal_interrupt_mask_regmap[vector];
531
    *imr &= ~hal_interrupt_bitmap[vector];
532
}
533
 
534
void hal_interrupt_unmask(int vector)
535
{
536
    volatile cyg_uint32 *imr;
537
    imr = (volatile cyg_uint32 *)hal_interrupt_mask_regmap[vector];
538
    *imr |= hal_interrupt_bitmap[vector];
539
}
540
 
541
void hal_interrupt_acknowledge(int vector)
542
{
543
    // Some interrupt sources have a register for this.
544
    volatile cyg_uint8 *icr;
545
    icr = (volatile cyg_uint8 *)hal_interrupt_clear_map[vector];
546
    if (icr) {
547
        *icr = 0;  // Any data clears interrupt
548
    }
549
}
550
 
551
void hal_interrupt_configure(int vector, int level, int up)
552
{
553
    // No interrupts are configurable on this hardware
554
}
555
 
556
void hal_interrupt_set_level(int vector, int level)
557
{
558
    // No interrupts are configurable on this hardware
559
}
560
 
561
#define _CYGHWR_LAYOUT_ONLY
562
#include <cyg/hal/hal_platform_setup.h>
563
 
564
unsigned long
565
_edb7xxx_physical_address(unsigned long addr)
566
{
567
    unsigned long res;
568
 
569
    if (addr < DRAM_LA_END) {
570
        res = addr + DRAM_PA;
571
    } else {
572
        res = addr | 0xC0000000;
573
    }
574
    return res;
575
}
576
 
577
/*------------------------------------------------------------------------*/
578
// EOF hal_misc.c

powered by: WebSVN 2.1.0

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