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-03-13 Bernard first version 9 * 2013-03-29 aozima Modify the interrupt interface implementations. 10 */ 11 12 #include <rtthread.h> 13 #include <rthw.h> 14 #include <sep4020.h> 15 16 #define MAX_HANDLERS 32 17 18 extern rt_uint32_t rt_interrupt_nest; 19 20 /* exception and interrupt handler table */ 21 struct rt_irq_desc isr_table[MAX_HANDLERS]; 22 rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread; 23 rt_uint32_t rt_thread_switch_interrupt_flag; 24 25 /** 26 * @addtogroup S3C24X0 27 */ 28 /*@{*/ 29 30 static void rt_hw_interrupt_handle(int vector, void *param) 31 { 32 rt_kprintf("Unhandled interrupt %d occured!!!\n", vector); 33 } 34 35 /** 36 * This function will initialize hardware interrupt 37 */ 38 void rt_hw_interrupt_init(void) 39 { 40 register rt_uint32_t idx; 41 42 /*Make sure all intc registers in proper state*/ 43 44 /*mask all the irq*/ 45 *(RP)(INTC_IMR) = 0xFFFFFFFF; 46 47 /*enable all the irq*/ 48 *(RP)(INTC_IER) = 0XFFFFFFFF; 49 50 /*Dont use any forced irq*/ 51 *(RP)(INTC_IFR) = 0x0; 52 53 /*Disable all the fiq*/ 54 *(RP)(INTC_FIER) = 0x0; 55 56 /*Mask all the fiq*/ 57 *(RP)(INTC_FIMR) = 0x0F; 58 59 /*Dont use forced fiq*/ 60 *(RP)(INTC_FIFR) = 0x0; 61 62 /*Intrrupt priority register*/ 63 *(RP)(INTC_IPLR) = 0x0; 64 65 /* init exceptions table */ 66 rt_memset(isr_table, 0x00, sizeof(isr_table)); 67 for(idx=0; idx < MAX_HANDLERS; idx++) 68 { 69 isr_table[idx].handler = rt_hw_interrupt_handle; 70 } 71 72 /* init interrupt nest, and context in thread sp */ 73 rt_interrupt_nest = 0; 74 rt_interrupt_from_thread = 0; 75 rt_interrupt_to_thread = 0; 76 rt_thread_switch_interrupt_flag = 0; 77 } 78 79 /** 80 * This function will mask a interrupt. 81 * @param vector the interrupt number 82 */ 83 void rt_hw_interrupt_mask(int vector) 84 { 85 *(RP)(INTC_IMR) |= 1 << vector; 86 } 87 88 /** 89 * This function will un-mask a interrupt. 90 * @param vector the interrupt number 91 */ 92 void rt_hw_interrupt_umask(int vector) 93 { 94 if(vector == 16) 95 { 96 rt_kprintf("Interrupt vec %d is not used!\n", vector); 97 } 98 else 99 *(RP)(INTC_IMR) &= ~(1 << vector); 100 } 101 102 103 /** 104 * This function will install a interrupt service routine to a interrupt. 105 * @param vector the interrupt number 106 * @param new_handler the interrupt service routine to be installed 107 * @param old_handler the old interrupt service routine 108 */ 109 rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler, 110 void *param, const char *name) 111 { 112 rt_isr_handler_t old_handler = RT_NULL; 113 114 if(vector < MAX_HANDLERS) 115 { 116 old_handler = isr_table[vector].handler; 117 118 if (handler != RT_NULL) 119 { 120 #ifdef RT_USING_INTERRUPT_INFO 121 rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX); 122 #endif /* RT_USING_INTERRUPT_INFO */ 123 isr_table[vector].handler = handler; 124 isr_table[vector].param = param; 125 } 126 } 127 128 return old_handler; 129 } 130 131 /*@}*/ 132