| 1 |
2 |
idiolatrie |
/******************************************************************************
|
| 2 |
|
|
* Interrupts *
|
| 3 |
|
|
******************************************************************************
|
| 4 |
|
|
* Copyright (C)2011 Mathias Hörtnagl <mathias.hoertnagl@gmail.com> *
|
| 5 |
|
|
* *
|
| 6 |
|
|
* This program is free software: you can redistribute it and/or modify *
|
| 7 |
|
|
* it under the terms of the GNU General Public License as published by *
|
| 8 |
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
| 9 |
|
|
* (at your option) any later version. *
|
| 10 |
|
|
* *
|
| 11 |
|
|
* This program is distributed in the hope that it will be useful, *
|
| 12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
| 14 |
|
|
* GNU General Public License for more details. *
|
| 15 |
|
|
* *
|
| 16 |
|
|
* You should have received a copy of the GNU General Public License *
|
| 17 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
| 18 |
|
|
******************************************************************************/
|
| 19 |
|
|
#include "stddef.h"
|
| 20 |
|
|
#include "interrupt.h"
|
| 21 |
|
|
|
| 22 |
|
|
/* Holds all interrupt callback routines. */
|
| 23 |
|
|
static callback irq_callbacks[8];
|
| 24 |
|
|
|
| 25 |
|
|
|
| 26 |
|
|
/******************************************************************************
|
| 27 |
|
|
* Status Register Operations *
|
| 28 |
|
|
******************************************************************************/
|
| 29 |
|
|
/* Set interrupts of mask. */
|
| 30 |
|
|
void set_intr(ushort mask) {
|
| 31 |
|
|
__asm__(
|
| 32 |
|
|
"mfc0 $k0, $12 \n\t"
|
| 33 |
|
|
"or $k0, $k0, $a0 \n\t"
|
| 34 |
|
|
"mtc0 $k0, $12 \n\t"
|
| 35 |
|
|
);
|
| 36 |
|
|
}
|
| 37 |
|
|
|
| 38 |
|
|
/* Unset interrupts of mask. */
|
| 39 |
|
|
void unset_intr(ushort mask) {
|
| 40 |
|
|
__asm__(
|
| 41 |
|
|
"mfc0 $k0, $12 \n\t"
|
| 42 |
|
|
"nor $k1, $0, $a0 \n\t" // Negate mask.
|
| 43 |
|
|
"and $k0, $k0, $k1 \n\t" // Turn off those, that are set in mask.
|
| 44 |
|
|
"mtc0 $k0, $12 \n\t"
|
| 45 |
|
|
);
|
| 46 |
|
|
}
|
| 47 |
|
|
|
| 48 |
|
|
|
| 49 |
|
|
/******************************************************************************
|
| 50 |
|
|
* Callback Functions *
|
| 51 |
|
|
******************************************************************************/
|
| 52 |
|
|
/* Registers a callback routine at some interrupt line. The interrupt line
|
| 53 |
|
|
can be one out of IRQ_0 - IRQ_7. */
|
| 54 |
|
|
void register_callback(int irq_line, callback c) {
|
| 55 |
|
|
irq_callbacks[irq_line] = c;
|
| 56 |
|
|
}
|
| 57 |
|
|
|
| 58 |
|
|
/* Set a interrupt callback to NULL. If a interrupt callback points to NULL,
|
| 59 |
|
|
the interrupt will be ignored. */
|
| 60 |
|
|
void free_callback(int irq_line) {
|
| 61 |
|
|
irq_callbacks[irq_line] = NULL;
|
| 62 |
|
|
}
|
| 63 |
|
|
|
| 64 |
|
|
/* Call the interrupt routines one by one starting with the interrupt at INTR_0
|
| 65 |
|
|
(or IRQ_0). Interrupts with NULL interrupt routines are ignored. */
|
| 66 |
|
|
void intr_dispatch(uchar irq) {
|
| 67 |
|
|
|
| 68 |
|
|
// Iterate through all interrupt lines.
|
| 69 |
|
|
for(int i=0; i<8; i++) {
|
| 70 |
|
|
|
| 71 |
|
|
// Check if callback function is defined.
|
| 72 |
|
|
// Check if there exists a pending interrupt.
|
| 73 |
|
|
if( ((*irq_callbacks[i]) != NULL) && (irq & 0x1) ) {
|
| 74 |
|
|
(*irq_callbacks[i])();
|
| 75 |
|
|
}
|
| 76 |
|
|
irq >>= 1;
|
| 77 |
|
|
}
|
| 78 |
|
|
}
|