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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [OpenRISC_SIM_GCC/] [arch/] [interrupts.c] - Blame information for rev 799

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 621 filepang
/* This file is part of test microkernel for OpenRISC 1000. */
2
/* (C) 2001 Simon Srot, srot@opencores.org */
3
 
4
#include "support.h"
5 584 jeremybenn
#include "spr_defs.h"
6 621 filepang
#include "interrupts.h"
7 584 jeremybenn
 
8 621 filepang
/* Interrupt handlers table */
9
static struct ihnd int_handlers[MAX_INT_HANDLERS];
10
 
11
/* Initialize routine */
12
int int_init(void) {
13
        int i;
14
 
15
        // initialize Interrupt handler table
16
        for(i = 0; i < MAX_INT_HANDLERS; i++) {
17
                int_handlers[i].handler = 0;
18
                int_handlers[i].arg = 0;
19
        }
20
 
21
        // mask all interrupt
22
        mtspr(SPR_PICMR, 0x00000000);
23
 
24
        // set OR1200 to accept exceptions (external interrupt enable)
25
        mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
26
 
27
        return 0;
28
}
29
 
30
/* Add interrupt handler */
31
int int_add(unsigned long vect, void (* handler)(void *), void *arg) {
32
        if(vect >= MAX_INT_HANDLERS)
33
                return -1;
34
 
35
        int_handlers[vect].handler = handler;
36
        int_handlers[vect].arg = arg;
37
 
38
        mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << vect));
39
 
40
        return 0;
41
}
42
 
43
/* Disable interrupt */
44
int int_disable(unsigned long vect) {
45
        if(vect >= MAX_INT_HANDLERS)
46
                return -1;
47
 
48
        mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(0x00000001L << vect));
49
 
50
        return 0;
51
}
52
 
53
/* Enable interrupt */
54
int int_enable(unsigned long vect) {
55
        if(vect >= MAX_INT_HANDLERS)
56
                return -1;
57
 
58
        mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << vect));
59
 
60
        return 0;
61
}
62
 
63
/* Main interrupt handler */
64
void int_main(void) {
65 799 filepang
        unsigned long picsr;
66
        unsigned long i;
67
 
68
        // vPortDisableInterrupts();    
69
        picsr = mfspr(SPR_PICSR);   // process only the interrupts asserted at signal catch, ignore all during process
70
        i = 0;
71 621 filepang
        while(i < 32) {
72
                if((picsr & (0x01L << i)) && (int_handlers[i].handler != 0)) {
73
                        (*int_handlers[i].handler)(int_handlers[i].arg);
74
                }
75
                i++;
76
        }
77
 
78
        mtspr(SPR_PICSR, 0);     // clear interrupt status: all modules have level interrupts, which have to be cleared by software,
79 799 filepang
                                // thus this is safe, since non processed interrupts will get re-asserted soon enough
80 621 filepang
 
81 799 filepang
        // vPortEnableInterrupts();     
82
}
83
 
84 584 jeremybenn
// Dummy or32 except vectors
85 799 filepang
static void stall(void) {
86
        while(1);
87
}
88
 
89 584 jeremybenn
void buserr_except(void) {
90 799 filepang
        unsigned long epcr = mfspr(SPR_EPCR_BASE);
91
        unsigned long eear = mfspr(SPR_EEAR_BASE);
92
 
93 584 jeremybenn
        uart_print_str("buserr_except\n\r");
94 799 filepang
        uart_print_str("\n\r");
95
        uart_print_int(epcr);
96
        uart_print_str("\n\r");
97
        uart_print_str("\n\r");
98
        uart_print_int(eear);
99
        uart_print_str("\n\r");
100
        report(epcr);
101
        report(eear);
102
        stall();
103 584 jeremybenn
}
104
 
105
void dpf_except(void) {
106
        uart_print_str("dpf_except\n\r");
107
}
108
 
109
void ipf_except(void) {
110
        uart_print_str("ipf_except\n\r");
111
}
112
 
113
void align_except(void) {
114 799 filepang
        unsigned long epcr = mfspr(SPR_EPCR_BASE);
115
        unsigned long eear = mfspr(SPR_EEAR_BASE);
116
 
117 584 jeremybenn
        uart_print_str("align_except\n\r");
118 799 filepang
        uart_print_str("\n\r");
119
        uart_print_int(epcr);
120
        uart_print_str("\n\r");
121
        uart_print_str("\n\r");
122
        uart_print_int(eear);
123
        uart_print_str("\n\r");
124
        report(epcr);
125
        report(eear);
126
        stall();
127 584 jeremybenn
}
128
 
129
void illegal_except(void) {
130
        uart_print_str("illegal_except\n\r");
131
}
132
 
133
void dtlbmiss_except(void) {
134
        uart_print_str("dtlbmiss_except\n\r");
135
}
136
 
137
void itlbmiss_except(void) {
138
        uart_print_str("itlbmiss_except\n\r");
139
}
140
 
141
void range_except(void) {
142
        uart_print_str("range_except\n\r");
143
}
144
 
145 621 filepang
void res1_except(void) {
146
        uart_print_str("res1_except\n\r");
147
}
148
 
149
void trap_except(void) {
150
        uart_print_str("trap_except\n\r");
151
}
152
 
153
void res2_except(void) {
154
        uart_print_str("res2_except\n\r");
155
}
156
 
157
void misc_int_handler(int arg) {
158
        switch(arg) {
159
        case 0x200: { buserr_except();   break; }
160
        case 0x300: { dpf_except();              break; }
161
        case 0x400: { ipf_except();      break; }
162
        case 0x600: { align_except();    break; }
163
        case 0x700: { illegal_except();  break; }
164
        case 0x900: { dtlbmiss_except(); break; }
165
        case 0xa00: { itlbmiss_except(); break; }
166
        case 0xb00: { range_except();    break; }
167
        case 0xd00: { res1_except();     break; }
168
        case 0xe00: { trap_except();     break; }
169
        case 0xf00: { res2_except();     break; }
170
        default: { break; }
171
        }
172
}
173
 
174 584 jeremybenn
static void syscall_enter_critical(void) {
175
        unsigned int exception_sr = mfspr(SPR_ESR_BASE);
176
        exception_sr &= (~SPR_SR_IEE);          // disable all external interrupt
177
        exception_sr &= (~SPR_SR_TEE);          // disable tick timer interrupt
178
 
179
        mtspr(SPR_ESR_BASE, exception_sr);
180
}
181
 
182
static void syscall_exit_critical(void) {
183
        unsigned int exception_sr = mfspr(SPR_ESR_BASE);
184
        exception_sr |= SPR_SR_IEE;             // enable all external interrupt
185
        exception_sr |= SPR_SR_TEE;             // enable tick timer interrupt
186
 
187
        mtspr(SPR_ESR_BASE, exception_sr);
188
}
189
 
190
void syscall_except(int id) {
191 621 filepang
        if(id == 0x0FCC) {
192
                vTaskSwitchContext();
193
        } else if(id == 0x0FCE) {
194 584 jeremybenn
                syscall_enter_critical();
195
        } else if(id == 0x0FCF) {
196
                syscall_exit_critical();
197
        } else {
198 621 filepang
                uart_print_int(id);
199 584 jeremybenn
                uart_print_str(" syscall is not impelmented yet....\n\r");
200
        }
201
}
202
 

powered by: WebSVN 2.1.0

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