Skip to content

Commit

Permalink
chg: adapted lfsampling, and swapped from 'silent' logic to the more …
Browse files Browse the repository at this point in the history
…natural 'verbose' logic
  • Loading branch information
iceman1001 committed Jan 7, 2020
1 parent a1d9356 commit f7156e7
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 166 deletions.
6 changes: 3 additions & 3 deletions armsrc/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,11 @@ static void PacketReceived(PacketCommandNG *packet) {
}
case CMD_LF_ACQ_RAW_ADC: {
struct p {
uint8_t silent;
uint8_t verbose;
uint32_t samples;
} PACKED;
struct p *payload = (struct p *)packet->data.asBytes;
uint32_t bits = SampleLF(payload->silent, payload->samples);
uint32_t bits = SampleLF(payload->verbose, payload->samples);
reply_ng(CMD_LF_ACQ_RAW_ADC, PM3_SUCCESS, (uint8_t *)&bits, sizeof(bits));
break;
}
Expand Down Expand Up @@ -1603,7 +1603,7 @@ static void PacketReceived(PacketCommandNG *packet) {
BigBuf_Clear_ext(false);
BigBuf_free();
}

// 40 000 - (512-3) 509 = 39491
uint16_t offset = MIN(BIGBUF_SIZE - PM3_CMD_DATA_SIZE - 3, payload->offset);

Expand Down
24 changes: 18 additions & 6 deletions armsrc/lfadc.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ size_t lf_count_edge_periods_ex(size_t max, bool wait, bool detect_gap) {
adc_val = AT91C_BASE_SSC->SSC_RHR;
periods++;

if (logging) logSample(adc_val, 1, 8, 0, 0);
if (logging) logSample(adc_val, 1, 8, 0);

// Only test field changes if state of adc values matter
if (!wait) {
Expand Down Expand Up @@ -91,7 +91,7 @@ size_t lf_count_edge_periods_ex(size_t max, bool wait, bool detect_gap) {
if (periods == max) return 0;
}
}
if (logging) logSample(255, 1, 8, 0, 0);
if (logging) logSample(255, 1, 8, 0);
return 0;
}

Expand Down Expand Up @@ -168,7 +168,7 @@ void lf_init(bool reader) {
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;

// Prepare data trace
if (logging) initSamplingBuffer();
if (logging) initSamplingBuffer(NULL);

}

Expand All @@ -189,17 +189,29 @@ void lf_finalize() {
size_t lf_detect_field_drop(size_t max) {
size_t periods = 0;
volatile uint8_t adc_val;
int16_t checked = 0;

while (true) {

// only every 1000th times, in order to save time when collecting samples.
if (checked == 1000) {
if (BUTTON_PRESS() || data_available()) {
checked = -1;
break;
} else {
checked = 0;
}
}
++checked;

// usb check?
while (!BUTTON_PRESS()) {
// Watchdog hit
WDT_HIT();

if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
periods++;
adc_val = AT91C_BASE_SSC->SSC_RHR;

if (logging) logSample(adc_val, 1, 8, 0, 0);
if (logging) logSample(adc_val, 1, 8, 0);

if (adc_val == 0) {
rising_edge = false;
Expand Down
34 changes: 17 additions & 17 deletions armsrc/lfops.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_ADC_READER_FIELD);

// now do the read
DoAcquisition_config(false, 0);
DoAcquisition_config(true, 0);

// Turn off antenna
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
Expand Down Expand Up @@ -1182,7 +1182,7 @@ static void nrzSimBit(uint8_t c, int *n, uint8_t clock) {
*n += clock;
}

// args clock,
// args clock,
void CmdNRZsimTAG(uint8_t invert, uint8_t separator, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol) {

FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
Expand All @@ -1198,7 +1198,7 @@ void CmdNRZsimTAG(uint8_t invert, uint8_t separator, uint8_t clk, uint16_t size,
nrzSimBit(bits[i] ^ invert, &n, clk);
}

if (bits[0] == bits[size - 1]) { //run a second set inverted (for ask/raw || biphase phase)
if (bits[0] == bits[size - 1]) {
for (i = 0; i < size; i++) {
nrzSimBit(bits[i] ^ invert ^ 1, &n, clk);
}
Expand Down Expand Up @@ -1239,7 +1239,7 @@ void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
WDT_HIT();
if (ledcontrol) LED_A_ON();

DoAcquisition_default(-1, true);
DoAcquisition_default(-1, false);
// FSK demodulator
size = 50 * 128 * 2; //big enough to catch 2 sequences of largest format
int idx = HIDdemodFSK(dest, &size, &hi2, &hi, &lo, &dummyIdx);
Expand Down Expand Up @@ -1330,7 +1330,7 @@ void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
WDT_HIT();
if (ledcontrol) LED_A_ON();

DoAcquisition_default(-1, true);
DoAcquisition_default(-1, false);
// FSK demodulator

size = MIN(12800, BigBuf_max_traceLen());
Expand Down Expand Up @@ -1421,11 +1421,11 @@ void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol)
WDT_HIT();
if (ledcontrol) LED_A_ON();

DoAcquisition_default(-1, true);
DoAcquisition_default(-1, false);

size = MIN(16385, BigBuf_max_traceLen());
//askdemod and manchester decode

//askdemod and manchester decode
int errCnt = askdemod(dest, &size, &clk, &invert, maxErr, 0, 1);
WDT_HIT();

Expand Down Expand Up @@ -1486,10 +1486,10 @@ void CmdIOdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) {
WDT_HIT();
if (ledcontrol) LED_A_ON();

DoAcquisition_default(-1, true);
DoAcquisition_default(-1, false);

size = MIN(12000, BigBuf_max_traceLen());

//fskdemod and get start index
int idx = detectIOProx(dest, &size, &dummyIdx);
if (idx < 0) continue;
Expand Down Expand Up @@ -1772,7 +1772,7 @@ void T55xxResetRead(uint8_t flags) {
TurnReadLFOn(T55xx_Timing.m[downlink_mode].read_gap);

// Acquisition
DoPartialAcquisition(0, true, BigBuf_max_traceLen(), 0);
DoPartialAcquisition(0, false, BigBuf_max_traceLen(), 0);

// Turn the field off
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
Expand Down Expand Up @@ -1869,7 +1869,7 @@ void T55xxWriteBlock(uint8_t *data) {
// response should be (for t55x7) a 0 bit then (ST if on)
// block data written in on repeat until reset.

//DoPartialAcquisition(20, true, 12000);
//DoPartialAcquisition(20, false, 12000);
}
// turn field off
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
Expand Down Expand Up @@ -1930,7 +1930,7 @@ bool brute_mem = (flags & 0x0100) >> 8;
// Acquisition
// Now do the acquisition
DoPartialAcquisition(0, true, samples, 0);
DoPartialAcquisition(0, false, samples, 0);
// Turn the field off
if (!brute_mem) {
Expand Down Expand Up @@ -1990,7 +1990,7 @@ void T55xxReadBlock(uint8_t page, bool pwd_mode, bool brute_mem, uint8_t block,

// Acquisition
// Now do the acquisition
DoPartialAcquisition(0, true, samples, 0);
DoPartialAcquisition(0, false, samples, 0);

// Turn the field off
if (!brute_mem) {
Expand Down Expand Up @@ -2447,7 +2447,7 @@ void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd) {

WaitUS(400);

DoPartialAcquisition(20, true, 6000, 1000);
DoPartialAcquisition(20, false, 6000, 1000);

FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
reply_ng(CMD_LF_EM4X_READWORD, PM3_SUCCESS, NULL, 0);
Expand Down Expand Up @@ -2480,7 +2480,7 @@ void EM4xWriteWord(uint8_t addr, uint32_t data, uint32_t pwd, uint8_t usepwd) {
//Wait 20ms for write to complete?
WaitMS(7);

DoPartialAcquisition(20, true, 6000, 1000);
DoPartialAcquisition(20, false, 6000, 1000);

FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
reply_ng(CMD_LF_EM4X_WRITEWORD, PM3_SUCCESS, NULL, 0);
Expand Down Expand Up @@ -2550,7 +2550,7 @@ void Cotag(uint32_t arg0) {
doCotagAcquisitionManchester();
break;
case 2:
DoAcquisition_config(true, 0);
DoAcquisition_config(true, true);
break;
}

Expand Down
Loading

0 comments on commit f7156e7

Please sign in to comment.