From fbc1b05dd8c07fb95d9d02a476a604252dbc7ac3 Mon Sep 17 00:00:00 2001 From: aozima Date: Sat, 23 Mar 2013 16:38:13 +0800 Subject: update mini2440: Modify the interrupt interface implementations. --- libcpu/arm/s3c24x0/interrupt.c | 79 +++++++++++++++++++++++++----------------- libcpu/arm/s3c24x0/trap.c | 35 +++++++++++-------- 2 files changed, 68 insertions(+), 46 deletions(-) (limited to 'libcpu') diff --git a/libcpu/arm/s3c24x0/interrupt.c b/libcpu/arm/s3c24x0/interrupt.c index 18cdbaa09f..df0c1406d3 100644 --- a/libcpu/arm/s3c24x0/interrupt.c +++ b/libcpu/arm/s3c24x0/interrupt.c @@ -10,9 +10,11 @@ * Change Logs: * Date Author Notes * 2006-03-13 Bernard first version + * 2013-03-29 aozima Modify the interrupt interface implementations. */ #include +#include #include "s3c24x0.h" #define MAX_HANDLERS 32 @@ -20,7 +22,7 @@ extern rt_uint32_t rt_interrupt_nest; /* exception and interrupt handler table */ -rt_isr_handler_t isr_table[MAX_HANDLERS]; +struct rt_irq_desc isr_table[MAX_HANDLERS]; rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread; rt_uint32_t rt_thread_switch_interrupt_flag; @@ -29,10 +31,9 @@ rt_uint32_t rt_thread_switch_interrupt_flag; */ /*@{*/ -rt_isr_handler_t rt_hw_interrupt_handle(rt_uint32_t vector) +static void rt_hw_interrupt_handle(int vector, void *param) { rt_kprintf("Unhandled interrupt %d occured!!!\n", vector); - return RT_NULL; } /** @@ -40,37 +41,38 @@ rt_isr_handler_t rt_hw_interrupt_handle(rt_uint32_t vector) */ void rt_hw_interrupt_init(void) { - register rt_uint32_t idx; + register rt_uint32_t idx; - /* all clear source pending */ - SRCPND = 0x0; + /* all clear source pending */ + SRCPND = 0x0; - /* all clear sub source pending */ - SUBSRCPND = 0x0; + /* all clear sub source pending */ + SUBSRCPND = 0x0; - /* all=IRQ mode */ - INTMOD = 0x0; + /* all=IRQ mode */ + INTMOD = 0x0; - /* all interrupt disabled include global bit */ - INTMSK = BIT_ALLMSK; + /* all interrupt disabled include global bit */ + INTMSK = BIT_ALLMSK; - /* all sub interrupt disable */ - INTSUBMSK = BIT_SUB_ALLMSK; + /* all sub interrupt disable */ + INTSUBMSK = BIT_SUB_ALLMSK; - /* all clear interrupt pending */ - INTPND = BIT_ALLMSK; + /* all clear interrupt pending */ + INTPND = BIT_ALLMSK; - /* init exceptions table */ - for(idx=0; idx < MAX_HANDLERS; idx++) - { - isr_table[idx] = (rt_isr_handler_t)rt_hw_interrupt_handle; - } + /* init exceptions table */ + rt_memset(isr_table, 0x00, sizeof(isr_table)); + for(idx=0; idx < MAX_HANDLERS; idx++) + { + isr_table[idx].handler = rt_hw_interrupt_handle; + } - /* init interrupt nest, and context in thread sp */ - rt_interrupt_nest = 0; - rt_interrupt_from_thread = 0; - rt_interrupt_to_thread = 0; - rt_thread_switch_interrupt_flag = 0; + /* init interrupt nest, and context in thread sp */ + rt_interrupt_nest = 0; + rt_interrupt_from_thread = 0; + rt_interrupt_to_thread = 0; + rt_thread_switch_interrupt_flag = 0; } /** @@ -105,13 +107,26 @@ void rt_hw_interrupt_umask(int vector) * @param new_handler the interrupt service routine to be installed * @param old_handler the old interrupt service routine */ -void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler) +rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler, + void *param, char *name) { - if(vector < MAX_HANDLERS) - { - if (old_handler != RT_NULL) *old_handler = isr_table[vector]; - if (new_handler != RT_NULL) isr_table[vector] = new_handler; - } + rt_isr_handler_t old_handler = RT_NULL; + + if(vector < MAX_HANDLERS) + { + old_handler = isr_table[vector].handler; + + if (handler != RT_NULL) + { +#ifdef RT_USING_INTERRUPT_INFO + rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX); +#endif /* RT_USING_INTERRUPT_INFO */ + isr_table[vector].handler = handler; + isr_table[vector].param = param; + } + } + + return old_handler; } /*@}*/ diff --git a/libcpu/arm/s3c24x0/trap.c b/libcpu/arm/s3c24x0/trap.c index bdeae9aab0..f1c81768c9 100644 --- a/libcpu/arm/s3c24x0/trap.c +++ b/libcpu/arm/s3c24x0/trap.c @@ -12,6 +12,7 @@ * 2006-03-13 Bernard first version * 2006-05-27 Bernard add skyeye support * 2007-11-19 Yi.Qiu fix rt_hw_trap_irq function + * 2013-03-29 aozima Modify the interrupt interface implementations. */ #include @@ -140,29 +141,35 @@ void rt_hw_trap_resv(struct rt_hw_register *regs) rt_hw_cpu_shutdown(); } -extern rt_isr_handler_t isr_table[]; +extern struct rt_irq_desc isr_table[]; -void rt_hw_trap_irq() +void rt_hw_trap_irq(void) { - unsigned long intstat; - rt_isr_handler_t isr_func; + unsigned long irq; + rt_isr_handler_t isr_func; + void *param; - intstat = INTOFFSET; + irq = INTOFFSET; - if (intstat == INTGLOBAL) return; + if (irq == INTGLOBAL) return; - /* get interrupt service routine */ - isr_func = isr_table[intstat]; + /* get interrupt service routine */ + isr_func = isr_table[irq].handler; + param = isr_table[irq].param; - /* turn to interrupt service routine */ - isr_func(intstat); + /* turn to interrupt service routine */ + isr_func(irq, param); - /* clear pending register */ - /* note: must be the last, if not, may repeat*/ - ClearPending(1 << intstat); + /* clear pending register */ + /* note: must be the last, if not, may repeat*/ + ClearPending(1 << irq); + +#ifdef RT_USING_INTERRUPT_INFO + isr_table[irq].counter++; +#endif /* RT_USING_INTERRUPT_INFO */ } -void rt_hw_trap_fiq() +void rt_hw_trap_fiq(void) { rt_kprintf("fast interrupt request\n"); } -- cgit v1.3.1 From 29a3ae43680f50123dbe045605093b2c0fe9616e Mon Sep 17 00:00:00 2001 From: aozima Date: Sat, 23 Mar 2013 17:03:09 +0800 Subject: update sep4020: Modify the interrupt interface implementations. --- bsp/mini4020/drivers/board.c | 11 +++--- bsp/mini4020/drivers/dm9161.c | 6 +-- bsp/mini4020/rtconfig.h | 1 + bsp/mini4020/template.Uv2 | 4 +- libcpu/arm/sep4020/interrupt.c | 86 ++++++++++++++++++++++++------------------ libcpu/arm/sep4020/trap.c | 50 +++++++++++++----------- 6 files changed, 91 insertions(+), 67 deletions(-) (limited to 'libcpu') diff --git a/bsp/mini4020/drivers/board.c b/bsp/mini4020/drivers/board.c index b8341b8054..72b75d4846 100644 --- a/bsp/mini4020/drivers/board.c +++ b/bsp/mini4020/drivers/board.c @@ -34,7 +34,7 @@ struct serial_device uart0 = /** * This function will handle rtos timer */ -void rt_timer_handler(int vector) +void rt_timer_handler(int vector, void *param) { rt_uint32_t clear_int; rt_tick_increase(); @@ -47,7 +47,7 @@ void rt_timer_handler(int vector) /** * This function will handle serial */ -void rt_serial_handler(int vector) +void rt_serial_handler(int vector, void *param) { //rt_kprintf("in rt_serial_handler\n"); rt_int32_t stat = *(RP)UART0_IIR ; @@ -78,16 +78,17 @@ static void rt_hw_board_led_init(void) *(RP)GPIO_PORTE_DATA &= ~0x38; /* low */ } + /** * This function will init timer4 for system ticks */ - void rt_hw_timer_init(void) +void rt_hw_timer_init(void) { /*Set timer1*/ *(RP)TIMER_T1LCR = 880000; *(RP)TIMER_T1CR = 0x06; - rt_hw_interrupt_install(INTSRC_TIMER1, rt_timer_handler, RT_NULL); + rt_hw_interrupt_install(INTSRC_TIMER1, rt_timer_handler, RT_NULL, "tick"); rt_hw_interrupt_umask(INTSRC_TIMER1); /*Enable timer1*/ @@ -119,7 +120,7 @@ void rt_hw_uart_init(void) /*Disable tx interrupt*/ *(RP)(UART0_IER) &= ~(0x1<<1); - rt_hw_interrupt_install(INTSRC_UART0, rt_serial_handler, RT_NULL); + rt_hw_interrupt_install(INTSRC_UART0, rt_serial_handler, RT_NULL, "UART0"); rt_hw_interrupt_umask(INTSRC_UART0); /* register uart0 */ rt_hw_serial_register(&uart0_device, "uart0", diff --git a/bsp/mini4020/drivers/dm9161.c b/bsp/mini4020/drivers/dm9161.c index ea8294575d..2b02650dde 100644 --- a/bsp/mini4020/drivers/dm9161.c +++ b/bsp/mini4020/drivers/dm9161.c @@ -81,7 +81,7 @@ struct rt_dm9161_eth static struct rt_dm9161_eth dm9161_device; static struct rt_semaphore sem_ack, sem_lock; -void rt_dm9161_isr(int irqno); +void rt_dm9161_isr(int irqno, void *param); static void udelay(unsigned long ns) { @@ -201,7 +201,7 @@ static void read_phy(unsigned char phy_addr, unsigned char address, unsigned int } /* interrupt service routine */ -void rt_dm9161_isr(int irqno) +void rt_dm9161_isr(int irqno, void *param) { unsigned long intstatus; rt_uint32_t address; @@ -469,7 +469,7 @@ static rt_err_t rt_dm9161_open(rt_device_t dev, rt_uint16_t oflag) *(volatile unsigned long*)GPIO_PORTA_INTRCLR |= 0x0080; //Çå³ýÖÐ¶Ï *(volatile unsigned long*)GPIO_PORTA_INTRCLR = 0x0000; //Çå³ýÖÐ¶Ï - rt_hw_interrupt_install(INTSRC_MAC, rt_dm9161_isr, RT_NULL); + rt_hw_interrupt_install(INTSRC_MAC, rt_dm9161_isr, RT_NULL, "EMAC"); enable_irq(INTSRC_EXINT7); diff --git a/bsp/mini4020/rtconfig.h b/bsp/mini4020/rtconfig.h index 2f0060b6aa..9385fe0056 100644 --- a/bsp/mini4020/rtconfig.h +++ b/bsp/mini4020/rtconfig.h @@ -20,6 +20,7 @@ /* #define RT_THREAD_DEBUG */ #define RT_USING_OVERFLOW_CHECK +#define RT_USING_INTERRUPT_INFO /* Using Hook */ #define RT_USING_HOOK diff --git a/bsp/mini4020/template.Uv2 b/bsp/mini4020/template.Uv2 index 6ad293a7b3..c64e205761 100644 --- a/bsp/mini4020/template.Uv2 +++ b/bsp/mini4020/template.Uv2 @@ -31,14 +31,14 @@ Options 1,0,0 // Target 'RT-Thread_Mini4020' EnvReg () OrgReg () TgStat=16 - OutDir (.\) + OutDir (.\build\) OutName (rtthread-mini4020) GenApp=1 GenLib=0 GenHex=0 Debug=1 Browse=0 - LstDir (.\) + LstDir (.\build\) HexSel=1 MG32K=0 TGMORE=0 diff --git a/libcpu/arm/sep4020/interrupt.c b/libcpu/arm/sep4020/interrupt.c index 8ed22dc816..88130c1a33 100644 --- a/libcpu/arm/sep4020/interrupt.c +++ b/libcpu/arm/sep4020/interrupt.c @@ -10,9 +10,11 @@ * Change Logs: * Date Author Notes * 2006-03-13 Bernard first version + * 2013-03-29 aozima Modify the interrupt interface implementations. */ #include +#include #include #define MAX_HANDLERS 32 @@ -20,7 +22,7 @@ extern rt_uint32_t rt_interrupt_nest; /* exception and interrupt handler table */ -rt_isr_handler_t isr_table[MAX_HANDLERS]; +struct rt_irq_desc isr_table[MAX_HANDLERS]; rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread; rt_uint32_t rt_thread_switch_interrupt_flag; @@ -38,44 +40,45 @@ rt_isr_handler_t rt_hw_interrupt_handle(rt_uint32_t vector) /** * This function will initialize hardware interrupt */ -void rt_hw_interrupt_init() +void rt_hw_interrupt_init(void) { - register rt_uint32_t idx; + register rt_uint32_t idx; - /*Make sure all intc registers in proper state*/ + /*Make sure all intc registers in proper state*/ - /*mask all the irq*/ - *(RP)(INTC_IMR) = 0xFFFFFFFF; + /*mask all the irq*/ + *(RP)(INTC_IMR) = 0xFFFFFFFF; - /*enable all the irq*/ - *(RP)(INTC_IER) = 0XFFFFFFFF; + /*enable all the irq*/ + *(RP)(INTC_IER) = 0XFFFFFFFF; - /*Dont use any forced irq*/ - *(RP)(INTC_IFR) = 0x0; + /*Dont use any forced irq*/ + *(RP)(INTC_IFR) = 0x0; - /*Disable all the fiq*/ - *(RP)(INTC_FIER) = 0x0; + /*Disable all the fiq*/ + *(RP)(INTC_FIER) = 0x0; - /*Mask all the fiq*/ - *(RP)(INTC_FIMR) = 0x0F; + /*Mask all the fiq*/ + *(RP)(INTC_FIMR) = 0x0F; - /*Dont use forced fiq*/ - *(RP)(INTC_FIFR) = 0x0; + /*Dont use forced fiq*/ + *(RP)(INTC_FIFR) = 0x0; - /*Intrrupt priority register*/ - *(RP)(INTC_IPLR) = 0x0; + /*Intrrupt priority register*/ + *(RP)(INTC_IPLR) = 0x0; - /* init exceptions table */ - for(idx=0; idx < MAX_HANDLERS; idx++) - { - isr_table[idx] = (rt_isr_handler_t)rt_hw_interrupt_handle; - } + /* init exceptions table */ + rt_memset(isr_table, 0x00, sizeof(isr_table)); + for(idx=0; idx < MAX_HANDLERS; idx++) + { + isr_table[idx].handler = rt_hw_interrupt_handle; + } - /* init interrupt nest, and context in thread sp */ - rt_interrupt_nest = 0; - rt_interrupt_from_thread = 0; - rt_interrupt_to_thread = 0; - rt_thread_switch_interrupt_flag = 0; + /* init interrupt nest, and context in thread sp */ + rt_interrupt_nest = 0; + rt_interrupt_from_thread = 0; + rt_interrupt_to_thread = 0; + rt_thread_switch_interrupt_flag = 0; } /** @@ -108,15 +111,26 @@ void rt_hw_interrupt_umask(rt_uint32_t vector) * @param new_handler the interrupt service routine to be installed * @param old_handler the old interrupt service routine */ -void rt_hw_interrupt_install(rt_uint32_t vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler) +rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler, + void *param, char *name) { - if(vector < MAX_HANDLERS) - { - if (*old_handler != RT_NULL) - *old_handler = isr_table[vector]; - if (new_handler != RT_NULL) - isr_table[vector] = new_handler; - } + rt_isr_handler_t old_handler = RT_NULL; + + if(vector < MAX_HANDLERS) + { + old_handler = isr_table[vector].handler; + + if (handler != RT_NULL) + { +#ifdef RT_USING_INTERRUPT_INFO + rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX); +#endif /* RT_USING_INTERRUPT_INFO */ + isr_table[vector].handler = handler; + isr_table[vector].param = param; + } + } + + return old_handler; } /*@}*/ diff --git a/libcpu/arm/sep4020/trap.c b/libcpu/arm/sep4020/trap.c index e7a6e369f9..33da0d9e98 100644 --- a/libcpu/arm/sep4020/trap.c +++ b/libcpu/arm/sep4020/trap.c @@ -12,6 +12,7 @@ * 2006-03-13 Bernard first version * 2006-05-27 Bernard add skyeye support * 2007-11-19 Yi.Qiu fix rt_hw_trap_irq function + * 2013-03-29 aozima Modify the interrupt interface implementations. */ #include @@ -131,31 +132,38 @@ void rt_hw_trap_resv(struct rt_hw_register *regs) rt_hw_cpu_shutdown(); } -extern rt_isr_handler_t isr_table[]; +extern struct rt_irq_desc isr_table[]; -void rt_hw_trap_irq() +void rt_hw_trap_irq(void) { - unsigned long intstat; - rt_uint32_t i = 0; - rt_isr_handler_t isr_func; - - /*Get the final intrrupt source*/ - intstat = *(RP)(INTC_IFSR);; - - /*Shift to get the intrrupt number*/ - while(intstat != 1) - { - intstat = intstat >> 1; - i++; - } - /* get interrupt service routine */ - isr_func = isr_table[i]; - - /* turn to interrupt service routine */ - isr_func(i); + unsigned long intstat; + rt_uint32_t irq = 0; + rt_isr_handler_t isr_func; + void *param; + + /*Get the final intrrupt source*/ + intstat = *(RP)(INTC_IFSR);; + + /*Shift to get the intrrupt number*/ + while(intstat != 1) + { + intstat = intstat >> 1; + irq++; + } + + /* get interrupt service routine */ + isr_func = isr_table[irq].isr_handle; + param = isr_table[irq].param; + + /* turn to interrupt service routine */ + isr_func(irq, param); + +#ifdef RT_USING_INTERRUPT_INFO + isr_table[irq].counter++; +#endif /* RT_USING_INTERRUPT_INFO */ } -void rt_hw_trap_fiq() +void rt_hw_trap_fiq(void) { rt_kprintf("fast interrupt request\n"); } -- cgit v1.3.1 From 6058efbd9ba70da9113c50c13e2493453c32c772 Mon Sep 17 00:00:00 2001 From: aozima Date: Sat, 23 Mar 2013 17:34:52 +0800 Subject: update Jz47xx: Modify the interrupt interface implementations. --- bsp/jz47xx/board.c | 2 +- bsp/jz47xx/uart.c | 2 +- libcpu/mips/jz47xx/interrupt.c | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'libcpu') diff --git a/bsp/jz47xx/board.c b/bsp/jz47xx/board.c index b2f1ba0092..c742d32e7d 100644 --- a/bsp/jz47xx/board.c +++ b/bsp/jz47xx/board.c @@ -39,7 +39,7 @@ void rt_hw_timer_handler(int vector, void* param) /** * This function will initial OS timer */ -void rt_hw_timer_init() +void rt_hw_timer_init(void) { rt_uint32_t val; diff --git a/bsp/jz47xx/uart.c b/bsp/jz47xx/uart.c index 309a89d63f..18edad9d67 100644 --- a/bsp/jz47xx/uart.c +++ b/bsp/jz47xx/uart.c @@ -10,7 +10,7 @@ /*@{*/ #if defined(RT_USING_UART) && defined(RT_USING_DEVICE) -#define UART_BAUDRATE 115200 +#define UART_BAUDRATE 57600 #define DEV_CLK 12000000 /* diff --git a/libcpu/mips/jz47xx/interrupt.c b/libcpu/mips/jz47xx/interrupt.c index f9ada3254a..0ea4827ee2 100644 --- a/libcpu/mips/jz47xx/interrupt.c +++ b/libcpu/mips/jz47xx/interrupt.c @@ -90,7 +90,9 @@ rt_isr_handler_t rt_hw_interrupt_install(int vector, { old_handler = irq_handle_table[vector].handler; +#ifdef RT_USING_INTERRUPT_INFO rt_strncpy(irq_handle_table[vector].name, name, RT_NAME_MAX); +#endif /* RT_USING_INTERRUPT_INFO */ irq_handle_table[vector].handler = handler; irq_handle_table[vector].param = param; } @@ -118,6 +120,10 @@ void rt_interrupt_dispatch(void *ptreg) /* do interrupt */ (*irq_func)(i, irq_handle_table[i].param); +#ifdef RT_USING_INTERRUPT_INFO + irq_handle_table[i].counter++; +#endif /* RT_USING_INTERRUPT_INFO */ + /* ack interrupt */ INTC_IPR = (1 << i); } -- cgit v1.3.1 From 93e04a13667608cb20d098f56a5f1cce75fd8f07 Mon Sep 17 00:00:00 2001 From: aozima Date: Sat, 23 Mar 2013 17:48:36 +0800 Subject: update loongson dev3210: Modify the interrupt interface implementations. --- bsp/dev3210/rtconfig.h | 1 + bsp/dev3210/uart.c | 6 +- libcpu/mips/loongson/interrupt.c | 116 +++++++++++++++++++++++---------------- 3 files changed, 73 insertions(+), 50 deletions(-) (limited to 'libcpu') diff --git a/bsp/dev3210/rtconfig.h b/bsp/dev3210/rtconfig.h index 7968b263f3..cd94adf742 100644 --- a/bsp/dev3210/rtconfig.h +++ b/bsp/dev3210/rtconfig.h @@ -18,6 +18,7 @@ /* Thread Debug */ #define RT_DEBUG #define RT_USING_OVERFLOW_CHECK +#define RT_USING_INTERRUPT_INFO /* Using Hook */ #define RT_USING_HOOK diff --git a/bsp/dev3210/uart.c b/bsp/dev3210/uart.c index 1b8db9ec39..9d638a515a 100644 --- a/bsp/dev3210/uart.c +++ b/bsp/dev3210/uart.c @@ -25,7 +25,7 @@ /* UART interrupt enable register value */ #define UARTIER_IME (1 << 3) -#define UARTIER_ILE (1 << 2) +#define UARTIER_ILE (1 << 2) #define UARTIER_ITXE (1 << 1) #define UARTIER_IRXE (1 << 0) @@ -59,7 +59,7 @@ struct rt_uart_soc3210 rt_uint8_t rx_buffer[RT_UART_RX_BUFFER_SIZE]; }uart_device; -static void rt_uart_irqhandler(int irqno) +static void rt_uart_irqhandler(int irqno, void *param) { rt_ubase_t level; rt_uint8_t isr; @@ -142,7 +142,7 @@ static rt_err_t rt_uart_open(rt_device_t dev, rt_uint16_t oflag) UART_IER(uart->hw_base) |= UARTIER_IRXE; /* install interrupt */ - rt_hw_interrupt_install(uart->irq, rt_uart_irqhandler, RT_NULL); + rt_hw_interrupt_install(uart->irq, rt_uart_irqhandler, RT_NULL, "UART"); rt_hw_interrupt_umask(uart->irq); } return RT_EOK; diff --git a/libcpu/mips/loongson/interrupt.c b/libcpu/mips/loongson/interrupt.c index 4b97068a70..7e59ec950d 100644 --- a/libcpu/mips/loongson/interrupt.c +++ b/libcpu/mips/loongson/interrupt.c @@ -10,8 +10,11 @@ * Change Logs: * Date Author Notes * 2010-10-15 Bernard first version + * 2013-03-29 aozima Modify the interrupt interface implementations. */ + #include +#include #include "soc3210.h" #define MAX_INTR 32 @@ -20,17 +23,17 @@ extern rt_uint32_t rt_interrupt_nest; rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread; rt_uint32_t rt_thread_switch_interrupt_flag; -static rt_isr_handler_t irq_handle_table[MAX_INTR]; +static struct rt_irq_desc irq_handle_table[MAX_INTR]; void rt_interrupt_dispatch(void *ptreg); void rt_hw_timer_handler(); /** * @addtogroup Loongson SoC3210 */ - + /*@{*/ -void rt_hw_interrupt_handler(int vector) +static void rt_hw_interrupt_handler(int vector, void *param) { rt_kprintf("Unhandled interrupt %d occured!!!\n", vector); } @@ -40,11 +43,12 @@ void rt_hw_interrupt_handler(int vector) */ void rt_hw_interrupt_init(void) { - rt_int32_t index; + rt_int32_t idx; - for (index = 0; index < MAX_INTR; index ++) + rt_memset(irq_handle_table, 0x00, sizeof(irq_handle_table)); + for (idx = 0; idx < MAX_INTR; idx ++) { - irq_handle_table[index] = (rt_isr_handler_t)rt_hw_interrupt_handler; + irq_handle_table[idx].handler = rt_hw_interrupt_handler; } /* init interrupt nest, and context in thread sp */ @@ -79,52 +83,70 @@ void rt_hw_interrupt_umask(int vector) * @param new_handler the interrupt service routine to be installed * @param old_handler the old interrupt service routine */ -void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler) +rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler, + void *param, char *name) { - if (vector >= 0 && vector < MAX_INTR) - { - if (old_handler != RT_NULL) - *old_handler = irq_handle_table[vector]; - if (new_handler != RT_NULL) - irq_handle_table[vector] = (rt_isr_handler_t)new_handler; - } + rt_isr_handler_t old_handler = RT_NULL; + + if(vector < MAX_INTR) + { + old_handler = irq_handle_table[vector].handler; + + if (handler != RT_NULL) + { +#ifdef RT_USING_INTERRUPT_INFO + rt_strncpy(irq_handle_table[vector].name, name, RT_NAME_MAX); +#endif /* RT_USING_INTERRUPT_INFO */ + irq_handle_table[vector].handler = handler; + irq_handle_table[vector].param = param; + } + } + + return old_handler; } void rt_interrupt_dispatch(void *ptreg) { - int i; - rt_isr_handler_t irq_func; - static rt_uint32_t status = 0; - rt_uint32_t c0_status; - - /* check os timer */ - c0_status = read_c0_status(); - if (c0_status & 0x8000) - { - rt_hw_timer_handler(); - } - - if (c0_status & 0x0400) - { - /* the hardware interrupt */ - status |= INT_ISR; - if (!status) return; - - for (i = MAX_INTR; i > 0; --i) - { - if ((status & (1< 0; --irq) + { + if ((status & (1 << irq))) + { + status &= ~(1 << irq); + + irq_func = irq_handle_table[irq].handler; + param = irq_handle_table[irq].param; + + /* do interrupt */ + (*irq_func)(irq, param); + +#ifdef RT_USING_INTERRUPT_INFO + irq_handle_table[irq].counter++; +#endif /* RT_USING_INTERRUPT_INFO */ + + /* ack interrupt */ + INT_CLR = (1 << irq); + } + } + } } /*@}*/ -- cgit v1.3.1 From 83ce43090276b976f99be5646abf7256ce8ec7e0 Mon Sep 17 00:00:00 2001 From: aozima Date: Sat, 23 Mar 2013 20:00:51 +0800 Subject: update loongson 1B dev: Modify the interrupt interface implementations. --- bsp/ls1bdev/drivers/uart.c | 4 +-- bsp/ls1bdev/rtconfig.h | 2 ++ libcpu/mips/loongson_1b/interrupt.c | 57 +++++++++++++++++++++++++------------ 3 files changed, 43 insertions(+), 20 deletions(-) (limited to 'libcpu') diff --git a/bsp/ls1bdev/drivers/uart.c b/bsp/ls1bdev/drivers/uart.c index 80df23f1d6..4e897391fb 100644 --- a/bsp/ls1bdev/drivers/uart.c +++ b/bsp/ls1bdev/drivers/uart.c @@ -37,7 +37,7 @@ struct rt_uart_ls1b rt_uint8_t rx_buffer[RT_UART_RX_BUFFER_SIZE]; }uart_device; -static void rt_uart_irqhandler(int irqno) +static void rt_uart_irqhandler(int irqno, void *param) { rt_ubase_t level; rt_uint8_t isr; @@ -121,7 +121,7 @@ static rt_err_t rt_uart_open(rt_device_t dev, rt_uint16_t oflag) UART_IER(uart->hw_base) |= UARTIER_IRXE; /* install interrupt */ - rt_hw_interrupt_install(uart->irq, rt_uart_irqhandler, RT_NULL); + rt_hw_interrupt_install(uart->irq, rt_uart_irqhandler, RT_NULL, "UART"); rt_hw_interrupt_umask(uart->irq); } return RT_EOK; diff --git a/bsp/ls1bdev/rtconfig.h b/bsp/ls1bdev/rtconfig.h index b0f8a55575..b09f7b044c 100644 --- a/bsp/ls1bdev/rtconfig.h +++ b/bsp/ls1bdev/rtconfig.h @@ -21,6 +21,8 @@ // #define RT_THREAD_DEBUG // #define RT_USING_OVERFLOW_CHECK +// +#define RT_USING_INTERRUPT_INFO // // diff --git a/libcpu/mips/loongson_1b/interrupt.c b/libcpu/mips/loongson_1b/interrupt.c index 63240053a8..c5b4bad038 100644 --- a/libcpu/mips/loongson_1b/interrupt.c +++ b/libcpu/mips/loongson_1b/interrupt.c @@ -11,9 +11,11 @@ * Date Author Notes * 2010-10-15 Bernard first version * 2010-10-15 lgnq modified for LS1B + * 2013-03-29 aozima Modify the interrupt interface implementations. */ #include +#include #include "ls1b.h" #define MAX_INTR 32 @@ -23,7 +25,7 @@ rt_uint32_t rt_interrupt_from_thread; rt_uint32_t rt_interrupt_to_thread; rt_uint32_t rt_thread_switch_interrupt_flag; -static rt_isr_handler_t irq_handle_table[MAX_INTR]; +static struct rt_irq_desc irq_handle_table[MAX_INTR]; void rt_interrupt_dispatch(void *ptreg); void rt_hw_timer_handler(); @@ -36,7 +38,7 @@ static struct ls1b_intc_regs volatile *ls1b_hw0_icregs /*@{*/ -void rt_hw_interrupt_handler(int vector) +static void rt_hw_interrupt_handler(int vector, void *param) { rt_kprintf("Unhandled interrupt %d occured!!!\n", vector); } @@ -46,7 +48,7 @@ void rt_hw_interrupt_handler(int vector) */ void rt_hw_interrupt_init(void) { - rt_int32_t index; + rt_int32_t idx; /* pci active low */ ls1b_hw0_icregs->int_pol = -1; //must be done here 20110802 lgnq @@ -55,9 +57,10 @@ void rt_hw_interrupt_init(void) /* mask all interrupts */ (ls1b_hw0_icregs+0)->int_clr = 0xffffffff; - for (index = 0; index < MAX_INTR; index ++) + rt_memset(irq_handle_table, 0x00, sizeof(irq_handle_table)); + for (idx = 0; idx < MAX_INTR; idx ++) { - irq_handle_table[index] = (rt_isr_handler_t)rt_hw_interrupt_handler; + irq_handle_table[idx].handler = rt_hw_interrupt_handler; } /* init interrupt nest, and context in thread sp */ @@ -92,20 +95,32 @@ void rt_hw_interrupt_umask(int vector) * @param new_handler the interrupt service routine to be installed * @param old_handler the old interrupt service routine */ -void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler) +rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler, + void *param, char *name) { + rt_isr_handler_t old_handler = RT_NULL; + if (vector >= 0 && vector < MAX_INTR) { - if (old_handler != RT_NULL) - *old_handler = irq_handle_table[vector]; - if (new_handler != RT_NULL) - irq_handle_table[vector] = (rt_isr_handler_t)new_handler; - } + old_handler = irq_handle_table[vector].handler; + + if (handler != RT_NULL) + { +#ifdef RT_USING_INTERRUPT_INFO + rt_strncpy(irq_handle_table[vector].name, name, RT_NAME_MAX); +#endif /* RT_USING_INTERRUPT_INFO */ + irq_handle_table[vector].handler = handler; + irq_handle_table[vector].param = param; + } + } + + return old_handler; } void rt_interrupt_dispatch(void *ptreg) { - int i; + int irq; + void *param; rt_isr_handler_t irq_func; static rt_uint32_t status = 0; rt_uint32_t c0_status; @@ -134,18 +149,24 @@ void rt_interrupt_dispatch(void *ptreg) if (!status) return; - for (i = MAX_INTR; i > 0; --i) + for (irq = MAX_INTR; irq > 0; --irq) { - if ((status & (1<int_clr |= (1 << i); + ls1b_hw0_icregs->int_clr |= (1 << irq); } } } -- cgit v1.3.1 From eab20a99750fbc685492e802ba9c543d1ca6420d Mon Sep 17 00:00:00 2001 From: aozima Date: Sat, 23 Mar 2013 20:13:43 +0800 Subject: update AT91SAM7X: Modify the interrupt interface implementations. --- bsp/sam7x/drivers/board.c | 2 +- libcpu/arm/AT91SAM7X/interrupt.c | 7 ++++--- libcpu/arm/AT91SAM7X/trap.c | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'libcpu') diff --git a/bsp/sam7x/drivers/board.c b/bsp/sam7x/drivers/board.c index 16dfacb9be..1e13656f66 100644 --- a/bsp/sam7x/drivers/board.c +++ b/bsp/sam7x/drivers/board.c @@ -154,7 +154,7 @@ static void rt_hw_console_init() /** * This function will initial sam7x board. */ -void rt_hw_board_init() +void rt_hw_board_init(void) { extern void rt_serial_init(void); diff --git a/libcpu/arm/AT91SAM7X/interrupt.c b/libcpu/arm/AT91SAM7X/interrupt.c index 1aced87b29..71884f9f3f 100644 --- a/libcpu/arm/AT91SAM7X/interrupt.c +++ b/libcpu/arm/AT91SAM7X/interrupt.c @@ -10,8 +10,10 @@ * Change Logs: * Date Author Notes * 2006-08-23 Bernard first version + * 2013-03-29 aozima Modify the interrupt interface implementations. */ +#include #include #include "AT91SAM7X256.h" @@ -30,7 +32,7 @@ rt_uint32_t rt_thread_switch_interrupt_flag; */ /*@{*/ -void rt_hw_interrupt_handler(int vector) +static void rt_hw_interrupt_handler(int vector, void *param) { rt_kprintf("Unhandled interrupt %d occured!!!\n", vector); } @@ -38,7 +40,7 @@ void rt_hw_interrupt_handler(int vector) /** * This function will initialize hardware interrupt */ -void rt_hw_interrupt_init() +void rt_hw_interrupt_init(void) { rt_base_t index; @@ -96,7 +98,6 @@ rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler, void *param, char *name) { rt_isr_handler_t old_handler = RT_NULL; - if(vector >= 0 && vector < MAX_HANDLERS) { old_handler = irq_desc[vector].handler; diff --git a/libcpu/arm/AT91SAM7X/trap.c b/libcpu/arm/AT91SAM7X/trap.c index 4b21f81c1c..74d1cba445 100644 --- a/libcpu/arm/AT91SAM7X/trap.c +++ b/libcpu/arm/AT91SAM7X/trap.c @@ -22,7 +22,7 @@ */ /*@{*/ -void rt_hw_trap_irq() +void rt_hw_trap_irq(void) { int irqno; extern struct rt_irq_desc irq_desc[]; @@ -37,13 +37,13 @@ void rt_hw_trap_irq() AT91C_BASE_AIC->AIC_EOICR = 0; } -void rt_hw_trap_fiq() +void rt_hw_trap_fiq(void) { rt_kprintf("fast interrupt request\n"); } extern struct rt_thread* rt_current_thread; -void rt_hw_trap_abort() +void rt_hw_trap_abort(void) { rt_kprintf("Abort occured!!! Thread [%s] suspended.\n",rt_current_thread->name); rt_thread_suspend(rt_current_thread); -- cgit v1.3.1 From 1549b7db90df55c638dd1102b9aee50986d7d9ba Mon Sep 17 00:00:00 2001 From: aozima Date: Sat, 23 Mar 2013 20:21:40 +0800 Subject: update LPC214X: Modify the interrupt interface implementations. --- bsp/lpc2148/drivers/board.c | 14 ++++----- bsp/lpc2148/drivers/serial.c | 50 ++++++++++++++++--------------- libcpu/arm/lpc214x/cpuport.c | 70 +++++++++++++++++++++++++++++--------------- 3 files changed, 80 insertions(+), 54 deletions(-) (limited to 'libcpu') diff --git a/bsp/lpc2148/drivers/board.c b/bsp/lpc2148/drivers/board.c index ff339d5fa3..10f25e079a 100644 --- a/bsp/lpc2148/drivers/board.c +++ b/bsp/lpc2148/drivers/board.c @@ -27,7 +27,7 @@ * This is the timer interrupt service routine. * @param vector the irq number for timer */ -void rt_hw_timer_handler(int vector) +void rt_hw_timer_handler(int vector, void *param) { rt_tick_increase(); @@ -53,10 +53,10 @@ void rt_hw_console_output(const char* str) while (!(U0LSR & 0x20)); U0THR = '\r'; } - + while (!(U0LSR & 0x20)); U0THR = *str; - + str ++; } } @@ -82,11 +82,11 @@ void rt_hw_console_init() /** * This function will initial sam7x256 board. */ -void rt_hw_board_init() +void rt_hw_board_init(void) { /* console init */ rt_hw_console_init(); - + /* prescaler = 0*/ T0PR = 0; T0PC = 0; @@ -94,12 +94,12 @@ void rt_hw_board_init() /* reset and enable MR0 interrupt */ T0MCR = 0x3; T0MR0 = PCLK / RT_TICK_PER_SECOND; - + /* enable timer 0 */ T0TCR = 1; /* install timer handler */ - rt_hw_interrupt_install(TIMER0_INT, rt_hw_timer_handler, RT_NULL); + rt_hw_interrupt_install(TIMER0_INT, rt_hw_timer_handler, RT_NULL, "TIMER0"); rt_hw_interrupt_umask(TIMER0_INT); } diff --git a/bsp/lpc2148/drivers/serial.c b/bsp/lpc2148/drivers/serial.c index 2a16be3f82..6cfcbb18a8 100644 --- a/bsp/lpc2148/drivers/serial.c +++ b/bsp/lpc2148/drivers/serial.c @@ -69,7 +69,7 @@ void rt_hw_uart_isr(struct rt_lpcserial* lpc_serial) UNUSED rt_uint32_t iir; RT_ASSERT(lpc_serial != RT_NULL) - + if (UART_LSR(lpc_serial->hw_base) & 0x01) { rt_base_t level; @@ -80,12 +80,12 @@ void rt_hw_uart_isr(struct rt_lpcserial* lpc_serial) level = rt_hw_interrupt_disable(); /* read character */ - lpc_serial->rx_buffer[lpc_serial->save_index] = + lpc_serial->rx_buffer[lpc_serial->save_index] = UART_RBR(lpc_serial->hw_base); lpc_serial->save_index ++; if (lpc_serial->save_index >= RT_UART_RX_BUFFER_SIZE) lpc_serial->save_index = 0; - + /* if the next position is read index, discard this 'read char' */ if (lpc_serial->save_index == lpc_serial->read_index) { @@ -113,7 +113,7 @@ void rt_hw_uart_isr(struct rt_lpcserial* lpc_serial) } #ifdef RT_USING_UART1 -void rt_hw_uart_isr_1(int irqno) +void rt_hw_uart_isr_1(int irqno, void *param) { /* get lpc serial device */ rt_hw_uart_isr(&serial1); @@ -121,7 +121,7 @@ void rt_hw_uart_isr_1(int irqno) #endif #ifdef RT_USING_UART2 -void rt_hw_uart_isr_2(int irqno) +void rt_hw_uart_isr_2(int irqno, void *param) { /* get lpc serial device */ rt_hw_uart_isr(&serial2); @@ -153,13 +153,15 @@ static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag) if (lpc_serial->irqno == UART0_INT) { #ifdef RT_USING_UART1 - rt_hw_interrupt_install(lpc_serial->irqno, rt_hw_uart_isr_1, RT_NULL); + rt_hw_interrupt_install(lpc_serial->irqno, + rt_hw_uart_isr_1, &serial1, "UART1"); #endif } else { #ifdef RT_USING_UART2 - rt_hw_interrupt_install(lpc_serial->irqno, rt_hw_uart_isr_2, RT_NULL); + rt_hw_interrupt_install(lpc_serial->irqno, + rt_hw_uart_isr_2, &serial2, "UART2"); #endif } @@ -173,7 +175,7 @@ static rt_err_t rt_serial_close(rt_device_t dev) { struct rt_lpcserial* lpc_serial; lpc_serial = (struct rt_lpcserial*) dev; - + RT_ASSERT(lpc_serial != RT_NULL); if (dev->flag & RT_DEVICE_FLAG_INT_RX) @@ -244,7 +246,7 @@ static rt_size_t rt_serial_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_ { /* Read Character */ *ptr = UART_RBR(lpc_serial->hw_base); - + ptr ++; size --; } @@ -271,7 +273,7 @@ static rt_size_t rt_serial_write(rt_device_t dev, rt_off_t pos, const void* buff /* polling write */ ptr = (char *)buffer; - + if (dev->flag & RT_DEVICE_FLAG_STREAM) { /* stream mode */ @@ -285,7 +287,7 @@ static rt_size_t rt_serial_write(rt_device_t dev, rt_off_t pos, const void* buff while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); UART_THR(lpc_serial->hw_base) = *ptr; - + ptr ++; size --; } @@ -296,37 +298,37 @@ static rt_size_t rt_serial_write(rt_device_t dev, rt_off_t pos, const void* buff { while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); UART_THR(lpc_serial->hw_base) = *ptr; - + ptr ++; size --; } } - + return (rt_size_t) ptr - (rt_size_t) buffer; } void rt_hw_serial_init(void) { struct rt_lpcserial* lpc_serial; - + #ifdef RT_USING_UART1 lpc_serial = &serial1; - + lpc_serial->parent.type = RT_Device_Class_Char; - + lpc_serial->hw_base = 0xE000C000; lpc_serial->baudrate = 115200; lpc_serial->irqno = UART0_INT; - + rt_memset(lpc_serial->rx_buffer, 0, sizeof(lpc_serial->rx_buffer)); lpc_serial->read_index = lpc_serial->save_index = 0; /* Enable UART0 RxD and TxD pins */ - PINSEL0 |= 0x05; + PINSEL0 |= 0x05; /* 8 bits, no Parity, 1 Stop bit */ UART_LCR(lpc_serial->hw_base) = 0x83; - + /* Setup Baudrate */ UART_DLL(lpc_serial->hw_base) = (PCLK/16/lpc_serial->baudrate) & 0xFF; UART_DLM(lpc_serial->hw_base) = ((PCLK/16/lpc_serial->baudrate) >> 8) & 0xFF; @@ -334,6 +336,7 @@ void rt_hw_serial_init(void) /* DLAB = 0 */ UART_LCR(lpc_serial->hw_base) = 0x03; + lpc_serial->parent.type = RT_Device_Class_Char; lpc_serial->parent.init = rt_serial_init; lpc_serial->parent.open = rt_serial_open; lpc_serial->parent.close = rt_serial_close; @@ -342,13 +345,13 @@ void rt_hw_serial_init(void) lpc_serial->parent.control = rt_serial_control; lpc_serial->parent.user_data = RT_NULL; - rt_device_register(&lpc_serial->parent, + rt_device_register(&lpc_serial->parent, "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX); #endif #ifdef RT_USING_UART2 lpc_serial = &serial2; - + lpc_serial->parent.type = RT_Device_Class_Char; lpc_serial->hw_base = 0xE0010000; @@ -363,7 +366,7 @@ void rt_hw_serial_init(void) /* 8 bits, no Parity, 1 Stop bit */ UART_LCR(lpc_serial->hw_base) = 0x83; - + /* Setup Baudrate */ UART_DLL(lpc_serial->hw_base) = (PCLK/16/lpc_serial->baudrate) & 0xFF; UART_DLM(lpc_serial->hw_base) = ((PCLK/16/lpc_serial->baudrate) >> 8) & 0xFF; @@ -371,6 +374,7 @@ void rt_hw_serial_init(void) /* DLAB = 0 */ UART_LCR(lpc_serial->hw_base) = 0x03; + lpc_serial->parent.type = RT_Device_Class_Char; lpc_serial->parent.init = rt_serial_init; lpc_serial->parent.open = rt_serial_open; lpc_serial->parent.close = rt_serial_close; @@ -379,7 +383,7 @@ void rt_hw_serial_init(void) lpc_serial->parent.control = rt_serial_control; lpc_serial->parent.user_data = RT_NULL; - rt_device_register(&lpc_serial->parent, + rt_device_register(&lpc_serial->parent, "uart2", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX); #endif } diff --git a/libcpu/arm/lpc214x/cpuport.c b/libcpu/arm/lpc214x/cpuport.c index 512ff89f08..1cd33b897b 100644 --- a/libcpu/arm/lpc214x/cpuport.c +++ b/libcpu/arm/lpc214x/cpuport.c @@ -10,9 +10,11 @@ * Change Logs: * Date Author Notes * 2011-06-15 aozima the first version for lpc214x + * 2013-03-29 aozima Modify the interrupt interface implementations. */ #include +#include #include "lpc214x.h" #define MAX_HANDLERS 32 @@ -20,6 +22,9 @@ extern rt_uint32_t rt_interrupt_nest; +/* exception and interrupt handler table */ +struct rt_irq_desc irq_desc[MAX_HANDLERS]; + /** * @addtogroup LPC214x */ @@ -71,7 +76,7 @@ rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter, rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread; rt_uint32_t rt_thread_switch_interrupt_flag; -void rt_hw_interrupt_handler(int vector) +void rt_hw_interrupt_handler(int vector, void *param) { rt_kprintf("Unhandled interrupt %d occured!!!\n", vector); } @@ -79,7 +84,7 @@ void rt_hw_interrupt_handler(int vector) /** * This function will initialize hardware interrupt */ -void rt_hw_interrupt_init() +void rt_hw_interrupt_init(void) { rt_base_t index; rt_uint32_t *vect_addr, *vect_ctl; @@ -90,12 +95,15 @@ void rt_hw_interrupt_init() /* set all to IRQ */ VICIntSelect = 0; + rt_memset(irq_desc, 0x00, sizeof(irq_desc)); for (index = 0; index < MAX_HANDLERS; index ++) { + irq_desc[index].handler = rt_hw_interrupt_handler; + vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + (index << 2)); vect_ctl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + (index << 2)); - *vect_addr = (rt_uint32_t)rt_hw_interrupt_handler; + *vect_addr = (rt_uint32_t)&irq_desc[index]; *vect_ctl = 0xF; } @@ -127,30 +135,39 @@ void rt_hw_interrupt_umask(int vector) /** * This function will install a interrupt service routine to a interrupt. * @param vector the interrupt number - * @param new_handler the interrupt service routine to be installed - * @param old_handler the old interrupt service routine + * @param handler the interrupt service routine to be installed + * @param param the interrupt service function parameter + * @param name the interrupt name + * @return old handler */ -void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler) +rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler, + void *param, char *name) { - if(vector >= 0 && vector < MAX_HANDLERS) - { - /* get VIC address */ - rt_uint32_t* vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + (vector << 2)); - rt_uint32_t* vect_ctl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + (vector << 2)); + rt_isr_handler_t old_handler = RT_NULL; - /* assign IRQ slot and enable this slot */ - *vect_ctl = 0x20 | (vector & 0x1F); + if(vector >= 0 && vector < MAX_HANDLERS) + { + rt_uint32_t* vect_ctl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + (vector << 2)); - if (old_handler != RT_NULL) *old_handler = (rt_isr_handler_t) *vect_addr; - if (new_handler != RT_NULL) *vect_addr = (rt_uint32_t) new_handler; - } + /* assign IRQ slot and enable this slot */ + *vect_ctl = 0x20 | (vector & 0x1F); + + old_handler = irq_desc[vector].handler; + if (handler != RT_NULL) + { + irq_desc[vector].handler = handler; + irq_desc[vector].param = param; + } + } + + return old_handler; } /** * this function will reset CPU * */ -void rt_hw_cpu_reset() +void rt_hw_cpu_reset(void) { } @@ -165,18 +182,23 @@ void rt_hw_cpu_shutdown() while (1); } -void rt_hw_trap_irq() +void rt_hw_trap_irq(void) { - rt_isr_handler_t isr_func; + int irqno; + struct rt_irq_desc* irq; + extern struct rt_irq_desc irq_desc[]; + + irq = (struct rt_irq_desc*) VICVectAddr; + irqno = ((rt_uint32_t) irq - (rt_uint32_t) &irq_desc[0])/sizeof(struct rt_irq_desc); - isr_func = (rt_isr_handler_t) VICVectAddr; - isr_func(0); + /* invoke isr */ + irq->handler(irqno, irq->param); - /* acknowledge Interrupt */ - // VICVectAddr = 0; + /* acknowledge Interrupt */ + // VICVectAddr = 0; } -void rt_hw_trap_fiq() +void rt_hw_trap_fiq(void) { rt_kprintf("fast interrupt request\n"); } -- cgit v1.3.1 From 2ccb3c7589f08d0c46ccd9b7ec7a35b1b678d609 Mon Sep 17 00:00:00 2001 From: aozima Date: Sat, 23 Mar 2013 20:33:41 +0800 Subject: update LPC2478: Modify the interrupt interface implementations. --- bsp/lpc2478/drivers/board.c | 2 +- bsp/lpc2478/drivers/serial.c | 33 ++++----------------------------- libcpu/arm/lpc24xx/interrupt.c | 10 ++++++---- libcpu/arm/lpc24xx/trap.c | 4 ++-- 4 files changed, 13 insertions(+), 36 deletions(-) (limited to 'libcpu') diff --git a/bsp/lpc2478/drivers/board.c b/bsp/lpc2478/drivers/board.c index 1ddc0aaf79..ac17305062 100644 --- a/bsp/lpc2478/drivers/board.c +++ b/bsp/lpc2478/drivers/board.c @@ -37,7 +37,7 @@ void rt_timer_handler(int vector, void* param) /** * This function will init LPC2478 board */ -void rt_hw_board_init() +void rt_hw_board_init(void) { #if defined(RT_USING_DEVICE) && defined(RT_USING_UART1) rt_hw_serial_init(); diff --git a/bsp/lpc2478/drivers/serial.c b/bsp/lpc2478/drivers/serial.c index a5edc3c988..8a0e1aa15b 100644 --- a/bsp/lpc2478/drivers/serial.c +++ b/bsp/lpc2478/drivers/serial.c @@ -64,9 +64,10 @@ void rt_hw_serial_init(void); #define U0PINS 0x00000005 -void rt_hw_uart_isr(struct rt_lpcserial* lpc_serial) +void rt_hw_uart_isr(int irqno, void *param) { UNUSED rt_uint32_t iir; + struct rt_lpcserial* lpc_serial = (struct rt_lpcserial*)param; RT_ASSERT(lpc_serial != RT_NULL) @@ -112,21 +113,6 @@ void rt_hw_uart_isr(struct rt_lpcserial* lpc_serial) VICVectAddr = 0; } -#ifdef RT_USING_UART1 -void rt_hw_uart_isr_1(int irqno, void* param) -{ - /* get lpc serial device */ - rt_hw_uart_isr(&serial1); -} -#endif - -#ifdef RT_USING_UART2 -void rt_hw_uart_isr_2(int irqno, void* param) -{ - /* get lpc serial device */ - rt_hw_uart_isr(&serial2); -} -#endif /** * @addtogroup LPC214x @@ -150,19 +136,8 @@ static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag) UART_IER(lpc_serial->hw_base) = 0x01; /* install ISR */ - if (lpc_serial->irqno == UART0_INT) - { -#ifdef RT_USING_UART1 - rt_hw_interrupt_install(lpc_serial->irqno, rt_hw_uart_isr_1, RT_NULL, "uart1"); -#endif - } - else - { -#ifdef RT_USING_UART2 - rt_hw_interrupt_install(lpc_serial->irqno, rt_hw_uart_isr_2, RT_NULL, "uart2"); -#endif - } - + rt_hw_interrupt_install(lpc_serial->irqno, + rt_hw_uart_isr, lpc_serial, RT_NULL); rt_hw_interrupt_umask(lpc_serial->irqno); } diff --git a/libcpu/arm/lpc24xx/interrupt.c b/libcpu/arm/lpc24xx/interrupt.c index 6d64d7a07c..16d1dd7e99 100644 --- a/libcpu/arm/lpc24xx/interrupt.c +++ b/libcpu/arm/lpc24xx/interrupt.c @@ -10,8 +10,10 @@ * Change Logs: * Date Author Notes * 2008-12-11 XuXinming first version + * 2013-03-29 aozima Modify the interrupt interface implementations. */ +#include #include #include "LPC24xx.h" @@ -35,7 +37,7 @@ void rt_hw_interrupt_handler(int vector, void *param) rt_kprintf("Unhandled interrupt %d occured!!!\n", vector); } -void rt_hw_interrupt_init() +void rt_hw_interrupt_init(void) { register int i; @@ -47,10 +49,10 @@ void rt_hw_interrupt_init() VICIntSelect = 0; /* init exceptions table */ + rt_memset(irq_desc, 0x00, sizeof(irq_desc)); for(i=0; i < MAX_HANDLERS; i++) { - irq_desc[i].handler = (rt_isr_handler_t)rt_hw_interrupt_handler; - irq_desc[i].param = RT_NULL; + irq_desc[i].handler = rt_hw_interrupt_handler; vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + i*4); vect_cntl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + i*4); @@ -94,7 +96,7 @@ rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler, old_handler = irq_desc[vector].handler; if (handler != RT_NULL) { - irq_desc[vector].handler = (rt_isr_handler_t)handler; + irq_desc[vector].handler = handler; irq_desc[vector].param = param; } } diff --git a/libcpu/arm/lpc24xx/trap.c b/libcpu/arm/lpc24xx/trap.c index 53ff13b4eb..71d88101fc 100644 --- a/libcpu/arm/lpc24xx/trap.c +++ b/libcpu/arm/lpc24xx/trap.c @@ -126,7 +126,7 @@ void rt_hw_trap_resv(struct rt_hw_register *regs) } extern rt_isr_handler_t isr_table[]; -void rt_hw_trap_irq() +void rt_hw_trap_irq(void) { int irqno; struct rt_irq_desc* irq; @@ -139,7 +139,7 @@ void rt_hw_trap_irq() irq->handler(irqno, irq->param); } -void rt_hw_trap_fiq() +void rt_hw_trap_fiq(void) { rt_kprintf("fast interrupt request\n"); } -- cgit v1.3.1