Refactor ISO14443A DMA RX to use cross-platform buffer helpers

Replace the hard-coded AT91 PDC register access in SniffIso14443a() with
cross-platform helpers for the RX double-buffer status/refresh, so the
sniffer no longer depends on AT91-specific registers.

- Add FPGA_SSC_DMA_RX_{Primary,Secondary}_Done and
  FPGA_SSC_DMA_RX_Refresh_{Both,Secondary} to fpga_apis.h.
- AT91: primary maps to PDC RPR/RCR, secondary ("next") to RNPR/RNCR.
- AT32: no double buffer, so the primary path is a no-op and all re-arming
  is done through the secondary (single-shot DMA re-arm).
This commit is contained in:
dxl authored and Philippe Teuwen committed 2026-08-19 15:51:53 +02:00
1 parent 676bc467cd
commit a286002d27
4 files changed
+73 -20

No files matched your search

+4 -20
View File
@@ -881,18 +881,10 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
dataLen = DMA_BUFFER_SIZE - readBufDataP + dmaBufDataP;
}
// TODO DXL This cross platform issue needs to be addressed
// When the current buffer address is zeroed, it usually means the next buffer hasn't been assigned a value in time,
// indicating that the MCU's processing speed is slow.
// The logic here is to reset the state machine to receive data again.
// DMA fully stalled: both buffers exhausted. Re-arm primary + secondary,
// resync the read pointer, and drop the in-flight frame.
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
if (FPGA_SSC_DMA_RX_Primary_Done()) {
FPGA_SSC_DMA_RX_Refresh_Both(dma->buf, DMA_BUFFER_SIZE);
data = dma->buf;
rx_samples += DMA_BUFFER_SIZE;
Uart14aReset();
@@ -919,17 +911,9 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
continue;
}
/**
* TODO DXL This problem needs to be addressed.
* if (FPGA_SSC_DMA_RX_Done()) {
* FPGA_SSC_DMA_RX_Refresh_Repeat(dma->buf, DMA_BUFFER_SIZE);
* }
*/
// secondary buffer exhausted, primary still running — refill secondary
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
if (FPGA_SSC_DMA_RX_Secondary_Done()) {
FPGA_SSC_DMA_RX_Refresh_Secondary(dma->buf, DMA_BUFFER_SIZE);
}
LED_A_OFF();
+21
View File
@@ -219,6 +219,27 @@ STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Refresh_Repeat(void *buf, uint16_t len)
// It can be used when data processing speed is slow or when asynchronous reception processing with multiple buffers is required.
STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Refresh_Single(void *buf, uint16_t len);
//-----------------------------------------------------------------------------
// DMA RX double-buffer status & refresh (primary + "next").
// The AT91 PDC exposes a primary buffer (RPR/RCR) and a "next" buffer
// (RNPR/RNCR); when the primary drains, the "next" buffer is swapped in
// automatically. Platforms without a "next" buffer (AT32) implement these
// so the primary operations degrade to no-ops and all (re)arming is done
// through the secondary buffer.
//-----------------------------------------------------------------------------
// Has the primary RX buffer fully drained (its remaining count reached 0)?
STATIC_FORCE_INLINE bool FPGA_SSC_DMA_RX_Primary_Done(void);
// Has the "next" RX buffer also been consumed (nothing left to swap in)?
STATIC_FORCE_INLINE bool FPGA_SSC_DMA_RX_Secondary_Done(void);
// Re-arm both the primary and the "next" RX buffer (restart continuous RX).
STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Refresh_Both(void *buf, uint16_t len);
// Re-arm only the "next" RX buffer.
STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Refresh_Secondary(void *buf, uint16_t len);
//-----------------------------------------------------------------------------
// Provide a 24MHz clock from ARM to FPGA
// This is the most important main clock for FPGA, so it must be implemented!
+28
View File
@@ -138,4 +138,32 @@ STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Refresh_Single(void *buf, uint16_t len)
FPGA_SSC_DMA_RX_Enable();
}
STATIC_FORCE_INLINE bool FPGA_SSC_DMA_RX_Primary_Done(void) {
// AT32 has no "primary + next" double buffer. The single-shot DMA simply
// stops when the buffer is full, and that is the normal end of one
// reception cycle (the data is still valid), not the "both buffers
// exhausted" hard stall this hook describes. So it never applies here.
return false;
}
STATIC_FORCE_INLINE bool FPGA_SSC_DMA_RX_Secondary_Done(void) {
// The single-shot DMA counter reaching 0 means the buffer is full and the
// next reception must be re-armed — this is the "secondary buffer" role on
// AT32 (the buffer that comes after the current one finishes).
return FPGA_SSC_DMA_RX_Done();
}
STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Refresh_Both(void *buf, uint16_t len) {
// AT32 does not support a primary-buffer refresh (there is no double
// buffer), so this is intentionally a no-op. Primary_Done() is always
// false, so the caller never reaches this path anyway.
(void)buf;
(void)len;
}
STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Refresh_Secondary(void *buf, uint16_t len) {
// Re-arm the single buffer to start the next reception.
FPGA_SSC_DMA_RX_Refresh_Single(buf, len);
}
#endif
+20
View File
@@ -83,4 +83,24 @@ STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Refresh_Single(void *buf, uint16_t len)
AT91C_BASE_PDC_SSC->PDC_RCR = len; // transfer this many samples
}
STATIC_FORCE_INLINE bool FPGA_SSC_DMA_RX_Primary_Done(void) {
return AT91C_BASE_PDC_SSC->PDC_RCR == 0;
}
STATIC_FORCE_INLINE bool FPGA_SSC_DMA_RX_Secondary_Done(void) {
return AT91C_BASE_PDC_SSC->PDC_RNCR == 0;
}
STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Refresh_Both(void *buf, uint16_t len) {
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) buf; // primary buffer address
AT91C_BASE_PDC_SSC->PDC_RCR = len; // primary buffer count
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) buf; // next buffer address
AT91C_BASE_PDC_SSC->PDC_RNCR = len; // next buffer count
}
STATIC_FORCE_INLINE void FPGA_SSC_DMA_RX_Refresh_Secondary(void *buf, uint16_t len) {
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) buf; // next buffer address
AT91C_BASE_PDC_SSC->PDC_RNCR = len; // next buffer count
}
#endif