📄 prd_iso14443a_anticollision.c
字号:
//=============================================================================
// Copyright (C) INSIDE Contactless 1998-2005
//
// INSIDE Contactless reserves the right to make changes, without notice,
// to any product (including application note) herein to improve
// reliability, functionality, or design. INSIDE Contactless advises its
// customers to obtain the latest version of device data sheets to verify,
// before placing orders, that the information being relied upon by the
// customer is current.
//
// INSIDE Contactless makes no warranty that the use will not infringe any
// third party patent, copyright or trademark.
//
// Information furnished by INSIDE Contactless is believed to be accurate
// and reliable. However, INSIDE Contactless does not assume any liability
// resulting from the application or use of any product described within.
//
// All rights are reserved. Reproduction in whole or in part is prohibited
// without the written consent of the copyright owner.
//
// Bat 11a,
// Parc Club du Golf,
// Z.A.C. du Pichaury Tel : +33 (0)4.42.39.33.00
// 13856 Aix-en-Provence Cedex 3 Fax : +33 (0)4.42.39.63.19
// FRANCE Email : info@insidefr.com
//
//-----------------------------------------------------------------------------
// Project Code : PICOREAD RF ISO15693-3 READER
// Project Name : APPLICATION NOTE
// Module Name : PRD_ISO14443A_ANTICOLLISION.H
// Platform dev : Keil 礦ision 3 (IDE ) + Keil ARM Compiler
// Target : GENERIC
// Language : C ANSI
// Revision : 1.1
// Description :
//=============================================================================
// Defines standard
#include <string.h> // Standard C Libray file containing basic functions to use serial host
// Defines for common C writting
#include "Defines_C.h" // TRUE, FALSE, etc
// Defines for PicoRead
#include "PRD_PicoReadRF_Pages_Parameters.h" // Definition of PicoRead chip registers
#include "PRD_Config.h" // Reader Configuration functions
#include "PRD_RF_Comm.h"
#include "PRD_BufferExchange.h"
// Defines for the Target
#include "Target.H" // Definition of processor registers & Low level functions to be modified according to the target, and the user needs
// ISO A Commands
#include "PRD_ISO14443A_Commands.h"
#include "PRD_COMMON_Anticollision_Parameters.h" //Common Anticollision parameters defines
#include "PRD_ISO14443A_Anticollision_Parameters.h" //Anticollision parameters defines for ISO14443A
#include "PRD_ISO14443A_Anticollision_Default_Parameters.h" //Default Anticollsion parameters for ISO14443A
#include "PRD_ISO14443A_Anticollision.h" // Anticollision functions for ISO14443A
//-----------------------------------------------------------------------------
// Function name : BYTE b_fnISO14443A_Anticol(BYTE* p_abUID, BYTE* p_bUIDLength)
//-----------------------------------------------------------------------------
// Description : Extract one card from x card and return the UID of the selected
// card using the ISO14443A protocol.
//
// IN : p_pStructReader : Pointer to the used StructReader structure.
//
// OUT : p_abUID : UID received
// p_bUIDLength : UID size (8)
//
// RETURN : true 1 if a card is selected.
// false 0 no card selected.
//
// Notes : This function makes several attemps before returning an error.
//-----------------------------------------------------------------------------
unsigned char b_fnISO14443A_Anticol(unsigned char* p_abUID, unsigned char* p_bUIDLength,StructReader* p_pStructReader)
{
unsigned char l_bPicoReadStatus;
unsigned char l_bRFReceiveEOF;
unsigned char l_abBuffer[255];
unsigned char l_bStatus;
unsigned char l_bDelay;
unsigned char l_bRetry;
unsigned char l_bNVB;
unsigned char l_bSEL;
unsigned char l_bOffsetSerial;
unsigned char l_bCurrentSerial;
unsigned short l_bDataBytesToSend;
unsigned char l_bDataBitsToSend;
unsigned short l_bDataBytesReceived;
unsigned char l_bDataBitsReceived;
unsigned char l_bTemp0;
unsigned char l_bTemp1;
unsigned char l_bAnticolRetry;
unsigned char l_bSFGT;
unsigned short l_wRFPicoReadByteCounter;
unsigned char l_bRFPicoReadBitCounter;
unsigned char l_bBitsToReceive;
l_bBitsToReceive=0;
l_bRFPicoReadBitCounter=0;
l_wRFPicoReadByteCounter=0;
memset(&l_abBuffer[0],0,20);
l_bRetry=(p_pStructReader->s_bRAnticolOpt1 & 0x03);
l_bSFGT=0;
//Delay 5 ms
for(l_bDelay=25;l_bDelay>0;l_bDelay--) delay_us(200);
lbl_Loop:
l_bBitsToReceive=0;
p_pStructReader->s_bRTimeoutUsed=TO_302US;
p_pStructReader->s_bRFrameSizeUsed=p_pStructReader->s_bRFrameSizeMax & 0xFE;
p_pStructReader->s_bCommunicationSupportedSpeed=(P0_S106K | P0_R106K);
v_fnConfigBitRate(p_pStructReader->s_bCommunicationSupportedSpeed,&l_bRFReceiveEOF,p_pStructReader);
p_pStructReader->s_bCommunicationSupportedSpeed=p_pStructReader->s_bReaderSupportedSpeed;
//RESET INDEX AND UID BUFFER
l_bCurrentSerial=0;
memset(&p_abUID[0],0,12);
// SEND REQA AND UID BUFFER
if(p_pStructReader->s_bRAnticolOpt0 & ISOA0_WUPA) l_abBuffer[0]= _ISOA_WUPA;
else l_abBuffer[0]= _ISOA_REQA;
v_fnSendBuffer(0,0,7,&l_abBuffer[0],p_pStructReader);
l_bStatus=b_fnReceiveBuffer(0,&l_abBuffer[0],p_pStructReader,&l_bDataBytesReceived,&l_bDataBitsReceived,&l_bPicoReadStatus,&l_bRFReceiveEOF,&l_bBitsToReceive);
if (l_bStatus!=ERR_COLL && l_bStatus!=ERR_NO_ERROR) goto lbl_Retry;
//ANTICOLLISION LEVEL
l_bSEL = _ISOA_SELECT ;
do
{
//SEND ANTICOLLISION COMMAND
l_abBuffer[0]=l_bSEL;
l_abBuffer[1]=0x20;
v_fnSendBuffer(0,2,0,&l_abBuffer[0],p_pStructReader);
l_bOffsetSerial= l_bCurrentSerial ;
l_bAnticolRetry =0 ;
l_bNVB=0 ;
do
{
l_bStatus=b_fnReceiveBuffer(0,&l_abBuffer[0],p_pStructReader,&l_wRFPicoReadByteCounter,&l_bRFPicoReadBitCounter,&l_bPicoReadStatus,&l_bRFReceiveEOF,&l_bBitsToReceive);
if(l_bStatus != ERR_NO_ERROR)
{
if(l_bStatus != ERR_COLL) goto lbl_Retry;
l_wRFPicoReadByteCounter--; // if a collision occurs g_wRFPicoReadByteCounter = number of valid bytes + 1
}
// BUFFER SHOULD BE INITIALIZED WITH 0x00 FROM 5 UNTIL 14
memset(&l_abBuffer[5],0,10);
// CONFIGURE NVB
l_bTemp0 = l_bRFPicoReadBitCounter + (l_wRFPicoReadByteCounter<<0x04);
l_bNVB += l_bTemp0;
if (bit_testChar(&l_bNVB,3))
{
bit_clearChar(&l_bNVB,3);
l_bNVB += 0x10;
}
// NUMBER OF READ BYTES
l_bTemp0 = l_wRFPicoReadByteCounter;
l_bTemp1 = 0;
while(l_bTemp0--)
{
// COMPLETE ALREADY READ SERIAL NUMBER WITH VALID BYTES
p_abUID[l_bOffsetSerial] |= l_abBuffer[l_bTemp1++];
l_bOffsetSerial++;
}
// COMPLETE ALREADY READ SERIAL NUMBER WITH VALID BITS + 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -