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 * 2008-12-11 XuXinming first version 9 * 2013-03-29 aozima Modify the interrupt interface implementations. 10 */ 11 12 #include <rtthread.h> 13 #include <rthw.h> 14 #include "LPC24xx.h" 15 16 #define MAX_HANDLERS 32 17 18 /* exception and interrupt handler table */ 19 struct rt_irq_desc irq_desc[MAX_HANDLERS]; 20 21 extern rt_uint32_t rt_interrupt_nest; 22 23 /* exception and interrupt handler table */ 24 rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread; 25 rt_uint32_t rt_thread_switch_interrupt_flag; 26 27 /** 28 * @addtogroup LPC2478 29 */ 30 /*@{*/ 31 void rt_hw_interrupt_handler(int vector, void *param) 32 { 33 rt_kprintf("Unhandled interrupt %d occured!!!\n", vector); 34 } 35 36 void rt_hw_interrupt_init(void) 37 { 38 register int i; 39 40 rt_uint32_t *vect_addr, *vect_cntl; 41 42 /* initialize VIC*/ 43 VICIntEnClr = 0xffffffff; 44 VICVectAddr = 0; 45 VICIntSelect = 0; 46 47 /* init exceptions table */ 48 rt_memset(irq_desc, 0x00, sizeof(irq_desc)); 49 for(i=0; i < MAX_HANDLERS; i++) 50 { 51 irq_desc[i].handler = rt_hw_interrupt_handler; 52 53 vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + i*4); 54 vect_cntl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + i*4); 55 *vect_addr = (rt_uint32_t)&irq_desc[i]; 56 *vect_cntl = 0xF; 57 } 58 59 /* init interrupt nest, and context in thread sp */ 60 rt_interrupt_nest = 0; 61 rt_interrupt_from_thread = 0; 62 rt_interrupt_to_thread = 0; 63 rt_thread_switch_interrupt_flag = 0; 64 } 65 66 void rt_hw_interrupt_mask(int vector) 67 { 68 VICIntEnClr = (1 << vector); 69 } 70 71 void rt_hw_interrupt_umask(int vector) 72 { 73 VICIntEnable = (1 << vector); 74 } 75 76 /** 77 * This function will install a interrupt service routine to a interrupt. 78 * @param vector the interrupt number 79 * @param handler the interrupt service routine to be installed 80 * @param param the parameter for interrupt service routine 81 * @name unused. 82 * 83 * @return the old handler 84 */ 85 rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler, 86 void *param, const char *name) 87 { 88 rt_isr_handler_t old_handler = RT_NULL; 89 90 if(vector >= 0 && vector < MAX_HANDLERS) 91 { 92 old_handler = irq_desc[vector].handler; 93 if (handler != RT_NULL) 94 { 95 irq_desc[vector].handler = handler; 96 irq_desc[vector].param = param; 97 } 98 } 99 100 return old_handler; 101 } 102 103 /*@}*/ 104