📄 prd_picopass_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_PICOPASS_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
// PicoPass Commands
#include "PRD_PicoPass_Commands.h"
#include "PRD_COMMON_Anticollision_Parameters.h" //Common Anticollision parameters defines
#include "PRD_PicoPass_Anticollision_Parameters.h" //Anticollision parameters defines for PicoPass
#include "PRD_PicoPass_Anticollision_Default_Parameters.h" //Default Anticollsion parameters for PicoPass
#include "PRD_PicoPass_Anticollision.h" // Anticollision functions for PicoPass
//-----------------------------------------------------------------------------
// Function name : BYTE b_fnPicoPass_Anticol(BYTE* p_abUID, BYTE* p_bUIDLength)
//-----------------------------------------------------------------------------
// Description : Extract one card from x card and return the UID of the selected
// card using the ISO15693 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_fnPicoPass_Anticol(unsigned char* p_abUID, unsigned short* p_bUIDLength,StructReader* p_pStructReader)
{
unsigned short l_wRFPicoReadByteCounter;
unsigned char l_bRFPicoReadBitCounter;
unsigned char l_bPicoReadStatus;
unsigned char l_bRFReceiveEOF=0;
unsigned char l_abBuffer[256];
unsigned char l_bActCmdCounter;
unsigned char l_bStatus;
unsigned char l_bDelay;
unsigned char l_bRetry;
unsigned char l_bBitToReceive=0;
unsigned char l_bCmd424kbps = 0x00;
unsigned char l_bMask424kbps = 0xFF;
if (p_pStructReader->s_bRProtocol==PICOPASS_ISOB424)
{
l_bCmd424kbps = 0xC0;
l_bMask424kbps = 0x7F;
}
l_bRetry=(p_pStructReader->s_bRAnticolOpt1 & 0x03);
lbl_Actall:
// DELAY 350US
for(l_bDelay=2;l_bDelay>0;l_bDelay--) delay_us(175);
// ACTALL
p_pStructReader->s_bRTimeoutUsed=TO_2MS42;
l_bActCmdCounter=8;
l_abBuffer[0] = (_PICOPASS_ACTALL | l_bCmd424kbps);
v_fnSendBuffer(0,1,0,&l_abBuffer[0],p_pStructReader);
l_bStatus=b_fnReceiveBuffer(_SOF_ONLY,&l_abBuffer[0],p_pStructReader,&l_wRFPicoReadByteCounter,&l_bRFPicoReadBitCounter,&l_bPicoReadStatus,&l_bRFReceiveEOF,&l_bBitToReceive);
if(l_bStatus!=ERR_NO_ERROR) goto lbl_Retry;
lbl_Identify:
// IDENTIFY
p_pStructReader->s_bRTimeoutUsed=TO_1MS21;
l_abBuffer[0] = (_PICOPASS_IDENTIFY | l_bCmd424kbps);
v_fnSendBuffer(0,1,0,&l_abBuffer[0],p_pStructReader);
l_bStatus=b_fnReceiveBuffer(_CHECKCRC,&p_abUID[0],p_pStructReader,&l_wRFPicoReadByteCounter,&l_bRFPicoReadBitCounter,&l_bPicoReadStatus,&l_bRFReceiveEOF,&l_bBitToReceive);
if(l_bStatus==ERR_NO_ERROR) goto lbl_Select;
if((l_bStatus==ERR_COLL || l_bStatus==ERR_CRC) && l_bActCmdCounter--) goto lbl_Act;
goto lbl_Retry;
lbl_Act:
// ACT
l_abBuffer[0] = (_PICOPASS_ACT | l_bCmd424kbps) & l_bMask424kbps;
v_fnSendBuffer(0,1,0,&l_abBuffer[0],p_pStructReader);
l_bStatus=b_fnReceiveBuffer(_SOF_ONLY,&l_abBuffer[0],p_pStructReader,&l_wRFPicoReadByteCounter,&l_bRFPicoReadBitCounter,&l_bPicoReadStatus,&l_bRFReceiveEOF,&l_bBitToReceive);
if(l_bStatus!=ERR_NO_ERROR) goto lbl_Retry;
else goto lbl_Identify;
lbl_Select:
// SELECT CHIP
p_pStructReader->s_bRTimeoutUsed=TO_4MS83;
l_abBuffer[0] = (_PICOPASS_SELECT | l_bCmd424kbps) & l_bMask424kbps;
memcpy(&l_abBuffer[1],p_abUID,8);
v_fnSendBuffer(0,9,0,&l_abBuffer[0],p_pStructReader);
l_bStatus=b_fnReceiveBuffer(_CHECKCRC,&p_abUID[0],p_pStructReader,p_bUIDLength,&l_bRFPicoReadBitCounter,&l_bPicoReadStatus,&l_bRFReceiveEOF,&l_bBitToReceive);
if(l_bStatus!=ERR_NO_ERROR) goto lbl_Retry;
// HALT CHIP IF REQUESTED
if(p_pStructReader->s_bRAnticolOpt0 & PICOPASS0_HALT)
{
l_abBuffer[0] = (_PICOPASS_HALT | l_bCmd424kbps);
v_fnSendBuffer(0,1,0,&l_abBuffer[0],p_pStructReader);
}
// ANTICOLLISION OK EVEN IF HALT DIDN'T WORK
p_pStructReader->s_bRTimeoutUsed=p_pStructReader->s_bRTimeoutDefault;
return TRUE;
lbl_Retry:
if(l_bRetry--)
{
if(p_pStructReader->s_bRAnticolOpt1 & PICOPASS1_RESET)
{
v_fnCS_reset();
v_fnSPI_SendByte(P0_REG_NO_RST | P0_PAGE_SELECT_1);
// DELAY 2MS
for(l_bDelay=10;l_bDelay>0;l_bDelay--) delay_us(200);
v_fnCS_reset();
v_fnSPI_SendByte(P0_REG_NO_RST | P0_PAGE_SELECT_1 | P0_RFON);
}
goto lbl_Actall;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -