#define TAG_READER_BUFFER_SIZE 2048
#define DEMOD_DMA_BUFFER_SIZE 1024
*/
+
+#define RECEIVE_SAMPLES_TIMEOUT 2000
+
//=============================================================================
// An ISO 14443 Type B tag. We listen for commands from the reader, using
// a UART kind of thing that's implemented in software. When we get a
// free all previous allocations first
BigBuf_free();
- // The command (reader -> tag) that we're receiving.
- uint8_t *receivedCmd = BigBuf_malloc(MAX_FRAME_SIZE);
-
// The response (tag -> reader) that we're receiving.
uint8_t *receivedResponse = BigBuf_malloc(MAX_FRAME_SIZE);
// Set up the demodulator for tag -> reader responses.
DemodInit(receivedResponse);
- // Set up the demodulator for the reader -> tag commands
- UartInit(receivedCmd);
// Setup and start DMA.
FpgaSetupSscDma(dmaBuf, DMA_BUFFER_SIZE);
ci = upTo[0];
cq = upTo[1];
upTo += 2;
- if(upTo - dmaBuf > DMA_BUFFER_SIZE) {
- upTo -= DMA_BUFFER_SIZE;
+ if(upTo >= dmaBuf + DMA_BUFFER_SIZE) {
+ upTo = dmaBuf;
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) upTo;
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
}
samples += 2;
- Handle14443UartBit(1);
- Handle14443UartBit(1);
-
if(Handle14443SamplesDemod(ci, cq)) {
gotFrame = 1;
}
}
- if(samples > 2000) {
+ if(samples > n) {
break;
}
}
//Tracing
if (tracing && Demod.len > 0) {
uint8_t parity[MAX_PARITY_SIZE];
- GetParity(Demod.output , Demod.len, parity);
- LogTrace(Demod.output,Demod.len, 0, 0, parity, FALSE);
+ GetParity(Demod.output, Demod.len, parity);
+ LogTrace(Demod.output, Demod.len, 0, 0, parity, FALSE);
}
}
CodeAndTransmit14443bAsReader(cmd1, sizeof(cmd1));
// LED_A_ON();
- GetSamplesFor14443Demod(TRUE, 2000,TRUE);
+ GetSamplesFor14443Demod(TRUE, RECEIVE_SAMPLES_TIMEOUT, TRUE);
// LED_A_OFF();
if (Demod.len == 0) {
CodeAndTransmit14443bAsReader(cmd1, sizeof(cmd1));
// LED_A_ON();
- GetSamplesFor14443Demod(TRUE, 2000,TRUE);
+ GetSamplesFor14443Demod(TRUE, RECEIVE_SAMPLES_TIMEOUT, TRUE);
// LED_A_OFF();
if (Demod.len != 3) {
Dbprintf("Expected 3 bytes from tag, got %d", Demod.len);
CodeAndTransmit14443bAsReader(cmd1, 3); // Only first three bytes for this one
// LED_A_ON();
- GetSamplesFor14443Demod(TRUE, 2000,TRUE);
+ GetSamplesFor14443Demod(TRUE, RECEIVE_SAMPLES_TIMEOUT, TRUE);
// LED_A_OFF();
if (Demod.len != 10) {
Dbprintf("Expected 10 bytes from tag, got %d", Demod.len);
CodeAndTransmit14443bAsReader(cmd1, sizeof(cmd1));
// LED_A_ON();
- GetSamplesFor14443Demod(TRUE, 2000,TRUE);
+ GetSamplesFor14443Demod(TRUE, RECEIVE_SAMPLES_TIMEOUT, TRUE);
// LED_A_OFF();
if (Demod.len != 6) { // Check if we got an answer from the tag
DbpString("Expected 6 bytes from tag, got less...");
cq = upTo[1];
upTo += 2;
lastRxCounter -= 2;
- if(upTo - dmaBuf > DMA_BUFFER_SIZE) {
- upTo -= DMA_BUFFER_SIZE;
+ if(upTo >= dmaBuf + DMA_BUFFER_SIZE) {
+ upTo = dmaBuf;
lastRxCounter += DMA_BUFFER_SIZE;
- AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) upTo;
+ AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dmaBuf;
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
}
if(recv)
{
+ GetSamplesFor14443Demod(TRUE, RECEIVE_SAMPLES_TIMEOUT, TRUE);
uint16_t iLen = MIN(Demod.len,USB_CMD_DATA_SIZE);
- GetSamplesFor14443Demod(TRUE, 2000, TRUE);
cmd_send(CMD_ACK,iLen,0,0,Demod.output,iLen);
}
if(!powerfield)