prd_bufferexchange.c
来自「读RF卡的源代码」· C语言 代码 · 共 270 行
C
270 行
//=============================================================================
// 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 LIBRARY
// Project Name : PICOREAD LIBRARY
// Module Name : PRD_BufferExchange.c
// Platform dev : Keil 礦ision 3 (IDE ) + Keil ARM Compiler
// Target : LPC2103 (ARM7TDMI Core)
// Language : C ANSI
// Revision : 1.0
// Description : Send & Receive commands
//=============================================================================
// When Who Ver What
// 06-04-24 MCY 1.1 restructuration
// 06-05-12 FPK 1.2 modifications
//=============================================================================
// C ANSI Defines
#include <string.h>
// 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"
// Functions for Buffer exchange
#include "PRD_Protocols_Defines.h" //Protocols defines
#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
#if ((defined PAYPASS) || (defined FULL))
#include "PayPass_TTAL1_Default_Anticollision_Options.h"
#include "PayPass_Anticollision.h"
#endif
//Global variable
unsigned char g_bRFReceiveEOFA=0;
unsigned char g_bRFReceiveEOFB=1;
unsigned char g_bDataBitsReceived;
unsigned char g_bPicoReadStatus;
unsigned short g_lDataBytesReceived;
unsigned char g_bBitsToReceive=0;
//-----------------------------------------------------------------------------
// Function name : v_fnSendBuffer(BYTE p_bParam, BYTE p_bNbBytestoSend,
// BYTE p_bNbBitstoSend, BYTE* p_pabDatain)
//-----------------------------------------------------------------------------
// Description : Transmit data to the chip.
//
// IN : p_bParam : Communication parameter including :
// b6..b0 : RFU
// b7 : Send CRC
// p_pabBuffer = Pointer to Buffer of the datas to send
// p_pStructReader = Pointer to the according StructReader Structure
// p_pwRFPicoReadByteCounter = Pointer to number of complete bytes to send including CRC16
// p_pbRFPicoReadBitCounter = Pointer to number of valid bits in the last byte to send (ISO A only)
//
//
// OUT : *p_pwRFPicoReadByteCounter : Number of data bytes sent
// *p_pbRFPicoReadBitCounter : Number of data bits sent (ISO A only)
// "*p_pabBuffer" : Contains datas just sent
//
//
// RETURN : - none -
//
// Notes : - none -
//-----------------------------------------------------------------------------
void v_fnSendBuffer(unsigned char p_bParam, unsigned short p_lNbBytestoSend, unsigned char p_bNbBitstoSend,unsigned char* p_pabBuffer,StructReader* p_pStructReader)
{
unsigned short* p_pwRFPicoReadByteCounter;
unsigned char* p_pbRFPicoReadBitCounter;
unsigned char l_bTemp;
if(p_pStructReader->s_bRProtocol == SONY_PROTOCOL)
{
for(l_bTemp=p_lNbBytestoSend+7;l_bTemp>7;l_bTemp--)
{
p_pabBuffer[l_bTemp] = p_pabBuffer[l_bTemp-8];
}
v_fnTypeCHeader(&p_pabBuffer[0]);
p_lNbBytestoSend += 8;
}
v_fnDefineTimeout(p_pStructReader->s_bRTimeoutUsed);
// EMIT DATA
p_pwRFPicoReadByteCounter=&p_lNbBytestoSend;
p_pbRFPicoReadBitCounter=&p_bNbBitstoSend;
if(p_pStructReader->s_bRProtocol == ISOA_PROTOCOL)
{
#if ((defined PAYPASS) || (defined FULL))
//Debug OC 31/8 WAIT 500祍 before a resending
delay_us(_FDT_A_PCD_MIN);
//to do : if((p_lNbBytestoSend!=0) && (p_pabBuffer[p_lNbBytestoSend-1]&0x01) ) p_pStructReader->s_bRTimeoutUsed-=
#endif
*p_pbRFPicoReadBitCounter = p_bNbBitstoSend;
}
#if ((defined PAYPASS) || (defined FULL))
else if(p_pStructReader->s_bRProtocol == ISOB_PROTOCOL)
{
delay_us(_FDT_A_PCD_MIN);
*p_pbRFPicoReadBitCounter = 0;
}
#endif
else
{
*p_pbRFPicoReadBitCounter = 0;
}
if(bit_testChar(&p_bParam,7))
{
v_fnSendRFCommand( (p_pStructReader->s_bRProtocol | P5_CRC_EN),p_pabBuffer,p_pwRFPicoReadByteCounter,p_pbRFPicoReadBitCounter) ;
}
else
{
v_fnSendRFCommand( (p_pStructReader->s_bRProtocol),p_pabBuffer,p_pwRFPicoReadByteCounter,p_pbRFPicoReadBitCounter) ;
}
v_fnTimeOutStart();
delay_us(50); ////// FP 20/09/07
// REINITIALIZE BIT COUNTER TO PREPARE RECEPTION
p_pbRFPicoReadBitCounter = 0;
}
//-----------------------------------------------------------------------------
// Function name : b_fnReceiveBuffer(BYTE p_bParam, long* p_lNbBytesReceived,
// BYTE* p_pbNbBitsReceived, BYTE* p_pabDataout)
//-----------------------------------------------------------------------------
// Description : Receive data from the chip.
//
// IN : p_bParam : Communication parameter including :
// b4..b0 : RFU
// b5 : Receive SOF only (PicoPass only)
// b6 : Verify CRC
// b7 : RFU
// p_pabBuffer = Pointer to Buffer in which received datas will be stored
// p_pStructReader = Pointer to the according StructReader Structure
// p_pwRFPicoReadByteCounter = Pointer to number of complete bytes to receive including CRC16
// p_pbRFPicoReadBitCounter = Pointer to number of valid bits in the last byte to receive
// p_pbPicoReadStatus = Pointer to the Status byte received by the PicoRead chip after having received the data bytes from the RF
// p_pbRFReceiveEOF = Pointer to value, that define (for ISO B) that EOF need to be taken into account or not.
// For ISOB : p_pbRFReceiveEOF=1
// Other Protocols : p_pbRFReceiveEOF=0
//
//
// OUT : *p_bNbBytesReceived : Number of data bytes received
// *p_pbNbBitsReceived : Number of data bits received
// "*p_pabBuffer" : Contains Datas received
//
// RETURN : Error code
//
// Notes : - none -
//-----------------------------------------------------------------------------
unsigned char b_fnReceiveBuffer(unsigned char p_bParam, unsigned char* p_pabBuffer,StructReader* p_pStructReader,unsigned short* p_pwRFPicoReadByteCounter,unsigned char* p_pbRFPicoReadBitCounter,unsigned char* p_pbPicoReadStatus,unsigned char* p_pbRFReceiveEOF,unsigned char* p_pbBitsToReceive )
{
unsigned char l_bReceiveOption;
unsigned char l_bError;
l_bReceiveOption = p_pStructReader->s_bRProtocol;
if (bit_testChar(&p_bParam,5))
{
l_bReceiveOption |= 0x80;
}
l_bError=b_fnReceiveRFResponse(l_bReceiveOption,p_pabBuffer,p_pwRFPicoReadByteCounter,p_pbRFPicoReadBitCounter,p_pbPicoReadStatus,p_pbRFReceiveEOF,*p_pbBitsToReceive);
//IF RECEPTION OK REMOVE CRC IN SONY
if(p_pStructReader->s_bRProtocol == SONY_PROTOCOL)
{
if ( ((*p_pwRFPicoReadByteCounter) != 0) && ((*p_pwRFPicoReadByteCounter) >= 2))
{
(*p_pwRFPicoReadByteCounter) -= 2;
}
}
// ANALYZE DATA
//PARITY ERROR
if ((l_bError == ERR_NO_ERROR) && ((*p_pbPicoReadStatus) & STATUS_ERR_PE))
{
l_bError = ERR_PAR;
}
// COLLISION ?
if((l_bError == ERR_NO_ERROR) && ((*p_pbPicoReadStatus) & STATUS_ERR_CD))
{
l_bError = ERR_COLL;
}
// CHECK CRC ?
if ( (l_bError == ERR_NO_ERROR) && (bit_testChar(&p_bParam,6)) && (!b_fnCheckCRCValid(*p_pbPicoReadStatus,p_pwRFPicoReadByteCounter)) )
{
l_bError = ERR_CRC;
}
// REMOVE 0xB2 0x4D IN SONY PROTOCOL
if(p_pStructReader->s_bRProtocol == SONY_PROTOCOL)
{memcpy(&p_pabBuffer[0],&p_pabBuffer[2],*p_pwRFPicoReadByteCounter); }
return l_bError;
}
//-----------------------------------------------------------------------------
// Function : void v_fnTypeCHeader(unsigned char* p_abBufferToFillwithHeader)
//-----------------------------------------------------------------------------
// Description : Fill the content of a buffer with the Felica header
//
// IN : p_abBufferToFillwithHeader[0..7] : Buffer to fill.
//
// OUT : p_abBufferToFillwithHeader[0..7] : Preamble and synchronous pattern bytes
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void v_fnTypeCHeader(unsigned char* p_abBufferToFillwithHeader)
{
p_abBufferToFillwithHeader[0] = 0x00;
p_abBufferToFillwithHeader[1] = 0x00;
p_abBufferToFillwithHeader[2] = 0x00;
p_abBufferToFillwithHeader[3] = 0x00;
p_abBufferToFillwithHeader[4] = 0x00;
p_abBufferToFillwithHeader[5] = 0x00;
p_abBufferToFillwithHeader[6] = 0xB2;
p_abBufferToFillwithHeader[7] = 0x4D;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?