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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [cma230/] [v2_0/] [src/] [cma230_misc.c] - Blame information for rev 802

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      cma230_misc.c
4
//
5
//      HAL misc board support code for ARM CMA230-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 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: gthomas
45
// Date:         1999-02-20
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_if.h>             // calling interface API
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_cma230.h>         // Hardware definitions
66
 
67
static cyg_uint32 _period;
68
 
69
// Use Timer/Counter #2 for system clock
70
 
71
void hal_clock_initialize(cyg_uint32 period)
72
{
73
    // Initialize counter
74
    *(volatile cyg_uint16 *)CMA230_TC_ENABLE = 0;  // Disable timer
75
    *(volatile cyg_uint16 *)CMA230_TC_CLEAR = 0;   // Resets counter
76
    *(volatile cyg_uint16 *)CMA230_TC_PRELOAD = period;
77
    *(volatile cyg_uint16 *)CMA230_TC_ENABLE = 1;  // Starts timer    
78
    _period = period;
79
}
80
 
81
// This routine is called during a clock interrupt.
82
 
83
void hal_clock_reset(cyg_uint32 vector, cyg_uint32 period)
84
{
85
    if (period != _period) {
86
        *(volatile cyg_uint16 *)CMA230_TC_PRELOAD = period;
87
        _period = period;
88
    }
89
}
90
 
91
// Read the current value of the clock, returning the number of hardware "ticks"
92
// that have occurred (i.e. how far away the current value is from the start)
93
 
94
void hal_clock_read(cyg_uint32 *pvalue)
95
{
96
    volatile cyg_int16 *tcct = (volatile cyg_int16 *)CMA230_TC_COUNT;
97
    static cyg_int32 clock_val;
98
    clock_val = *tcct;                 // Register has only 16 bits
99
    *pvalue = (cyg_uint32)(_period - clock_val);    // 'clock_val' counts down and wraps
100
}
101
 
102
//
103
// Early stage hardware initialization
104
//   Some initialization has already been done before we get here.  For now
105
// just set up the interrupt environment.
106
 
107
// Note: The hardware interrupt mask (read) doesn't seem to give reliable results.
108
static cyg_uint8 _imrr;
109
#undef  CMA230_IMRr
110
#define CMA230_IMRr (&_imrr)
111
 
112
void hal_hardware_init(void)
113
{
114
#if 0
115
    // Clear and initialize instruction cache
116
    HAL_ICACHE_INVALIDATE_ALL();
117
    HAL_ICACHE_ENABLE();
118
#endif
119
    // Any hardware/platform initialization that needs to be done.
120
    // Reset all interrupt masks (disable all interrupt sources)
121
    *(volatile cyg_uint8 *)CMA230_IMRw = 0;
122
    *(volatile cyg_uint8 *)CMA230_CLR = 0xFF;  // Clear all current interrupts
123
 
124
    // Set up eCos/ROM interfaces
125
    hal_if_init();
126
}
127
 
128
//
129
// This routine is called to respond to a hardware interrupt (IRQ).  It
130
// should interrogate the hardware and return the IRQ vector number.
131
 
132
#if 0
133
// TEMP
134
int tot_ints;
135
cyg_uint32 int_PC[2048];
136
// TEMP
137
#endif
138
 
139
int hal_IRQ_handler(HAL_SavedRegisters *regs)
140
{
141
    volatile cyg_uint8 isr = *(volatile cyg_uint8 *)CMA230_ISR;
142
    volatile cyg_uint8 *imrr = (volatile cyg_uint8 *)CMA230_IMRr;
143
    int vector;
144
    isr &= *imrr;  // The Interrupt Source Register shows _all_ current
145
                   // interrupt sources, not just the enabled ones
146
#if 0
147
// TEMP
148
    int_PC[tot_ints++] = 0xFFFFFFFF;
149
    int_PC[tot_ints++] = isr;
150
    int_PC[tot_ints++] = regs->cpsr;
151
    int_PC[tot_ints++] = regs->pc;
152
    if (tot_ints == 2048) tot_ints = 0;
153
// TEMP
154
#endif
155
 
156
    for (vector = 0;  vector < 8;  vector++) {
157
        if (isr & (1<<vector)) {
158
            return (vector+1);
159
        }
160
    }
161
    return CYGNUM_HAL_INTERRUPT_NONE; // This shouldn't happen!
162
}
163
 
164
//
165
// Interrupt control
166
//
167
 
168
// Disable (mask) an interrupt
169
void hal_interrupt_mask(int vector)
170
{
171
    volatile cyg_uint8 *imrr = (volatile cyg_uint8 *)CMA230_IMRr;
172
    volatile cyg_uint8 *imrw = (volatile cyg_uint8 *)CMA230_IMRw;
173
    cyg_uint8 new_mask = *imrr & ~(1<<(vector-1));
174
    *imrw = new_mask;
175
// TEMP
176
    *imrr = new_mask;
177
// TEMP
178
//    diag_printf("Mask interrupt #%d - mask: %x\n", vector, *imrr);
179
}
180
 
181
// Enable (unmask) an interrupt
182
void hal_interrupt_unmask(int vector)
183
{
184
    volatile cyg_uint8 *imrr = (volatile cyg_uint8 *)CMA230_IMRr;
185
    volatile cyg_uint8 *imrw = (volatile cyg_uint8 *)CMA230_IMRw;
186
    cyg_uint8 new_mask = *imrr | (1<<(vector-1));
187
    *imrw = new_mask;
188
// TEMP
189
    *imrr = new_mask;
190
// TEMP
191
//    diag_printf("Unmask interrupt #%d - mask: %x\n", vector, *imrr);
192
}
193
 
194
void hal_interrupt_acknowledge(int vector)
195
{
196
    // These two vectors are "sticky" and must be reset
197
    if ((vector == CYGNUM_HAL_INTERRUPT_TIMER) ||
198
        (vector == CYGNUM_HAL_INTERRUPT_ABORT)) {
199
        *(volatile cyg_uint8 *)CMA230_CLR = (1<<(vector-1));
200
    }
201
}
202
 
203
void hal_interrupt_configure(int vector, int level, int up)
204
{
205
    // No interrupts are configurable on this hardware
206
}
207
 
208
void hal_interrupt_set_level(int vector, int level)
209
{
210
    // No interrupts are configurable on this hardware
211
}
212
 
213
/*------------------------------------------------------------------------*/
214
// EOF hal_misc.c

powered by: WebSVN 2.1.0

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