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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      e7t_misc.c
4
//
5
//      HAL misc board support code for ARM E7T
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):    gthomas
43
// Contributors: gthomas, jskov
44
// Date:         2001-03-16
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_cache.h>
63
#include <cyg/hal/hal_if.h>             // calling interface
64
#include <cyg/hal/hal_misc.h>           // helper functions
65
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
66
#include <cyg/hal/drv_api.h>            // HAL ISR support
67
#endif
68
#include <cyg/hal/plf_io.h>             // platform registers
69
 
70
static cyg_uint32 _period;
71
 
72
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
73
static cyg_interrupt abort_interrupt;
74
static cyg_handle_t  abort_interrupt_handle;
75
 
76
// This ISR is called only for the Abort button interrupt
77
static int
78
e7t_abort_isr(cyg_vector_t vector, cyg_addrword_t data, HAL_SavedRegisters *regs)
79
{
80
    cyg_hal_user_break((CYG_ADDRWORD*)regs);
81
    cyg_drv_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_EXT0);
82
    return 0;  // No need to run DSR
83
}
84
#endif
85
 
86
void hal_clock_initialize(cyg_uint32 period)
87
{
88
    cyg_uint32 tmod;
89
 
90
    // Disable timer 0
91
    HAL_READ_UINT32(E7T_TMOD, tmod);
92
    tmod &= ~(E7T_TMOD_TE0);
93
    HAL_WRITE_UINT32(E7T_TMOD, 0);
94
 
95
    tmod &= ~(E7T_TMOD_TMD0 | E7T_TMOD_TCLR0);
96
    tmod |= E7T_TMOD_TE0;
97
 
98
    // Set counter
99
    HAL_WRITE_UINT32(E7T_TDATA0, period);
100
 
101
    // And enable timer
102
    HAL_WRITE_UINT32(E7T_TMOD, tmod);
103
 
104
    _period = period;
105
 
106
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
107
    cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_EXT0,
108
                             99,           // Priority
109
                             0,            // Data item passed to interrupt handler
110
                             e7t_abort_isr,
111
                             0,
112
                             &abort_interrupt_handle,
113
                             &abort_interrupt);
114
    cyg_drv_interrupt_attach(abort_interrupt_handle);
115
    cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_EXT0);
116
#endif
117
}
118
 
119
void hal_clock_reset(cyg_uint32 vector, cyg_uint32 period)
120
{
121
    _period = period;
122
}
123
 
124
void hal_clock_read(cyg_uint32 *pvalue)
125
{
126
    cyg_uint32 value;
127
 
128
    HAL_READ_UINT32(E7T_TCNT0, value);
129
    *pvalue = _period - value;
130
}
131
 
132
// -------------------------------------------------------------------------
133
//
134
// Delay for some number of micro-seconds
135
//
136
void hal_delay_us(cyg_int32 usecs)
137
{
138
    cyg_uint32 count;
139
    cyg_uint32 ticks = ((CYGNUM_HAL_RTC_PERIOD*CYGNUM_HAL_RTC_DENOMINATOR)/1000000) * usecs;
140
    cyg_uint32 tmod;
141
 
142
    // Disable timer 1
143
    HAL_READ_UINT32(E7T_TMOD, tmod);
144
    tmod &= ~(E7T_TMOD_TE1);
145
    HAL_WRITE_UINT32(E7T_TMOD, tmod);
146
 
147
    tmod &= ~(E7T_TMOD_TMD1 | E7T_TMOD_TCLR1);
148
    tmod |= E7T_TMOD_TE1;
149
 
150
    // Clear pending flag
151
    HAL_WRITE_UINT32(E7T_INTPND, (1 << CYGNUM_HAL_INTERRUPT_TIMER1));
152
 
153
    // Set counter
154
    HAL_WRITE_UINT32(E7T_TDATA1, ticks);
155
 
156
    // And enable timer
157
    HAL_WRITE_UINT32(E7T_TMOD, tmod);
158
 
159
    // Wait for timer to underflow. Can't test the timer completion
160
    // bit without actually enabling the interrupt. So instead watch
161
    // the counter.
162
    ticks /= 2;                         // wait for this threshold
163
 
164
    // Wait till timer counts below threshold
165
    do {
166
        HAL_READ_UINT32(E7T_TCNT1, count);
167
    } while (count >= ticks);
168
    // then wait for it to be reloaded
169
    do {
170
        HAL_READ_UINT32(E7T_TCNT1, count);
171
    } while (count < ticks);
172
 
173
    // Then disable timer 1 again
174
    tmod &= ~E7T_TMOD_TE1;
175
    HAL_WRITE_UINT32(E7T_TMOD, tmod);
176
}
177
 
178
// -------------------------------------------------------------------------
179
// Hardware init
180
void hal_hardware_init(void)
181
{
182
    cyg_uint32 intmask;
183
 
184
    // Set up eCos/ROM interfaces
185
    hal_if_init();
186
 
187
    // Enable cache
188
    HAL_WRITE_UINT32(E7T_SYSCFG,
189
                     0x07FFFF80|E7T_SYSCFG_CM_0R_8C|E7T_SYSCFG_WE);
190
    HAL_UCACHE_INVALIDATE_ALL();
191
    HAL_UCACHE_ENABLE();
192
 
193
    // Clear global interrupt mask bit
194
    HAL_READ_UINT32(E7T_INTMSK, intmask);
195
    intmask &= ~E7T_INTMSK_GLOBAL;
196
    HAL_WRITE_UINT32(E7T_INTMSK, intmask);
197
}
198
 
199
//
200
// This routine is called to respond to a hardware interrupt (IRQ).  It
201
// should interrogate the hardware and return the IRQ vector number.
202
 
203
int hal_IRQ_handler(void)
204
{
205
    // Do hardware-level IRQ handling
206
    cyg_uint32 irq_status;
207
    HAL_READ_UINT32(E7T_INTOFFSET_IRQ, irq_status);
208
    irq_status = irq_status / 4;
209
    if (CYGNUM_HAL_ISR_MAX >= irq_status)
210
        return irq_status;
211
    // It's a bit bogus to test for FIQs after IRQs, but we use the
212
    // latter more, so don't impose the overhead of checking for FIQs
213
    HAL_READ_UINT32(E7T_INTOFFSET_FIQ, irq_status);
214
    irq_status = irq_status / 4;
215
    if (CYGNUM_HAL_ISR_MAX >= irq_status)
216
        return irq_status;
217
    return CYGNUM_HAL_INTERRUPT_NONE;
218
}
219
 
220
//
221
// Interrupt control
222
//
223
 
224
void hal_interrupt_mask(int vector)
225
{
226
    cyg_uint32 mask, old_mask;
227
    HAL_READ_UINT32(E7T_INTMSK, mask);
228
    old_mask = mask;
229
    mask |= (1<<vector);
230
    HAL_WRITE_UINT32(E7T_INTMSK, mask);
231
}
232
 
233
void hal_interrupt_unmask(int vector)
234
{
235
    cyg_uint32 mask, old_mask;
236
    HAL_READ_UINT32(E7T_INTMSK, mask);
237
    old_mask = mask;
238
    mask &= ~(1<<vector);
239
    HAL_WRITE_UINT32(E7T_INTMSK, mask);
240
}
241
 
242
void hal_interrupt_acknowledge(int vector)
243
{
244
    HAL_WRITE_UINT32(E7T_INTPND, (1<<vector));
245
}
246
 
247
void hal_interrupt_configure(int vector, int level, int up)
248
{
249
}
250
 
251
void hal_interrupt_set_level(int vector, int level)
252
{
253
}
254
 
255
void hal_show_IRQ(int vector, int data, int handler)
256
{
257
}
258
 
259
//--------------------------------------------------------------------------
260
// EOF hal_misc.c

powered by: WebSVN 2.1.0

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