📄 vicinit.c
字号:
/*************************************************************************
*
* Used with ICCARM and AARM.
*
* (c) Copyright IAR Systems 2003
*
* File name : LPC_Vic.h
* Description : Define API for VIC
*
* $Revision: 1.1.6.1 $
**************************************************************************/
#include "config.h"
/***************************************************************************
**
** VIC Interrupt channels
**
***************************************************************************/
#define VIC_WDT 0 /* Watchdog */
#define VIC_SW 1 /* Software interrupts */
#define VIC_DEBUGRX 2 /* Embedded ICE, DbgCommRx */
#define VIC_DEBUGTX 3 /* Embedded ICE, DbgCommTx */
#define VIC_TIMER0 4 /* Timer 0 (Match 0-3 Capture 0-3) */
#define VIC_TIMER1 5 /* Timer 1 (Match 0-3 Capture 0-3) */
#define VIC_UART0 6 /* UART 0 (RLS, THRE, RDA, CTI) */
#define VIC_UART1 7 /* UART 1 (RLS, THRE, RDA, CTI, MSI) */
#define VIC_PWM0 8 /* PWM 0 (Match 0-6 Capture 0-3) */
#define VIC_I2C 9 /* I2C 0 (SI) */
#define VIC_SPI 10 /* SPI 0 (SPIF, MODF) */
#define VIC_SSP 11 /* SSP */
#define VIC_PLL 12 /* PLL lock (PLOCK) */
#define VIC_RTC 13 /* RTC (RTCCIF, RTCALF) */
#define VIC_EINT0 14 /* External interrupt 0 (EINT0) */
#define VIC_EINT1 15 /* External interrupt 1 (EINT1) */
#define VIC_EINT2 16 /* External interrupt 2 (EINT2) */
#define VIC_EINT3 17 /* External interrupt 3 (EINT3) */
#define VIC_AD0 18 /* A/D converter 0 */
#define VIC_I2C1 19 /* I2C 1 */
#define VIC_BOD 20 /* Brown out detect */
#define VIC_AD1 21 /* A/D converter 1 */
#define VIC_USB 22 /* USB Low and High priority */
extern void UART0_ISR(void);
extern void UART1_ISR(void);
extern void TIMER0_ISR(void);
extern void TIMER1_ISR(void);
/*************************************************************************
* Function Name: NonVectISR
* Parameters: void
* Return: void
*
* Description: non vectored callback subroutine
*
*************************************************************************/
void NonVectISR(void)
{
}
/*************************************************************************
* Function Name: VIC_Clear
* Parameters: void
* Return: void
*
* Description:
*
*************************************************************************/
void VIC_Clear(void)
{
// Assign all interrupt chanels to IRQ
VICIntSelect = 0;
// Diasable all interrupts
VICIntEnClr = 0xFFFFFFFF;
// Clear all software interrutps
VICSoftIntClear = 0xFFFFFFFF;
// VIC registers can be accessed in User or privileged mode
VICProtection = 0;
// Clear interrupt
VICVectAddr = 0;
// Clear address of the Interrupt Service routine (ISR) for non-vectored IRQs.
VICDefVectAddr = 0;
// Clear address of the Interrupt Service routine (ISR) for vectored IRQs.
VICVectAddr0 = 0;
VICVectAddr1 = 0;
VICVectAddr2 = 0;
VICVectAddr3 = 0;
VICVectAddr4 = 0;
VICVectAddr5 = 0;
VICVectAddr6 = 0;
VICVectAddr7 = 0;
VICVectAddr8 = 0;
VICVectAddr9 = 0;
VICVectAddr10 = 0;
VICVectAddr11 = 0;
VICVectAddr12 = 0;
VICVectAddr13 = 0;
VICVectAddr14 = 0;
VICVectAddr15 = 0;
// Disable all vectored IRQ slots
VICVectCntl0 = 0;
VICVectCntl1 = 0;
VICVectCntl2 = 0;
VICVectCntl3 = 0;
VICVectCntl4 = 0;
VICVectCntl5 = 0;
VICVectCntl6 = 0;
VICVectCntl7 = 0;
VICVectCntl8 = 0;
VICVectCntl9 = 0;
VICVectCntl10 = 0;
VICVectCntl11 = 0;
VICVectCntl12 = 0;
VICVectCntl13 = 0;
VICVectCntl14 = 0;
VICVectCntl15 = 0;
}
/*************************************************************************
* Function Name: VIC_Init
* Parameters: void
* Return: void
*
* Description: Initialize VIC
*
*************************************************************************/
void VIC_Init(void)
{
VIC_Clear();
// Enable interrupts non vectored interrupts
VICDefVectAddr = (uint32)NonVectISR; // 设置非向量中断服务程序地址
VICIntSelect = 0x00; // 所有中断通道设置为IRQ中断
// UART0 interrupt
VICVectCntl0 = 0x20 | VIC_UART0; // 设置串口0中断通道分配
VICVectAddr0 = (uint32)UART0_ISR; // 设置中断服务程序地址
VICIntEnable = 1 << VIC_UART0; // 使能串口0中断
// UART1 interrupt
VICVectCntl1 = 0x20 | VIC_UART1; // 设置串口1中断通道分配
VICVectAddr1 = (uint32)UART1_ISR; // 设置中断服务程序地址
VICIntEnable = 1 << VIC_UART1; // 使能串口1中断
// Timer0 interrupt
VICVectCntl2 = 0x20 | VIC_TIMER0; // 设置定时器0中断通道分配
VICVectAddr2 = (uint32)TIMER0_ISR; // 设置中断服务程序地址
VICIntEnable = 1 << VIC_TIMER0; // 使能定时器0中断
// Timer1 interrupt
VICVectCntl3 = 0x20 | VIC_TIMER1; // 设置定时器1中断通道分配
VICVectAddr3 = (uint32)TIMER1_ISR; // 设置中断服务程序地址
VICIntEnable = 1 << VIC_TIMER1; // 使能定时器1中断
IRQEnable(); // IRQ中断使能
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -