]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/appmain.c
Added LF frequency adjustments from d18c7db, cleaned up code,
[proxmark3-svn] / armsrc / appmain.c
index 303127548619488912b0eabd96cb9ac75582b3d2..bb733feff6cf8b5094a5e6cb29d339370b78bd6b 100644 (file)
@@ -87,8 +87,10 @@ void AcquireRawAdcSamples125k(BOOL at134khz)
        memset(dest,0,n);\r
 \r
        if(at134khz) {\r
        memset(dest,0,n);\r
 \r
        if(at134khz) {\r
+               FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz\r
                FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_READER_USE_134_KHZ);\r
        } else {\r
                FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_READER_USE_134_KHZ);\r
        } else {\r
+               FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz\r
                FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_READER_USE_125_KHZ);\r
        }\r
 \r
                FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_READER_USE_125_KHZ);\r
        }\r
 \r
@@ -121,7 +123,7 @@ void AcquireRawAdcSamples125k(BOOL at134khz)
 \r
 //-----------------------------------------------------------------------------\r
 // Read an ADC channel and block till it completes, then return the result\r
 \r
 //-----------------------------------------------------------------------------\r
 // Read an ADC channel and block till it completes, then return the result\r
-// in ADC units (0 to 1023). Also a routine to average sixteen samples and\r
+// in ADC units (0 to 1023). Also a routine to average 32 samples and\r
 // return that.\r
 //-----------------------------------------------------------------------------\r
 static int ReadAdc(int ch)\r
 // return that.\r
 //-----------------------------------------------------------------------------\r
 static int ReadAdc(int ch)\r
@@ -152,6 +154,29 @@ static int AvgAdc(int ch)
 \r
        return (a + 15) >> 5;\r
 }\r
 \r
        return (a + 15) >> 5;\r
 }\r
+
+/*
+ * Sweeps the useful LF range of the proxmark from
+ * 46.8kHz (divisor=255) to 600kHz (divisor=19) and
+ * reads the voltage in the antenna: the result is a graph
+ * which should clearly show the resonating frequency of your
+ * LF antenna ( hopefully around 90 if it is tuned to 125kHz!)
+ */\r
+void SweepLFrange()\r
+{\r
+       BYTE *dest = (BYTE *)BigBuf;\r
+       int i;\r
+\r
+       // clear buffer\r
+       memset(BigBuf,0,sizeof(BigBuf));\r
+\r
+       FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER);\r
+       for (i=255; i>19; i--) {\r
+               FpgaSendCommand(FPGA_CMD_SET_DIVISOR, i);\r
+               SpinDelay(20);\r
+               dest[i] = (137500 * AvgAdc(4)) >> 18;\r
+       }\r
+}\r
 \r
 void MeasureAntennaTuning(void)\r
 {\r
 \r
 void MeasureAntennaTuning(void)\r
 {\r
@@ -164,6 +189,7 @@ void MeasureAntennaTuning(void)
        UsbCommand c;\r
 \r
        // Let the FPGA drive the low-frequency antenna around 125 kHz.\r
        UsbCommand c;\r
 \r
        // Let the FPGA drive the low-frequency antenna around 125 kHz.\r
+       FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_READER_USE_125_KHZ);\r
        SpinDelay(20);\r
        vLf125 = AvgAdc(4);\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_READER_USE_125_KHZ);\r
        SpinDelay(20);\r
        vLf125 = AvgAdc(4);\r
@@ -172,6 +198,7 @@ void MeasureAntennaTuning(void)
        vLf125 = (137500 * vLf125) >> 10;\r
 \r
        // Let the FPGA drive the low-frequency antenna around 134 kHz.\r
        vLf125 = (137500 * vLf125) >> 10;\r
 \r
        // Let the FPGA drive the low-frequency antenna around 134 kHz.\r
+       FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_READER_USE_134_KHZ);\r
        SpinDelay(20);\r
        vLf134 = AvgAdc(4);\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_READER_USE_134_KHZ);\r
        SpinDelay(20);\r
        vLf134 = AvgAdc(4);\r
@@ -207,7 +234,7 @@ void SimulateTagLowFrequency(int period)
        PIO_OUTPUT_DISABLE = (1 << GPIO_SSC_CLK);\r
 \r
 #define SHORT_COIL()   LOW(GPIO_SSC_DOUT)\r
        PIO_OUTPUT_DISABLE = (1 << GPIO_SSC_CLK);\r
 \r
 #define SHORT_COIL()   LOW(GPIO_SSC_DOUT)\r
-#define OPEN_COIL()            HIGH(GPIO_SSC_DOUT)\r
+#define OPEN_COIL()    HIGH(GPIO_SSC_DOUT)\r
 \r
        i = 0;\r
        for(;;) {\r
 \r
        i = 0;\r
        for(;;) {\r
@@ -345,6 +372,7 @@ static void CmdHIDdemodFSK(void)
        int m=0, n=0, i=0, idx=0, found=0, lastval=0;\r
        DWORD hi=0, lo=0;\r
 \r
        int m=0, n=0, i=0, idx=0, found=0, lastval=0;\r
        DWORD hi=0, lo=0;\r
 \r
+       FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_READER_USE_125_KHZ);\r
 \r
        // Connect the A/D to the peak-detected low-frequency path.\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_READER_USE_125_KHZ);\r
 \r
        // Connect the A/D to the peak-detected low-frequency path.\r
@@ -448,7 +476,7 @@ static void CmdHIDdemodFSK(void)
                                                dest[i++]=dest[idx-1];\r
                                                dest[i++]=dest[idx-1];\r
                                                break;\r
                                                dest[i++]=dest[idx-1];\r
                                                dest[i++]=dest[idx-1];\r
                                                break;\r
-                                       // When a logic 0 is immediately followed by the start of the next transmisson \r
+                                       // When a logic 0 is immediately followed by the start of the next transmisson\r
                                        // (special pattern) a pattern of 4 bit duration lengths is created.\r
                                        case 4:\r
                                                dest[i++]=dest[idx-1];\r
                                        // (special pattern) a pattern of 4 bit duration lengths is created.\r
                                        case 4:\r
                                                dest[i++]=dest[idx-1];\r
@@ -573,20 +601,19 @@ void UsbPacketReceived(BYTE *packet, int len)
                        break;\r
 \r
                case CMD_READER_ISO_15693:\r
                        break;\r
 \r
                case CMD_READER_ISO_15693:\r
-                       ReaderIso15693(c->ext1); \r
+                       ReaderIso15693(c->ext1);\r
                        break;\r
 \r
                case CMD_SIMTAG_ISO_15693:\r
                        break;\r
 \r
                case CMD_SIMTAG_ISO_15693:\r
-                       SimTagIso15693(c->ext1); \r
+                       SimTagIso15693(c->ext1);\r
                        break;\r
 \r
                        break;\r
 \r
-\r
                case CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443:\r
                        AcquireRawAdcSamplesIso14443(c->ext1);\r
                        break;\r
 \r
                case CMD_READER_ISO_14443a:\r
                case CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443:\r
                        AcquireRawAdcSamplesIso14443(c->ext1);\r
                        break;\r
 \r
                case CMD_READER_ISO_14443a:\r
-                       ReaderIso14443a(c->ext1); \r
+                       ReaderIso14443a(c->ext1);\r
                        break;\r
 \r
                case CMD_SNOOP_ISO_14443:\r
                        break;\r
 \r
                case CMD_SNOOP_ISO_14443:\r
@@ -656,6 +683,14 @@ void UsbPacketReceived(BYTE *packet, int len)
                        LCDReset();\r
                        break;\r
 \r
                        LCDReset();\r
                        break;\r
 \r
+               case CMD_SWEEP_LF:\r
+                       SweepLFrange();\r
+                       break;\r
+\r
+               case CMD_SET_LF_DIVISOR:\r
+                       FpgaSendCommand(FPGA_CMD_SET_DIVISOR, c->ext1);\r
+                       break;\r
+\r
                case CMD_LCD:\r
                        LCDSend(c->ext1);\r
                        break;\r
                case CMD_LCD:\r
                        LCDSend(c->ext1);\r
                        break;\r
Impressum, Datenschutz