📄 intr.c
字号:
#include <44b.h>#include <sys.h>#include <errno.h>#include <event.h>#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <sys/vm.h>#include <sys/tmr.h>#include <sys/mem.h>#include <sys/intr.h>#include <sys/types.h>#include <sys/config.h>#include <sys/syscall.h>
void HaltSwi(void);
void HaltUndef(void);
void HaltPabort(void);
void HaltDabort(void);
void __irq Rtc_Tick(void)
{
intr_eoi(INTR_TICK);
handle(INTR_TICK);}
void HaltUndef(void)
{
kprintf("Undefined instruction exception!!!\n");
while(1);
}
void HaltSwi(void)
{
kprintf("SWI exception!!!\n");
while(1);
}
void HaltPabort(void)
{
kprintf("Pabort exception!!!\n");
while(1);
}
void HaltDabort(void)
{
kprintf("Dabort exception!!!\n");
while(1);
}
/* * This table holds isr function pointers that can be chained together * to support multiple isrs per interrupt */static struct isr isrfunctab[ISRS];/* * This table maintains the lists of isrs that are called when an * interrupt occurs. The elements of each list are elements of the * isr function table. */static isr_t isrtab[INTRS];
voidintr_init(){
pISR_UNDEF=(unsigned)HaltUndef;
pISR_SWI =(unsigned)HaltSwi;
pISR_PABORT=(unsigned)HaltPabort;
pISR_DABORT=(unsigned)HaltDabort;
//rINTCON=0x1; // Vectored Int. IRQ enable,FIQ disable
rINTCON=0x5; // Non-vectored,IRQ enable,FIQ disable
rINTMOD=0x0; // All=IRQ mode
rINTMSK=~BIT_GLOBAL; // All interrupt is masked.
pISR_TICK=(unsigned)Rtc_Tick;
}intintr_unmask(int intr){
rINTMSK = rINTMSK & ~(0x01 << intr);}voidintr_eoi(int intr){ rI_ISPC=0x01 << intr;
}voidisr_init(isr_t isr){ isr->f = NULL; isr->params = NULL; isr->next = NULL;}voidisrtab_init(){ int i; for (i = 0; i < ISRS; i++) isr_init(&(isrfunctab[i])); for (i = 0; i < INTRS; i++) isrtab[i] = NULL;}static intfatal(int intr){ if (intr < 26) return 1; return 0;}void handle(int intr){ isr_t isr; for (isr = isrtab[intr]; isr != NULL; isr = isr->next) (*(isr->f))(isr->params); event_raise(intr);
}intisr_inst(int intr, isr_func_t f, void *params){ isr_t isr; int i; if (intr < 0 || intr >= INTRS || f == NULL) return EINVAL; disable; // Get a free slot in the isr function table for (i = 0; i < ISRS; i++) if (isrfunctab[i].f == NULL) break; if (i == ISRS) { enable; return EAGAIN; } isrfunctab[i].f = f; isrfunctab[i].params = params; if (isrtab[intr] == NULL) { isrtab[intr] = &(isrfunctab[i]); enable; return 0; } for (isr = isrtab[intr]; isr->next != NULL; isr = isr->next); isr->next = &(isrfunctab[i]); enable; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -