Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Travis Geiselbrecht |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #include <err.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <kernel/thread.h> |
| 26 | #include <platform.h> |
| 27 | #include <platform/interrupts.h> |
| 28 | #include <platform/at91sam7.h> |
| 29 | #include <arch/arm.h> |
| 30 | |
| 31 | static int do_nothing() |
| 32 | { |
| 33 | return INT_NO_RESCHEDULE; |
| 34 | } |
| 35 | |
| 36 | void platform_init_interrupts(void) |
| 37 | { |
| 38 | AT91AIC *aic = AT91AIC_ADDR; |
| 39 | int n; |
| 40 | |
| 41 | for(n = 0; n < 31; n++) { |
| 42 | aic->SVR[n] = (unsigned) do_nothing; |
| 43 | } |
| 44 | aic->SPU = (unsigned) do_nothing; |
| 45 | } |
| 46 | |
| 47 | |
Travis Geiselbrecht | f1cdea3 | 2008-09-13 14:13:54 -0700 | [diff] [blame] | 48 | status_t mask_interrupt(unsigned int vector) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 49 | { |
| 50 | AT91AIC *aic = AT91AIC_ADDR; |
| 51 | |
| 52 | if(vector > 31) return ERR_INVALID_ARGS; |
| 53 | |
Travis Geiselbrecht | f1cdea3 | 2008-09-13 14:13:54 -0700 | [diff] [blame] | 54 | aic->IDCR = (1 << vector); |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 55 | |
| 56 | return NO_ERROR; |
| 57 | } |
| 58 | |
Travis Geiselbrecht | f1cdea3 | 2008-09-13 14:13:54 -0700 | [diff] [blame] | 59 | status_t unmask_interrupt(unsigned int vector) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 60 | { |
| 61 | AT91AIC *aic = AT91AIC_ADDR; |
| 62 | if(vector > 31) return ERR_INVALID_ARGS; |
| 63 | |
Travis Geiselbrecht | f1cdea3 | 2008-09-13 14:13:54 -0700 | [diff] [blame] | 64 | aic->IECR = (1 << vector); |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 65 | |
| 66 | return NO_ERROR; |
| 67 | } |
| 68 | |
| 69 | void platform_irq(struct arm_iframe *frame) |
| 70 | { |
| 71 | AT91AIC *aic = AT91AIC_ADDR; |
| 72 | int_handler func; |
| 73 | enum handler_return ret; |
| 74 | |
| 75 | inc_critical_section(); |
| 76 | |
| 77 | func = (int_handler) aic->IVR; |
| 78 | // dprintf("platform_irq() -> %p\n", func); |
| 79 | |
| 80 | ret = func(0); |
| 81 | |
| 82 | aic->EOICR = (unsigned) aic; |
| 83 | |
| 84 | if(ret == INT_RESCHEDULE) { |
| 85 | thread_preempt(); |
| 86 | } |
| 87 | |
| 88 | dec_critical_section(); |
| 89 | } |
| 90 | |
| 91 | void platform_fiq(struct arm_iframe *frame) |
| 92 | { |
| 93 | } |
| 94 | |
| 95 | void register_int_handler(unsigned int vector, int_handler handler, void *arg) |
| 96 | { |
| 97 | AT91AIC *aic = AT91AIC_ADDR; |
| 98 | if(vector > 31) return; |
| 99 | aic->SVR[vector] = (unsigned) handler; |
| 100 | } |