- WORD crc;
- // If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
- // followed by teh block data
- // one sub-carrier, inventory, 1 slot, fast rate
- cmd[0] = (1 << 5) | (1 << 1); // no SELECT bit
- // READ BLOCK command code
- cmd[1] = CmdCode;
- // UID may be optionally specified here
- // 64-bit UID
- cmd[2] = 0x32;
- cmd[3]= 0x4b;
- cmd[4] = 0x03;
- cmd[5] = 0x01;
- cmd[6] = 0x00;
- cmd[7] = 0x10;
- cmd[8] = 0x05;
- cmd[9]= 0xe0; // always e0 (not exactly unique)
- // Parameter
- cmd[10] = 0x00;
- cmd[11] = 0x0a;
-
-// cmd[12] = 0x00;
-// cmd[13] = 0x00; //Now the CRC
- crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes
- cmd[12] = crc & 0xff;
- cmd[13] = crc >> 8;
-
- CodeIso15693AsReader(cmd, sizeof(cmd));
-}
-
-static void __attribute__((unused)) BuildArbitraryCustomRequest(BYTE uid[], BYTE CmdCode)
-{
- BYTE cmd[14];
-
- WORD crc;
- // If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
- // followed by teh block data
- // one sub-carrier, inventory, 1 slot, fast rate
- cmd[0] = (1 << 5) | (1 << 1); // no SELECT bit
- // READ BLOCK command code
- cmd[1] = CmdCode;
- // UID may be optionally specified here
- // 64-bit UID
- cmd[2] = 0x32;
- cmd[3]= 0x4b;
- cmd[4] = 0x03;
- cmd[5] = 0x01;
- cmd[6] = 0x00;
- cmd[7] = 0x10;
- cmd[8] = 0x05;
- cmd[9]= 0xe0; // always e0 (not exactly unique)
- // Parameter
- cmd[10] = 0x05; // for custom codes this must be manufcturer code
- cmd[11] = 0x00;
-
-// cmd[12] = 0x00;
-// cmd[13] = 0x00; //Now the CRC
- crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes
- cmd[12] = crc & 0xff;
- cmd[13] = crc >> 8;
-
- CodeIso15693AsReader(cmd, sizeof(cmd));
-}
-
-/////////////////////////////////////////////////////////////////////////
-// Now the VICC>VCD responses when we are simulating a tag
-////////////////////////////////////////////////////////////////////
-
- static void BuildInventoryResponse(void)
-{
- BYTE cmd[12];
-
- WORD crc;
- // one sub-carrier, inventory, 1 slot, fast rate
- // AFI is at bit 5 (1<<4) when doing an INVENTORY
- cmd[0] = 0; //(1 << 2) | (1 << 5) | (1 << 1);
- cmd[1] = 0;
- // 64-bit UID
- cmd[2] = 0x32;
- cmd[3]= 0x4b;
- cmd[4] = 0x03;
- cmd[5] = 0x01;
- cmd[6] = 0x00;
- cmd[7] = 0x10;
- cmd[8] = 0x05;
- cmd[9]= 0xe0;
- //Now the CRC
- crc = Crc(cmd, 10);
- cmd[10] = crc & 0xff;
- cmd[11] = crc >> 8;
-
- CodeIso15693AsReader(cmd, sizeof(cmd));
-}
-
-//-----------------------------------------------------------------------------
-// Transmit the command (to the tag) that was placed in ToSend[].
-//-----------------------------------------------------------------------------
-static void TransmitTo15693Tag(const BYTE *cmd, int len, int *samples, int *wait)
-{
- int c;
-
-// FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_MOD);
- FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX);
- if(*wait < 10) { *wait = 10; }
-
-// for(c = 0; c < *wait;) {
-// if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
-// AT91C_BASE_SSC->SSC_THR = 0x00; // For exact timing!
-// c++;
-// }
-// if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
-// volatile DWORD r = AT91C_BASE_SSC->SSC_RHR;
-// (void)r;
-// }
-// WDT_HIT();
-// }
-
- c = 0;
- for(;;) {
- if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
- AT91C_BASE_SSC->SSC_THR = cmd[c];
- c++;
- if(c >= len) {
- break;
- }
- }
- if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- volatile DWORD r = AT91C_BASE_SSC->SSC_RHR;
- (void)r;
- }
- WDT_HIT();
- }
- *samples = (c + *wait) << 3;
-}
-
-//-----------------------------------------------------------------------------
-// Transmit the command (to the reader) that was placed in ToSend[].
-//-----------------------------------------------------------------------------
-static void TransmitTo15693Reader(const BYTE *cmd, int len, int *samples, int *wait)
-{
- int c;
-
-// FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX);
- FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR); // No requirement to energise my coils
- if(*wait < 10) { *wait = 10; }
-
- c = 0;
- for(;;) {
- if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
- AT91C_BASE_SSC->SSC_THR = cmd[c];
- c++;
- if(c >= len) {
- break;
- }
- }
- if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- volatile DWORD r = AT91C_BASE_SSC->SSC_RHR;
- (void)r;
- }
- WDT_HIT();
- }
- *samples = (c + *wait) << 3;
-}
-
-static int GetIso15693AnswerFromTag(BYTE *receivedResponse, int maxLen, int *samples, int *elapsed)
-{
- int c = 0;
- BYTE *dest = (BYTE *)BigBuf;
- int getNext = 0;
-
- SBYTE prev = 0;
-
-// NOW READ RESPONSE
- FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
- //spindelay(60); // greg - experiment to get rid of some of the 0 byte/failed reads
- c = 0;
- getNext = FALSE;
- for(;;) {
- if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
- AT91C_BASE_SSC->SSC_THR = 0x43;
- }
- if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- SBYTE b;
- b = (SBYTE)AT91C_BASE_SSC->SSC_RHR;
-
- // The samples are correlations against I and Q versions of the
- // tone that the tag AM-modulates, so every other sample is I,
- // every other is Q. We just want power, so abs(I) + abs(Q) is
- // close to what we want.
- if(getNext) {
- SBYTE r;
-
- if(b < 0) {
- r = -b;
- } else {
- r = b;