提交 608074de 编写于 作者: B Bernard Xiong

update to interrupt description

上级 aaf01868
...@@ -27,7 +27,7 @@ extern void rt_hw_serial_init(void); ...@@ -27,7 +27,7 @@ extern void rt_hw_serial_init(void);
*/ */
/*@{*/ /*@{*/
void rt_timer_handler(int vector) void rt_timer_handler(int vector, void* param)
{ {
T0IR |= 0x01; /* clear interrupt flag */ T0IR |= 0x01; /* clear interrupt flag */
rt_tick_increase(); rt_tick_increase();
...@@ -49,7 +49,7 @@ void rt_hw_board_init() ...@@ -49,7 +49,7 @@ void rt_hw_board_init()
T0MCR = 0x03; T0MCR = 0x03;
T0MR0 = (DATA_COUNT); T0MR0 = (DATA_COUNT);
rt_hw_interrupt_install(TIMER0_INT, rt_timer_handler, RT_NULL); rt_hw_interrupt_install(TIMER0_INT, rt_timer_handler, RT_NULL, "tick");
rt_hw_interrupt_umask(TIMER0_INT); rt_hw_interrupt_umask(TIMER0_INT);
T0TCR = 0x01; //enable timer0 counter T0TCR = 0x01; //enable timer0 counter
......
...@@ -113,7 +113,7 @@ void rt_hw_uart_isr(struct rt_lpcserial* lpc_serial) ...@@ -113,7 +113,7 @@ void rt_hw_uart_isr(struct rt_lpcserial* lpc_serial)
} }
#ifdef RT_USING_UART1 #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 */ /* get lpc serial device */
rt_hw_uart_isr(&serial1); rt_hw_uart_isr(&serial1);
...@@ -121,7 +121,7 @@ void rt_hw_uart_isr_1(int irqno) ...@@ -121,7 +121,7 @@ void rt_hw_uart_isr_1(int irqno)
#endif #endif
#ifdef RT_USING_UART2 #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 */ /* get lpc serial device */
rt_hw_uart_isr(&serial2); rt_hw_uart_isr(&serial2);
...@@ -153,13 +153,13 @@ static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag) ...@@ -153,13 +153,13 @@ static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag)
if (lpc_serial->irqno == UART0_INT) if (lpc_serial->irqno == UART0_INT)
{ {
#ifdef RT_USING_UART1 #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, RT_NULL, "uart1");
#endif #endif
} }
else else
{ {
#ifdef RT_USING_UART2 #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, RT_NULL, "uart2");
#endif #endif
} }
......
...@@ -97,7 +97,7 @@ void rtthread_startup(void) ...@@ -97,7 +97,7 @@ void rtthread_startup(void)
#elif __ICCARM__ #elif __ICCARM__
rt_system_heap_init(__segment_end("HEAP"), (void*)0x00210000); rt_system_heap_init(__segment_end("HEAP"), (void*)0x00210000);
#else #else
rt_system_heap_init(&__bss_end, 0x00210000); rt_system_heap_init(&__bss_end, (void*)0x00210000);
#endif #endif
#endif #endif
......
...@@ -33,7 +33,7 @@ static void rt_hw_board_led_init(void); ...@@ -33,7 +33,7 @@ static void rt_hw_board_led_init(void);
* This is the timer interrupt service routine. * This is the timer interrupt service routine.
* @param vector the irq number for timer * @param vector the irq number for timer
*/ */
void rt_hw_timer_handler(int vector) void rt_hw_timer_handler(int vector, void* param)
{ {
if (AT91C_BASE_PITC->PITC_PISR & 0x01) if (AT91C_BASE_PITC->PITC_PISR & 0x01)
{ {
...@@ -168,7 +168,7 @@ void rt_hw_board_init() ...@@ -168,7 +168,7 @@ void rt_hw_board_init()
AT91C_BASE_PITC->PITC_PIMR = (1 << 25) | (1 << 24) | PIV; AT91C_BASE_PITC->PITC_PIMR = (1 << 25) | (1 << 24) | PIV;
/* install timer handler */ /* install timer handler */
rt_hw_interrupt_install(AT91C_ID_SYS, rt_hw_timer_handler, RT_NULL); rt_hw_interrupt_install(AT91C_ID_SYS, rt_hw_timer_handler, RT_NULL, "tick");
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_SYS] = 0; AT91C_BASE_AIC->AIC_SMR[AT91C_ID_SYS] = 0;
rt_hw_interrupt_umask(AT91C_ID_SYS); rt_hw_interrupt_umask(AT91C_ID_SYS);
} }
......
...@@ -120,7 +120,7 @@ rt_inline void sam7xether_reset_tx_desc(void) ...@@ -120,7 +120,7 @@ rt_inline void sam7xether_reset_tx_desc(void)
/* interrupt service routing */ /* interrupt service routing */
static void sam7xether_isr(int irq) static void sam7xether_isr(int irq, void* param)
{ {
/* Variable definitions can be made now. */ /* Variable definitions can be made now. */
volatile rt_uint32_t isr, rsr; volatile rt_uint32_t isr, rsr;
...@@ -377,7 +377,7 @@ rt_err_t sam7xether_init(rt_device_t dev) ...@@ -377,7 +377,7 @@ rt_err_t sam7xether_init(rt_device_t dev)
AT91C_BASE_EMAC->EMAC_IER = AT91C_EMAC_RCOMP | AT91C_EMAC_TCOMP; AT91C_BASE_EMAC->EMAC_IER = AT91C_EMAC_RCOMP | AT91C_EMAC_TCOMP;
/* setup interrupt */ /* setup interrupt */
rt_hw_interrupt_install(AT91C_ID_EMAC, sam7xether_isr, RT_NULL); rt_hw_interrupt_install(AT91C_ID_EMAC, sam7xether_isr, RT_NULL, "emac");
*(volatile unsigned int*)(0xFFFFF000 + AT91C_ID_EMAC * 4) = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 5; *(volatile unsigned int*)(0xFFFFF000 + AT91C_ID_EMAC * 4) = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 5;
// AT91C_AIC_SMR(AT91C_ID_EMAC) = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 5; // AT91C_AIC_SMR(AT91C_ID_EMAC) = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 5;
rt_hw_interrupt_umask(AT91C_ID_EMAC); rt_hw_interrupt_umask(AT91C_ID_EMAC);
......
...@@ -76,27 +76,12 @@ struct rt_at91serial serial1; ...@@ -76,27 +76,12 @@ struct rt_at91serial serial1;
struct rt_at91serial serial2; struct rt_at91serial serial2;
#endif #endif
static void rt_hw_serial_isr(int irqno) static void rt_hw_serial_isr(int irqno, void* param)
{ {
rt_base_t level; rt_base_t level;
struct rt_device* device; struct rt_device* device;
struct rt_at91serial* serial = RT_NULL; struct rt_at91serial* serial = (struct rt_at91serial*)param;
#ifdef RT_USING_UART1
if (irqno == AT91C_ID_US0)
{
/* serial 1 */
serial = &serial1;
}
#endif
#ifdef RT_USING_UART2
if (irqno == AT91C_ID_US1)
{
/* serial 2 */
serial = &serial2;
}
#endif
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
/* get generic device object */ /* get generic device object */
...@@ -202,7 +187,7 @@ static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag) ...@@ -202,7 +187,7 @@ static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag)
//serial->hw_base->US_IMR |= 1 << 0; /* umask RxReady interrupt */ //serial->hw_base->US_IMR |= 1 << 0; /* umask RxReady interrupt */
/* install UART handler */ /* install UART handler */
rt_hw_interrupt_install(serial->peripheral_id, rt_hw_serial_isr, RT_NULL); rt_hw_interrupt_install(serial->peripheral_id, rt_hw_serial_isr, serial, "uart");
// SAM7X Datasheet 30.5.3: // SAM7X Datasheet 30.5.3:
// It is notrecommended to use the USART interrupt line in edge sensitive mode // It is notrecommended to use the USART interrupt line in edge sensitive mode
//AT91C_AIC_SMR(serial->peripheral_id) = 5 | (0x01 << 5); //AT91C_AIC_SMR(serial->peripheral_id) = 5 | (0x01 << 5);
......
...@@ -12,11 +12,14 @@ ...@@ -12,11 +12,14 @@
* 2006-08-23 Bernard first version * 2006-08-23 Bernard first version
*/ */
#include <rtthread.h> #include <rthw.h>
#include "AT91SAM7X256.h" #include "AT91SAM7X256.h"
#define MAX_HANDLERS 32 #define MAX_HANDLERS 32
/* exception and interrupt handler table */
struct rt_irq_desc irq_desc[MAX_HANDLERS];
extern rt_uint32_t rt_interrupt_nest; extern rt_uint32_t rt_interrupt_nest;
rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread; rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
...@@ -39,6 +42,13 @@ void rt_hw_interrupt_init() ...@@ -39,6 +42,13 @@ void rt_hw_interrupt_init()
{ {
rt_base_t index; rt_base_t index;
/* init exceptions table */
for(index=0; index < MAX_HANDLERS; index++)
{
irq_desc[index].handler = (rt_isr_handler_t)rt_hw_interrupt_handler;
irq_desc[index].param = RT_NULL;
}
for (index = 0; index < MAX_HANDLERS; index ++) for (index = 0; index < MAX_HANDLERS; index ++)
{ {
AT91C_BASE_AIC->AIC_SVR[index] = (rt_uint32_t)rt_hw_interrupt_handler; AT91C_BASE_AIC->AIC_SVR[index] = (rt_uint32_t)rt_hw_interrupt_handler;
...@@ -76,16 +86,28 @@ void rt_hw_interrupt_umask(int vector) ...@@ -76,16 +86,28 @@ void rt_hw_interrupt_umask(int vector)
/** /**
* This function will install a interrupt service routine to a interrupt. * This function will install a interrupt service routine to a interrupt.
* @param vector the interrupt number * @param vector the interrupt number
* @param new_handler the interrupt service routine to be installed * @param handler the interrupt service routine to be installed
* @param old_handler the old interrupt service routine * @param param the parameter for interrupt service routine
* @name unused.
*
* @return the 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)
{ {
rt_isr_handler_t old_handler = RT_NULL;
if(vector >= 0 && vector < MAX_HANDLERS) if(vector >= 0 && vector < MAX_HANDLERS)
{ {
if (old_handler != RT_NULL) *old_handler = (rt_isr_handler_t)AT91C_BASE_AIC->AIC_SVR[vector]; old_handler = irq_desc[vector].handler;
if (new_handler != RT_NULL) AT91C_BASE_AIC->AIC_SVR[vector] = (rt_uint32_t)new_handler; if (handler != RT_NULL)
{
irq_desc[vector].handler = (rt_isr_handler_t)handler;
irq_desc[vector].param = param;
}
} }
return old_handler;
} }
/*@}*/ /*@}*/
...@@ -24,9 +24,14 @@ ...@@ -24,9 +24,14 @@
void rt_hw_trap_irq() void rt_hw_trap_irq()
{ {
rt_isr_handler_t hander = (rt_isr_handler_t)AT91C_BASE_AIC->AIC_IVR; int irqno;
extern struct rt_irq_desc irq_desc[];
hander(AT91C_BASE_AIC->AIC_ISR); /* get interrupt number */
irqno = AT91C_BASE_AIC->AIC_ISR;
/* invoke isr with parameters */
irq_desc[irqno].handler(irqno, irq_desc[irqno].param);
/* end of interrupt */ /* end of interrupt */
AT91C_BASE_AIC->AIC_EOICR = 0; AT91C_BASE_AIC->AIC_EOICR = 0;
......
...@@ -12,24 +12,25 @@ ...@@ -12,24 +12,25 @@
* 2008-12-11 XuXinming first version * 2008-12-11 XuXinming first version
*/ */
#include <rtthread.h> #include <rthw.h>
#include "LPC24xx.h" #include "LPC24xx.h"
#define MAX_HANDLERS 32 #define MAX_HANDLERS 32
/* exception and interrupt handler table */
struct rt_irq_desc irq_desc[MAX_HANDLERS];
extern rt_uint32_t rt_interrupt_nest; extern rt_uint32_t rt_interrupt_nest;
/* exception and interrupt handler table */ /* exception and interrupt handler table */
rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread; rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
rt_uint32_t rt_thread_switch_interrupt_flag; rt_uint32_t rt_thread_switch_interrupt_flag;
/** /**
* @addtogroup LPC2478 * @addtogroup LPC2478
*/ */
/*@{*/ /*@{*/
void rt_hw_interrupt_handler(int vector, void *param)
void rt_hw_interrupt_handle(int vector)
{ {
rt_kprintf("Unhandled interrupt %d occured!!!\n", vector); rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
} }
...@@ -45,11 +46,15 @@ void rt_hw_interrupt_init() ...@@ -45,11 +46,15 @@ void rt_hw_interrupt_init()
VICVectAddr = 0; VICVectAddr = 0;
VICIntSelect = 0; VICIntSelect = 0;
for ( i = 0; i < 32; i++ ) /* init exceptions table */
for(i=0; i < MAX_HANDLERS; i++)
{ {
vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + i*4); irq_desc[i].handler = (rt_isr_handler_t)rt_hw_interrupt_handler;
vect_cntl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + i*4); irq_desc[i].param = RT_NULL;
*vect_addr = 0x0;
vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + i*4);
vect_cntl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + i*4);
*vect_addr = (rt_uint32_t)&irq_desc[i];
*vect_cntl = 0xF; *vect_cntl = 0xF;
} }
...@@ -70,20 +75,31 @@ void rt_hw_interrupt_umask(int vector) ...@@ -70,20 +75,31 @@ void rt_hw_interrupt_umask(int vector)
VICIntEnable = (1 << vector); VICIntEnable = (1 << vector);
} }
void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler) /**
* This function will install a interrupt service routine to a interrupt.
* @param vector the interrupt number
* @param handler the interrupt service routine to be installed
* @param param the parameter for interrupt service routine
* @name unused.
*
* @return the old handler
*/
rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
void *param, char *name)
{ {
rt_uint32_t *vect_addr; rt_isr_handler_t old_handler = RT_NULL;
if(vector < MAX_HANDLERS)
{
/* find first un-assigned VIC address for the handler */
vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + vector*4);
/* get old handler */ if(vector >= 0 && vector < MAX_HANDLERS)
if (old_handler != RT_NULL) *old_handler = (rt_isr_handler_t)*vect_addr; {
old_handler = irq_desc[vector].handler;
*vect_addr = (rt_uint32_t)new_handler; /* set interrupt vector */ if (handler != RT_NULL)
{
irq_desc[vector].handler = (rt_isr_handler_t)handler;
irq_desc[vector].param = param;
}
} }
return old_handler;
} }
/*@}*/ /*@}*/
...@@ -128,12 +128,15 @@ void rt_hw_trap_resv(struct rt_hw_register *regs) ...@@ -128,12 +128,15 @@ void rt_hw_trap_resv(struct rt_hw_register *regs)
extern rt_isr_handler_t isr_table[]; extern rt_isr_handler_t isr_table[];
void rt_hw_trap_irq() void rt_hw_trap_irq()
{ {
rt_isr_handler_t isr_func; int irqno;
struct rt_irq_desc* irq;
isr_func = (rt_isr_handler_t) VICVectAddr; extern struct rt_irq_desc irq_desc[];
/* fixme, how to get interrupt number */ irq = (struct rt_irq_desc*) VICVectAddr;
isr_func(0); irqno = ((rt_uint32_t) irq - (rt_uint32_t) &irq_desc[0])/sizeof(struct rt_irq_desc);
/* invoke isr */
irq->handler(irqno, irq->param);
} }
void rt_hw_trap_fiq() void rt_hw_trap_fiq()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册