在使用CodeWarrior建立了MCF52259工程以后,系统会生成一个exceptions.c文件,冷火的中断向量表就在这个文件中。
中断向量表如下所示:
/* Interrupt vector table */
__declspec(vectortable) vectorTableEntryType _vect[256] =
{
(vectorTableEntryType)__SP_AFTER_RESET,
/* 0 (0x000) Initial supervisor SP */
_startup, /* 1 (0x004) Initial PC */
asm_exception_handler, /* 2 (0x008) Access Error */
asm_exception_handler, /* 3 (0x00C) Address Error */
asm_exception_handler, /* 4 (0x010) Illegal Instruction */
..........
..........
..........
..........
asm_exception_handler, /* 252 (0x___) Reserved */
asm_exception_handler, /* 253 (0x___) Reserved */
asm_exception_handler, /* 254 (0x___) Reserved */
asm_exception_handler, /* 255 (0x___) Reserved */
};
冷火一共有64个中断源共256个中断,这些中断一共分为7个中断优先级,第7级优先级最高,第1级优先级最低。前64个中断是保留给处理器处理复位,以及系统的各种异常,后面的64-255 中断是保留给用户配置的。
总的来说,冷火的中断配置过程如下:
1.使能相应的中断源
2.配置中断优先级和中断级别
3.将该中断的中断服务程序加入到向量表中。
下面以配置PIT中断为例说明:
PIT的定时周期计算公式为:
Timeout period=2^PCSRn[PRE]*(PMRn[PM] + 1)/(fsys/2)
/***********************************************
* 配置 1ms中断 系统频率 128MHz
* ((2*2)*16000)/(128000000/2) = 0.001s
***********************************************/
void PIT_Init(void)
{
MCF_PIT_PCSR(0)=MCF_PIT_PCSR_PRE(2)
|MCF_PIT_PCSR_PIE
|MCF_PIT_PCSR_RLD
|MCF_PIT_PCSR_OVW
|MCF_PIT_PCSR_PIF;
MCF_PIT_PMR(0)=(uint16)(16000 - 1);
/****************************************
在中断向量表119 的位置写入PIT 中断服务函数
中断向量表的位置 = 中断源号 + 64
配置PIT的中断级别 55 + 64 = 119
to allow the request to be disabled
the IMR is set to all ones by reset
****************************************/
MCF_INTC0_IMRL&=~MCF_INTC_IMRL_MASKALL;
//使能PIT中断
MCF_INTC0_IMRH&=~MCF_INTC_IMRH_INT_MASK55;
//配置中断优先级和中断级别
MCF_INTC0_ICR55=MCF_INTC_ICR_IP(6)+MCF_INTC_ICR_IL(2);
//使能PIT
MCF_PIT_PCSR(0)|=MCF_PIT_PCSR_EN;
}
PIT的中断服务程序中一定记得清中断标志位,否则会一直进中断,PIT的中断服务代码如下:
__declspec(interrupt:0) void PIT0_handler(void)
{
//user code
count++;
//clear interrupt flag
MCF_PIT_PCSR(0)|=MCF_PIT_PCSR_PIF;
}
最后修改中断向量表如下:
asm_exception_handler, /* 117 (0x___) Reserved */
asm_exception_handler, /* 118 (0x___) Reserved */
PIT0_handler, /* PIT0中断 */
asm_exception_handler, /* 120 (0x___) Reserved */
asm_exception_handler, /* 121 (0x___) Reserved */