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

📄 drv_exint.c

📁 Enhanced LPC213x device drivers,tools ADS1.2
💻 C
字号:
#include "config_60_61.h"
#include "config_GD61.h"
#include "include_GD61.h"

///////////////////////////////////////////////////////////////////////////
extern char TxCurrent;
extern char RxCurrent;
extern char RF_RxPll;
extern char RF_TxPll;

extern volatile uint16 r_inp0,r_outp0,r_count0;
extern volatile uint16 MP_FailedmSecondCnt;		// for main power failed detector

volatile uint8  CC1000Mode;
volatile uint8  RF_RxSynSemaphore;	
volatile uint32 RF_Rx_PreHead;		  			// equal to 0xAAAAAAAA 

volatile uint8  RF_BufferFlag;
volatile uint8  RF_Rx_Buf[RX_BUFFER_LEN];		// UART1 receiving buffer
volatile uint8  RF_Tx_Buf[TX_BUFFER_LEN];		// UART1 sending buffer
volatile uint16 RFr_inp=0,RFr_outp=0,RF_RxCounter=0;
volatile uint16 RFt_inp=0,RFt_outp=0,RF_TxCounter=0;

volatile uint8  RF_TxBitCounter=0;	// bit pointer of data_byte in sending
volatile uint8  RF_RxBitCounter=0;	// bit pointer of data_byte in sending

volatile uint8  RF_SendingBuf;
volatile uint8  RF_ReceivingBuf;

//////////////////////////////////////////////////////////////////////////

void __irq IRQ_Eint0Serving (void);
void EINT0_Initialize(void);
//void __irq IRQ_Eint2Serving(void);
//void EINT2_Initialize(void);

/*************************************************************************
** 函数名称 :IRQ_Eint0Serving()
** 函数功能 :外部中断0 EINT0服务程序口。
*************************************************************************/
void __irq IRQ_Eint0Serving (void)
{

uint32 tp1,tp2;
uint8  buff;
static uint8 frameByteCnt=0;

	PINSEL1 = PINSEL1& 0xfffffffc; 		// set p0.16 as GPIO
	IO0DIR  = IO0DIR & (~CC_EINT0_P0i);	// set p0.16 into input mode

	tp1 = IO0PIN   & CC_EINT0_P0i;		// sampling the pin level
	tp2 = EXTPOLAR & 0x00000001;		// 设置EINT0为 raiseing edge 触发

/////////////////////////////////////////////////////////////////////////
// raising edge, receiving mode
	if((tp1==CC_EINT0_P0i)&&(tp2==1)){
		if(CC1000Mode==RFinRX_MODE){			//in receiving mode
			IO0DIR  = IO0DIR&(~CC_PPDIO_P0i);	// CC_PPDIO_P0i serve as inpin
			
			tp1		= IO0PIN & CC_PPDIO_P0i;	// get the input bit
			switch(RF_RxSynSemaphore){
//////////////////////////////////////////////////			
// WAIT_SYN_F state
				case WAIT_SYN_F:
					RF_Rx_PreHead = RF_Rx_PreHead<<1;					//get a bit
					if(tp1==CC_PPDIO_P0i){
						RF_Rx_PreHead = RF_Rx_PreHead&(~0x00000001);	//reverse the bit polarity
					}
					else{
						RF_Rx_PreHead = RF_Rx_PreHead|0x00000001;		//reverse the bit polarity
					}
//
					if(RF_Rx_PreHead==SYN_FLAG){
						RF_RxSynSemaphore=SYN_STATE0;		//check if system synchronization flag
						RF_RxBitCounter=0;
					}
					break;
					
//////////////////////////////////////////////////
// state0 receiving byteCnt
				case SYN_STATE0:							//after synchronized
// get a bit
					RF_RxBitCounter++;
					RF_ReceivingBuf = RF_ReceivingBuf<<1;		//get a high bit
					if(tp1==CC_PPDIO_P0i){							//system in asynchronize state
						RF_ReceivingBuf = RF_ReceivingBuf&(~0x01);	//reverse the bit polarity				
					}
					else{
						RF_ReceivingBuf = RF_ReceivingBuf|0x01;		//reverse the bit polarity
					}
// get a byte, here is receivingCnt
					if(RF_RxBitCounter>=8){					//get a byte
						RF_RxBitCounter=0;

						if((RF_ReceivingBuf>0)&&(RF_ReceivingBuf<=RX_BUFFER_LEN)){
							RF_RxSynSemaphore=SYN_STATE1;
							frameByteCnt=RF_ReceivingBuf;
						}
						else{
							RF_RxSynSemaphore=WAIT_SYN_F;	//lost the too large frame
							frameByteCnt=0;
						}
					}
					break;

////////////////////////////////////////////////
// state1 receiving ~receivingCnt
				case SYN_STATE1:				//after synchronized
// get a bit
					RF_RxBitCounter++;
					RF_ReceivingBuf = RF_ReceivingBuf<<1;		//get a high bit
					if(tp1==CC_PPDIO_P0i){							//system in asynchronize state
						RF_ReceivingBuf = RF_ReceivingBuf&(~0x01);	//reverse the bit polarity				
					}
					else{
						RF_ReceivingBuf = RF_ReceivingBuf|0x01;		//reverse the bit polarity
					}
// get a byte, here is ~receivingCnt
					if(RF_RxBitCounter>=8){			//get a byte
						RF_RxBitCounter=0;			//reset byte counter

						RF_ReceivingBuf=(~RF_ReceivingBuf);
						if(frameByteCnt==RF_ReceivingBuf){
							RF_RxSynSemaphore=SYN_STATE2;		//receivingCnt check ok
						}
						else{
							RF_RxSynSemaphore=WAIT_SYN_F;		//lost the too long package
							frameByteCnt=0;
						}
					}
					break;
					
///////////////////////////////////////////////
// state2 receiving a byte
				case SYN_STATE2:								//after synchronized
// get a bit
					RF_RxBitCounter++;
					RF_ReceivingBuf = RF_ReceivingBuf<<1;		//get a high bit
					if(tp1==CC_PPDIO_P0i){							//system in asynchronize state
						RF_ReceivingBuf = RF_ReceivingBuf&(~0x01);	//reverse the bit polarity				
					}
					else{
						RF_ReceivingBuf = RF_ReceivingBuf|0x01;		//reverse the bit polarity
					}
// get a byte
					if(RF_RxBitCounter>=8){		//get a byte
						RF_RxBitCounter=0;		//reset bit counter

						RF_Rx_Buf[RFr_inp]=RF_ReceivingBuf;	//sending data to receiving buffer
						RFr_inp++;	if(RFr_inp>=RX_BUFFER_LEN)  RFr_inp=0;
						RF_RxCounter++;

// check if receiving all data
						frameByteCnt--;
						if(frameByteCnt==0){
							RF_RxSynSemaphore=WAIT_SYN_F;	//received a whole frame
							RF_BufferFlag = _DATA_OK;
							frameByteCnt=0;
						}
					}
					break;
					
/////////////////////////////////////////////
// default condition , reset the state machine
				default:
					RF_RxBitCounter=0;				//reset byte counter
					RF_RxSynSemaphore=WAIT_SYN_F;	//reset the state machine
					frameByteCnt=0;
					break;
			}
		}
	}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////	
// falling edge, for sending data
	else if((tp1==0)&&(tp2==0)){
		if((CC1000Mode==RFinTX_MODE)&&(RF_TxCounter!=0)){
			IO0DIR  = IO0DIR|CC_PPDIO_P0i;			// CC_PPDIO_P0i serve as outpin

// sending a bit
			RF_SendingBuf = RF_Tx_Buf[RFt_outp];		// get the sending data
			buff=(0x01<<(7-RF_TxBitCounter));	// get the bit position of sending data

			if((RF_SendingBuf&buff)==buff){		// sending data on cc1000 pin
				IO0SET	= CC_PPDIO_P0i;
				}
			else{
				IO0CLR	= CC_PPDIO_P0i;
				}
				RF_TxBitCounter++;				//next bit

// sending 1 byte
			if((RF_TxCounter!=1)&&(RF_TxBitCounter>=8)){
				RF_TxBitCounter=0;
				RFt_outp++;		if(RFt_outp>=TX_BUFFER_LEN)  RFt_outp=0;
				RF_TxCounter--;						//byte counter-1
			}  				//last byte with two bit as ending padding
			else if((RF_TxCounter==1)&&(RF_TxBitCounter>=10)){
				RF_TxBitCounter=0;
				RFt_outp++;		if(RFt_outp>=TX_BUFFER_LEN)  RFt_outp=0;
				RF_TxCounter--;						//byte counter-1
			}
		}
	}
	
//////////////////////////////////////////////////////////////////////////////////////
	PINSEL1  = PINSEL1  & 0xfffffffc; 	// set p0.16 as GPIO
	PINSEL1  = PINSEL1  | 0x00000001;	// 设置管脚连接,P0.16为EINT0
//	EXTMODE  = EXTMODE  | 0x01;			// 设置EINT0为 edge 触发
//	EXTPOLAR = EXTPOLAR ^ 0x01;			// reverse interrupt trigger edge

	EXTINT  	= 0x01;					// 清除EINT0中断标志
	VICVectAddr = 0;					// 向量中断结束
}


///////////////////////////////////////////////////////////////////////////////////////
void EINT0_Initialize(void)
{
	IRQDisable();
	
	PINSEL1  = PINSEL1 & 0xfffffcfc; 	// set p0.16 and p0.20 as GPIO
	PINSEL1  = PINSEL1 | 0x00000001;	// set P0.16 as EINT0, be used as DCLK

	EXTMODE  = 0x01;					// 设置EINT0为 edge 触发
	EXTPOLAR = 0x01;					// 设置EINT0为 raising edge trigger type

	EXTINT   = 0x01;					// 清除EINT0中断标志

	VICVectCntl4   = 0x20|INT_EINT0;	// 0x20 vector enable,分配外部中断0到向量中断4
	VICVectAddr4   = (uint32)IRQ_Eint0Serving;	// 设置中断服务程序地址
	VICIntEnable   = 1<<INT_EINT0;		// 使能EINT0中断

	IRQEnable();						// 使能IRQ中断
}

/********************************************************************************
**                            End Of File
*********************************************************************************/

⌨️ 快捷键说明

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