\r
//static void GetSamplesFor14443(BOOL weTx, int n);\r
\r
-#define DMA_BUFFER_SIZE 256\r
+#define DEMOD_TRACE_SIZE 4096\r
+#define READER_TAG_BUFFER_SIZE 2048\r
+#define TAG_READER_BUFFER_SIZE 2048\r
+#define DMA_BUFFER_SIZE 1024\r
\r
//=============================================================================\r
// An ISO 14443 Type B tag. We listen for commands from the reader, using\r
//-----------------------------------------------------------------------------\r
/*\r
* Memory usage for this function, (within BigBuf)\r
- * 0-1023 : Demodulated samples receive (1024 bytes)\r
- * 1024-1535 : Last Received command, 512 bytes (reader->tag)\r
- * 1536-2047 : Last Received command, 512 bytes(tag->reader)\r
- * 2048-2304 : DMA Buffer, 256 bytes (samples)\r
+ * 0-4095 : Demodulated samples receive (4096 bytes) - DEMOD_TRACE_SIZE\r
+ * 4096-6143 : Last Received command, 2048 bytes (reader->tag) - READER_TAG_BUFFER_SIZE\r
+ * 6144-8191 : Last Received command, 2048 bytes(tag->reader) - TAG_READER_BUFFER_SIZE\r
+ * 8192-9215 : DMA Buffer, 1024 bytes (samples) - DMA_BUFFER_SIZE\r
*/\r
void SnoopIso14443(void)\r
{\r
BOOL triggered = FALSE;\r
\r
// The command (reader -> tag) that we're working on receiving.\r
- BYTE *receivedCmd = (BYTE *)(BigBuf) + 1024;\r
+ BYTE *receivedCmd = (BYTE *)(BigBuf) + DEMOD_TRACE_SIZE;\r
// The response (tag -> reader) that we're working on receiving.\r
- BYTE *receivedResponse = (BYTE *)(BigBuf) + 1536;\r
+ BYTE *receivedResponse = (BYTE *)(BigBuf) + DEMOD_TRACE_SIZE + READER_TAG_BUFFER_SIZE;\r
\r
// As we receive stuff, we copy it from receivedCmd or receivedResponse\r
// into trace, along with its length and other annotations.\r
int traceLen = 0;\r
\r
// The DMA buffer, used to stream samples from the FPGA.\r
- SBYTE *dmaBuf = (SBYTE *)(BigBuf) + 2048;\r
+ SBYTE *dmaBuf = (SBYTE *)(BigBuf) + DEMOD_TRACE_SIZE + READER_TAG_BUFFER_SIZE + TAG_READER_BUFFER_SIZE;\r
int lastRxCounter;\r
SBYTE *upTo;\r
int ci, cq;\r
int samples = 0;\r
\r
// Initialize the trace buffer\r
- memset(trace, 0x44, 1024);\r
+ memset(trace, 0x44, DEMOD_TRACE_SIZE);\r
\r
// Set up the demodulator for tag -> reader responses.\r
Demod.output = receivedResponse;\r
Uart.byteCntMax = 100;\r
Uart.state = STATE_UNSYNCD;\r
\r
+ // Print some debug information about the buffer sizes\r
+ Dbprintf("Snooping buffers initialized:");\r
+ Dbprintf(" Trace: %i bytes", DEMOD_TRACE_SIZE);\r
+ Dbprintf(" Reader -> tag: %i bytes", READER_TAG_BUFFER_SIZE);\r
+ Dbprintf(" tag -> Reader: %i bytes", TAG_READER_BUFFER_SIZE);\r
+ Dbprintf(" DMA: %i bytes", DMA_BUFFER_SIZE);\r
+ \r
+ // Use a counter for blinking the LED\r
+ long ledCount=0;\r
+ long ledFlashAt=200000;\r
+ \r
// And put the FPGA in the appropriate mode\r
// Signal field is off with the appropriate LED\r
LED_D_OFF();\r
FpgaSetupSscDma((BYTE *)dmaBuf, DMA_BUFFER_SIZE);\r
// And now we loop, receiving samples.\r
for(;;) {\r
+ // Blink the LED while Snooping\r
+ ledCount++;\r
+ if (ledCount == ledFlashAt) {\r
+ LED_D_ON();\r
+ }\r
+ if (ledCount >= 2*ledFlashAt) {\r
+ LED_D_OFF();\r
+ ledCount=0;\r
+ }\r
+ \r
int behindBy = (lastRxCounter - AT91C_BASE_PDC_SSC->PDC_RCR) &\r
(DMA_BUFFER_SIZE-1);\r
if(behindBy > maxBehindBy) {\r
\r
#define HANDLE_BIT_IF_BODY \\r
if(triggered) { \\r
+ ledFlashAt=30000; \\r
trace[traceLen++] = ((samples >> 0) & 0xff); \\r
trace[traceLen++] = ((samples >> 8) & 0xff); \\r
trace[traceLen++] = ((samples >> 16) & 0xff); \\r
trace[traceLen++] = Demod.len;\r
memcpy(trace+traceLen, receivedResponse, Demod.len);\r
traceLen += Demod.len;\r
- if(traceLen > 1000) break;\r
+ if(traceLen > DEMOD_TRACE_SIZE) { \r
+ DbpString("Reached trace limit");\r
+ goto done;\r
+ }\r
\r
triggered = TRUE;\r
\r
}\r
}\r
\r
- DbpString("in done pt");\r
- Dbprintf("%x %x %x", maxBehindBy, Uart.state, Uart.byteCnt);\r
- Dbprintf("%x %x %x", Uart.byteCntMax, traceLen, 0x23);\r
-\r
done:\r
LED_D_OFF();\r
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;\r
+ DbpString("Snoop statistics:");\r
+ Dbprintf(" Max behind by: %i", maxBehindBy);\r
+ Dbprintf(" Uart State: %x", Uart.state);\r
+ Dbprintf(" Uart ByteCnt: %i", Uart.byteCnt);\r
+ Dbprintf(" Uart ByteCntMax: %i", Uart.byteCntMax);\r
+ Dbprintf(" Trace length: %i", traceLen);\r
}\r