?? isr.c
字號:
/***************************************************************************\
Copyright (c) 2004-2007 threewater@up-tech.com, All rights reserved.
by threewter 2004.5.12
\***************************************************************************/
/***************************************************************************\
#說明:中斷處理函數
#接口函數
---------------------------------- Bug --------------------------------------
---------------------------------- TODO list --------------------------------------
2004-5-12 對于邋IO口的多中斷源的共享
----------------------------------修正--------------------------------------
2004-5-12 1、移植
2、改變了中斷函數的定義,添加了一個標志中斷號的參數
3、添加了void ISR_Init(void)函數定義,系統初始化中斷的時候調用
\***************************************************************************/
#include "../inc/drv/register.h"
#include "isr.h"
#include "includes.h"
#include "../inc/sys/lib.h"
#include <string.h>
typedef struct{
Interrupt_func_t InterruptHandlers;
void* data;
}struct_InterruptFunc;
static struct_InterruptFunc InterruptFunc[MAXHNDLRS];
//#define GetISROffsetClr() IDR_GETIRQ
int GetISROffsetClr()
{
//計算中斷的偏移地址,低位優先
int i,ispr=VICIRQStatus; //temp bit
for(i=0; i<MAXHNDLRS; i++){
if(ispr&0x1){
return i;
}
ispr>>=1;
}
return i;
}
void ISR_Init(void)
{
VICIntEnClr = 0xffffffff; //disable all interrupt
VICVectAddr = 0; //write vector address
VICIntSelect = 0; //set all interrupt to irq
memset(InterruptFunc, 0, sizeof(InterruptFunc));
}
void SetISR_Interrupt(int vector, void (*handler)(int, void*), void* data)
{
#if OS_CRITICAL_METHOD == 3
OS_CPU_SR cpu_sr;
#endif
OS_ENTER_CRITICAL();
if(vector>=MAXHNDLRS || vector<0)
return;
// tmp=rINTC_STAT; //clear interrupt status
InterruptFunc[vector].InterruptHandlers = handler;
InterruptFunc[vector].data = data;
VICIntEnable|= (1<<vector); //enable interrupt
OS_EXIT_CRITICAL();
}
void ISR_Handler(void)
{
unsigned int IntOffset=GetISROffsetClr(); //得到中斷向量的偏移地址
if(IntOffset>=14)
printk("@%d ",IntOffset);
if(IntOffset>=MAXHNDLRS)
return;
if(InterruptFunc[IntOffset].InterruptHandlers==NULL){
VICVectAddr = 0; //write vector address
printk("Unexpected Interrupt %d occur\n", IntOffset);
return;
}
OSIntEnter();
// Call interrupt service routine
(*InterruptFunc[IntOffset].InterruptHandlers)(IntOffset, InterruptFunc[IntOffset].data);
VICVectAddr = 0; //write vector address
OSIntExit();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -