]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/appmain.c
fast flash mode (button already held down) and both (os & fpga) flashing mode
[proxmark3-svn] / armsrc / appmain.c
index dec71dcde6d479c97d322bbee41abaac2db7b381..f35a82fa544ce1d4c7ab13e4d8ec9e494c2251da 100644 (file)
@@ -206,23 +206,22 @@ void ModThenAcquireRawAdcSamples125k(int delay_off,int period_0,int period_1,BYT
        DoAcquisition125k(at134khz);
 }
 
-//-----------------------------------------------------------------------------
-// Read a TI-type tag. We assume that the tag has already been illuminated,
-// and that the exciting signal has been turned off. That means that we just
-// acquire the `one-bit DAC' bits from the comparator.
-//-----------------------------------------------------------------------------
 void AcquireTiType(void)
 {
        int i;
-       int n = sizeof(BigBuf);
+       int n = 5000;
 
        // clear buffer
        memset(BigBuf,0,sizeof(BigBuf));
 
-  // Set up the synchronous serial port
+       // Set up the synchronous serial port
   PIO_DISABLE = (1<<GPIO_SSC_DIN);
   PIO_PERIPHERAL_A_SEL = (1<<GPIO_SSC_DIN);
 
+       // steal this pin from the SSP and use it to control the modulation
+  PIO_ENABLE = (1<<GPIO_SSC_DOUT);
+       PIO_OUTPUT_ENABLE       = (1<<GPIO_SSC_DOUT);
+
   SSC_CONTROL = SSC_CONTROL_RESET;
   SSC_CONTROL = SSC_CONTROL_RX_ENABLE | SSC_CONTROL_TX_ENABLE;
 
@@ -231,41 +230,52 @@ void AcquireTiType(void)
   SSC_CLOCK_DIVISOR = 12;
 
   SSC_RECEIVE_CLOCK_MODE = SSC_CLOCK_MODE_SELECT(0);
-  SSC_RECEIVE_FRAME_MODE = SSC_FRAME_MODE_BITS_IN_WORD(32) | SSC_FRAME_MODE_MSB_FIRST;
-  SSC_TRANSMIT_CLOCK_MODE = 0;
-  SSC_TRANSMIT_FRAME_MODE = 0;
-
-  i = 0;
-  for(;;) {
-      if(SSC_STATUS & SSC_STATUS_RX_READY) {
-          BigBuf[i] = SSC_RECEIVE_HOLDING;     // store 32 bit values in buffer
-          i++; if(i >= n) return;
-      }
-      WDT_HIT();
-  }
-}
+       SSC_RECEIVE_FRAME_MODE = SSC_FRAME_MODE_BITS_IN_WORD(32) | SSC_FRAME_MODE_MSB_FIRST;
+       SSC_TRANSMIT_CLOCK_MODE = 0;
+       SSC_TRANSMIT_FRAME_MODE = 0;
 
-void AcquireRawBitsTI(void)
-{
        LED_D_ON();
-       // TI tags charge at 134.2Khz
-       FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz
-       FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER);
+
+       // modulate antenna
+       PIO_OUTPUT_DATA_SET = (1<<GPIO_SSC_DOUT);
 
        // Charge TI tag for 50ms.
        SpinDelay(50);
+
+       // stop modulating antenna and listen
+       PIO_OUTPUT_DATA_CLEAR = (1<<GPIO_SSC_DOUT);
+
        LED_D_OFF();
 
-       LED_A_ON();
-       // Place FPGA in passthrough mode so as to stop driving the LF coil,
-       // in this mode the CROSS_LO line connects to SSP_DIN
+       i = 0;
+       for(;;) {
+                       if(SSC_STATUS & SSC_STATUS_RX_READY) {
+                                       BigBuf[i] = SSC_RECEIVE_HOLDING;        // store 32 bit values in buffer
+                                       i++; if(i >= n) return;
+                       }
+                       WDT_HIT();
+       }
+
+       // return stolen pin to SSP
+       PIO_DISABLE = (1<<GPIO_SSC_DOUT);
+       PIO_PERIPHERAL_A_SEL = (1<<GPIO_SSC_DIN) | (1<<GPIO_SSC_DOUT);
+}
+
+void AcquireRawBitsTI(void)
+{
+       LED_D_ON();
+       // TI tags charge at 134.2Khz
+       FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz
+       // Place FPGA in passthrough mode, in this mode the CROSS_LO line
+       // connects to SSP_DIN and the SSP_DOUT logic level controls
+       // whether we're modulating the antenna (high)
+       // or listening to the antenna (low)
        FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_PASSTHRU);
 
        // get TI tag data into the buffer
        AcquireTiType();
 
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
-       LED_A_OFF();
 }
 
 //-----------------------------------------------------------------------------
@@ -1080,85 +1090,168 @@ void SamyRun()
 }
 
 
-// listen for external reader
-void ListenReaderField(int limit)
-{
-       int lf_av, lf_av_new, lf_baseline= 0, lf_count= 0;
-       int hf_av, hf_av_new,  hf_baseline= 0, hf_count= 0;
-
-#define LF_ONLY                1
-#define HF_ONLY                2
-
-       LED_A_OFF();
-       LED_B_OFF();
-       LED_C_OFF();
-       LED_D_OFF();
-
-       lf_av= ReadAdc(ADC_CHAN_LF);
-
-       if(limit != HF_ONLY)
-               {
-               DbpString("LF 125/134 Baseline:");
-               DbpIntegers(lf_av,0,0);
-               lf_baseline= lf_av;
-               }
-
-       hf_av= ReadAdc(ADC_CHAN_HF);
-
-
-       if (limit != LF_ONLY)
-               {
-               DbpString("HF 13.56 Baseline:");
-               DbpIntegers(hf_av,0,0);
-               hf_baseline= hf_av;
-               }
-
-       for(;;)
-               {
-               if(BUTTON_PRESS())
-                       {
-                       DbpString("Stopped");
-                       LED_B_OFF();
-                       LED_D_OFF();
-                       return;
-                       }
-               WDT_HIT();
-
-
-               if (limit != HF_ONLY)
-                       {
-                       if (abs(lf_av - lf_baseline) > 10)
-                               LED_D_ON();
-                       else
-                               LED_D_OFF();
-                       ++lf_count;
-                       lf_av_new= ReadAdc(ADC_CHAN_LF);
-                       // see if there's a significant change
-                       if(abs(lf_av - lf_av_new) > 10)
-                               {
-                               DbpString("LF 125/134 Field Change:");
-                               DbpIntegers(lf_av,lf_av_new,lf_count);
-                               lf_av= lf_av_new;
-                               lf_count= 0;
-                               }
-                       }
-
-               if (limit != LF_ONLY)
-                       {
-                       if (abs(hf_av - hf_baseline) > 10)
-                               LED_B_ON();
-                       else
-                               LED_B_OFF();
-                       ++hf_count;
-                       hf_av_new= ReadAdc(ADC_CHAN_HF);
-                       // see if there's a significant change
-                       if(abs(hf_av - hf_av_new) > 10)
-                               {
-                               DbpString("HF 13.56 Field Change:");
-                               DbpIntegers(hf_av,hf_av_new,hf_count);
-                               hf_av= hf_av_new;
-                               hf_count= 0;
-                               }
-                       }
-               }
-}
+/* \r
+OBJECTIVE\r
+Listen and detect an external reader. Determine the best location\r
+for the antenna.\r
+\r
+INSTRUCTIONS:\r
+Inside the ListenReaderField() function, there is two mode. \r
+By default, when you call the function, you will enter mode 1.\r
+If you press the PM3 button one time, you will enter mode 2.\r
+If you press the PM3 button a second time, you will exit the function.\r
+\r
+DESCRIPTION OF MODE 1:\r
+This mode just listens for an external reader field and lights up green \r
+for HF and/or red for LF. This is the original mode of the detectreader\r
+function.\r
+\r
+DESCRIPTION OF MODE 2:\r
+This mode will visually represent, using the LEDs, the actual strength of the\r
+current compared to the maximum current detected. Basically, once you know \r
+what kind of external reader is present, it will help you spot the best location to place\r
+your antenna. You will probably not get some good results if there is a LF and a HF reader\r
+at the same place! :-)\r
+\r
+LIGHT SCHEME USED:\r
+\r
+Light scheme | Descriptiong\r
+----------------------------------------------------\r
+    ----     | No field detected\r
+    X---     | 14% of maximum current detected\r
+    -X--     | 29% of maximum current detected\r
+    --X-     | 43% of maximum current detected\r
+    ---X     | 57% of maximum current detected\r
+    --XX     | 71% of maximum current detected\r
+    -XXX     | 86% of maximum current detected\r
+    XXXX     | 100% of maximum current detected\r
+\r
+TODO:\r
+Add the LF part for MODE 2\r
+\r
+*/\r
+void ListenReaderField(int limit)\r
+{\r
+       int lf_av, lf_av_new, lf_baseline= 0, lf_count= 0;\r
+       int hf_av, hf_av_new,  hf_baseline= 0, hf_count= 0, hf_max;\r
+       int mode=1;\r
+\r
+#define LF_ONLY                1\r
+#define HF_ONLY                2\r
+\r
+       LED_A_OFF();\r
+       LED_B_OFF();\r
+       LED_C_OFF();\r
+       LED_D_OFF();\r
+\r
+       lf_av= ReadAdc(ADC_CHAN_LF);\r
+\r
+       if(limit != HF_ONLY) \r
+               {\r
+               DbpString("LF 125/134 Baseline:");\r
+               DbpIntegers(lf_av,0,0);\r
+               lf_baseline= lf_av;\r
+               }\r
+\r
+       hf_av=hf_max=ReadAdc(ADC_CHAN_HF);\r
+\r
+       if (limit != LF_ONLY) \r
+               {\r
+               DbpString("HF 13.56 Baseline:");\r
+               DbpIntegers(hf_av,0,0);\r
+               hf_baseline= hf_av;\r
+               }\r
+\r
+       for(;;) \r
+               {\r
+               if (BUTTON_PRESS()) {\r
+                       SpinDelay(500);\r
+                       switch (mode) {\r
+                               case 1:\r
+                                       mode=2;\r
+                                       DbpString("Signal Strength Mode");
+                                       break;\r
+                               case 2:\r
+                               default:\r
+                                       DbpString("Stopped");\r
+                                       LED_A_OFF();\r
+                                       LED_B_OFF();\r
+                                       LED_C_OFF();\r
+                                       LED_D_OFF();\r
+                                       return;\r
+                                       break;\r
+                       }\r
+               }\r
+               WDT_HIT();\r
+\r
+               if (limit != HF_ONLY) \r
+                       {\r
+                       if (abs(lf_av - lf_baseline) > 10)\r
+                               LED_D_ON();\r
+                       else\r
+                               LED_D_OFF();\r
+                       ++lf_count;\r
+                       lf_av_new= ReadAdc(ADC_CHAN_LF);\r
+                       // see if there's a significant change\r
+                       if(abs(lf_av - lf_av_new) > 10) \r
+                               {\r
+                               DbpString("LF 125/134 Field Change:");\r
+                               DbpIntegers(lf_av,lf_av_new,lf_count);\r
+                               lf_av= lf_av_new;\r
+                               lf_count= 0;\r
+                               }\r
+                       }\r
+\r
+               if (limit != LF_ONLY) \r
+                       {\r
+                       if (abs(hf_av - hf_baseline) > 10) {\r
+                               if (mode == 1)\r
+                                       LED_B_ON();\r
+                               if (mode == 2) {\r
+                                       if ( hf_av>(hf_max/7)*6) {\r
+                                               LED_A_ON();     LED_B_ON();     LED_C_ON();     LED_D_ON();\r
+                                       }\r
+                                       if ( (hf_av>(hf_max/7)*5) && (hf_av<=(hf_max/7)*6) ) {\r
+                                               LED_A_ON();     LED_B_ON();     LED_C_OFF(); LED_D_ON();\r
+                                       }\r
+                                       if ( (hf_av>(hf_max/7)*4) && (hf_av<=(hf_max/7)*5) ) {\r
+                                               LED_A_OFF(); LED_B_ON(); LED_C_OFF(); LED_D_ON();\r
+                                       }\r
+                                       if ( (hf_av>(hf_max/7)*3) && (hf_av<=(hf_max/7)*4) ) {\r
+                                               LED_A_OFF(); LED_B_OFF(); LED_C_OFF(); LED_D_ON();\r
+                                       }\r
+                                       if ( (hf_av>(hf_max/7)*2) && (hf_av<=(hf_max/7)*3) ) {\r
+                                               LED_A_OFF(); LED_B_ON(); LED_C_OFF(); LED_D_OFF();\r
+                                       }\r
+                                       if ( (hf_av>(hf_max/7)*1) && (hf_av<=(hf_max/7)*2) ) {\r
+                                               LED_A_ON();     LED_B_OFF(); LED_C_OFF(); LED_D_OFF();\r
+                                       }\r
+                                       if ( (hf_av>(hf_max/7)*0) && (hf_av<=(hf_max/7)*1) ) {\r
+                                               LED_A_OFF(); LED_B_OFF(); LED_C_ON(); LED_D_OFF();\r
+                                       }\r
+                               } \r
+                       } else {\r
+                               if (mode == 1) {\r
+                                       LED_B_OFF();\r
+                               }\r
+                               if (mode == 2) {\r
+                                       LED_A_OFF(); LED_B_OFF(); LED_C_OFF(); LED_D_OFF();\r
+                               }\r
+                       }\r
+\r
+                       ++hf_count;\r
+                       hf_av_new= ReadAdc(ADC_CHAN_HF);\r
+                       // see if there's a significant change\r
+                       if(abs(hf_av - hf_av_new) > 10) \r
+                               {\r
+                               DbpString("HF 13.56 Field Change:");\r
+                               DbpIntegers(hf_av,hf_av_new,hf_count);\r
+                               hf_av= hf_av_new;\r
+                               if (hf_av > hf_max)\r
+                                       hf_max = hf_av;\r
+                               hf_count= 0;\r
+                               }\r
+                       }\r
+               }\r
+}\r
+\r
Impressum, Datenschutz