1 /* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2006-08-23 Bernard first version 9 */ 10 11 #include <rtthread.h> 12 #include "AT91SAM7S.h" 13 14 #define MAX_HANDLERS 32 15 16 extern rt_uint32_t rt_interrupt_nest; 17 18 rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread; 19 rt_uint32_t rt_thread_switch_interrupt_flag; 20 21 /** 22 * @addtogroup AT91SAM7 23 */ 24 /*@{*/ 25 rt_hw_interrupt_handler(int vector)26void rt_hw_interrupt_handler(int vector) 27 { 28 rt_kprintf("Unhandled interrupt %d occured!!!\n", vector); 29 } 30 31 /** 32 * This function will initialize hardware interrupt 33 */ rt_hw_interrupt_init()34void rt_hw_interrupt_init() 35 { 36 rt_base_t index; 37 38 for (index = 0; index < MAX_HANDLERS; index ++) 39 { 40 AT91C_AIC_SVR(index) = (rt_uint32_t)rt_hw_interrupt_handler; 41 } 42 43 /* init interrupt nest, and context in thread sp */ 44 rt_interrupt_nest = 0; 45 rt_interrupt_from_thread = 0; 46 rt_interrupt_to_thread = 0; 47 rt_thread_switch_interrupt_flag = 0; 48 } 49 50 /** 51 * This function will mask a interrupt. 52 * @param vector the interrupt number 53 */ rt_hw_interrupt_mask(int vector)54void rt_hw_interrupt_mask(int vector) 55 { 56 /* disable interrupt */ 57 AT91C_AIC_IDCR = 1 << vector; 58 59 /* clear interrupt */ 60 AT91C_AIC_ICCR = 1 << vector; 61 } 62 63 /** 64 * This function will un-mask a interrupt. 65 * @param vector the interrupt number 66 */ rt_hw_interrupt_umask(int vector)67void rt_hw_interrupt_umask(int vector) 68 { 69 AT91C_AIC_IECR = 1 << vector; 70 } 71 72 /** 73 * This function will install a interrupt service routine to a interrupt. 74 * @param vector the interrupt number 75 * @param new_handler the interrupt service routine to be installed 76 * @param old_handler the old interrupt service routine 77 */ rt_hw_interrupt_install(int vector,rt_isr_handler_t new_handler,rt_isr_handler_t * old_handler)78void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler) 79 { 80 if(vector >= 0 && vector < MAX_HANDLERS) 81 { 82 if (*old_handler != RT_NULL) *old_handler = (rt_isr_handler_t)AT91C_AIC_SVR(vector); 83 if (new_handler != RT_NULL) AT91C_AIC_SVR(vector) = (rt_uint32_t)new_handler; 84 } 85 } 86 87 /*@}*/ 88