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()
This commit is contained in:
iceman1001 2016-03-13 07:16:42 +01:00
commit f2c2b174cd
5 changed files with 41 additions and 46 deletions

View file

@ -9,18 +9,14 @@
// The main application code. This is the first thing called after start.c // The main application code. This is the first thing called after start.c
// executes. // executes.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "usb_cdc.h" #include "usb_cdc.h"
#include "cmd.h" #include "cmd.h"
#include "proxmark3.h" #include "proxmark3.h"
#include "apps.h" #include "apps.h"
#include "util.h" #include "util.h"
#include "printf.h" #include "printf.h"
#include "string.h" #include "string.h"
#include <stdarg.h> #include <stdarg.h>
#include "legicrf.h" #include "legicrf.h"
#include "hitag2.h" #include "hitag2.h"
#include "hitagS.h" #include "hitagS.h"
@ -28,6 +24,7 @@
#include "BigBuf.h" #include "BigBuf.h"
#include "mifareutil.h" #include "mifareutil.h"
#include "pcf7931.h" #include "pcf7931.h"
#ifdef WITH_LCD #ifdef WITH_LCD
#include "LCD.h" #include "LCD.h"
#endif #endif
@ -38,8 +35,6 @@
#include "protocols.h" #include "protocols.h"
#endif #endif
#define abs(x) ( ((x)<0) ? -(x) : (x) )
//============================================================================= //=============================================================================
// A buffer where we can queue things up to be sent through the FPGA, for // 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 // 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 (limit != HF_ONLY) {
if(mode == 1) { if(mode == 1) {
if (abs(lf_av - lf_baseline) > REPORT_CHANGE) if (ABS(lf_av - lf_baseline) > REPORT_CHANGE)
LED_D_ON(); LED_D_ON();
else else
LED_D_OFF(); LED_D_OFF();
@ -840,7 +835,7 @@ void ListenReaderField(int limit) {
lf_av_new = AvgAdc(ADC_CHAN_LF); lf_av_new = AvgAdc(ADC_CHAN_LF);
// see if there's a significant change // 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); Dbprintf("LF 125/134kHz Field Change: %5dmV", (MAX_ADC_LF_VOLTAGE * lf_av_new) >> 10);
lf_av = lf_av_new; lf_av = lf_av_new;
if (lf_av > lf_max) if (lf_av > lf_max)
@ -850,7 +845,7 @@ void ListenReaderField(int limit) {
if (limit != LF_ONLY) { if (limit != LF_ONLY) {
if (mode == 1){ if (mode == 1){
if (abs(hf_av - hf_baseline) > REPORT_CHANGE) if (ABS(hf_av - hf_baseline) > REPORT_CHANGE)
LED_B_ON(); LED_B_ON();
else else
LED_B_OFF(); LED_B_OFF();
@ -858,7 +853,7 @@ void ListenReaderField(int limit) {
hf_av_new = AvgAdc(ADC_CHAN_HF); hf_av_new = AvgAdc(ADC_CHAN_HF);
// see if there's a significant change // 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); Dbprintf("HF 13.56MHz Field Change: %5dmV", (MAX_ADC_HF_VOLTAGE * hf_av_new) >> 10);
hf_av = hf_av_new; hf_av = hf_av_new;
if (hf_av > hf_max) if (hf_av > hf_max)

View file

@ -8,7 +8,6 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Definitions internal to the app source. // Definitions internal to the app source.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifndef __APPS_H #ifndef __APPS_H
#define __APPS_H #define __APPS_H

View file

@ -295,21 +295,19 @@ static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int
// number of decoded bytes // number of decoded bytes
static int GetIso15693AnswerFromTag(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed) static int GetIso15693AnswerFromTag(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed)
{ {
int c = 0;
uint8_t *dest = BigBuf_get_addr(); uint8_t *dest = BigBuf_get_addr();
int getNext = 0;
int c = 0;
int getNext = FALSE;
int8_t prev = 0; int8_t prev = 0;
// NOW READ RESPONSE
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR); FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
//spindelay(60); // greg - experiment to get rid of some of the 0 byte/failed reads SpinDelay(100); // greg - experiment to get rid of some of the 0 byte/failed reads
c = 0;
getNext = FALSE;
for(;;) { 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; AT91C_BASE_SSC->SSC_THR = 0x43;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) { if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
int8_t b; int8_t b;
b = (int8_t)AT91C_BASE_SSC->SSC_RHR; b = (int8_t)AT91C_BASE_SSC->SSC_RHR;
@ -321,11 +319,14 @@ static int GetIso15693AnswerFromTag(uint8_t *receivedResponse, int maxLen, int *
if(getNext) { if(getNext) {
int8_t r; int8_t r;
if(b < 0) { r = ABS(b);
r = -b;
} else { // if(b < 0) {
r = b; // r = -b;
} // } else {
// r = b;
// }
// ABS(prev)
if(prev < 0) { if(prev < 0) {
r -= prev; r -= prev;
} else { } else {
@ -437,29 +438,26 @@ static int GetIso15693AnswerFromTag(uint8_t *receivedResponse, int maxLen, int *
} // "end if correlation > 0" (max/(arraylen(FrameSOF)/skip)) } // "end if correlation > 0" (max/(arraylen(FrameSOF)/skip))
return k; // return the number of bytes demodulated 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 // Now the GetISO15693 message from sniffing command
static int GetIso15693AnswerFromSniff(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed) static int GetIso15693AnswerFromSniff(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed)
{ {
int c = 0;
uint8_t *dest = BigBuf_get_addr(); uint8_t *dest = BigBuf_get_addr();
int getNext = 0;
int c = 0;
int getNext = FALSE;
int8_t prev = 0; int8_t prev = 0;
// NOW READ RESPONSE
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR); FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
//spindelay(60); // greg - experiment to get rid of some of the 0 byte/failed reads SpinDelay(100); // greg - experiment to get rid of some of the 0 byte/failed reads
c = 0;
getNext = FALSE;
for(;;) { 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; AT91C_BASE_SSC->SSC_THR = 0x43;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) { if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
int8_t b = (int8_t)AT91C_BASE_SSC->SSC_RHR; 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) { if(getNext) {
int8_t r; int8_t r;
if(b < 0) { r = ABS(b);
r = -b; // if(b < 0) {
} else { // r = -b;
r = b; // } else {
} // r = b;
// }
if(prev < 0) { if(prev < 0) {
r -= prev; r -= prev;
} else { } else {

View file

@ -7,9 +7,6 @@
#define T0_PCF 8 //period for the pcf7931 in us #define T0_PCF 8 //period for the pcf7931 in us
#define ALLOC 16 #define ALLOC 16
#define abs(x) ( ((x)<0) ? -(x) : (x) )
#define max(x,y) ( x<y ? y:x)
int DemodPCF7931(uint8_t **outBlocks) { int DemodPCF7931(uint8_t **outBlocks) {
uint8_t bits[256] = {0x00}; uint8_t bits[256] = {0x00};
@ -71,7 +68,7 @@ int DemodPCF7931(uint8_t **outBlocks) {
// Switch depending on lc length: // Switch depending on lc length:
// Tolerance is 1/8 of clock rate (arbitrary) // Tolerance is 1/8 of clock rate (arbitrary)
if (abs(lc-clock/4) < tolerance) { if (ABS(lc-clock/4) < tolerance) {
// 16T0 // 16T0
if((i - pmc) == lc) { /* 16T0 was previous one */ if((i - pmc) == lc) { /* 16T0 was previous one */
/* It's a PMC ! */ /* It's a PMC ! */
@ -83,7 +80,7 @@ int DemodPCF7931(uint8_t **outBlocks) {
else { else {
pmc = i; pmc = i;
} }
} else if (abs(lc-clock/2) < tolerance) { } else if (ABS(lc-clock/2) < tolerance) {
// 32TO // 32TO
if((i - pmc) == lc) { /* 16T0 was previous one */ if((i - pmc) == lc) { /* 16T0 was previous one */
/* It's a PMC ! */ /* It's a PMC ! */
@ -98,7 +95,7 @@ int DemodPCF7931(uint8_t **outBlocks) {
} }
else else
half_switch++; half_switch++;
} else if (abs(lc-clock) < tolerance) { } else if (ABS(lc-clock) < tolerance) {
// 64TO // 64TO
bits[bitidx++] = 1; bits[bitidx++] = 1;
} else { } else {
@ -205,7 +202,7 @@ void ReadPCF7931() {
Blocks[0][ALLOC] = 1; Blocks[0][ALLOC] = 1;
memcpy(Blocks[1], tmpBlocks[i+1], 16); memcpy(Blocks[1], tmpBlocks[i+1], 16);
Blocks[1][ALLOC] = 1; 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 // Debug print
Dbprintf("(dbg) Max blocks: %d", max_blocks); Dbprintf("(dbg) Max blocks: %d", max_blocks);
num_blocks = 2; num_blocks = 2;

View file

@ -21,10 +21,15 @@ typedef unsigned char byte_t;
#ifndef MIN #ifndef MIN
# define MIN(a, b) (((a) < (b)) ? (a) : (b)) # define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif #endif
#ifndef MAX #ifndef MAX
# define MAX(a, b) (((a) > (b)) ? (a) : (b)) # define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif #endif
#ifndef ABS
# define ABS(a) ( ((a)<0) ? -(a) : (a) )
#endif
#define RAMFUNC __attribute((long_call, section(".ramfunc"))) #define RAMFUNC __attribute((long_call, section(".ramfunc")))
#endif #endif