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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [integrator/] [v2_0/] [src/] [integrator_misc.c] - Blame information for rev 174

Details | Compare with Previous | View Log

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