mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
CHG: remove strange thr 0x43 in LF sampling
CHG: refactor cotag init
This commit is contained in:
parent
f215ebef80
commit
a5833fe390
2 changed files with 29 additions and 53 deletions
|
@ -1548,7 +1548,7 @@ void T55xxReadBlock(uint16_t arg0, uint8_t Block, uint32_t Pwd) {
|
||||||
// Turn field on to read the response
|
// Turn field on to read the response
|
||||||
// 137*8 seems to get to the start of data pretty well...
|
// 137*8 seems to get to the start of data pretty well...
|
||||||
// but we want to go past the start and let the repeating data settle in...
|
// but we want to go past the start and let the repeating data settle in...
|
||||||
TurnReadLFOn(210*8);
|
TurnReadLFOn(200*8);
|
||||||
|
|
||||||
// Acquisition
|
// Acquisition
|
||||||
// Now do the acquisition
|
// Now do the acquisition
|
||||||
|
@ -2089,7 +2089,6 @@ void EM4xWriteWord(uint32_t flag, uint32_t data, uint32_t pwd) {
|
||||||
//Wait 20ms for write to complete?
|
//Wait 20ms for write to complete?
|
||||||
WaitMS(7);
|
WaitMS(7);
|
||||||
|
|
||||||
//Capture response if one exists
|
|
||||||
DoPartialAcquisition(20, true, 6000, 1000);
|
DoPartialAcquisition(20, true, 6000, 1000);
|
||||||
|
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
|
@ -2113,7 +2112,7 @@ This triggers a COTAG tag to response
|
||||||
*/
|
*/
|
||||||
void Cotag(uint32_t arg0) {
|
void Cotag(uint32_t arg0) {
|
||||||
#ifndef OFF
|
#ifndef OFF
|
||||||
# define OFF { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); WaitUS(2035); }
|
# define OFF(x) { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); WaitUS((x)); }
|
||||||
#endif
|
#endif
|
||||||
#ifndef ON
|
#ifndef ON
|
||||||
# define ON(x) { FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD); WaitUS((x)); }
|
# define ON(x) { FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD); WaitUS((x)); }
|
||||||
|
@ -2122,29 +2121,15 @@ void Cotag(uint32_t arg0) {
|
||||||
|
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
|
|
||||||
// Switching to LF image on FPGA. This might empty BigBuff
|
LFSetupFPGAForADC(89, true);
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
|
||||||
|
|
||||||
//clear buffer now so it does not interfere with timing later
|
//clear buffer now so it does not interfere with timing later
|
||||||
BigBuf_Clear_ext(false);
|
BigBuf_Clear_ext(false);
|
||||||
|
|
||||||
// Set up FPGA, 132kHz to power up the tag
|
|
||||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 89);
|
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
|
|
||||||
|
|
||||||
// Connect the A/D to the peak-detected low-frequency path.
|
|
||||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
|
||||||
|
|
||||||
// Now set up the SSC to get the ADC samples that are now streaming at us.
|
|
||||||
FpgaSetupSsc();
|
|
||||||
|
|
||||||
// start clock - 1.5ticks is 1us
|
|
||||||
StartTicks();
|
|
||||||
|
|
||||||
//send COTAG start pulse
|
//send COTAG start pulse
|
||||||
ON(740) OFF
|
ON(740) OFF(2035)
|
||||||
ON(3330) OFF
|
ON(3330) OFF(2035)
|
||||||
ON(740) OFF
|
ON(740) OFF(2035)
|
||||||
ON(1000)
|
ON(1000)
|
||||||
|
|
||||||
switch(rawsignal) {
|
switch(rawsignal) {
|
||||||
|
|
|
@ -117,21 +117,21 @@ void LFSetupFPGAForADC(int divisor, bool lf_field) {
|
||||||
* @return the number of bits occupied by the samples.
|
* @return the number of bits occupied by the samples.
|
||||||
*/
|
*/
|
||||||
uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averaging, int trigger_threshold, bool silent, int bufsize, uint32_t cancel_after) {
|
uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averaging, int trigger_threshold, bool silent, int bufsize, uint32_t cancel_after) {
|
||||||
//bigbuf, to hold the aquired raw data signal
|
|
||||||
uint8_t *dest = BigBuf_get_addr();
|
uint8_t *dest = BigBuf_get_addr();
|
||||||
bufsize = (bufsize > 0 && bufsize < BigBuf_max_traceLen()) ? bufsize : BigBuf_max_traceLen();
|
bufsize = (bufsize > 0 && bufsize < BigBuf_max_traceLen()) ? bufsize : BigBuf_max_traceLen();
|
||||||
|
|
||||||
|
|
||||||
if (bits_per_sample < 1) bits_per_sample = 1;
|
if (bits_per_sample < 1) bits_per_sample = 1;
|
||||||
if (bits_per_sample > 8) bits_per_sample = 8;
|
if (bits_per_sample > 8) bits_per_sample = 8;
|
||||||
|
|
||||||
if (decimation < 1) decimation = 1;
|
if (decimation < 1) decimation = 1;
|
||||||
|
|
||||||
// Use a bit stream to handle the output
|
// use a bit stream to handle the output
|
||||||
BitstreamOut data = { dest , 0, 0};
|
BitstreamOut data = { dest , 0, 0};
|
||||||
int sample_counter = 0;
|
int sample_counter = 0;
|
||||||
uint8_t sample = 0;
|
uint8_t sample = 0;
|
||||||
//If we want to do averaging
|
|
||||||
|
// if we want to do averaging
|
||||||
uint32_t sample_sum =0 ;
|
uint32_t sample_sum =0 ;
|
||||||
uint32_t sample_total_numbers = 0;
|
uint32_t sample_total_numbers = 0;
|
||||||
uint32_t sample_total_saved = 0;
|
uint32_t sample_total_saved = 0;
|
||||||
|
@ -139,13 +139,13 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag
|
||||||
|
|
||||||
while (!BUTTON_PRESS() && !usb_poll_validate_length() ) {
|
while (!BUTTON_PRESS() && !usb_poll_validate_length() ) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
|
||||||
AT91C_BASE_SSC->SSC_THR = 0x43;
|
|
||||||
LED_D_ON();
|
|
||||||
}
|
|
||||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||||
|
|
||||||
|
// Testpoint 8 (TP8) can be used to trigger oscilliscope
|
||||||
LED_D_OFF();
|
LED_D_OFF();
|
||||||
|
|
||||||
// threshold either high or low values 128 = center 0. if trigger = 178
|
// threshold either high or low values 128 = center 0. if trigger = 178
|
||||||
if ((trigger_threshold > 0) && (sample < (trigger_threshold + 128)) && (sample > (128 - trigger_threshold))) {
|
if ((trigger_threshold > 0) && (sample < (trigger_threshold + 128)) && (sample > (128 - trigger_threshold))) {
|
||||||
if (cancel_after > 0) {
|
if (cancel_after > 0) {
|
||||||
|
@ -162,24 +162,26 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag
|
||||||
if (averaging)
|
if (averaging)
|
||||||
sample_sum += sample;
|
sample_sum += sample;
|
||||||
|
|
||||||
//Check decimation
|
// check decimation
|
||||||
if (decimation > 1) {
|
if (decimation > 1) {
|
||||||
sample_counter++;
|
sample_counter++;
|
||||||
if (sample_counter < decimation) continue;
|
if (sample_counter < decimation) continue;
|
||||||
sample_counter = 0;
|
sample_counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Averaging
|
// averaging
|
||||||
if (averaging && decimation > 1) {
|
if (averaging && decimation > 1) {
|
||||||
sample = sample_sum / decimation;
|
sample = sample_sum / decimation;
|
||||||
sample_sum =0;
|
sample_sum =0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Store the sample
|
// store the sample
|
||||||
sample_total_saved ++;
|
sample_total_saved ++;
|
||||||
if (bits_per_sample == 8){
|
if (bits_per_sample == 8) {
|
||||||
dest[sample_total_saved-1] = sample;
|
dest[sample_total_saved-1] = sample;
|
||||||
data.numbits = sample_total_saved << 3;//Get the return value correct
|
|
||||||
|
// Get the return value correct
|
||||||
|
data.numbits = sample_total_saved << 3;
|
||||||
if (sample_total_saved >= bufsize) break;
|
if (sample_total_saved >= bufsize) break;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -190,9 +192,8 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag
|
||||||
if (bits_per_sample > 4) pushBit(&data, sample & 0x08);
|
if (bits_per_sample > 4) pushBit(&data, sample & 0x08);
|
||||||
if (bits_per_sample > 5) pushBit(&data, sample & 0x04);
|
if (bits_per_sample > 5) pushBit(&data, sample & 0x04);
|
||||||
if (bits_per_sample > 6) pushBit(&data, sample & 0x02);
|
if (bits_per_sample > 6) pushBit(&data, sample & 0x02);
|
||||||
//Not needed, 8bps is covered above
|
|
||||||
//if (bits_per_sample > 7) pushBit(&data, sample & 0x01);
|
if ((data.numbits >> 3) + 1 >= bufsize) break;
|
||||||
if ((data.numbits >> 3) +1 >= bufsize) break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,10 +286,8 @@ void doT55x7Acquisition(size_t sample_size) {
|
||||||
|
|
||||||
while(!BUTTON_PRESS() && !usb_poll_validate_length() && skipCnt < 1000 && (i < bufsize) ) {
|
while(!BUTTON_PRESS() && !usb_poll_validate_length() && skipCnt < 1000 && (i < bufsize) ) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
|
||||||
AT91C_BASE_SSC->SSC_THR = 0x43; //43
|
|
||||||
LED_D_ON();
|
|
||||||
}
|
|
||||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||||
curSample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
curSample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||||
LED_D_OFF();
|
LED_D_OFF();
|
||||||
|
@ -352,10 +351,6 @@ void doCotagAcquisition(size_t sample_size) {
|
||||||
|
|
||||||
while (!BUTTON_PRESS() && !usb_poll_validate_length() && (i < bufsize) && (noise_counter < (COTAG_T1 << 1)) ) {
|
while (!BUTTON_PRESS() && !usb_poll_validate_length() && (i < bufsize) && (noise_counter < (COTAG_T1 << 1)) ) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
|
||||||
AT91C_BASE_SSC->SSC_THR = 0x43;
|
|
||||||
LED_D_ON();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||||
|
@ -407,10 +402,6 @@ uint32_t doCotagAcquisitionManchester() {
|
||||||
|
|
||||||
while (!BUTTON_PRESS() && !usb_poll_validate_length() && (sample_counter < bufsize) && (noise_counter < (COTAG_T1 << 1)) ) {
|
while (!BUTTON_PRESS() && !usb_poll_validate_length() && (sample_counter < bufsize) && (noise_counter < (COTAG_T1 << 1)) ) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
|
||||||
AT91C_BASE_SSC->SSC_THR = 0x43;
|
|
||||||
LED_D_ON();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue