Skip to content

Commit 6a5d4e1

Browse files
authored
rework iso14443b device functions including FPGA I/Q signal transfer (#669)
* rework iso14443b device functions * hf_read_rx_xcorr.v: transfer i/q pair in one 16bit frame * hi_read_tx.v: invert ssp_dout. When nothing is transferred (ssp_dout=0), this results in no modulation (carrier on) * adjust arm sources accordingly * iso14443b.c: switch off carrier after hf 14b sri512read and hf 14b srix4kread * iso14443b.c: fix DMA circular buffer handling
1 parent 53edb04 commit 6a5d4e1

14 files changed

+206
-315
lines changed

armsrc/fpgaloader.c

+16-13
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ void SetupSpi(int mode)
112112
}
113113

114114
//-----------------------------------------------------------------------------
115-
// Set up the synchronous serial port, with the one set of options that we
116-
// always use when we are talking to the FPGA. Both RX and TX are enabled.
115+
// Set up the synchronous serial port with the set of options that fits
116+
// the FPGA mode. Both RX and TX are always enabled.
117117
//-----------------------------------------------------------------------------
118-
void FpgaSetupSsc(void)
118+
void FpgaSetupSsc(uint8_t FPGA_mode)
119119
{
120120
// First configure the GPIOs, and get ourselves a clock.
121121
AT91C_BASE_PIOA->PIO_ASR =
@@ -134,11 +134,15 @@ void FpgaSetupSsc(void)
134134
// on RX clock rising edge, sampled on falling edge
135135
AT91C_BASE_SSC->SSC_RCMR = SSC_CLOCK_MODE_SELECT(1) | SSC_CLOCK_MODE_START(1);
136136

137-
// 8 bits per transfer, no loopback, MSB first, 1 transfer per sync
137+
// 8, 16 or 32 bits per transfer, no loopback, MSB first, 1 transfer per sync
138138
// pulse, no output sync
139-
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
139+
if ((FPGA_mode & 0xe0) == FPGA_MAJOR_MODE_HF_READER_RX_XCORR) {
140+
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
141+
} else {
142+
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
143+
}
140144

141-
// clock comes from TK pin, no clock output, outputs change on falling
145+
// TX clock comes from TK pin, no clock output, outputs change on falling
142146
// edge of TK, sample on rising edge of TK, start on positive-going edge of sync
143147
AT91C_BASE_SSC->SSC_TCMR = SSC_CLOCK_MODE_SELECT(2) | SSC_CLOCK_MODE_START(5);
144148

@@ -154,16 +158,15 @@ void FpgaSetupSsc(void)
154158
// ourselves, not to another buffer). The stuff to manipulate those buffers
155159
// is in apps.h, because it should be inlined, for speed.
156160
//-----------------------------------------------------------------------------
157-
bool FpgaSetupSscDma(uint8_t *buf, int len)
161+
bool FpgaSetupSscDma(uint8_t *buf, uint16_t sample_count)
158162
{
159163
if (buf == NULL) return false;
160164

161-
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer
162-
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) buf; // transfer to this memory address
163-
AT91C_BASE_PDC_SSC->PDC_RCR = len; // transfer this many bytes
164-
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) buf; // next transfer to same memory address
165-
AT91C_BASE_PDC_SSC->PDC_RNCR = len; // ... with same number of bytes
166-
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN; // go!
165+
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer
166+
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) buf; // transfer to this memory address
167+
AT91C_BASE_PDC_SSC->PDC_RCR = sample_count; // transfer this many samples
168+
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) buf; // next transfer to same memory address
169+
AT91C_BASE_PDC_SSC->PDC_RNCR = sample_count; // ... with same number of samples AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN; // go!
167170

168171
return true;
169172
}

armsrc/fpgaloader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
void FpgaSendCommand(uint16_t cmd, uint16_t v);
2020
void FpgaWriteConfWord(uint8_t v);
2121
void FpgaDownloadAndGo(int bitstream_version);
22-
void FpgaSetupSsc(void);
22+
void FpgaSetupSsc(uint8_t mode);
2323
void SetupSpi(int mode);
2424
bool FpgaSetupSscDma(uint8_t *buf, int len);
2525
void Fpga_print_status();

armsrc/hfsnoop.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void HfSnoop(int samplesToSkip, int triggersToSkip)
3737
// Select correct configs
3838
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
3939
// Set up the synchronous serial port
40-
FpgaSetupSsc();
40+
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_SNOOP);
4141
// connect Demodulated Signal to ADC:
4242
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
4343
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SNOOP);

armsrc/iclass.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ void RAMFUNC SnoopIClass(void)
676676
Demod.state = DEMOD_UNSYNCD;
677677

678678
// Setup for the DMA.
679-
FpgaSetupSsc();
679+
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_ISO14443A);
680680
upTo = dmaBuf;
681681
lastRxCounter = DMA_BUFFER_SIZE;
682682
FpgaSetupSscDma((uint8_t *)dmaBuf, DMA_BUFFER_SIZE);
@@ -1163,7 +1163,7 @@ int doIClassSimulation( int simulationMode, uint8_t *reader_mac_buf)
11631163
StartCountSspClk();
11641164
// We need to listen to the high-frequency, peak-detected path.
11651165
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
1166-
FpgaSetupSsc();
1166+
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_ISO14443A);
11671167

11681168
// To control where we are in the protocol
11691169
int cmdsRecvd = 0;
@@ -1360,7 +1360,7 @@ static int SendIClassAnswer(uint8_t *resp, int respLen, int delay)
13601360
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR|FPGA_HF_SIMULATOR_MODULATE_424K_8BIT);
13611361

13621362
AT91C_BASE_SSC->SSC_THR = 0x00;
1363-
FpgaSetupSsc();
1363+
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_SIMULATOR);
13641364
while(!BUTTON_PRESS()) {
13651365
if((AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY)){
13661366
b = AT91C_BASE_SSC->SSC_RHR; (void) b;
@@ -1398,7 +1398,7 @@ static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int
13981398
int c;
13991399
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_MOD);
14001400
AT91C_BASE_SSC->SSC_THR = 0x00;
1401-
FpgaSetupSsc();
1401+
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_ISO14443A);
14021402

14031403
if (wait)
14041404
{
@@ -1586,7 +1586,7 @@ void setupIclassReader()
15861586
clear_trace();
15871587

15881588
// Setup SSC
1589-
FpgaSetupSsc();
1589+
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_ISO14443A);
15901590
// Start from off (no field generated)
15911591
// Signal field is off with the appropriate LED
15921592
LED_D_OFF();

armsrc/iso14443a.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ int iso14443a_select_card(byte_t *uid_ptr, iso14a_card_select_t *p_hi14a_card, u
18891889
void iso14443a_setup(uint8_t fpga_minor_mode) {
18901890
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
18911891
// Set up the synchronous serial port
1892-
FpgaSetupSsc();
1892+
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_ISO14443A);
18931893
// connect Demodulated Signal to ADC:
18941894
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
18951895

0 commit comments

Comments
 (0)