From f2c2b174cdf702045d5fdd59aecf5dac8e8b44f2 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 13 Mar 2016 07:16:42 +0100 Subject: [PATCH] CHG: moved some #define into include\common.h (which is call by apps.h), so we have one place for them. Also changed them to CAPITAL. ABS(), MIN(), MAX() --- armsrc/appmain.c | 15 +++++-------- armsrc/apps.h | 1 - armsrc/iso15693.c | 55 +++++++++++++++++++++++------------------------ armsrc/pcf7931.c | 11 ++++------ include/common.h | 5 +++++ 5 files changed, 41 insertions(+), 46 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 2ba3d75c..428d187e 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -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 - #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) diff --git a/armsrc/apps.h b/armsrc/apps.h index a556a6e7..928ac4e5 100644 --- a/armsrc/apps.h +++ b/armsrc/apps.h @@ -8,7 +8,6 @@ //----------------------------------------------------------------------------- // Definitions internal to the app source. //----------------------------------------------------------------------------- - #ifndef __APPS_H #define __APPS_H diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index 17501526..888f6aaf 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -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 { diff --git a/armsrc/pcf7931.c b/armsrc/pcf7931.c index 24a871aa..799167e9 100644 --- a/armsrc/pcf7931.c +++ b/armsrc/pcf7931.c @@ -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 (b)) ? (a) : (b)) #endif +#ifndef ABS +# define ABS(a) ( ((a)<0) ? -(a) : (a) ) +#endif + #define RAMFUNC __attribute((long_call, section(".ramfunc"))) #endif -- 2.39.2