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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [h8300/] [h8300h/] [current/] [src/] [var_misc.c] - Blame information for rev 838

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      var_misc.c
4
//
5
//      HAL CPU variant miscellaneous functions
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):    ysato
43
// Contributors: ysato
44
// Date:         2002-03-01
45
// Purpose:      HAL miscellaneous functions
46
// Description:  This file contains miscellaneous functions provided by the
47
//               HAL.
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
#include <cyg/hal/var_arch.h>
59
#include <cyg/hal/var_intr.h>
60
#include <cyg/hal/hal_io.h>
61
 
62
/*------------------------------------------------------------------------*/
63
/* Variant specific initialization routine.                               */
64
 
65
void hal_variant_init(void)
66
{
67
}
68
 
69
struct int_regs {
70
    CYG_BYTE *ier;
71
    CYG_BYTE *isr;
72
    CYG_BYTE mask;
73
    CYG_BYTE status;
74
};
75
 
76
#define REGS_DEF(ier,isr,mask,status) \
77
        {(CYG_BYTE *)ier,(CYG_BYTE *)isr,mask,status}
78
 
79
const struct int_regs interrupt_registers[]= {
80
    REGS_DEF(CYGARC_IER,CYGARC_ISR,0x01,0x01),
81
    REGS_DEF(CYGARC_IER,CYGARC_ISR,0x02,0x02),
82
    REGS_DEF(CYGARC_IER,CYGARC_ISR,0x04,0x04),
83
    REGS_DEF(CYGARC_IER,CYGARC_ISR,0x08,0x08),
84
    REGS_DEF(CYGARC_IER,CYGARC_ISR,0x10,0x10),
85
    REGS_DEF(CYGARC_IER,CYGARC_ISR,0x20,0x20),
86
    REGS_DEF(CYGARC_IER,CYGARC_ISR,0x40,0x40),
87
    REGS_DEF(CYGARC_IER,CYGARC_ISR,0x80,0x80),
88
    REGS_DEF(CYGARC_TCSR,CYGARC_TCSR,0x20,0x80),
89
    REGS_DEF(CYGARC_RTMCSR,CYGARC_RTMCSR,0x40,0x80),
90
    REGS_DEF(NULL,NULL,0,0),
91
    REGS_DEF(CYGARC_ADCSR,CYGARC_ADCSR,0x40,0x80),
92
    REGS_DEF(CYGARC_TISRA,CYGARC_TISRA,0x10,0x01),
93
    REGS_DEF(CYGARC_TISRB,CYGARC_TISRB,0x10,0x01),
94
    REGS_DEF(CYGARC_TISRC,CYGARC_TISRC,0x10,0x01),
95
    REGS_DEF(NULL,NULL,0,0),
96
    REGS_DEF(CYGARC_TISRA,CYGARC_TISRA,0x20,0x02),
97
    REGS_DEF(CYGARC_TISRB,CYGARC_TISRB,0x20,0x02),
98
    REGS_DEF(CYGARC_TISRC,CYGARC_TISRC,0x20,0x02),
99
    REGS_DEF(NULL,NULL,0,0),
100
    REGS_DEF(CYGARC_TISRA,CYGARC_TISRA,0x40,0x04),
101
    REGS_DEF(CYGARC_TISRB,CYGARC_TISRB,0x40,0x04),
102
    REGS_DEF(CYGARC_TISRC,CYGARC_TISRC,0x40,0x04),
103
    REGS_DEF(NULL,NULL,0,0),
104
    REGS_DEF(CYGARC_8TCR0,CYGARC_8TCSR0,0x40,0x40),
105
    REGS_DEF(CYGARC_8TCR0,CYGARC_8TCSR0,0x80,0x80),
106
    REGS_DEF(CYGARC_8TCR1,CYGARC_8TCSR1,0xC0,0xC0),
107
    REGS_DEF(CYGARC_8TCR0,CYGARC_8TCSR0,0x20,0x20),
108
    REGS_DEF(CYGARC_8TCR2,CYGARC_8TCSR2,0x40,0x40),
109
    REGS_DEF(CYGARC_8TCR2,CYGARC_8TCSR2,0x80,0x80),
110
    REGS_DEF(CYGARC_8TCR3,CYGARC_8TCSR3,0xC0,0xC0),
111
    REGS_DEF(CYGARC_8TCR2,CYGARC_8TCSR2,0x20,0x20),
112
    REGS_DEF(CYGARC_DTCR0A,CYGARC_DTCR0A,0x08,0x80),
113
    REGS_DEF(CYGARC_DTCR0B,CYGARC_DTCR0B,0x08,0x80),
114
    REGS_DEF(CYGARC_DTCR1A,CYGARC_DTCR1A,0x08,0x80),
115
    REGS_DEF(CYGARC_DTCR1B,CYGARC_DTCR1B,0x08,0x80),
116
    REGS_DEF(NULL,NULL,0,0),
117
    REGS_DEF(NULL,NULL,0,0),
118
    REGS_DEF(NULL,NULL,0,0),
119
    REGS_DEF(NULL,NULL,0,0),
120
    REGS_DEF(CYGARC_SCR0,CYGARC_SSR0,0x40,0x30),
121
    REGS_DEF(CYGARC_SCR0,CYGARC_SSR0,0x40,0x40),
122
    REGS_DEF(CYGARC_SCR0,CYGARC_SSR0,0x80,0x80),
123
    REGS_DEF(CYGARC_SCR0,CYGARC_SSR0,0x04,0x04),
124
    REGS_DEF(CYGARC_SCR1,CYGARC_SSR1,0x40,0x30),
125
    REGS_DEF(CYGARC_SCR1,CYGARC_SSR1,0x40,0x40),
126
    REGS_DEF(CYGARC_SCR1,CYGARC_SSR1,0x80,0x80),
127
    REGS_DEF(CYGARC_SCR1,CYGARC_SSR1,0x04,0x04),
128
    REGS_DEF(CYGARC_SCR2,CYGARC_SSR2,0x40,0x30),
129
    REGS_DEF(CYGARC_SCR2,CYGARC_SSR2,0x40,0x40),
130
    REGS_DEF(CYGARC_SCR2,CYGARC_SSR2,0x80,0x80),
131
    REGS_DEF(CYGARC_SCR2,CYGARC_SSR2,0x04,0x04)
132
};
133
 
134
void
135
hal_interrupt_mask(int vector)
136
{
137
    CYG_BYTE ier;
138
    const struct int_regs *regs;
139
    if( vector < 12 )
140
        return;
141
    regs=&interrupt_registers[vector-12];
142
    if (vector == CYGNUM_HAL_INTERRUPT_WDT) {
143
        HAL_READ_UINT8(CYGARC_TCSR,ier);
144
        ier &= ~0x20;
145
        HAL_WRITE_UINT16(CYGARC_TCSR,0xa500 | ier);
146
    } else {
147
        if ((vector >= CYGNUM_HAL_INTERRUPT_EXTERNAL_0) && regs->ier) {
148
            HAL_READ_UINT8(regs->ier,ier);
149
            ier &= ~(regs->mask);
150
            HAL_WRITE_UINT8(regs->ier,ier);
151
        } else {
152
            CYG_FAIL("Unknown interrupt vector");
153
        }
154
    }
155
}
156
 
157
void
158
hal_interrupt_unmask(int vector)
159
{
160
    CYG_BYTE ier;
161
    const struct int_regs *regs;
162
    if( vector < 12 )
163
        return;
164
    regs=&interrupt_registers[vector-12];
165
    if (vector == CYGNUM_HAL_INTERRUPT_WDT) {
166
        HAL_READ_UINT8(CYGARC_TCSR,ier);
167
        ier |= 0x20;
168
        HAL_WRITE_UINT16(CYGARC_TCSR,0xa500 | ier);
169
    } else {
170
        if ((vector >= CYGNUM_HAL_INTERRUPT_EXTERNAL_0) && regs->ier) {
171
            HAL_READ_UINT8(regs->ier,ier);
172
            ier |= regs->mask;
173
            HAL_WRITE_UINT8(regs->ier,ier);
174
        } else {
175
            CYG_FAIL("Unknown interrupt vector");
176
        }
177
    }
178
}
179
 
