]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
CHG: moved some #define into include\common.h (which is call by apps.h), so we...
authoriceman1001 <iceman@iuse.se>
Sun, 13 Mar 2016 06:16:42 +0000 (07:16 +0100)
committericeman1001 <iceman@iuse.se>
Sun, 13 Mar 2016 06:16:42 +0000 (07:16 +0100)
ABS(),  MIN(), MAX()

armsrc/appmain.c
armsrc/apps.h
armsrc/iso15693.c
armsrc/pcf7931.c
include/common.h

index 2ba3d75c8762fcd0475691946a4f69c3d8c91eb1..428d187ec8535590678a4bbe7137c84e221d108f 100644 (file)
@@ -9,18 +9,14 @@
 // The main application code. This is the first thing called after start.c
 // executes.
 //-----------------------------------------------------------------------------
-
 #include "usb_cdc.h"
 #include "cmd.h"
-
 #include "proxmark3.h"
 #include "apps.h"
 #include "util.h"
 #include "printf.h"
 #include "string.h"
-
 #include <stdarg.h>
-
 #include "legicrf.h"
 #include "hitag2.h"
 #include "hitagS.h"
@@ -28,6 +24,7 @@
 #include "BigBuf.h"
 #include "mifareutil.h"
 #include "pcf7931.h"
+
 #ifdef WITH_LCD
  #include "LCD.h"
 #endif
@@ -38,8 +35,6 @@
  #include "protocols.h"
 #endif
 
-#define abs(x) ( ((x)<0) ? -(x) : (x) )
-
 //=============================================================================
 // A buffer where we can queue things up to be sent through the FPGA, for
 // any purpose (fake tag, as reader, whatever). We go MSB first, since that
@@ -832,7 +827,7 @@ void ListenReaderField(int limit) {
 
                if (limit != HF_ONLY) {
                        if(mode == 1) {
-                               if (abs(lf_av - lf_baseline) > REPORT_CHANGE) 
+                               if (ABS(lf_av - lf_baseline) > REPORT_CHANGE) 
                                        LED_D_ON();
                                else
                                        LED_D_OFF();
@@ -840,7 +835,7 @@ void ListenReaderField(int limit) {
 
                        lf_av_new = AvgAdc(ADC_CHAN_LF);
                        // see if there's a significant change
-                       if(abs(lf_av - lf_av_new) > REPORT_CHANGE) {
+                       if(ABS(lf_av - lf_av_new) > REPORT_CHANGE) {
                                Dbprintf("LF 125/134kHz Field Change: %5dmV", (MAX_ADC_LF_VOLTAGE * lf_av_new) >> 10);
                                lf_av = lf_av_new;
                                if (lf_av > lf_max)
@@ -850,7 +845,7 @@ void ListenReaderField(int limit) {
 
                if (limit != LF_ONLY) {
                        if (mode == 1){
-                               if (abs(hf_av - hf_baseline) > REPORT_CHANGE)   
+                               if (ABS(hf_av - hf_baseline) > REPORT_CHANGE)   
                                        LED_B_ON();
                                else
                                        LED_B_OFF();
@@ -858,7 +853,7 @@ void ListenReaderField(int limit) {
 
                        hf_av_new = AvgAdc(ADC_CHAN_HF);
                        // see if there's a significant change
-                       if(abs(hf_av - hf_av_new) > REPORT_CHANGE) {
+                       if(ABS(hf_av - hf_av_new) > REPORT_CHANGE) {
                                Dbprintf("HF 13.56MHz Field Change: %5dmV", (MAX_ADC_HF_VOLTAGE * hf_av_new) >> 10);
                                hf_av = hf_av_new;
                                if (hf_av > hf_max)
index a556a6e70f75e0b1824c1072af7d67576aa55d68..928ac4e56e576a1c4e76e7bdcde1899a1f76d31f 100644 (file)
@@ -8,7 +8,6 @@
 //-----------------------------------------------------------------------------
 // Definitions internal to the app source.
 //-----------------------------------------------------------------------------
-
 #ifndef __APPS_H
 #define __APPS_H
 
index 1750152678da3aba436d41d553e42f7538a7cef8..888f6aaf0709fdba641a79009bf3fa47291026b8 100644 (file)
@@ -295,21 +295,19 @@ static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int
 //             number of decoded bytes
 static int GetIso15693AnswerFromTag(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed)
 {
-       int c = 0;
        uint8_t *dest = BigBuf_get_addr();
-       int getNext = 0;
 
+       int c = 0;
+       int getNext = FALSE;
        int8_t prev = 0;
 
-// NOW READ RESPONSE
        FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
-       //spindelay(60);        // greg - experiment to get rid of some of the 0 byte/failed reads
-       c = 0;
-       getNext = FALSE;
+       SpinDelay(100); // greg - experiment to get rid of some of the 0 byte/failed reads
+
        for(;;) {
-               if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
+               if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))
                        AT91C_BASE_SSC->SSC_THR = 0x43;
-               }
+
                if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
                        int8_t b;
                        b = (int8_t)AT91C_BASE_SSC->SSC_RHR;
@@ -321,11 +319,14 @@ static int GetIso15693AnswerFromTag(uint8_t *receivedResponse, int maxLen, int *
                        if(getNext) {
                                int8_t r;
 
-                               if(b < 0) {
-                                       r = -b;
-                               } else {
-                                       r = b;
-                               }
+                               r = ABS(b);
+                               
+                               // if(b < 0) {
+                                       // r = -b;
+                               // } else {
+                                       // r = b;
+                               // }
+                               // ABS(prev)
                                if(prev < 0) {
                                        r -= prev;
                                } else {
@@ -437,29 +438,26 @@ static int GetIso15693AnswerFromTag(uint8_t *receivedResponse, int maxLen, int *
        } // "end if correlation > 0"   (max/(arraylen(FrameSOF)/skip))
        return k; // return the number of bytes demodulated
 
-///    DbpString("CRC=%04x", Iso15693Crc(outBuf, k-2));
-
+//     DbpString("CRC=%04x", Iso15693Crc(outBuf, k-2));
 }
 
 
 // Now the GetISO15693 message from sniffing command
 static int GetIso15693AnswerFromSniff(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed)
 {
-       int c = 0;
        uint8_t *dest = BigBuf_get_addr();
-       int getNext = 0;
 
+       int c = 0;
+       int getNext = FALSE;
        int8_t prev = 0;
 
-// NOW READ RESPONSE
        FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
-       //spindelay(60);        // greg - experiment to get rid of some of the 0 byte/failed reads
-       c = 0;
-       getNext = FALSE;
+       SpinDelay(100); // greg - experiment to get rid of some of the 0 byte/failed reads
+
        for(;;) {
-               if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
+               if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))
                        AT91C_BASE_SSC->SSC_THR = 0x43;
-               }
+
                if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
                        int8_t b = (int8_t)AT91C_BASE_SSC->SSC_RHR;
 
@@ -470,11 +468,12 @@ static int GetIso15693AnswerFromSniff(uint8_t *receivedResponse, int maxLen, int
                        if(getNext) {
                                int8_t r;
 
-                               if(b < 0) {
-                                       r = -b;
-                               } else {
-                                       r = b;
-                               }
+                               r = ABS(b);
+                               // if(b < 0) {
+                                       // r = -b;
+                               // } else {
+                                       // r = b;
+                               // }
                                if(prev < 0) {
                                        r -= prev;
                                } else {
index 24a871aa117d9ff87f8beb6cfd1849ed96f327ba..799167e991fc5159075f5873d2e579531d8b8aea 100644 (file)
@@ -7,9 +7,6 @@
 #define T0_PCF 8 //period for the pcf7931 in us
 #define ALLOC 16
 
-#define abs(x) ( ((x)<0) ? -(x) : (x) )
-#define max(x,y) ( x<y ? y:x)
-
 int DemodPCF7931(uint8_t **outBlocks) {
 
     uint8_t bits[256] = {0x00};
@@ -71,7 +68,7 @@ int DemodPCF7931(uint8_t **outBlocks) {
 
                        // Switch depending on lc length:
                        // Tolerance is 1/8 of clock rate (arbitrary)
-                       if (abs(lc-clock/4) < tolerance) {
+                       if (ABS(lc-clock/4) < tolerance) {
                                // 16T0
                                if((i - pmc) == lc) { /* 16T0 was previous one */
                                        /* It's a PMC ! */
@@ -83,7 +80,7 @@ int DemodPCF7931(uint8_t **outBlocks) {
                                else {
                                        pmc = i;
                                }
-                       } else if (abs(lc-clock/2) < tolerance) {
+                       } else if (ABS(lc-clock/2) < tolerance) {
                                // 32TO
                                if((i - pmc) == lc) { /* 16T0 was previous one */
                                        /* It's a PMC ! */
@@ -98,7 +95,7 @@ int DemodPCF7931(uint8_t **outBlocks) {
                                }
                                else
                                        half_switch++;
-                       } else if (abs(lc-clock) < tolerance) {
+                       } else if (ABS(lc-clock) < tolerance) {
                                // 64TO
                 bits[bitidx++] = 1;
                        } else {
@@ -205,7 +202,7 @@ void ReadPCF7931() {
                                                Blocks[0][ALLOC] = 1;
                                                memcpy(Blocks[1], tmpBlocks[i+1], 16);
                                                Blocks[1][ALLOC] = 1;
-                                               max_blocks = max((Blocks[1][14] & 0x7f), Blocks[1][15]) + 1;
+                                               max_blocks = MAX((Blocks[1][14] & 0x7f), Blocks[1][15]) + 1;
                                                // Debug print
                                                Dbprintf("(dbg) Max blocks: %d", max_blocks);
                                                num_blocks = 2;
index feed109c2dfe3faa216edb89fd0852100b542896..70188ca93dc45d296b40cc8df37479745812d5ff 100644 (file)
@@ -21,10 +21,15 @@ typedef unsigned char byte_t;
 #ifndef MIN
 # define MIN(a, b) (((a) < (b)) ? (a) : (b))
 #endif
+
 #ifndef MAX
 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
 #endif
 
+#ifndef ABS
+# define ABS(a) ( ((a)<0) ? -(a) : (a) )
+#endif
+
 #define RAMFUNC __attribute((long_call, section(".ramfunc")))
 
 #endif
Impressum, Datenschutz