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

📄 target.c

📁 基于ARM7处理器的中断与串口在ucos下切换的演示程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			target.c
** Last modified Date:	2004-09-17
** Last Version:		1.0
** Descriptions:		header file of the specific codes for LPC2100 target boards
**						Every project should include a copy of this file, user may modify it as needed
**------------------------------------------------------------------------------------------------------
** Created by:			Chenmingji
** Created date:		2004-02-02
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:			Chenmingji
** Modified date:		2004-09-17
** Version:				1.01
** Descriptions:		Renewed the template, added more compiler supports 
**
**------------------------------------------------------------------------------------------------------
** Modified by: 
** Modified date:
** Version:	
** Descriptions: 
**
********************************************************************************************************/

#define IN_TARGET
#include "config.h"

uint32 eint0i = 0;

volatile uint8  RcvSendBuf[16384];
volatile unsigned int eintqin = 0;
volatile unsigned int eintqout = 0;
volatile unsigned int eintinbufsize = 16384;

/*********************************************************************************************************
** Function name:			IRQ_Exception
**
** Descriptions:			interrupt exceptional handler , change it as needed
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void IRQ_Exception(void)
{
    while(1);                   // change it to your code  这一句替换为自己的代码
}

/*********************************************************************************************************
** Function name:			FIQ_Exception
**
** Descriptions:			Fast interrupt exceptional handler , change it as needed
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void FIQ_Exception(void)
{
    while(1);                   // change it to your code  这一句替换为自己的代码
}
/*********************************************************************************************************
** Function name:			Timer0_Exception
**
** Descriptions:			Timer0 interrupt service function
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void Timer0_Exception(void)
{
    T0IR = 0x01;
    VICVectAddr = 0;            //interrupt close 通知中断控制器中断结束
    OSTimeTick();
}

/*********************************************************************************************************
** Function name:			Timer0Init
**
** Descriptions:			Initialize the Time0
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void Timer0Init(void)
{
    T0IR = 0xffffffff;
    T0TC = 0;
    T0TCR = 0x01;
    T0MCR = 0x03;
    T0MR0 = (Fpclk / OS_TICKS_PER_SEC);
 }


void Eint0_Exception(void)
{

	uint8  tempchar;

    eint0i++;
	EXTINT = 0x01;

	/*tempchar = ((IO0PIN & 0x00600000) >> 21)|  //P0.22 P0.21
              ((IO1PIN & 0x00040000) >> 16)|  //P1.18
              ((IO0PIN & 0x0E000000) >> 22)|  //P0.27 P0.26 P0.25
              ((IO1PIN & 0x00020000) >> 11)|  //P1.17
              ((IO0PIN & 0x10000000) >> 21);   //P0.28
    */

	tempchar = eint0i &0xFF;

	RcvSendBuf[eintqin]= tempchar;
	if ( ++eintqin >= eintinbufsize)
    {
        eintqin = 0;
    };	

	
	VICVectAddr = 0;				/* 向量中断结束				*/
}

int EintrdUsed(void)
{
   int length;

   OS_ENTER_CRITICAL();
   if (eintqin >= eintqout)
   {
      length = eintqin - eintqout;
   }
   else
   {
      length = eintinbufsize -eintqout + eintqin ;
   }
   OS_EXIT_CRITICAL();
   return length;
   
}

int EintRead(void *data, int length, unsigned long tmout) 
{
   char * p;
   int templength;

   
   tmout = tmout;
   p = (char *)data;

   if (eintqin == eintqout)
   {
     length = 0;
	 return 0;
   }
   OS_ENTER_CRITICAL();
   if (eintqin > eintqout)
   {
      templength = eintqin - eintqout;
   }
   else
   {
      templength = eintinbufsize - eintqout + eintqin ;
   }
   if (length < templength)
   {
       templength = length;
       while (templength >0)
       {
       	  *p = RcvSendBuf[eintqout];
		  p++;
		  templength--;
		  if ( ++eintqout >= eintinbufsize)
          {
             eintqout = 0;
          }		  
       }	   	
   }
   else
   {
	   while (eintqout != eintqin)
	   {
	      *p = RcvSendBuf[eintqout];
		  p++;
		  if ( ++eintqout >= eintinbufsize)
	      {
	         eintqout = 0;
	      }
	   }
   }
   
   OS_EXIT_CRITICAL();

   return length;
   
}

void EintFlush(void)
{
   OS_ENTER_CRITICAL();
   eintqin =0;
   eintqout =0;
   OS_EXIT_CRITICAL();
}


void EInt0Init(void)
{
    PINSEL1 = (PINSEL1 & 0xFFFFFFFC)|0x00000001; //P0.16 Eint0
    EXTMODE = (EXTMODE & 0xFFFFFFFE)|0x01;
	EXTPOLAR = (EXTPOLAR & 0xFFFFFFFE) | 0x01;
}
/*********************************************************************************************************
** Function name:			VICInit
**
** Descriptions:			Initialize the Interrupt Vevtor Controller
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void VICInit(void)
{
    extern void IRQ_Handler(void);
    extern void Timer0_Handler(void);
    extern void Eint0_Handler(void);
	extern void Uart0_Handler(void);
	extern void Uart1_Handler(void);

    VICIntEnClr = 0xffffffff;
    VICDefVectAddr = (uint32)IRQ_Handler;

    VICVectAddr3 = (uint32)Timer0_Handler;
    VICVectCntl3 = (0x20 | 0x04);
    VICIntEnable = 1 << 4;
    
	/* 打开EINT0中断(使用向量中断) */

⌨️ 快捷键说明

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