ADD: 'lf cotag read' - COTAG can be read now.
This commit is contained in:
@@ -1017,7 +1017,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
|
||||
CopyVikingtoT55xx(c->arg[0], c->arg[1], c->arg[2]);
|
||||
break;
|
||||
case CMD_COTAG:
|
||||
Cotag();
|
||||
Cotag(c->arg[0]);
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ void T55xxWakeUp(uint32_t Pwd);
|
||||
void TurnReadLFOn(uint32_t delay);
|
||||
void EM4xReadWord(uint8_t Address, uint32_t Pwd, uint8_t PwdMode);
|
||||
void EM4xWriteWord(uint32_t Data, uint8_t Address, uint32_t Pwd, uint8_t PwdMode);
|
||||
void Cotag();
|
||||
void Cotag(uint32_t arg0);
|
||||
|
||||
/// iso14443b.h
|
||||
void SimulateIso14443bTag(uint32_t pupi);
|
||||
|
||||
@@ -799,7 +799,7 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
|
||||
WDT_HIT();
|
||||
if (ledcontrol) LED_A_ON();
|
||||
|
||||
DoAcquisition_default(-1,true);
|
||||
DoAcquisition_default(0, true);
|
||||
// FSK demodulator
|
||||
size = 50*128*2; //big enough to catch 2 sequences of largest format
|
||||
idx = HIDdemodFSK(dest, &size, &hi2, &hi, &lo);
|
||||
@@ -1740,18 +1740,36 @@ void EM4xWriteWord(uint32_t Data, uint8_t Address, uint32_t Pwd, uint8_t PwdMode
|
||||
LED_D_OFF();
|
||||
}
|
||||
|
||||
void Cotag() {
|
||||
/*
|
||||
Reading a COTAG.
|
||||
|
||||
COTAG needs the reader to send a startsequence and the card has an extreme slow datarate.
|
||||
because of this, we can "sample" the data signal but we interpreate it to Manchester direct.
|
||||
|
||||
READER START SEQUENCE:
|
||||
burst 800 us, gap 2.2 msecs
|
||||
burst 3.6 msecs gap 2.2 msecs
|
||||
burst 800 us gap 2.2 msecs
|
||||
pulse 3.6 msecs
|
||||
|
||||
This triggers a COTAG tag to response
|
||||
*/
|
||||
void Cotag(uint32_t arg0) {
|
||||
|
||||
#define OFF { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); WaitUS(2035); }
|
||||
//#define WAIT2200 { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); WaitUS(2200); }
|
||||
#define ON(x) { FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 89); FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD); WaitUS((x)); }
|
||||
LED_A_ON();
|
||||
#define ON(x) { FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD); WaitUS((x)); }
|
||||
|
||||
uint8_t rawsignal = arg0 & 0xF;
|
||||
|
||||
LED_A_ON();
|
||||
|
||||
// Switching to LF image on FPGA. This might empty BigBuff
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||
|
||||
//clear buffer now so it does not interfere with timing later
|
||||
BigBuf_Clear_ext(false);
|
||||
|
||||
// Set up FPGA, 132kHz to power up the tag
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -1761,27 +1779,20 @@ void Cotag() {
|
||||
// Now set up the SSC to get the ADC samples that are now streaming at us.
|
||||
FpgaSetupSsc();
|
||||
|
||||
// start a 1.5ticks is 1us
|
||||
// start clock - 1.5ticks is 1us
|
||||
StartTicks();
|
||||
|
||||
//send start pulse
|
||||
//send COTAG start pulse
|
||||
ON(740) OFF
|
||||
ON(3330) OFF
|
||||
ON(740) OFF
|
||||
ON(1000)
|
||||
|
||||
/*
|
||||
ON(800) OFF
|
||||
ON(3600) OFF
|
||||
ON(800) OFF
|
||||
ON(1000)
|
||||
|
||||
burst 800 us, gap 2.2 msecs
|
||||
burst 3.6 msecs gap 2.2 msecs
|
||||
burst 800 us gap 2.2 msecs
|
||||
pulse 3.6 msecs
|
||||
*/
|
||||
DoAcquisition_config(FALSE);
|
||||
switch(rawsignal) {
|
||||
case 0: doCotagAcquisition(50000); break;
|
||||
case 1: doCotagAcquisitionManchester(); break;
|
||||
case 2: DoAcquisition_config(TRUE); break;
|
||||
}
|
||||
|
||||
// Turn the field off
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); // field off
|
||||
|
||||
@@ -20,7 +20,7 @@ sample_config config = { 1, 8, 1, 95, 0 } ;
|
||||
|
||||
void printConfig() {
|
||||
Dbprintf("LF Sampling config: ");
|
||||
Dbprintf(" [q] divisor: %d ", config.divisor);
|
||||
Dbprintf(" [q] divisor: %d (%d KHz)", config.divisor, 12000 / (config.divisor+1));
|
||||
Dbprintf(" [b] bps: %d ", config.bits_per_sample);
|
||||
Dbprintf(" [d] decimation: %d ", config.decimation);
|
||||
Dbprintf(" [a] averaging: %s ", (config.averaging) ? "Yes" : "No");
|
||||
@@ -140,7 +140,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag
|
||||
while(!BUTTON_PRESS() && !usb_poll_validate_length() ) {
|
||||
WDT_HIT();
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
||||
AT91C_BASE_SSC->SSC_THR = 0x00; //0x43;
|
||||
AT91C_BASE_SSC->SSC_THR = 0x43;
|
||||
LED_D_ON();
|
||||
}
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
@@ -310,4 +310,122 @@ void doT55x7Acquisition(size_t sample_size) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* acquisition of Cotag LF signal. Similart to other LF, since the Cotag has such long datarate RF/384
|
||||
* and is Manchester?, we directly gather the manchester data into bigbuff
|
||||
**/
|
||||
|
||||
#define COTAG_T1 384
|
||||
#define COTAG_T2 (COTAG_T1>>1)
|
||||
#define COTAG_ONE_THRESHOLD 128+30
|
||||
#define COTAG_ZERO_THRESHOLD 128-30
|
||||
void doCotagAcquisition(size_t sample_size) {
|
||||
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
uint16_t bufsize = BigBuf_max_traceLen();
|
||||
|
||||
if ( bufsize > sample_size )
|
||||
bufsize = sample_size;
|
||||
|
||||
dest[0] = 0;
|
||||
uint8_t sample = 0, firsthigh = 0, firstlow = 0;
|
||||
uint16_t i = 0;
|
||||
|
||||
while (!BUTTON_PRESS() && !usb_poll_validate_length() && (i < bufsize) ) {
|
||||
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) {
|
||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
LED_D_OFF();
|
||||
|
||||
// find first peak
|
||||
if ( !firsthigh ) {
|
||||
if (sample < COTAG_ONE_THRESHOLD)
|
||||
continue;
|
||||
firsthigh = 1;
|
||||
}
|
||||
if ( !firstlow ){
|
||||
if (sample > COTAG_ZERO_THRESHOLD )
|
||||
continue;
|
||||
firstlow = 1;
|
||||
}
|
||||
|
||||
++i;
|
||||
|
||||
if ( sample > COTAG_ONE_THRESHOLD)
|
||||
dest[i] = 255;
|
||||
else if ( sample < COTAG_ZERO_THRESHOLD)
|
||||
dest[i] = 0;
|
||||
else
|
||||
dest[i] = dest[i-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t doCotagAcquisitionManchester() {
|
||||
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
uint16_t bufsize = BigBuf_max_traceLen();
|
||||
|
||||
if ( bufsize > 320 )
|
||||
bufsize = 320;
|
||||
|
||||
dest[0] = 0;
|
||||
uint8_t sample = 0, firsthigh = 0, firstlow = 0;
|
||||
uint16_t sample_counter = 0, period = 0;
|
||||
uint8_t curr = 0, prev = 0;
|
||||
|
||||
while (!BUTTON_PRESS() && !usb_poll_validate_length() && (sample_counter < bufsize) ) {
|
||||
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) {
|
||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
LED_D_OFF();
|
||||
|
||||
// find first peak
|
||||
if ( !firsthigh ) {
|
||||
if (sample < COTAG_ONE_THRESHOLD)
|
||||
continue;
|
||||
firsthigh = 1;
|
||||
}
|
||||
|
||||
if ( !firstlow ){
|
||||
if (sample > COTAG_ZERO_THRESHOLD )
|
||||
continue;
|
||||
firstlow = 1;
|
||||
}
|
||||
|
||||
// set sample 255, 0, or previous
|
||||
if ( sample > COTAG_ONE_THRESHOLD){
|
||||
prev = curr;
|
||||
curr = 1;
|
||||
}
|
||||
else if ( sample < COTAG_ZERO_THRESHOLD) {
|
||||
prev = curr;
|
||||
curr = 0;
|
||||
}
|
||||
else {
|
||||
curr = prev;
|
||||
}
|
||||
|
||||
// full T1 periods,
|
||||
if ( period > 0 ) {
|
||||
--period;
|
||||
continue;
|
||||
}
|
||||
|
||||
dest[sample_counter] = curr;
|
||||
++sample_counter;
|
||||
period = COTAG_T1;
|
||||
}
|
||||
}
|
||||
return sample_counter;
|
||||
}
|
||||
@@ -11,7 +11,14 @@
|
||||
typedef struct BitstreamOut BitstreamOut;
|
||||
|
||||
/**
|
||||
* acquisition of T55x7 LF signal. Similart to other LF, but adjusted with @marshmellows thresholds
|
||||
* acquisition of Cotag LF signal. Similar to other LF, since the Cotag has such long datarate RF/384
|
||||
* and is Manchester?, we directly gather the manchester data into bigbuff
|
||||
**/
|
||||
void doCotagAcquisition(size_t sample_size);
|
||||
uint32_t doCotagAcquisitionManchester(void);
|
||||
|
||||
/**
|
||||
* acquisition of T55x7 LF signal. Similar to other LF, but adjusted with @marshmellows thresholds
|
||||
* the data is collected in BigBuf.
|
||||
**/
|
||||
void doT55x7Acquisition(size_t sample_size);
|
||||
|
||||
Reference in New Issue
Block a user