paul@68 | 1 | /* |
paul@68 | 2 | * Interrupt handling. |
paul@68 | 3 | * |
paul@121 | 4 | * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> |
paul@68 | 5 | * |
paul@68 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@68 | 7 | * it under the terms of the GNU General Public License as published by |
paul@68 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@68 | 9 | * (at your option) any later version. |
paul@68 | 10 | * |
paul@68 | 11 | * This program is distributed in the hope that it will be useful, |
paul@68 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@68 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@68 | 14 | * GNU General Public License for more details. |
paul@68 | 15 | * |
paul@68 | 16 | * You should have received a copy of the GNU General Public License |
paul@68 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@68 | 18 | */ |
paul@68 | 19 | |
paul@155 | 20 | #include "board-defs.h" |
paul@108 | 21 | |
paul@154 | 22 | #include "init.h" |
paul@68 | 23 | #include "board.h" |
paul@68 | 24 | #include "cpu.h" |
paul@186 | 25 | #include "cpu_op.h" |
paul@121 | 26 | #include "irq.h" |
paul@156 | 27 | #include "tasks.h" |
paul@68 | 28 | |
paul@68 | 29 | /* Initialisation and handling. */ |
paul@68 | 30 | |
paul@68 | 31 | void irq_init() |
paul@68 | 32 | { |
paul@136 | 33 | handle_error_level(); |
paul@68 | 34 | timer_init_irq(); |
paul@84 | 35 | init_interrupts(); |
paul@68 | 36 | } |
paul@68 | 37 | |
paul@68 | 38 | void irq_handle() |
paul@68 | 39 | { |
paul@68 | 40 | unsigned short i; |
paul@68 | 41 | |
paul@68 | 42 | /* Check interrupt identity. */ |
paul@68 | 43 | |
paul@68 | 44 | if (REG_INTC_IPR & (1 << TIMER_CHAN_IRQ)) { |
paul@68 | 45 | |
paul@133 | 46 | /* Switch task. */ |
paul@68 | 47 | |
paul@143 | 48 | switch_task(); |
paul@68 | 49 | |
paul@68 | 50 | /* Clear interrupt status. */ |
paul@68 | 51 | |
paul@153 | 52 | timer_clear(); |
paul@68 | 53 | |
paul@68 | 54 | /* Handle other interrupts, anyway. */ |
paul@68 | 55 | |
paul@68 | 56 | } else { |
paul@68 | 57 | for (i = 0; i < 32; i++) { |
paul@68 | 58 | if (REG_INTC_IPR & (1 << i)) |
paul@68 | 59 | __intc_ack_irq(i); |
paul@68 | 60 | } |
paul@68 | 61 | } |
paul@68 | 62 | } |