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

📄 spi.c~

📁 this the firmware provided freely for the trf7960
💻 C~
📖 第 1 页 / 共 2 页
字号:
			*Register = Reset;		//reset the FIFO after last byte has been read out
			DirectCommand(Register);

			i_reg = 0xFF;			//signal to the recieve funnction that this are the last bytes
		}
		//-------------------------------------------------------------
		else if(*Register == 0x60){	//RX active and 9 bytes allready in FIFO
			
			i_reg = 0x01;
			buf[RXTXstate] = FIFO;
			ReadCont(&buf[RXTXstate], 9);	//read 9 bytes from FIFO
			RXTXstate = RXTXstate + 9;
			kputchar('F');
			
			if(!(P2IFG & BIT3)) goto END;
			*Register=IRQStatus;		//IRQ status register address
			ReadSingle(Register, 1);	//function call for single address read
//			*Register = *Register & 0xF7;	//set the parity flag to 0
			
			if(*Register == 0x40){		//end of recieve
				*Register = FIFOStatus;
				ReadSingle(Register, 1);	//determine the number of bytes left in FIFO
				*Register = 0x0F & (*Register + 0x01);
				buf[RXTXstate] = FIFO;	//write the recieved bytes to the correct place of the buffer;
				ReadCont(&buf[RXTXstate], *Register);
				RXTXstate = RXTXstate + *Register;
			
				*Register = TXLenghtByte2;		//determine if there are broken bytes
				ReadSingle(Register, 1);		//determine the number of bits
				
				if((*Register & BIT0) == BIT0){
					*Register = (*Register >> 1) & 0x07;	//mask the first 5 bits
					*Register = 8 - *Register;	
					buf[RXTXstate - 1] &= 0xFF << *Register;
				}//if
				kputchar('E');
				i_reg = 0xFF;		//signal to the recieve funnction that this are the last bytes
				*Register = Reset;	//reset the FIFO after last byte has been read out
				DirectCommand(Register);
			}else if(*Register == 0x50){		//end of recieve and error
                          	i_reg = 0x02;
                                kputchar('x');
                        }
                END:
                        Register[0] = IRQStatus;
			ReadSingle(Register, 1);	//function call for single address read
                        if(Register[0] == 0x00)
                        	i_reg = 0xFF;
		}
		//-------------------------------------------------------------
		else if((*Register & BIT4) == BIT4){	//CRC error
			if((*Register & BIT5) == BIT5){
				i_reg = 0x01;		//RX active
				RXErrorFlag = 0x02;
			}else
				i_reg = 0x02;		//end of RX
		}
		//-------------------------------------------------------------
		else if((*Register & BIT2) == BIT2){	//byte framing error
			if((*Register & BIT5) == BIT5){
				i_reg = 0x01;		//RX active
				RXErrorFlag = 0x02;
			}else
				i_reg = 0x02;		//end of RX
		}
		//-------------------------------------------------------------
		else if(*Register == BIT0){	//No response interrupt
			i_reg = 0x00;
			kputchar('N');
		}
		//-------------------------------------------------------------
		else{				//Interrupt register not properly set
			sprintf(phello, "Interrupt error. %x\n\r", *Register);
        		send_cstring(phello);
        		i_reg = 0x02;		
		}
	
}//InterruptHandlerReader


void InterruptHandlerNFC(unsigned char Register)
{
	//bit0 - RF collision avoidance error
	//bit1 - RF collision avoidance OK
	//bit2 - Change in RF field level
	//bit3 - SDD OK
	//bit4 - Communication error
	//bit5 - FIFO high/low
	//bit6 - RX
	//bit7 - TX
	//--------------------------------
	//i_reg is used for signaling to the protocol functions
	//i_reg = 0x00 - OK
	//i_reg = 0x01 - progress
	//i_reg = 0x02 - error
	//i_reg = 0xFF - end of RX
  	put_crlf();
	Put_byte(Register);
	//-------------------------------------------------------------
	if(Register == BIT0){
		i_reg = 0x02;
	}
	//-------------------------------------------------------------
	else if(Register == BIT1){
		i_reg = 0x00;
	}
	//-------------------------------------------------------------
	else if(Register == BIT2){	//RF field change
		i_reg = 0x01;
		kputchar('R');
	}
	//-------------------------------------------------------------
	else if(Register == BIT3){
		i_reg = 0x00;
	}
	//-------------------------------------------------------------
	else if((Register & BIT4) == BIT4){
		i_reg = 0x02;
	}
	//-------------------------------------------------------------
	else if(Register == BIT7){	//TX complete
		i_reg = 0x00;
		kputchar('T');
	}
	//-------------------------------------------------------------
	else if(Register == 0xA0){	//TX active and only 3 bytes left in FIFO
		i_reg = 0x01;
		kputchar('.');
	}
	//-------------------------------------------------------------
	else if(Register == 0x40 || Register == 0x00){	//RX flag means that EOF has been recieved
							//and the number of unread bytes is in FIFOstatus regiter          	
		Register = FIFOStatus;
		ReadSingle(&Register, 1);	//determine the number of bytes left in FIFO
		Register = (0x0F & Register) + 0x01;
		
		buf[NFCstate] = FIFO;	//write the recieved bytes to the correct place of the buffer;
		ReadCont(&buf[NFCstate], Register);
		NFCstate = NFCstate + Register;

		kputchar('E');
		
		Register = Reset;		//reset the FIFO after last byte has been read out
		DirectCommand(&Register);

		i_reg = 0xFF;			//signal to the recieve funnction that this are the last bytes
		Register = IRQStatus;
		ReadSingle(&Register, 1);	
	}
	//------------------------------------------------------------------
	else if((Register == 0x60) || (Register == 0x64)){	//RX & FIFO interrupt
		i_reg = 0x01;
		buf[NFCstate] = FIFO;
		ReadCont(&buf[NFCstate], 9);	//read 9 bytes from FIFO
		NFCstate = NFCstate + 9;
		kputchar('F');

		if(!(P2IFG & BIT3)) return;
		Register=IRQStatus;		//IRQ status register address
		ReadSingle(&Register, 1);	//function call for single address read
//		Register = Register & 0xF7;	//set the parity flag to 0
			
		if(Register == 0x40){		//end of recieve
			Register = FIFOStatus;
			ReadSingle(&Register, 1);	//determine the number of bytes left in FIFO
			Register = (0x0F & Register) + 0x01;
		
		
			buf[NFCstate] = FIFO;	//write the recieved bytes to the correct place of the buffer;
			ReadCont(&buf[NFCstate], Register);
			NFCstate = NFCstate + Register;
					

			kputchar('E');
			i_reg = 0xFF;		//signal to the recieve funnction that this are the last bytes
			Register = Reset;	//reset the FIFO after last byte has been read out
			DirectCommand(&Register);
		}//if
        }
        else if(Register == 0x48){	//SDD complete
		i_reg = 0x00;
		kputchar('S');
	}
	
	
}//InterruptHandlerNFC


void InterruptHandlerNFCtarget(unsigned char Register)
{
  	unsigned char command, i;

        put_crlf();
	Put_byte(Register);

        if(Register == 0x40){
        	//determine the NFC target protocol
               	command = NFCTargetProtocol;
        	ReadSingle(&command, 1);	//read the NFCtargetprotocol register

        	put_crlf();
                kputchar('<');
        	Put_byte(command);
        	kputchar('>');

                command &= 0x3F;

                buf[50] = ISOControl;

                if(command == 0x09){
	                send_cstring("14443A - passive.\r\n");
                        NFCprotocol = 0x01;
                }
                else{
        		Register = FIFOStatus;
			ReadSingle(&Register, 1);	//determine the number of bytes left in FIFO
			Register = (0x0F & Register) + 0x01;
		
			buf[NFCstate] = FIFO;	//write the recieved bytes to the correct place of the buffer;
			ReadCont(&buf[NFCstate], Register);
			NFCstate = NFCstate + Register;
                	i_reg = 0xFF;

                        if(command == 0x01){	//14443A - active
                        	buf[51] = NFC106;
                                WriteSingle(&buf[50], 2);
                                send_cstring("14443A - active.\r\n");
                                NFCprotocol = 0x02;
                                Active = 0xFF;
                        }
                        else if(command == 0x12){
                        	if(buf[0] == 0x06){	//Felica 212 - passive
	                       		buf[51] = NFC212;
                                       	WriteSingle(&buf[50], 2);
                                       	send_cstring("Felica 212 - passive.\r\n");
                                        NFCprotocol = 0x03;
                                        Active = 0x00;
                                }else{			//Felica 212 - active
                                       	buf[51] = NFC212;
                                      	WriteSingle(&buf[50], 2);
                                       	send_cstring("Felica 212 - active.\r\n");
                                        NFCprotocol = 0x04;
                                        Active = 0xFF;
                                }
                        }
                        else if(command == 0x13){
                               	if(buf[0] == 0x06){	//Felica 424 - passive
	                       		buf[51] = NFC424;
	                       	 	WriteSingle(&buf[50], 2);
	                               	send_cstring("Felica 424 - passive.\r\n");
                                        NFCprotocol = 0x05;
                                        Active = 0x00;
                                }else{			//Felica 424 - active
                                       	buf[51] = NFC424;
                                      	WriteSingle(&buf[50], 2);
                                       	send_cstring("Felica 424 - active.\r\n");
                                        NFCprotocol = 0x06;
                                        Active = 0xFF;
                                }
                        }
                }//if-else
        }
        else if(Register == 0x06){
          	i_reg = 0x01;
		buf[NFCstate] = FIFO;
		ReadCont(&buf[NFCstate], 9);	//read 9 bytes from FIFO
		NFCstate = NFCstate + 9;
        }
        else if((Register & BIT3) == BIT3){	//SDD finished
          	i_reg = 0xFF;
                for(i = 0; i < 255; i++);
                buf[50] = ISOControl;
                buf[51] = NFC106;
	        WriteSingle(&buf[50], 2);
                send_cstring("14443A - SDD complete.\r\n");
                command = Reset;
                DirectCommand(&command);
                buf[51] = NFC106;
                WriteSingle(&buf[50], 2);
        }
}//InterruptHandlerNFCtarget



#pragma vector=PORT1_VECTOR
__interrupt void Port_B(void)		//interrupt handler
{
	unsigned char Register[2];
	
	TACTL &= !MC0;			//stop timer mode

        do{
		Register[0] = IRQStatus;		//IRQ status register address
		Register[1] = IRQStatus;
	
		ReadSingle(Register, 1);	//function call for single address read
						//IRQ status register has to be read
		if(*Register == 0xA0){		//TX active and only 3 bytes left in FIFO
			goto FINISH;
		}
//	ReadSingle(&dummy, 1);
	
		switch(ReaderNFCSelection){
			case 0x00:	InterruptHandlerReader(&Register[0]);
			break;
	        	case 0xF0:	InterruptHandlerNFCtarget(Register[0]);
	                break;
			case 0xFF:	InterruptHandlerNFC(Register[0]);
			break;
			default: break;
		}//switch

		irqCLR;			//PORT2 interrupt flag clear
        }while((irqPORT & irqPIN) == irqPIN);
FINISH:
	irqCLR;			//PORT2 interrupt flag clear
	__low_power_mode_off_on_exit();
}

⌨️ 快捷键说明

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