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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      integrator_misc.c
4
//
5
//      HAL misc board support code for ARM INTEGRATOR7
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):    David A Rusling
43
// Contributors: Philippe Robin
44
// Date:         November 7, 2000
45
// Purpose:      HAL board support
46
// Description:  Implementations of HAL board interfaces
47
//
48
//####DESCRIPTIONEND####
49
//
50
//===========================================================================*/
51
 
52
#include <pkgconf/hal.h>
53
 
54
#include <cyg/infra/cyg_type.h>         // base types
55
#include <cyg/infra/cyg_trac.h>         // tracing macros
56
#include <cyg/infra/cyg_ass.h>          // assertion macros
57
 
58
#include <cyg/hal/hal_io.h>             // IO macros
59
#include <cyg/hal/hal_arch.h>           // Register state info
60
#include <cyg/hal/hal_diag.h>
61
#include <cyg/hal/hal_intr.h>           // necessary?
62
#include <cyg/hal/hal_integrator.h>
63
 
64
/*------------------------------------------------------------------------*/
65
// On-board timer
66
/*------------------------------------------------------------------------*/
67
 
68
// forward declarations
69
void hal_if_init(void);
70
 
71
// declarations
72
static cyg_uint32 _period;
73
 
74
void hal_clock_initialize(cyg_uint32 period)
75
{
76
    //diag_init();  diag_printf("%s(%d)\n", __PRETTY_FUNCTION__, period);
77
    //diag_printf("psr = %x\n", psr());
78
    HAL_WRITE_UINT32(CYG_DEVICE_TIMER_CONTROL, CTL_DISABLE);    // Turn off
79
    HAL_WRITE_UINT32(CYG_DEVICE_TIMER_LOAD, period);
80
    HAL_WRITE_UINT32(CYG_DEVICE_TIMER_CONTROL,
81
                     CTL_ENABLE | CTL_PERIODIC | CTL_SCALE_16);
82
    _period = period;
83
}
84
 
85
void hal_clock_reset(cyg_uint32 vector, cyg_uint32 period)
86
{
87
    //diag_init();  diag_printf("%s\n", __PRETTY_FUNCTION__);
88
    HAL_WRITE_UINT32(CYG_DEVICE_TIMER_CLEAR, 0);
89
    _period = period;
90
}
91
 
92
void hal_clock_read(cyg_uint32 *pvalue)
93
{
94
    cyg_uint32 value;
95
//    diag_init();  diag_printf("%s\n", __PRETTY_FUNCTION__);
96
    HAL_READ_UINT32(CYG_DEVICE_TIMER_CURRENT, value);
97
    value &= 0xFFFF;
98
    *pvalue = _period - (value & 0xFFFF);   // Note: counter is only 16 bits
99
                                            //       and decreases
100
}
101
 
102
// Delay for some usecs.
103
void hal_delay_us(cyg_uint32 delay)
104
{
105
#if 0
106
    int i;
107
    for( i = 0; i < delay; i++ );
108
 
109
#else
110
    cyg_uint32 now, last, diff, ticks;
111
 
112
    // The timer actually runs at 1.25 ticks per micrsecond.
113
    // Adjust the supplied delay to compensate.
114
 
115
    delay *= 4;
116
    delay /= 5;
117
 
118
    hal_clock_read(&last);
119
    diff = ticks = 0;
120
 
121
    while (delay > ticks) {
122
        hal_clock_read(&now);
123
 
124
        // Cope with wrap-around of timer
125
        if (now < last)
126
            diff = ((_period - last) + now);
127
        else
128
            diff = (now - last);
129
 
130
        last = now;
131
 
132
        ticks += diff;
133
    }
134
#endif
135
}
136
 
137
 
138
#if defined(CYGPKG_HAL_ARM_INTEGRATOR_ARM7)
139
void hal_hardware_init(void)
140
#elif defined(CYGPKG_HAL_ARM_INTEGRATOR_ARM9)
141
void plf_hardware_init(void)
142
#endif
143
{
144
    // Any hardware/platform initialization that needs to be done.
145
 
146
    // Clear all interrupt sources
147
    HAL_WRITE_UINT32(CYG_DEVICE_IRQ_EnableClear, 0xFFFF);
148
 
149
#ifndef CYGFUN_HAL_COMMON_KERNEL_SUPPORT
150
    HAL_CLOCK_INITIALIZE( CYGNUM_HAL_RTC_PERIOD );
151
#endif
152
 
153
    // FIXME: The line with the thumb check is a hack, allowing
154
    // the farm to run test. Problem is that virtual vector table
155
    // API needs to be ARM/Thumb consistent. Will fix later.
156
#if !defined(__thumb__) && !defined(CYGPKG_HAL_ARM_INTEGRATOR_ARM9)
157
    // Set up eCos/ROM interfaces
158
    hal_if_init();
159
#endif
160
}
161
 
162
//
163
// This routine is called to respond to a hardware interrupt (IRQ).  It
164
// should interrogate the hardware and return the IRQ vector number.
165
 
166
int hal_IRQ_handler(void)
167
{
168
    // Do hardware-level IRQ handling
169
    int irq_status, vector;
170
    HAL_READ_UINT32(CYG_DEVICE_IRQ_Status, irq_status);
171
    //diag_init();  diag_printf("IRQ status: 0x%x\n", irq_status); 
172
    for (vector = 1;  vector <= 16;  vector++) {
173
        if (irq_status & (1<<vector)) return vector;
174
    }
175
    return -1 ; // This shouldn't happen!
176
}
177
 
178
//
179
// Interrupt control
180
//
181
 
182
void hal_interrupt_mask(int vector)
183
{
184
    //diag_init();  diag_printf("hal_interrupt_mask(%d)\n", vector);
185
    HAL_WRITE_UINT32(CYG_DEVICE_IRQ_EnableClear, 1<<vector);
186
}
187
 
188
#if 0
189
void hal_interrupt_status(void)
190
{
191
    int irq_status, irq_enable, timer_status, timer_value, timer_load;
192
    HAL_READ_UINT32(CYG_DEVICE_IRQ_Status, irq_status);
193
    HAL_READ_UINT32(CYG_DEVICE_IRQ_Enable, irq_enable);
194
    HAL_READ_UINT32(CYG_DEVICE_TIMER_LOAD, timer_load);
195
    HAL_READ_UINT32(CYG_DEVICE_TIMER_CURRENT, timer_value);
196
    HAL_READ_UINT32(CYG_DEVICE_TIMER_CONTROL, timer_status);
197
    diag_printf("Interrupt: IRQ: %x.%x, TIMER: %x.%x.%x, psr: %x\n",
198
                irq_status, irq_enable, timer_status, timer_value,
199
                timer_load, psr());
200
}
201
#endif
202
 
203
void hal_interrupt_unmask(int vector)
204
{
205
    //diag_init();  diag_printf("hal_interrupt_unmask(%d)\n", vector);
206
    HAL_WRITE_UINT32(CYG_DEVICE_IRQ_EnableSet, 1<<vector);
207
}
208
 
209
void hal_interrupt_acknowledge(int vector)
210
{
211
    //diag_init();  diag_printf("%s(%d)\n", __PRETTY_FUNCTION__, vector);
212
}
213
 
214
void hal_interrupt_configure(int vector, int level, int up)
215
{
216
    //diag_init();  diag_printf("%s(%d,%d,%d)\n", __PRETTY_FUNCTION__, vector, level, up);
217
}
218
 
219
void hal_interrupt_set_level(int vector, int level)
220
{
221
    //diag_init();  diag_printf("%s(%d,%d)\n", __PRETTY_FUNCTION__, vector, level);
222
}
223
 
224
void hal_show_IRQ(int vector, int data, int handler)
225
{
226
    //    diag_printf("IRQ - vector: %x, data: %x, handler: %x\n", vector, data, handler);
227
}
228
 
229
/*---------------------------------------------------------------------------*/
230
 
231
__externC void cyg_plf_pci_init(void)
232
{
233
    // Only do this for non-RAM startups. If we do it during RAM
234
    // startup and we are using the ethernet for debugging, this kills
235
    // the ethernet controller.
236
#ifndef CYG_HAL_STARTUP_RAM
237
 
238
    volatile int i, j;
239
 
240
    /* setting this register will take the V3 out of reset */
241
 
242
    *(volatile cyg_uint32 *)(INTEGRATOR_SC_PCIENABLE) = 1;
243
 
244
    /* wait a few usecs to settle the device and the PCI bus */
245
 
246
    for (i = 0; i < 100 ; i++)
247
           j = i + 1;
248
 
249
    /* Now write the Base I/O Address Word to V3_BASE + 0x6C */
250
 
251
    *(volatile cyg_uint16 *)(V3_BASE + V3_LB_IO_BASE) = (cyg_uint16)(V3_BASE >> 16);
252
 
253
    do {
254
        *(volatile cyg_uint8 *)(V3_BASE + V3_MAIL_DATA) = 0xAA;
255
        *(volatile cyg_uint8 *)(V3_BASE + V3_MAIL_DATA + 4) = 0x55;
256
    } while (*(volatile cyg_uint8 *)(V3_BASE + V3_MAIL_DATA) != 0xAA ||
257
             *(volatile cyg_uint8 *)(V3_BASE + V3_MAIL_DATA + 4) != 0x55);
258
 
259
    /* Make sure that V3 register access is not locked, if it is, unlock it */
260
 
261
    if ((*(volatile cyg_uint16 *)(V3_BASE + V3_SYSTEM) & V3_SYSTEM_M_LOCK)
262
                                == V3_SYSTEM_M_LOCK)
263
        *(volatile cyg_uint16 *)(V3_BASE + V3_SYSTEM) = 0xA05F;
264
 
265
    /* Ensure that the slave accesses from PCI are disabled while we */
266
    /* setup windows */
267
 
268
    *(volatile cyg_uint16 *)(V3_BASE + V3_PCI_CMD) &=
269
                                ~(V3_COMMAND_M_MEM_EN | V3_COMMAND_M_IO_EN);
270
 
271
    /* Clear RST_OUT to 0; keep the PCI bus in reset until we've finished */
272
 
273
    *(volatile cyg_uint16 *)(V3_BASE + V3_SYSTEM) &= ~V3_SYSTEM_M_RST_OUT;
274
 
275
    /* Make all accesses from PCI space retry until we're ready for them */
276
 
277
    *(volatile cyg_uint16 *)(V3_BASE + V3_PCI_CFG) |= V3_PCI_CFG_M_RETRY_EN;
278
 
279
    /* Set up any V3 PCI Configuration Registers that we absolutely have to */
280
    /* LB_CFG controls Local Bus protocol. */
281
    /* Enable LocalBus byte strobes for READ accesses too. */
282
    /* set bit 7 BE_IMODE and bit 6 BE_OMODE */
283
 
284
    *(volatile cyg_uint16 *)(V3_BASE + V3_LB_CFG) |= 0x0C0;
285
 
286
    /* PCI_CMD controls overall PCI operation. */
287
    /* Enable PCI bus master. */
288
 
289
    *(volatile cyg_uint16 *)(V3_BASE + V3_PCI_CMD) |= 0x04;
290
 
291
    /* PCI_MAP0 controls where the PCI to CPU memory window is on Local Bus*/
292
 
293
    *(volatile cyg_uint32 *)(V3_BASE + V3_PCI_MAP0) = (INTEGRATOR_BOOT_ROM_BASE) |
294
                                        (V3_PCI_MAP_M_ADR_SIZE_512M |
295
                                        V3_PCI_MAP_M_REG_EN |
296
                                        V3_PCI_MAP_M_ENABLE);
297
 
298
    /* PCI_BASE0 is the PCI address of the start of the window */
299
 
300
    *(volatile cyg_uint32 *)(V3_BASE + V3_PCI_BASE0) = INTEGRATOR_BOOT_ROM_BASE;
301
 
302
    /* PCI_MAP1 is LOCAL address of the start of the window */
303
 
304
    *(volatile cyg_uint32 *)(V3_BASE + V3_PCI_MAP1) = (INTEGRATOR_HDR0_SDRAM_BASE) |
305
                        (V3_PCI_MAP_M_ADR_SIZE_1024M | V3_PCI_MAP_M_REG_EN |
306
                         V3_PCI_MAP_M_ENABLE);
307
 
308
    /* PCI_BASE1 is the PCI address of the start of the window */
309
 
310
    *(volatile cyg_uint32 *)(V3_BASE + V3_PCI_BASE1) = INTEGRATOR_HDR0_SDRAM_BASE;
311
 
312
    /* Set up the windows from local bus memory into PCI configuration, */
313
    /* I/O and Memory. */
314
    /* PCI I/O, LB_BASE2 and LB_MAP2 are used exclusively for this. */
315
 
316
    *(volatile cyg_uint16 *)(V3_BASE +V3_LB_BASE2) =
317
                        ((CPU_PCI_IO_ADRS >> 24) << 8) | V3_LB_BASE_M_ENABLE;
318
    *(volatile cyg_uint16 *)(V3_BASE + V3_LB_MAP2) = 0;
319
 
320
    /* PCI Configuration, use LB_BASE1/LB_MAP1. */
321
 
322
    /* PCI Memory use LB_BASE0/LB_MAP0 and LB_BASE1/LB_MAP1 */
323
    /* Map first 256Mbytes as non-prefetchable via BASE0/MAP0 */
324
    /* (INTEGRATOR_PCI_BASE == PCI_MEM_BASE) */
325
 
326
    *(volatile cyg_uint32 *)(V3_BASE + V3_LB_BASE0) =
327
                        INTEGRATOR_PCI_BASE | (0x80 | V3_LB_BASE_M_ENABLE);
328
 
329
    *(volatile cyg_uint16 *)(V3_BASE + V3_LB_MAP0) =
330
                        ((INTEGRATOR_PCI_BASE >> 20) << 0x4) | 0x0006;
331
 
332
    /* Map second 256 Mbytes as prefetchable via BASE1/MAP1 */
333
 
334
    *(volatile cyg_uint32 *)(V3_BASE + V3_LB_BASE1) =
335
                        INTEGRATOR_PCI_BASE | (0x84 | V3_LB_BASE_M_ENABLE);
336
 
337
    *(volatile cyg_uint16 *)(V3_BASE + V3_LB_MAP1) =
338
                        (((INTEGRATOR_PCI_BASE + SZ_256M) >> 20) << 4) | 0x0006;
339
 
340
    /* Allow accesses to PCI Configuration space */
341
    /* and set up A1, A0 for type 1 config cycles */
342
 
343
    *(volatile cyg_uint16 *)(V3_BASE + V3_PCI_CFG) =
344
                        ((*(volatile cyg_uint16 *)(V3_BASE + V3_PCI_CFG)) &
345
                           ~(V3_PCI_CFG_M_RETRY_EN | V3_PCI_CFG_M_AD_LOW1) ) |
346
                           V3_PCI_CFG_M_AD_LOW0;
347
 
348
    /* now we can allow in PCI MEMORY accesses */
349
 
350
    *(volatile cyg_uint16 *)(V3_BASE + V3_PCI_CMD) =
351
                (*(volatile cyg_uint16 *)(V3_BASE + V3_PCI_CMD)) | V3_COMMAND_M_MEM_EN;
352
 
353
    /* Set RST_OUT to take the PCI bus is out of reset, PCI devices can */
354
    /* initialise and lock the V3 system register so that no one else */
355
    /* can play with it */
356
 
357
   *(volatile cyg_uint16 *)(V3_BASE + V3_SYSTEM) =
358
                (*(volatile cyg_uint16 *)(V3_BASE + V3_SYSTEM)) | V3_SYSTEM_M_RST_OUT;
359
 
360
   *(volatile cyg_uint16 *)(V3_BASE + V3_SYSTEM) =
361
                (*(volatile cyg_uint16 *)(V3_BASE + V3_SYSTEM)) | V3_SYSTEM_M_LOCK;
362
 
363
#endif
364
}
365
 
366
/*---------------------------------------------------------------------------*/
367
/* End of hal_misc.c */

powered by: WebSVN 2.1.0

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