read directly without dma

This commit is contained in:
merlokk 2022-06-27 00:30:49 +03:00
commit 9813f85567
2 changed files with 22 additions and 59 deletions

View file

@ -29,7 +29,6 @@
#include "commonutil.h" #include "commonutil.h"
#include "lfsampling.h" #include "lfsampling.h"
int HfReadADC(uint32_t samplesCount, bool ledcontrol) { int HfReadADC(uint32_t samplesCount, bool ledcontrol) {
if (ledcontrol) LEDsoff(); if (ledcontrol) LEDsoff();
@ -39,80 +38,45 @@ int HfReadADC(uint32_t samplesCount, bool ledcontrol) {
FpgaDownloadAndGo(FPGA_BITSTREAM_HF); FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
// And put the FPGA in the appropriate mode // And put the FPGA in the appropriate mode
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_2SUBCARRIERS_424_484_KHZ | FPGA_HF_READER_MODE_RECEIVE_AMPLITUDE); FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_SUBCARRIER_212_KHZ | FPGA_HF_READER_MODE_RECEIVE_AMPLITUDE);
// Setup and start DMA. // Setup
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER); FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
// The DMA buffer, used to stream samples from the FPGA
dmabuf16_t *dma = get_dma16();
memset((uint8_t *) dma->buf, 0, DMA_BUFFER_SIZE);
// Setup and start DMA.
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscDma failed. Exiting");
FpgaDisableSscDma();
FpgaSetupSsc(FPGA_MAJOR_MODE_OFF);
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
return PM3_EINIT;
}
if (ledcontrol) LED_A_ON(); if (ledcontrol) LED_A_ON();
uint16_t *upTo = dma->buf;
uint32_t sbs = samplesCount; uint32_t sbs = samplesCount;
initSampleBuffer(&sbs); initSampleBuffer(&sbs);
uint32_t wdtcntr = 0;
for (;;) { for (;;) {
if (BUTTON_PRESS()) { if (BUTTON_PRESS()) {
break; break;
} }
volatile uint16_t behindBy = ((uint16_t *)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1); if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
if (behindBy == 0) volatile uint16_t sample = AT91C_BASE_SSC->SSC_RHR;
// FPGA side:
// corr_i_out <= {2'b00, corr_amplitude[13:8]};
// corr_q_out <= corr_amplitude[7:0];
if (sample > 0x1fff)
sample = 0xff;
else
sample = sample >> 5;
logSample(sample & 0xff, 1, 8, false);
if (getSampleCounter() >= samplesCount)
break;
if (wdtcntr++ > 512) {
WDT_HIT();
wdtcntr = 0;
}
} else {
continue; continue;
// FPGA side:
// corr_i_out <= {2'b00, corr_amplitude[13:8]};
// corr_q_out <= corr_amplitude[7:0];
// ci = upTo >> 8, cq = upTo
volatile uint16_t sample = *upTo++;
//if (sample & 0xc000) {
// Dbprintf("sample!!!! %d \r\n", getSampleCounter());
// break;
//}
logSample((sample >> 6) & 0xff, 1, 8, false);
if (getSampleCounter() >= samplesCount)
break;
if (upTo >= dma->buf + DMA_BUFFER_SIZE) { // we have read all of the DMA buffer content.
upTo = dma->buf; // start reading the circular buffer from the beginning
}
// DMA Counter Register had reached 0, already rotated.
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
// primary buffer was stopped
if (AT91C_BASE_PDC_SSC->PDC_RCR == false) {
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
Dbprintf("blew\r\n");
}
// secondary buffer sets as primary, secondary buffer was stopped
if (AT91C_BASE_PDC_SSC->PDC_RNCR == false) {
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
}
WDT_HIT();
} }
} }
FpgaDisableSscDma();
FpgaDisableTracing(); FpgaDisableTracing();
FpgaSetupSsc(FPGA_MAJOR_MODE_OFF); FpgaSetupSsc(FPGA_MAJOR_MODE_OFF);

View file

@ -23,5 +23,4 @@
int HfReadADC(uint32_t samplesCount, bool ledcontrol); int HfReadADC(uint32_t samplesCount, bool ledcontrol);
#endif #endif