]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
add l/h option to hw tune and optimize order of tuning 181/head
authorRichard Antony Burton <richardaburton@gmail.com>
Mon, 30 May 2016 17:30:38 +0000 (18:30 +0100)
committerRichard Antony Burton <richardaburton@gmail.com>
Wed, 1 Jun 2016 07:13:20 +0000 (08:13 +0100)
.gitignore
CHANGELOG.md
armsrc/appmain.c
armsrc/fpgaloader.c
armsrc/fpgaloader.h
client/cmddata.c
client/cmdhw.c
include/usb_cmd.h

index fa74326ed6f9297683b6124cb138becaa61bc94f..4af73fb12625d454c10459ea96660e5c689cc811 100644 (file)
@@ -21,6 +21,7 @@ flasher
 version.c
 lua
 luac
+fpga_compress
 
 fpga/*
 !fpga/tests
index 7055d087d5cacf51d5f313b6f9816db23cc07d05..57fb549a8d0968b3fba3a8920521a16c5a1b0846 100644 (file)
@@ -33,6 +33,7 @@ of stream transmissions (marshmellow)
 - Added 'hf snoop'. This command take digitalized signal from FPGA and put in BigBuffer. (pwpiwi + enio)
 - Added Topaz (NFC type 1) protocol support ('hf topaz reader', 'hf list topaz', 'hf 14a raw -T', 'hf topaz snoop'). (piwi)
 - Added option c to 'hf list' (mark CRC bytes) (piwi)
+- Added option `l` or `h` to `hw tune` to save time and unnecessary fpga writes if you are only interested in lf or hf.
 
 ### Changed
 - Added `[l] <length>` option to data printdemodbuffer
index 475b1c1b8e7e2a3e593d9dde365e70b5229a50a5..eded359e0da364906aef836339d13ee34c9d6152 100644 (file)
@@ -182,13 +182,9 @@ int AvgAdc(int ch) // was static - merlok
        return (a + 15) >> 5;
 }
 
-void MeasureAntennaTuning(void)
+void MeasureAntennaTuningLfOnly(int *vLf125, int *vLf134, int *peakf, int *peakv, uint8_t LF_Results[])
 {
-       uint8_t LF_Results[256];
-       int i, adcval = 0, peak = 0, peakv = 0, peakf = 0; //ptr = 0 
-       int vLf125 = 0, vLf134 = 0, vHf = 0;    // in mV
-
-       LED_B_ON();
+       int i, adcval = 0, peak = 0;
 
 /*
  * Sweeps the useful LF range of the proxmark from
@@ -198,38 +194,67 @@ void MeasureAntennaTuning(void)
  * the resonating frequency of your LF antenna
  * ( hopefully around 95 if it is tuned to 125kHz!)
  */
-  
-       FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
+
+       FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
        FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
        for (i=255; i>=19; i--) {
-    WDT_HIT();
+               WDT_HIT();
                FpgaSendCommand(FPGA_CMD_SET_DIVISOR, i);
                SpinDelay(20);
                adcval = ((MAX_ADC_LF_VOLTAGE * AvgAdc(ADC_CHAN_LF)) >> 10);
-               if (i==95)      vLf125 = adcval; // voltage at 125Khz
-               if (i==89)      vLf134 = adcval; // voltage at 134Khz
+               if (i==95) *vLf125 = adcval; // voltage at 125Khz
+               if (i==89) *vLf134 = adcval; // voltage at 134Khz
 
                LF_Results[i] = adcval>>8; // scale int to fit in byte for graphing purposes
                if(LF_Results[i] > peak) {
-                       peakv = adcval;
+                       *peakv = adcval;
                        peak = LF_Results[i];
-                       peakf = i;
+                       *peakf = i;
                        //ptr = i;
                }
        }
 
        for (i=18; i >= 0; i--) LF_Results[i] = 0;
-       
-       LED_A_ON();
+
+       return;
+}
+
+void MeasureAntennaTuningHfOnly(int *vHf)
+{
        // Let the FPGA drive the high-frequency antenna around 13.56 MHz.
-       FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
+       LED_A_ON();
+       FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
        FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
        SpinDelay(20);
-       vHf = (MAX_ADC_HF_VOLTAGE * AvgAdc(ADC_CHAN_HF)) >> 10;
+       *vHf = (MAX_ADC_HF_VOLTAGE * AvgAdc(ADC_CHAN_HF)) >> 10;
+       LED_A_OFF();
+
+       return;
+}
+
+void MeasureAntennaTuning(int mode)
+{
+       uint8_t LF_Results[256] = {0};
+       int peakv = 0, peakf = 0;
+       int vLf125 = 0, vLf134 = 0, vHf = 0; // in mV
+
+       LED_B_ON();
+
+       if (((mode & FLAG_TUNE_ALL) == FLAG_TUNE_ALL) && (FpgaGetCurrent() == FPGA_BITSTREAM_HF)) {
+               // Reverse "standard" order if HF already loaded, to avoid unnecessary swap.
+               MeasureAntennaTuningHfOnly(&vHf);
+               MeasureAntennaTuningLfOnly(&vLf125, &vLf134, &peakf, &peakv, LF_Results);
+       } else {
+               if (mode & FLAG_TUNE_LF) {
+                       MeasureAntennaTuningLfOnly(&vLf125, &vLf134, &peakf, &peakv, LF_Results);
+               }
+               if (mode & FLAG_TUNE_HF) {
+                       MeasureAntennaTuningHfOnly(&vHf);
+               }
+       }
 
        cmd_send(CMD_MEASURED_ANTENNA_TUNING, vLf125 | (vLf134<<16), vHf, peakf | (peakv<<16), LF_Results, 256);
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
-       LED_A_OFF();
        LED_B_OFF();
        return;
 }
@@ -1231,7 +1256,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
                        break;
 
                case CMD_MEASURE_ANTENNA_TUNING:
-                       MeasureAntennaTuning();
+                       MeasureAntennaTuning(c->arg[0]);
                        break;
 
                case CMD_MEASURE_ANTENNA_TUNING_HF:
index 308dda8c09e6ebf8fd0a691df91ccb0c0c3189d2..e211c12fbd5a7e5119b86d6196da954e1b0198ef 100644 (file)
@@ -566,3 +566,7 @@ void Fpga_print_status(void)
        else if(downloaded_bitstream == FPGA_BITSTREAM_LF) Dbprintf("  mode.............LF");
        else Dbprintf("  mode.............%d", downloaded_bitstream);
 }
+
+int FpgaGetCurrent() {
+       return downloaded_bitstream;
+}
index 38724cdba3dc996d71b58ccbd671b49b8bbf13ac..7dfc5c1265e539e8e8e419bb9ad68da857e6a061 100644 (file)
@@ -18,6 +18,7 @@ void FpgaSetupSsc(void);
 void SetupSpi(int mode);
 bool FpgaSetupSscDma(uint8_t *buf, int len);
 void Fpga_print_status();
+int FpgaGetCurrent();
 #define FpgaDisableSscDma(void)        AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
 #define FpgaEnableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN;
 void SetAdcMuxFor(uint32_t whichGpio);
index c7fdc91e36a79cfe17052e3299f9dcc880e1915c..394dcbc2286ee5dfc8002899f4dd3555be2ce290 100644 (file)
@@ -2048,10 +2048,20 @@ int CmdSamples(const char *Cmd)
 
 int CmdTuneSamples(const char *Cmd)
 {
-       int timeout = 0;
+       int timeout = 0, arg = FLAG_TUNE_ALL;
+
+       if(*Cmd == 'l') {
+         arg = FLAG_TUNE_LF;
+       } else if (*Cmd == 'h') {
+         arg = FLAG_TUNE_HF;
+       } else if (*Cmd != '\0') {
+         PrintAndLog("use 'tune' or 'tune l' or 'tune h'");
+         return 0;
+       }
+
        printf("\nMeasuring antenna characteristics, please wait...");
 
-       UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING};
+       UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING, {arg, 0, 0}};
        SendCommand(&c);
 
        UsbCommand resp;
index 33dc78aeb523c5731ec297e9432159336d774580..74e476eb55067a3c72eb4c666cb82f32dd1f4086 100644 (file)
@@ -467,7 +467,7 @@ static command_t CommandTable[] =
        {"reset",         CmdReset,       0, "Reset the Proxmark3"},
        {"setlfdivisor",  CmdSetDivisor,  0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
        {"setmux",        CmdSetMux,      0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
-       {"tune",          CmdTune,        0, "Measure antenna tuning"},
+       {"tune",          CmdTune,        0, "['l'|'h'] -- Measure antenna tuning (option 'l' or 'h' to limit to LF or HF)"},
        {"version",       CmdVersion,     0, "Show version information about the connected Proxmark"},
        {"status",        CmdStatus,      0, "Show runtime status information about the connected Proxmark"},
        {"ping",          CmdPing,        0, "Test if the pm3 is responsive"},
index 8448b06a09284e61e8566dc4f1c2b8b069847517..6978a3ada2a30daf9a9b42cb8807f516598c4e35 100644 (file)
@@ -228,6 +228,11 @@ typedef struct{
 #define FLAG_ICLASS_READER_CEDITKEY     0x40
 
 
+//hw tune args
+#define FLAG_TUNE_LF   1
+#define FLAG_TUNE_HF   2
+#define FLAG_TUNE_ALL  3
+
 
 // CMD_DEVICE_INFO response packet has flags in arg[0], flag definitions:
 /* Whether a bootloader that understands the common_area is present */
Impressum, Datenschutz