📄 vic.c
字号:
/*********************************************************************
* Copyright (c) 2011-2012,李士伟
* All rights reserved.
*文 件 名:vic.c
*描 述:中断控制器驱动源文件
*当前版本:V1.01
*作 者:李士伟
*创建日期:2011.09.30
**********************************************************************/
/*********************************************************************
*版 本:V1.01
*修 改 人:李士伟
*修改日期:2012.01.24
*描 述:VIC_RegisterIRQ添加判断中断优先级是否已使用功能
**********************************************************************/
#include <drivers\lpc2103\vic.h>
extern void IRQ_Default(void);
/*********************************************************************
*函 数 名:VIC_Init
*描 述:初始化中断控制器
*输入参数:protect: 1,保护VIC寄存器在特权下访问,0,不保护
*输出参数:无
*返 回 值:无
*注 意:
**********************************************************************/
void VIC_Init(INT32U protect)
{
VICIntEnClr = 0xffffffff; /* 禁止所有中断 */
VICDefVectAddr = (INT32U)IRQ_Default; /* 设置默认中断服务例程 */
/* 保护VIC寄存器在特权模式下访问 */
protect > 0 ? (VICProtection |= 1)/*保护*/: (VICProtection &= 0xfffffffe)/*不受保护*/;
}
/*********************************************************************
*函 数 名:VIC_RegisterIRQ
*描 述:注册irq中断服务例程
*输入参数:ISR_addr: 服务例程地址
* intr_num: 中断源通道号
* prio: 中断优先级
*输出参数:无
*返 回 值:0,注册失败,1,注册成功
*注 意:
**********************************************************************/
INT32U VIC_RegisterIRQ(void (*ISR_addr)(void), INT8U intr_num, INT8U prio)
{
switch (prio)
{
case 0: /*IRQ优先级最高*/
{
if (VICVectAddr0 != 0)
{
return 0;
}
VICVectCntl0 = 0x20 | intr_num;
VICVectAddr0 = (INT32U)ISR_addr;
break;
}
case 1:
{
if (VICVectAddr1 != 0)
{
return 0;
}
VICVectCntl1 = 0x20 | intr_num;
VICVectAddr1 = (INT32U)ISR_addr;
break;
}
case 2:
{
if (VICVectAddr2 != 0)
{
return 0;
}
VICVectCntl2 = 0x20 | intr_num;
VICVectAddr2 = (INT32U)ISR_addr;
break;
}
case 3:
{
if (VICVectAddr3 != 0)
{
return 0;
}
VICVectCntl3 = 0x20 | intr_num;
VICVectAddr3 = (INT32U)ISR_addr;
break;
}
case 4:
{
if (VICVectAddr4 != 0)
{
return 0;
}
VICVectCntl4 = 0x20 | intr_num;
VICVectAddr4 = (INT32U)ISR_addr;
break;
}
case 5:
{
if (VICVectAddr5 != 0)
{
return 0;
}
VICVectCntl5 = 0x20 | intr_num;
VICVectAddr5 = (INT32U)ISR_addr;
break;
}
case 6:
{
if (VICVectAddr6 != 0)
{
return 0;
}
VICVectCntl6 = 0x20 | intr_num;
VICVectAddr6 = (INT32U)ISR_addr;
break;
}
case 7:
{
if (VICVectAddr7 != 0)
{
return 0;
}
VICVectCntl7 = 0x20 | intr_num;
VICVectAddr7 = (INT32U)ISR_addr;
break;
}
case 8:
{
if (VICVectAddr8 != 0)
{
return 0;
}
VICVectCntl8 = 0x20 | intr_num;
VICVectAddr8 = (INT32U)ISR_addr;
break;
}
case 9:
{
if (VICVectAddr9 != 0)
{
return 0;
}
VICVectCntl9 = 0x20 | intr_num;
VICVectAddr9 = (INT32U)ISR_addr;
break;
}
case 10:
{
if (VICVectAddr10 != 0)
{
return 0;
}
VICVectCntl10 = 0x20 | intr_num;
VICVectAddr10 = (INT32U)ISR_addr;
break;
}
case 11:
{
if (VICVectAddr11 != 0)
{
return 0;
}
VICVectCntl11 = 0x20 | intr_num;
VICVectAddr11 = (INT32U)ISR_addr;
break;
}
case 12:
{
if (VICVectAddr12 != 0)
{
return 0;
}
VICVectCntl12 = 0x20 | intr_num;
VICVectAddr12 = (INT32U)ISR_addr;
break;
}
case 13:
{
if (VICVectAddr13 != 0)
{
return 0;
}
VICVectCntl13 = 0x20 | intr_num;
VICVectAddr13 = (INT32U)ISR_addr;
break;
}
case 14:
{
if (VICVectAddr14 != 0)
{
return 0;
}
VICVectCntl14 = 0x20 | intr_num;
VICVectAddr14 = (INT32U)ISR_addr;
break;
}
case 15:
{
if (VICVectAddr15 != 0)
{
return 0;
}
VICVectCntl15 = 0x20 | intr_num;
VICVectAddr15 = (INT32U)ISR_addr;
break;
}
default: /*IRQ优先级最低*/
{
if (VICDefVectAddr != 0)
{
return 0;
}
VICDefVectAddr = (INT32U)ISR_addr;
break;
}
}
VICIntSelect &= ~(0x00000001 << intr_num); /*设为IRQ中断*/
VICIntEnable = (1 << intr_num); /*使能中断*/
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -