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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [openrisc/] [arch/] [current/] [include/] [hal_intr.h] - Blame information for rev 791

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      hal_intr.h
4
//
5
//      HAL Interrupt and clock support
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):    sfurman
43
// Contributors: 
44
// Date:         2003-01-24
45
// Purpose:      Define Interrupt support
46
// Description:  The macros defined here provide the HAL APIs for handling
47
//               both external interrupts and clock interrupts.
48
//              
49
// Usage:
50
//              #include <cyg/hal/hal_intr.h>
51
//              ...
52
//              
53
//
54
//####DESCRIPTIONEND####
55
//
56
//==========================================================================
57
 
58
#ifndef CYGONCE_HAL_HAL_INTR_H
59
#define CYGONCE_HAL_HAL_INTR_H
60
 
61
#include <cyg/hal/hal_arch.h>
62
 
63
//--------------------------------------------------------------------------
64
// OpenRISC vectors. 
65
 
66
// These are the exception/interrupt causes defined by the hardware.
67
// These values are the ones to use for HAL_VSR_GET/SET
68
 
69
// Reset
70
#define CYGNUM_HAL_VECTOR_RESET                0x01
71
 
72
// Bus Error - probably invalid physical address
73
#define CYGNUM_HAL_VECTOR_BUS_ERROR            0x02
74
 
75
// Either no matching page-table entry or protection fault
76
// while executing load/store operation
77
#define CYGNUM_HAL_VECTOR_DATA_PAGE_FAULT      0x03
78
 
79
// Either no matching page-table entry or protection fault
80
// while fetching instruction
81
#define CYGNUM_HAL_VECTOR_INSTR_PAGE_FAULT     0x04
82
 
83
// Tick Timer interrupt
84
#define CYGNUM_HAL_VECTOR_TICK_TIMER           0x05
85
 
86
// Unaligned access
87
#define CYGNUM_HAL_VECTOR_UNALIGNED_ACCESS     0x06
88
 
89
// Illegal instruction
90
#define CYGNUM_HAL_VECTOR_RESERVED_INSTRUCTION 0x07
91
 
92
// External Interrupt from PIC
93
#define CYGNUM_HAL_VECTOR_INTERRUPT            0x08
94
 
95
// D-TLB Miss
96
#define CYGNUM_HAL_VECTOR_DTLB_MISS            0x09
97
 
98
// I-TLB Miss
99
#define CYGNUM_HAL_VECTOR_ITLB_MISS            0x0A
100
 
101
// Numeric overflow, etc.
102
#define CYGNUM_HAL_VECTOR_RANGE                0x0B
103
 
104
// System Call
105
#define CYGNUM_HAL_VECTOR_SYSTEM_CALL          0x0C
106
 
107
// TRAP instruction executed
108
#define CYGNUM_HAL_VECTOR_TRAP                 0x0E
109
 
110
#define CYGNUM_HAL_VSR_MIN                     CYGNUM_HAL_VECTOR_RESET
111
#define CYGNUM_HAL_VSR_MAX                     CYGNUM_HAL_VECTOR_TRAP
112
#define CYGNUM_HAL_VSR_COUNT                   (CYGNUM_HAL_VSR_MAX-CYGNUM_HAL_VSR_MIN+1)
113
 
114
// Exception vectors. These are the values used when passed out to an
115
// external exception handler using cyg_hal_deliver_exception()
116
 
117
#define CYGNUM_HAL_EXCEPTION_DATA_TLBMISS_ACCESS \
118
          CYGNUM_HAL_VECTOR_DTLB_MISS
119
#define CYGNUM_HAL_EXCEPTION_DATA_TLBMISS_ACCESS \
120
          CYGNUM_HAL_VECTOR_DTLB_MISS
121
#define CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS \
122
          CYGNUM_HAL_VECTOR_UNALIGNED_ACCESS
123
#define CYGNUM_HAL_EXCEPTION_SYSTEM_CALL    CYGNUM_HAL_VECTOR_SYSTEM_CALL
124
#define CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION \
125
          CYGNUM_HAL_VECTOR_RESERVED_INSTRUCTION
126
#define CYGNUM_HAL_EXCEPTION_OVERFLOW       CYGNUM_HAL_VECTOR_RANGE
127
#define CYGNUM_HAL_EXCEPTION_INTERRUPT      CYGNUM_HAL_VECTOR_INTERRUPT
128
 
129
// Min/Max exception numbers and how many there are
130
#define CYGNUM_HAL_EXCEPTION_MIN                CYGNUM_HAL_VSR_MIN
131
#define CYGNUM_HAL_EXCEPTION_MAX                CYGNUM_HAL_VSR_MAX
132
#define CYGNUM_HAL_EXCEPTION_COUNT           \
133
                 ( CYGNUM_HAL_EXCEPTION_MAX - CYGNUM_HAL_EXCEPTION_MIN + 1 )
134
 
135
 
136
#ifndef CYGHWR_HAL_INTERRUPT_VECTORS_DEFINED
137
#define CYGHWR_HAL_INTERRUPT_VECTORS_DEFINED
138
 
139
// Interrupts 0-31 are connected to the PIC
140
#define CYGNUM_HAL_INTERRUPT_0                0
141
#define CYGNUM_HAL_INTERRUPT_1                1
142
#define CYGNUM_HAL_INTERRUPT_2                2
143
#define CYGNUM_HAL_INTERRUPT_3                3
144
#define CYGNUM_HAL_INTERRUPT_4                4
145
#define CYGNUM_HAL_INTERRUPT_5                5
146
#define CYGNUM_HAL_INTERRUPT_6                6
147
#define CYGNUM_HAL_INTERRUPT_7                7
148
#define CYGNUM_HAL_INTERRUPT_8                8
149
#define CYGNUM_HAL_INTERRUPT_9                9
150
#define CYGNUM_HAL_INTERRUPT_10               10
151
#define CYGNUM_HAL_INTERRUPT_11               11
152
#define CYGNUM_HAL_INTERRUPT_12               12
153
#define CYGNUM_HAL_INTERRUPT_13               13
154
#define CYGNUM_HAL_INTERRUPT_14               14
155
#define CYGNUM_HAL_INTERRUPT_15               15
156
#define CYGNUM_HAL_INTERRUPT_16               16
157
#define CYGNUM_HAL_INTERRUPT_17               17
158
#define CYGNUM_HAL_INTERRUPT_18               18
159
#define CYGNUM_HAL_INTERRUPT_19               19
160
#define CYGNUM_HAL_INTERRUPT_20               20
161
#define CYGNUM_HAL_INTERRUPT_21               21
162
#define CYGNUM_HAL_INTERRUPT_22               22
163
#define CYGNUM_HAL_INTERRUPT_23               23
164
#define CYGNUM_HAL_INTERRUPT_24               24
165
#define CYGNUM_HAL_INTERRUPT_25               25
166
#define CYGNUM_HAL_INTERRUPT_26               26
167
#define CYGNUM_HAL_INTERRUPT_27               27
168
#define CYGNUM_HAL_INTERRUPT_28               28
169
#define CYGNUM_HAL_INTERRUPT_29               29
170
#define CYGNUM_HAL_INTERRUPT_30               30
171
#define CYGNUM_HAL_INTERRUPT_31               31
172
 
173
// By SW convention, interrupt #32 is the tick timer
174
#define CYGNUM_HAL_INTERRUPT_32               32
175
 
176
// The interrupt vector used by the RTC, aka tick timer
177
#define CYGNUM_HAL_INTERRUPT_RTC            CYGNUM_HAL_INTERRUPT_32
178
 
179
// Min/Max ISR numbers and how many there are
180
#define CYGNUM_HAL_ISR_MIN                     0
181
#define CYGNUM_HAL_ISR_MAX                     32
182
#define CYGNUM_HAL_ISR_COUNT                   33
183
 
184
#endif
185
 
186
#ifndef __ASSEMBLER__
187
#include <pkgconf/hal.h>
188
 
189
#include <cyg/infra/cyg_type.h>
190
#include <cyg/hal/hal_io.h>
191
 
192
#include <cyg/hal/plf_intr.h>
193
 
194
//--------------------------------------------------------------------------
195
// Static data used by HAL
196
 
197
// ISR tables
198
externC volatile CYG_ADDRESS    hal_interrupt_handlers[CYGNUM_HAL_ISR_COUNT];
199
externC volatile CYG_ADDRWORD   hal_interrupt_data[CYGNUM_HAL_ISR_COUNT];
200
externC volatile CYG_ADDRESS    hal_interrupt_objects[CYGNUM_HAL_ISR_COUNT];
201
 
202
// VSR table
203
externC volatile CYG_ADDRESS    hal_vsr_table[CYGNUM_HAL_VSR_MAX+1];
204
 
205
//--------------------------------------------------------------------------
206
// Default ISR
207
// The #define is used to test whether this routine exists, and to allow
208
// us to call it.
209
 
210
externC cyg_uint32 hal_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data);
211
 
212
#define HAL_DEFAULT_ISR hal_default_isr
213
 
214
//--------------------------------------------------------------------------
215
// Interrupt state storage
216
 
217
typedef cyg_uint32 CYG_INTERRUPT_STATE;
218
 
219
//--------------------------------------------------------------------------
220
// Interrupt control macros
221
#ifndef CYGHWR_HAL_INTERRUPT_ENABLE_DISABLE_RESTORE_DEFINED
222
 
223
// Clear both tick timer and external interrupts in the Supervisor Register
224
#define HAL_DISABLE_INTERRUPTS(_old_)                     \
225
    CYG_MACRO_START                                       \
226
    _old_ = MFSPR(SPR_SR);                                \
227
    MTSPR(SPR_SR, _old_ & ~(SPR_SR_IEE|SPR_SR_TEE));      \
228
    CYG_MACRO_END
229
 
230
// Enable both tick timer and external interrupts in the Supervisor Register
231
#define HAL_ENABLE_INTERRUPTS()                           \
232
    MTSPR(SPR_SR, MFSPR(SPR_SR) | (SPR_SR_IEE|SPR_SR_TEE))
233
 
234
// Copy interrupt flags from argument into Supervisor Register
235
#define HAL_RESTORE_INTERRUPTS(_old_)                     \
236
    CYG_MACRO_START                                       \
237
    cyg_uint32 t1,t2;                                     \
238
    t1 = MFSPR(SPR_SR) & ~(SPR_SR_IEE|SPR_SR_TEE);        \
239
    t2 = (_old_) & (SPR_SR_IEE|SPR_SR_TEE);               \
240
    MTSPR(SPR_SR, t1 | t2);                               \
241
    CYG_MACRO_END
242
 
243
#define HAL_QUERY_INTERRUPTS( _state_ )                   \
244
    CYG_MACRO_START                                       \
245
    _state = MFSPR(SPR_SR);                               \
246
    CYG_MACRO_END
247
 
248
#endif // CYGHWR_HAL_INTERRUPT_ENABLE_DISABLE_RESTORE_DEFINED
249
 
250
//--------------------------------------------------------------------------
251
// Routine to execute DSRs using separate interrupt stack
252
 
253
#ifdef  CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
254
externC void hal_interrupt_stack_call_pending_DSRs(void);
255
#define HAL_INTERRUPT_STACK_CALL_PENDING_DSRS() \
256
    hal_interrupt_stack_call_pending_DSRs()
257
 
258
// these are offered solely for stack usage testing
259
// if they are not defined, then there is no interrupt stack.
260
#define HAL_INTERRUPT_STACK_BASE cyg_interrupt_stack_base
261
#define HAL_INTERRUPT_STACK_TOP  cyg_interrupt_stack
262
// use them to declare these extern however you want:
263
//       extern char HAL_INTERRUPT_STACK_BASE[];
264
//       extern char HAL_INTERRUPT_STACK_TOP[];
265
// is recommended
266
#endif
267
 
268
//--------------------------------------------------------------------------
269
// Vector translation.
270
// For chained interrupts we only have a single vector though which all
271
// are passed. For unchained interrupts we have a vector per interrupt.
272
 
273
#ifndef HAL_TRANSLATE_VECTOR
274
 
275
#if defined(CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN)
276
 
277
#define HAL_TRANSLATE_VECTOR(_vector_,_index_) (_index_) = 0
278
 
279
#else
280
 
281
#define HAL_TRANSLATE_VECTOR(_vector_,_index_) (_index_) = (_vector_)
282
 
283
#endif
284
 
285
#endif
286
 
287
//--------------------------------------------------------------------------
288
// Interrupt and VSR attachment macros
289
 
290
#define HAL_INTERRUPT_IN_USE( _vector_, _state_)                          \
291
    CYG_MACRO_START                                                       \
292
    cyg_uint32 _index_;                                                   \
293
    HAL_TRANSLATE_VECTOR ((_vector_), _index_);                           \
294
                                                                          \
295
    if( hal_interrupt_handlers[_index_] == (CYG_ADDRESS)HAL_DEFAULT_ISR ) \
296
        (_state_) = 0;                                                    \
297
    else                                                                  \
298
        (_state_) = 1;                                                    \
299
    CYG_MACRO_END
300
 
301
#define HAL_INTERRUPT_ATTACH( _vector_, _isr_, _data_, _object_ )           \
302
{                                                                           \
303
    cyg_uint32 _index_;                                                     \
304
    HAL_TRANSLATE_VECTOR( _vector_, _index_ );                              \
305
                                                                            \
306
    if( hal_interrupt_handlers[_index_] == (CYG_ADDRESS)HAL_DEFAULT_ISR )   \
307
    {                                                                       \
308
        hal_interrupt_handlers[_index_] = (CYG_ADDRESS)_isr_;               \
309
        hal_interrupt_data[_index_] = (CYG_ADDRWORD)_data_;                 \
310
        hal_interrupt_objects[_index_] = (CYG_ADDRESS)_object_;             \
311
    }                                                                       \
312
}
313
 
314
#define HAL_INTERRUPT_DETACH( _vector_, _isr_ )                         \
315
{                                                                       \
316
    cyg_uint32 _index_;                                                 \
317
    HAL_TRANSLATE_VECTOR( _vector_, _index_ );                          \
318
                                                                        \
319
    if( hal_interrupt_handlers[_index_] == (CYG_ADDRESS)_isr_ )         \
320
    {                                                                   \
321
        hal_interrupt_handlers[_index_] = (CYG_ADDRESS)HAL_DEFAULT_ISR; \
322
        hal_interrupt_data[_index_] = 0;                                \
323
        hal_interrupt_objects[_index_] = 0;                             \
324
    }                                                                   \
325
}
326
 
327
#define HAL_VSR_GET( _vector_, _pvsr_ )                 \
328
    *(_pvsr_) = (void (*)())hal_vsr_table[_vector_];
329
 
330
 
331
#define HAL_VSR_SET( _vector_, _vsr_, _poldvsr_ ) CYG_MACRO_START         \
332
    if( (void*)_poldvsr_ != NULL)                                         \
333
        *(CYG_ADDRESS *)_poldvsr_ = (CYG_ADDRESS)hal_vsr_table[_vector_]; \
334
    hal_vsr_table[_vector_] = (CYG_ADDRESS)_vsr_;                         \
335
CYG_MACRO_END
336
 
337
// This is an ugly name, but what it means is: grab the VSR back to eCos
338
// internal handling, or if you like, the default handler.  But if
339
// cooperating with GDB and CygMon, the default behaviour is to pass most
340
// exceptions to CygMon.  This macro undoes that so that eCos handles the
341
// exception.  So use it with care.
342
 
343
externC void cyg_hal_default_exception_vsr(void);
344
externC void cyg_hal_default_interrupt_vsr(void);
345
 
346
#define HAL_VSR_SET_TO_ECOS_HANDLER( _vector_, _poldvsr_ ) CYG_MACRO_START  \
347
    HAL_VSR_SET( _vector_, _vector_ == CYGNUM_HAL_VECTOR_INTERRUPT          \
348
                              ? (CYG_ADDRESS)cyg_hal_default_interrupt_vsr  \
349
                              : (CYG_ADDRESS)cyg_hal_default_exception_vsr, \
350
                 _poldvsr_ );                                               \
351
CYG_MACRO_END
352
 
353
//--------------------------------------------------------------------------
354
// Interrupt controller access
355
 
356
#ifndef CYGHWR_HAL_INTERRUPT_CONTROLLER_ACCESS_DEFINED
357
#define CYGHWR_HAL_INTERRUPT_CONTROLLER_ACCESS_DEFINED
358
 
359
// Mask (disable) interrupts from specified source
360
#define HAL_INTERRUPT_MASK( _vector_ )            \
361
CYG_MACRO_START                                   \
362
    int mask;                                     \
363
    if ((_vector_) == CYGNUM_HAL_INTERRUPT_RTC) { \
364
        /* The tick timer interrupt isn't */      \
365
        /* controlled by the PIC; It has its own*/\
366
        /* enable bit in the SR. */               \
367
        MTSPR(SPR_SR, MFSPR(SPR_SR)& ~SPR_SR_TEE);\
368
    } else {                                      \
369
        mask = ~(1 << (_vector_));                \
370
        MTSPR(SPR_PICMR, MFSPR(SPR_PICMR)& mask); \
371
    }                                             \
372
CYG_MACRO_END
373
 
374
// Allow interrupts from specified source
375
#define HAL_INTERRUPT_UNMASK( _vector_ )          \
376
CYG_MACRO_START                                   \
377
    int bit;                                      \
378
    if ((_vector_) == CYGNUM_HAL_INTERRUPT_RTC) { \
379
        /* The tick timer interrupt isn't */      \
380
        /* controlled by the PIC; It has its own*/\
381
        /* enable bit in the SR. */               \
382
        MTSPR(SPR_SR, MFSPR(SPR_SR) | SPR_SR_TEE);\
383
    } else {                                      \
384
        bit = (1 << (_vector_));                  \
385
        MTSPR(SPR_PICMR, MFSPR(SPR_PICMR) | bit); \
386
    }                                             \
387
CYG_MACRO_END
388
 
389
// Reset interrupt request in the PIC for specified device
390
#define HAL_INTERRUPT_ACKNOWLEDGE( _vector_ )     \
391
CYG_MACRO_START                                   \
392
    int mask;                                     \
393
    if ((_vector_) != CYGNUM_HAL_INTERRUPT_RTC) { \
394
        mask = ~(1 << (_vector_));                \
395
        MTSPR(SPR_PICSR, MFSPR(SPR_PICSR) & mask);\
396
    }                                             \
397
CYG_MACRO_END
398
 
399
#define HAL_INTERRUPT_CONFIGURE( _vector_, _level_, _up_ ) CYG_EMPTY_STATEMENT
400
 
401
#define HAL_INTERRUPT_SET_LEVEL( _vector_, _level_ )  CYG_EMPTY_STATEMENT
402
 
403
#endif
404
 
405
//--------------------------------------------------------------------------
406
// Clock control.
407
 
408
externC CYG_WORD32 cyg_hal_clock_period;
409
#define CYGHWR_HAL_CLOCK_PERIOD_DEFINED
410
 
411
// Start tick timer interrupts
412
#define HAL_CLOCK_INITIALIZE( _period_ )        \
413
CYG_MACRO_START                                 \
414
{                                               \
415
    int ttmr_new = _period_ | 0x60000000;       \
416
    MTSPR(SPR_TTMR, 0);                         \
417
    MTSPR(SPR_TTCR, 0);                         \
418
    MTSPR(SPR_TTMR, ttmr_new);                  \
419
    cyg_hal_clock_period = _period_;            \
420
}                                               \
421
CYG_MACRO_END
422
 
423
// Acknowledge clock timer interrupt
424
#define HAL_CLOCK_RESET( _vector_, _period_ )   \
425
CYG_MACRO_START                                 \
426
    int ttmr_new = _period_ | 0x60000000;       \
427
    MTSPR(SPR_TTMR, ttmr_new);                  \
428
CYG_MACRO_END
429
 
430
// Read the current value of the tick timer
431
#define HAL_CLOCK_READ( _pvalue_ )              \
432
CYG_MACRO_START                                 \
433
    *(_pvalue_) = MFSPR(SPR_TTCR);              \
434
CYG_MACRO_END
435
 
436
#if defined(CYGVAR_KERNEL_COUNTERS_CLOCK_LATENCY) && \
437
    !defined(HAL_CLOCK_LATENCY)
438
#define HAL_CLOCK_LATENCY( _pvalue_ )                   \
439
CYG_MACRO_START                                         \
440
    register CYG_WORD32 _cval_;                         \
441
    HAL_CLOCK_READ(&_cval_);                            \
442
    *(_pvalue_) = _cval_ - cyg_hal_clock_period;        \
443
CYG_MACRO_END
444
#endif
445
 
446
 
447
//--------------------------------------------------------------------------
448
// Microsecond delay function provided in hal_misc.c
449
externC void hal_delay_us(int us);
450
 
451
#define HAL_DELAY_US(n)          hal_delay_us(n)
452
 
453
#endif /* #ifndef __ASSEMBLER__ */
454
 
455
//--------------------------------------------------------------------------
456
#endif // ifndef CYGONCE_HAL_HAL_INTR_H
457
// End of hal_intr.h

powered by: WebSVN 2.1.0

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