180
void
181
hal_interrupt_acknowledge(int vector)
182
{
183
    CYG_BYTE isr;
184
    const struct int_regs *regs;
185
    if( vector < 12 )
186
        return;
187
    regs=&interrupt_registers[vector-12];
188
    if (vector >= CYGNUM_HAL_INTERRUPT_DEND0A &&
189
        vector <= CYGNUM_HAL_INTERRUPT_DEND1B)
190
        return;
191
    if (vector == CYGNUM_HAL_INTERRUPT_WDT) {
192
        HAL_READ_UINT8(CYGARC_TCSR,isr);
193
        isr &= ~0x80;
194
        HAL_WRITE_UINT16(CYGARC_TCSR,0xa500 | isr);
195
    } else {
196
        if ((vector >= CYGNUM_HAL_INTERRUPT_EXTERNAL_0) && regs->isr) {
197
            HAL_READ_UINT8(regs->isr,isr);
198
            isr &= ~(regs->status);
199
            HAL_WRITE_UINT8(regs->isr,isr);
200
        } else {
201
            CYG_FAIL("Unknown interrupt vector");
202
        }
203
    }
204
}
205
 
206
const char priority_table[]={
207
   7, 6, 5, 5, 4, 4,-1,-1,
208
   3, 3,-1, 3, 2, 2, 2, 2,
209
   1, 1, 1, 1, 0, 0, 0, 0,
210
  15,15,15,15,14,14,14,14,
211
  13,13,13,13,-1,-1,-1,-1,
212
  11,11,11,11,10,10,10,10,
213
   9,9,9,9
214
};
215
 
216
CYG_BYTE cyg_hal_level_table[64];
217
 
218
void
219
hal_interrupt_set_level(int vector,int level)
220
{
221
    CYG_BYTE *ipr;
222
    CYG_BYTE ipr_mask;
223
    int priority;
224
    if( vector < 12 )
225
        return;
226
    priority = priority_table[vector-12];
227
    ipr = (CYG_BYTE *)CYGARC_IPRA + ((priority & 0xf8) >> 3);
228
    if (priority>=0) {
229
        ipr_mask = 1 << (priority & 0x07);
230
        if (level == 0) {
231
            *ipr &= ~ipr_mask;
232
            cyg_hal_level_table[vector] = 0x00;
233
        } else {
234
            *ipr |= ipr_mask;
235
            cyg_hal_level_table[vector] = 0x80;
236
        }
237
    } else {
238
        CYG_FAIL("Unknown interrupt vector");
239
    }
240
}
241
 
242
void
243
hal_interrupt_configure(int vector,int level,int up)
244
{
245
    cyg_uint8 iscr,mask;
246
    if (vector >= CYGNUM_HAL_INTERRUPT_EXTERNAL_0 &&
247
        vector <= CYGNUM_HAL_INTERRUPT_EXTERNAL_7) {
248
        mask = 1 << (vector - CYGNUM_HAL_INTERRUPT_EXTERNAL_0);
249
        HAL_READ_UINT8(CYGARC_ISCR,iscr);
250
        if (level) {
251
            iscr &= ~mask;
252
        }
253
        if (up) {
254
            iscr |= mask;
255
        }
256
        CYG_ASSERT(!(up && level), "Cannot trigger on high level!");
257
        HAL_WRITE_UINT8(CYGARC_ISCR,iscr);
258
    }
259
}
260
 
261
/*------------------------------------------------------------------------*/
262
/* End of var_misc.c                                                      */

powered by: WebSVN 2.1.0

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