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@196 | 35 | gpio_init_irq(); |
paul@84 | 36 | init_interrupts(); |
paul@68 | 37 | } |
paul@68 | 38 | |
paul@68 | 39 | void irq_handle() |
paul@68 | 40 | { |
paul@68 | 41 | /* Check interrupt identity. */ |
paul@68 | 42 | |
paul@68 | 43 | if (REG_INTC_IPR & (1 << TIMER_CHAN_IRQ)) { |
paul@68 | 44 | |
paul@68 | 45 | /* Clear interrupt status. */ |
paul@68 | 46 | |
paul@153 | 47 | timer_clear(); |
paul@196 | 48 | } |
paul@196 | 49 | |
paul@196 | 50 | /* GPIO interrupts. */ |
paul@196 | 51 | |
paul@196 | 52 | if (REG_INTC_IPR & (1 << GPIO_IRQ)) { |
paul@196 | 53 | |
paul@196 | 54 | /* Check for the power button. */ |
paul@196 | 55 | |
paul@196 | 56 | if (gpio_have_irq(GPIO_POWER)) { |
paul@196 | 57 | |
paul@196 | 58 | /* Switch task. */ |
paul@196 | 59 | |
paul@196 | 60 | switch_task(); |
paul@196 | 61 | |
paul@196 | 62 | /* Clear interrupt status. */ |
paul@196 | 63 | |
paul@196 | 64 | gpio_clear(GPIO_POWER); |
paul@196 | 65 | } |
paul@196 | 66 | } |
paul@68 | 67 | |
paul@68 | 68 | /* Handle other interrupts, anyway. */ |
paul@68 | 69 | |
paul@196 | 70 | irq_clear(); |
paul@68 | 71 | } |