⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vicinit_old.c

📁 基于飞利浦公司ARM7处理器
💻 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          */

typedef enum {
  VIC_Slot0 = 0,  // high priority
  VIC_Slot1,VIC_Slot2,VIC_Slot3,VIC_Slot4,VIC_Slot5,VIC_Slot6,VIC_Slot7,VIC_Slot8,
  VIC_Slot9,VIC_Slot10,VIC_Slot11,VIC_Slot12,VIC_Slot13,VIC_Slot14,VIC_Slot15
}LPC_VicIrqSlots_t;

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_Init
 * Parameters: void
 * Return: void
 *
 * Description: Initialize VIC
 *
 *************************************************************************/
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_EnableInt
 * Parameters: lpc_uint32 IntType
 * Return: void
 *
 * Description: Enable specific interrupt
 *
 *************************************************************************/
void VIC_EnableInt(unsigned int IntType)
{
  VICIntEnable |= IntType;
}

/*************************************************************************
 * Function Name: VIC_DisableInt
 * Parameters: unsigned int IntType
 * Return: void
 *
 * Description: Disable specific interrupt
 *
 *************************************************************************/
void VIC_DisableInt(unsigned int IntType)
{
  VICIntEnClr |= IntType;
}

/*************************************************************************
 * Function Name: VIC_SetFastInt
 * Parameters: lpc_uint32 IntType
 * Return: void
 *
 * Description: Enable FIQ interrupt
 *
 *************************************************************************/
void VIC_EnableFastInt(unsigned int FastIntMask)
{
  VICIntSelect |= FastIntMask;
}

/*************************************************************************
 * Function Name: VIC_DisFastInt
 * Parameters: lpc_uint32 IntType
 * Return: void
 *
 * Description: Disable FIQ interrupt
 *
 *************************************************************************/
void VIC_DisableFastInt(unsigned int FastIntMask)
{
  VICIntSelect &= ~FastIntMask;
}

/*************************************************************************
 * Function Name: VIC_EnableNonVectoredIRQ
 * Parameters:  pIRQSub - Non Vectored IRQ Sub address
 * Return: void
 *
 * Description:  Set VICDefVectAddr to be the IRQ Sub address.
 *
 *************************************************************************/
void VIC_EnableNonVectoredIRQ(void(*pIRQSub)())
{
  VICDefVectAddr = (unsigned int)pIRQSub;
}

/*************************************************************************
 * Function Name: VIC_SetVectoredIRQ
 * Parameters:  void(*pIRQSub)()
 *              LPC_VicIrqSlots_t VicIrqSlot
 *              unsigned int VicIntSouce
 *
 * Return: void
 *
 * Description:  Init vectored inerrutps
 *
 *************************************************************************/
void VIC_SetVectoredIRQ(void(*pIRQSub)(), LPC_VicIrqSlots_t VicIrqSlot, unsigned int VicIntSource)
{
  unsigned long volatile *pReg;
  // load base address of vectored address registers
  pReg = &VICVectAddr0;
  // Set Address of callback function to corresponding Slot
  *(pReg+VicIrqSlot) = (unsigned long)pIRQSub;
  // load base address of ctrl registers
  pReg = &VICVectCntl0;
  // Set source chanel and enable the slot
  *(pReg+VicIrqSlot) = VicIntSource | 0x20;
  // Clear FIQ select bit
  VICIntSelect &= ~(1<<VicIntSource);
}

void VIC_Init(void)
{
  VIC_Clear();
  // Enable interrupts non vectored interrupts
/*  VIC_EnableNonVectoredIRQ(NonVectISR);
  	
  // UART0 interrupt
  VIC_SetVectoredIRQ(UART0_ISR,VIC_Slot0,VIC_UART0);
  VIC_EnableInt(1<<VIC_UART0);

  // UART1 interrupt
  VIC_SetVectoredIRQ(UART1_ISR,VIC_Slot1,VIC_UART1);
  VIC_EnableInt(1<<VIC_UART1);

  // Timer0 interrupt
  VIC_SetVectoredIRQ(TIMER0_ISR,VIC_Slot2,VIC_TIMER0);
  VIC_EnableInt(1<<VIC_TIMER0);
  
  // Timer1 interrupt
  VIC_SetVectoredIRQ(TIMER1_ISR,VIC_Slot3,VIC_TIMER1);
  VIC_EnableInt(1<<VIC_TIMER1);
*/  
  	VICDefVectAddr = (uint32)NonVectISR;
  	
  	VICIntSelect = 0x00;				// 所有中断通道设置为IRQ中断
  	
  	VICVectCntl0 = 0x20 | VIC_UART0;	// 设置串口0中断通道分配
	VICVectAddr0 = (uint32)UART0_ISR;	// 设置中断服务程序地址
	VICIntEnable = 1 << VIC_UART0;		// 使能串口0中断
	
	VICVectCntl1 = 0x20 | VIC_UART1;	// 设置串口1中断通道分配
	VICVectAddr1 = (uint32)UART1_ISR;	// 设置中断服务程序地址
	VICIntEnable = 1 << VIC_UART1;		// 使能串口1中断
		
	VICVectCntl2 = 0x20 | VIC_TIMER0;	// 设置定时器0中断通道分配
	VICVectAddr2 = (uint32)TIMER0_ISR;	// 设置中断服务程序地址
	VICIntEnable = 1 << VIC_TIMER0;		// 使能定时器0中断
	
	VICVectCntl3 = 0x20 | VIC_TIMER1;	// 设置定时器1中断通道分配
	VICVectAddr3 = (uint32)TIMER1_ISR;	// 设置中断服务程序地址
	VICIntEnable = 1 << VIC_TIMER1;		// 使能定时器1中断
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -