armsrc: clarify static vars vs global vars

This commit is contained in:
Philippe Teuwen 2020-05-19 17:05:43 +02:00
commit 3e7512a5d5
20 changed files with 101 additions and 102 deletions

View file

@ -73,7 +73,7 @@ int ToSendMax = -1;
static int ToSendBit; static int ToSendBit;
struct common_area common_area __attribute__((section(".commonarea"))); struct common_area common_area __attribute__((section(".commonarea")));
int button_status = BUTTON_NO_CLICK; int button_status = BUTTON_NO_CLICK;
bool allow_send_wtx = false; static bool allow_send_wtx = false;
inline void send_wtx(uint16_t wtx) { inline void send_wtx(uint16_t wtx) {
if (allow_send_wtx) { if (allow_send_wtx) {
@ -385,12 +385,12 @@ static void SendStatus(void) {
static void SendCapabilities(void) { static void SendCapabilities(void) {
capabilities_t capabilities; capabilities_t capabilities;
capabilities.version = CAPABILITIES_VERSION; capabilities.version = CAPABILITIES_VERSION;
capabilities.via_fpc = reply_via_fpc; capabilities.via_fpc = g_reply_via_fpc;
capabilities.via_usb = reply_via_usb; capabilities.via_usb = g_reply_via_usb;
capabilities.baudrate = 0; // no real baudrate for USB-CDC capabilities.baudrate = 0; // no real baudrate for USB-CDC
#ifdef WITH_FPC_USART #ifdef WITH_FPC_USART
if (reply_via_fpc) if (g_reply_via_fpc)
capabilities.baudrate = usart_baudrate; capabilities.baudrate = g_usart_baudrate;
#endif #endif
#ifdef WITH_FLASH #ifdef WITH_FLASH
@ -701,8 +701,8 @@ static void PacketReceived(PacketCommandNG *packet) {
case CMD_BREAK_LOOP: case CMD_BREAK_LOOP:
break; break;
case CMD_QUIT_SESSION: { case CMD_QUIT_SESSION: {
reply_via_fpc = false; g_reply_via_fpc = false;
reply_via_usb = false; g_reply_via_usb = false;
break; break;
} }
// emulator // emulator

View file

@ -13,9 +13,8 @@
#include "common.h" #include "common.h"
extern int rsamples; // = 0; extern int g_rsamples; // = 0;
extern uint8_t trigger; extern uint8_t g_trigger;
extern bool allow_send_wtx;
// ADC Vref = 3300mV, and an (10M+1M):1M voltage divider on the HF input can measure voltages up to 36300 mV // ADC Vref = 3300mV, and an (10M+1M):1M voltage divider on the HF input can measure voltages up to 36300 mV
#define MAX_ADC_HF_VOLTAGE 36300 #define MAX_ADC_HF_VOLTAGE 36300

View file

@ -36,11 +36,11 @@
#include "string.h" #include "string.h"
// Flags to tell where to add CRC on sent replies // Flags to tell where to add CRC on sent replies
bool reply_with_crc_on_usb = false; bool g_reply_with_crc_on_usb = false;
bool reply_with_crc_on_fpc = true; bool g_reply_with_crc_on_fpc = true;
// "Session" flag, to tell via which interface next msgs should be sent: USB or FPC USART // "Session" flag, to tell via which interface next msgs should be sent: USB or FPC USART
bool reply_via_fpc = false; bool g_reply_via_fpc = false;
bool reply_via_usb = false; bool g_reply_via_usb = false;
int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) { int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) {
PacketResponseOLD txcmd = {CMD_UNKNOWN, {0, 0, 0}, {{0}}}; PacketResponseOLD txcmd = {CMD_UNKNOWN, {0, 0, 0}, {{0}}};
@ -68,11 +68,11 @@ int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *d
int resultusb = PM3_EUNDEF; int resultusb = PM3_EUNDEF;
// Send frame and make sure all bytes are transmitted // Send frame and make sure all bytes are transmitted
if (reply_via_usb) { if (g_reply_via_usb) {
resultusb = usb_write((uint8_t *)&txcmd, sizeof(PacketResponseOLD)); resultusb = usb_write((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
} }
if (reply_via_fpc) { if (g_reply_via_fpc) {
#ifdef WITH_FPC_USART_HOST #ifdef WITH_FPC_USART_HOST
resultfpc = usart_writebuffer_sync((uint8_t *)&txcmd, sizeof(PacketResponseOLD)); resultfpc = usart_writebuffer_sync((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
#else #else
@ -80,9 +80,9 @@ int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *d
#endif #endif
} }
// we got two results, let's prioritize the faulty one and USB over FPC. // we got two results, let's prioritize the faulty one and USB over FPC.
if (reply_via_usb && (resultusb != PM3_SUCCESS)) return resultusb; if (g_reply_via_usb && (resultusb != PM3_SUCCESS)) return resultusb;
#ifdef WITH_FPC_USART_HOST #ifdef WITH_FPC_USART_HOST
if (reply_via_fpc && (resultfpc != PM3_SUCCESS)) return resultfpc; if (g_reply_via_fpc && (resultfpc != PM3_SUCCESS)) return resultfpc;
#endif #endif
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -112,7 +112,7 @@ static int reply_ng_internal(uint16_t cmd, int16_t status, uint8_t *data, size_t
PacketResponseNGPostamble *tx_post = (PacketResponseNGPostamble *)((uint8_t *)&txBufferNG + sizeof(PacketResponseNGPreamble) + len); PacketResponseNGPostamble *tx_post = (PacketResponseNGPostamble *)((uint8_t *)&txBufferNG + sizeof(PacketResponseNGPreamble) + len);
// Note: if we send to both FPC & USB, we'll set CRC for both if any of them require CRC // Note: if we send to both FPC & USB, we'll set CRC for both if any of them require CRC
if ((reply_via_fpc && reply_with_crc_on_fpc) || ((reply_via_usb) && reply_with_crc_on_usb)) { if ((g_reply_via_fpc && g_reply_with_crc_on_fpc) || ((g_reply_via_usb) && g_reply_with_crc_on_usb)) {
uint8_t first, second; uint8_t first, second;
compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(PacketResponseNGPreamble) + len, &first, &second); compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(PacketResponseNGPreamble) + len, &first, &second);
tx_post->crc = (first << 8) + second; tx_post->crc = (first << 8) + second;
@ -127,10 +127,10 @@ static int reply_ng_internal(uint16_t cmd, int16_t status, uint8_t *data, size_t
int resultusb = PM3_EUNDEF; int resultusb = PM3_EUNDEF;
// Send frame and make sure all bytes are transmitted // Send frame and make sure all bytes are transmitted
if (reply_via_usb) { if (g_reply_via_usb) {
resultusb = usb_write((uint8_t *)&txBufferNG, txBufferNGLen); resultusb = usb_write((uint8_t *)&txBufferNG, txBufferNGLen);
} }
if (reply_via_fpc) { if (g_reply_via_fpc) {
#ifdef WITH_FPC_USART_HOST #ifdef WITH_FPC_USART_HOST
resultfpc = usart_writebuffer_sync((uint8_t *)&txBufferNG, txBufferNGLen); resultfpc = usart_writebuffer_sync((uint8_t *)&txBufferNG, txBufferNGLen);
#else #else
@ -138,9 +138,9 @@ static int reply_ng_internal(uint16_t cmd, int16_t status, uint8_t *data, size_t
#endif #endif
} }
// we got two results, let's prioritize the faulty one and USB over FPC. // we got two results, let's prioritize the faulty one and USB over FPC.
if (reply_via_usb && (resultusb != PM3_SUCCESS)) return resultusb; if (g_reply_via_usb && (resultusb != PM3_SUCCESS)) return resultusb;
#ifdef WITH_FPC_USART_HOST #ifdef WITH_FPC_USART_HOST
if (reply_via_fpc && (resultfpc != PM3_SUCCESS)) return resultfpc; if (g_reply_via_fpc && (resultfpc != PM3_SUCCESS)) return resultfpc;
#endif #endif
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -216,8 +216,8 @@ static int receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t *da
if ((first << 8) + second != rx->crc) if ((first << 8) + second != rx->crc)
return PM3_EIO; return PM3_EIO;
} }
reply_via_usb = usb; g_reply_via_usb = usb;
reply_via_fpc = fpc; g_reply_via_fpc = fpc;
} else { // Old style command } else { // Old style command
PacketCommandOLD rx_old; PacketCommandOLD rx_old;
memcpy(&rx_old, &rx_raw.pre, sizeof(PacketCommandNGPreamble)); memcpy(&rx_old, &rx_raw.pre, sizeof(PacketCommandNGPreamble));
@ -225,8 +225,8 @@ static int receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t *da
if (bytes != sizeof(PacketCommandOLD) - sizeof(PacketCommandNGPreamble)) if (bytes != sizeof(PacketCommandOLD) - sizeof(PacketCommandNGPreamble))
return PM3_EIO; return PM3_EIO;
reply_via_usb = usb; g_reply_via_usb = usb;
reply_via_fpc = fpc; g_reply_via_fpc = fpc;
rx->ng = false; rx->ng = false;
rx->magic = 0; rx->magic = 0;
rx->crc = 0; rx->crc = 0;

View file

@ -37,11 +37,11 @@
#include "pm3_cmd.h" #include "pm3_cmd.h"
// Flags to tell where to add CRC on sent replies // Flags to tell where to add CRC on sent replies
extern bool reply_with_crc_on_usb; extern bool g_reply_with_crc_on_usb;
extern bool reply_with_crc_on_fpc; extern bool g_reply_with_crc_on_fpc;
// "Session" flag, to tell via which interface next msgs should be sent: USB and/or FPC USART // "Session" flag, to tell via which interface next msgs should be sent: USB and/or FPC USART
extern bool reply_via_fpc; extern bool g_reply_via_fpc;
extern bool reply_via_usb; extern bool g_reply_via_usb;
int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
int reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len); int reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len);

View file

@ -15,31 +15,31 @@
#include "ansi.h" #include "ansi.h"
#define Dbprintf_usb(...) {\ #define Dbprintf_usb(...) {\
bool tmpfpc = reply_via_fpc;\ bool tmpfpc = g_reply_via_fpc;\
bool tmpusb = reply_via_usb;\ bool tmpusb = g_reply_via_usb;\
reply_via_fpc = false;\ g_reply_via_fpc = false;\
reply_via_usb = true;\ g_reply_via_usb = true;\
Dbprintf(__VA_ARGS__);\ Dbprintf(__VA_ARGS__);\
reply_via_fpc = tmpfpc;\ g_reply_via_fpc = tmpfpc;\
reply_via_usb = tmpusb;} g_reply_via_usb = tmpusb;}
#define Dbprintf_fpc(...) {\ #define Dbprintf_fpc(...) {\
bool tmpfpc = reply_via_fpc;\ bool tmpfpc = g_reply_via_fpc;\
bool tmpusb = reply_via_usb;\ bool tmpusb = g_reply_via_usb;\
reply_via_fpc = true;\ g_reply_via_fpc = true;\
reply_via_usb = false;\ g_reply_via_usb = false;\
Dbprintf(__VA_ARGS__);\ Dbprintf(__VA_ARGS__);\
reply_via_fpc = tmpfpc;\ g_reply_via_fpc = tmpfpc;\
reply_via_usb = tmpusb;} g_reply_via_usb = tmpusb;}
#define Dbprintf_all(...) {\ #define Dbprintf_all(...) {\
bool tmpfpc = reply_via_fpc;\ bool tmpfpc = g_reply_via_fpc;\
bool tmpusb = reply_via_usb;\ bool tmpusb = g_reply_via_usb;\
reply_via_fpc = true;\ g_reply_via_fpc = true;\
reply_via_usb = true;\ g_reply_via_usb = true;\
Dbprintf(__VA_ARGS__);\ Dbprintf(__VA_ARGS__);\
reply_via_fpc = tmpfpc;\ g_reply_via_fpc = tmpfpc;\
reply_via_usb = tmpusb;} g_reply_via_usb = tmpusb;}
void DbpString(const char *str); void DbpString(const char *str);

View file

@ -35,7 +35,7 @@ static uint32_t felica_lasttime_prox2air_start;
static void iso18092_setup(uint8_t fpga_minor_mode); static void iso18092_setup(uint8_t fpga_minor_mode);
static uint8_t felica_select_card(felica_card_select_t *card); static uint8_t felica_select_card(felica_card_select_t *card);
static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing, uint8_t power, uint8_t highspeed); static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing, uint8_t power, uint8_t highspeed);
bool WaitForFelicaReply(uint16_t maxbytes); static bool WaitForFelicaReply(uint16_t maxbytes);
static void iso18092_set_timeout(uint32_t timeout) { static void iso18092_set_timeout(uint32_t timeout) {
felica_timeout = timeout + (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / (16 * 8) + 2; felica_timeout = timeout + (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / (16 * 8) + 2;

View file

@ -48,8 +48,8 @@ static bool bCrypto;
// Is in auth stage // Is in auth stage
static bool bAuthenticating; static bool bAuthenticating;
// Successful password auth // Successful password auth
bool bSelecting; static bool bSelecting;
bool bCollision; static bool bCollision;
static bool bPwd; static bool bPwd;
static bool bSuccessful; static bool bSuccessful;
@ -89,14 +89,14 @@ static uint8_t password[4];
static uint8_t NrAr[8]; static uint8_t NrAr[8];
static uint8_t key[8]; static uint8_t key[8];
static uint8_t writedata[4]; static uint8_t writedata[4];
uint8_t logdata_0[4], logdata_1[4]; static uint8_t logdata_0[4], logdata_1[4];
uint8_t nonce[4]; static uint8_t nonce[4];
bool key_no; static bool key_no;
static uint64_t cipher_state; static uint64_t cipher_state;
int16_t blocknr; static int16_t blocknr;
size_t flipped_bit = 0; static size_t flipped_bit = 0;
uint32_t byte_value = 0; static uint32_t byte_value = 0;
static int hitag2_reset(void) { static int hitag2_reset(void) {
tag.state = TAG_STATE_RESET; tag.state = TAG_STATE_RESET;
@ -997,7 +997,7 @@ void SniffHitag2(void) {
lf_init(false, false); lf_init(false, false);
logging = false; g_logging = false;
size_t periods = 0; size_t periods = 0;
uint8_t periods_bytes[4]; uint8_t periods_bytes[4];
@ -1031,8 +1031,8 @@ void SniffHitag2(void) {
// Test if we detected the first reader modulation edge // Test if we detected the first reader modulation edge
if (periods != 0) { if (periods != 0) {
if (logging == false) { if (g_logging == false) {
logging = true; g_logging = true;
LED_D_ON(); LED_D_ON();
} }
} }

View file

@ -17,9 +17,9 @@
#define READP0CMD "1100000111" #define READP0CMD "1100000111"
#define ERROR_RESPONSE "F402889C" #define ERROR_RESPONSE "F402889C"
extern const uint8_t Hitag2Sync[5]; static const uint8_t Hitag2Sync[5];
extern bool CryptoActive; static bool CryptoActive;
extern Hitag_State Hitag_Crypto_State; static Hitag_State Hitag_Crypto_State;
// hitag2_crack implements the first crack algorithm described in the paper, // hitag2_crack implements the first crack algorithm described in the paper,
// Gone In 360 Seconds by Verdult, Garcia and Balasch. // Gone In 360 Seconds by Verdult, Garcia and Balasch.

View file

@ -48,8 +48,7 @@ static int temp2 = 0;
static int sof_bits; // number of start-of-frame bits static int sof_bits; // number of start-of-frame bits
static uint8_t pwdh0, pwdl0, pwdl1; // password bytes static uint8_t pwdh0, pwdl0, pwdl1; // password bytes
static uint32_t rnd = 0x74124485; // randomnumber static uint32_t rnd = 0x74124485; // randomnumber
size_t blocknr; static bool end = false;
bool end = false;
//#define SENDBIT_TEST //#define SENDBIT_TEST
/* array index 3 2 1 0 // bytes in sim.bin file are 0 1 2 3 /* array index 3 2 1 0 // bytes in sim.bin file are 0 1 2 3

View file

@ -1802,7 +1802,7 @@ static void ReaderTransmitIClass_ext(uint8_t *frame, int len, int wait) {
TransmitIClassCommand(ToSend, ToSendMax, &wait); TransmitIClassCommand(ToSend, ToSendMax, &wait);
LED_A_ON(); LED_A_ON();
LogTrace(frame, len, rsamples, rsamples, NULL, true); LogTrace(frame, len, g_rsamples, g_rsamples, NULL, true);
} }
static void ReaderTransmitIClass(uint8_t *frame, int len) { static void ReaderTransmitIClass(uint8_t *frame, int len) {
ReaderTransmitIClass_ext(frame, len, 330); ReaderTransmitIClass_ext(frame, len, 330);
@ -1867,7 +1867,7 @@ static int ReaderReceiveIClass(uint8_t *receivedAnswer) {
if (GetIClassAnswer(receivedAnswer, 0, NULL) == false) if (GetIClassAnswer(receivedAnswer, 0, NULL) == false)
return 0; return 0;
LogTrace(receivedAnswer, Demod.len, rsamples, rsamples, NULL, false); LogTrace(receivedAnswer, Demod.len, g_rsamples, g_rsamples, NULL, false);
return Demod.len; return Demod.len;
} }

View file

@ -31,9 +31,9 @@ static uint32_t iso14a_timeout;
// if iso14443a not active - transmit/receive dont try to execute // if iso14443a not active - transmit/receive dont try to execute
static bool hf_field_active = false; static bool hf_field_active = false;
uint8_t colpos = 0; static uint8_t colpos = 0;
int rsamples = 0; int g_rsamples = 0;
uint8_t trigger = 0; uint8_t g_trigger = 0;
// the block number for the ISO14443-4 PCB // the block number for the ISO14443-4 PCB
static uint8_t iso14_pcb_blocknum = 0; static uint8_t iso14_pcb_blocknum = 0;
@ -123,7 +123,7 @@ static uint32_t LastProxToAirDuration;
#define SEC_Z 0xc0 #define SEC_Z 0xc0
void iso14a_set_trigger(bool enable) { void iso14a_set_trigger(bool enable) {
trigger = enable; g_trigger = enable;
} }
void iso14a_set_timeout(uint32_t timeout) { void iso14a_set_timeout(uint32_t timeout) {
@ -2145,7 +2145,7 @@ void ReaderTransmitBitsPar(uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t
CodeIso14443aBitsAsReaderPar(frame, bits, par); CodeIso14443aBitsAsReaderPar(frame, bits, par);
// Send command to tag // Send command to tag
TransmitFor14443a(ToSend, ToSendMax, timing); TransmitFor14443a(ToSend, ToSendMax, timing);
if (trigger) LED_A_ON(); if (g_trigger) LED_A_ON();
LogTrace(frame, nbytes(bits), (LastTimeProxToAirStart << 4) + DELAY_ARM2AIR_AS_READER, ((LastTimeProxToAirStart + LastProxToAirDuration) << 4) + DELAY_ARM2AIR_AS_READER, par, true); LogTrace(frame, nbytes(bits), (LastTimeProxToAirStart << 4) + DELAY_ARM2AIR_AS_READER, ((LastTimeProxToAirStart + LastProxToAirDuration) << 4) + DELAY_ARM2AIR_AS_READER, par, true);
} }

View file

@ -1150,7 +1150,7 @@ static void CodeAndTransmit14443bAsReader(const uint8_t *cmd, int len) {
TransmitFor14443b_AsReader(); TransmitFor14443b_AsReader();
if (trigger) LED_A_ON(); if (g_trigger) LED_A_ON();
LogTrace(cmd, len, time_start, GetCountSspClk() - time_start, NULL, true); LogTrace(cmd, len, time_start, GetCountSspClk() - time_start, NULL, true);
} }
@ -1578,7 +1578,7 @@ void RAMFUNC SniffIso14443b(void) {
} }
static void iso14b_set_trigger(bool enable) { static void iso14b_set_trigger(bool enable) {
trigger = enable; g_trigger = enable;
} }
/* /*

View file

@ -25,13 +25,18 @@
// T0 = timer/carrier = 1500kHz/125kHz = 1500000/125000 = 6 // T0 = timer/carrier = 1500kHz/125kHz = 1500000/125000 = 6
//#define HITAG_T0 3 //#define HITAG_T0 3
//////////////////////////////////////////////////////////////////////////////
// Exported global variables
//////////////////////////////////////////////////////////////////////////////
bool g_logging = true;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Global variables // Global variables
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
bool rising_edge = false; static bool rising_edge = false;
bool logging = true; static bool reader_mode = false;
bool reader_mode = false;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Auxiliary functions // Auxiliary functions
@ -90,7 +95,7 @@ static size_t lf_count_edge_periods_ex(size_t max, bool wait, bool detect_gap) {
adc_val = AT91C_BASE_SSC->SSC_RHR; adc_val = AT91C_BASE_SSC->SSC_RHR;
periods++; periods++;
if (logging) logSampleSimple(adc_val); if (g_logging) logSampleSimple(adc_val);
// Only test field changes if state of adc values matter // Only test field changes if state of adc values matter
if (wait == false) { if (wait == false) {
@ -120,7 +125,7 @@ static size_t lf_count_edge_periods_ex(size_t max, bool wait, bool detect_gap) {
if (periods >= max) return 0; if (periods >= max) return 0;
} }
} }
if (logging) logSampleSimple(0xFF); if (g_logging) logSampleSimple(0xFF);
return 0; return 0;
} }
@ -223,7 +228,7 @@ void lf_init(bool reader, bool simulate) {
uint32_t bufsize = 10000; uint32_t bufsize = 10000;
// use malloc // use malloc
if (logging) initSampleBufferEx(&bufsize, true); if (g_logging) initSampleBufferEx(&bufsize, true);
lf_sample_mean(); lf_sample_mean();
} }
@ -269,7 +274,7 @@ size_t lf_detect_field_drop(size_t max) {
periods++; periods++;
volatile uint8_t adc_val = AT91C_BASE_SSC->SSC_RHR; volatile uint8_t adc_val = AT91C_BASE_SSC->SSC_RHR;
if (logging) logSampleSimple(adc_val); if (g_logging) logSampleSimple(adc_val);
if (adc_val == 0) { if (adc_val == 0) {
rising_edge = false; rising_edge = false;

View file

@ -15,7 +15,7 @@
#include "util.h" #include "util.h"
#include "string.h" #include "string.h"
extern bool logging; extern bool g_logging;
void lf_sample_mean(void); void lf_sample_mean(void);
bool lf_test_periods(size_t expected, size_t count); bool lf_test_periods(size_t expected, size_t count);

View file

@ -15,10 +15,6 @@
#include "pm3_cmd.h" // struct #include "pm3_cmd.h" // struct
extern uint8_t decimation;
extern uint8_t bits_per_sample ;
extern bool averaging;
void AcquireRawAdcSamples125k(int divisor); void AcquireRawAdcSamples125k(int divisor);
void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint32_t period_1, uint8_t *command); void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint32_t period_1, uint8_t *command);
void ReadTItag(void); void ReadTItag(void);

View file

@ -27,7 +27,7 @@ Default LF config is set to:
samples_to_skip = 0 samples_to_skip = 0
verbose = YES verbose = YES
*/ */
sample_config config = { 1, 8, 1, LF_DIVISOR_125, 0, 0, 1} ; static sample_config config = { 1, 8, 1, LF_DIVISOR_125, 0, 0, 1} ;
void printConfig(void) { void printConfig(void) {
uint32_t d = config.divisor; uint32_t d = config.divisor;

View file

@ -25,7 +25,7 @@
#define RECEIVE_SIZE 64 #define RECEIVE_SIZE 64
// the block number for the ISO14443-4 PCB // the block number for the ISO14443-4 PCB
uint8_t pcb_blocknum = 0; static uint8_t pcb_blocknum = 0;
// Deselect card by sending a s-block. the crc is precalced for speed // Deselect card by sending a s-block. the crc is precalced for speed
static uint8_t deselect_cmd[] = {0xc2, 0xe0, 0xb4}; static uint8_t deselect_cmd[] = {0xc2, 0xe0, 0xb4};

View file

@ -47,7 +47,7 @@ typedef int ssize_t;
#define NBBY 8 /* number of bits in a byte */ #define NBBY 8 /* number of bits in a byte */
char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz"; static char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz";
#define hex2ascii(hex) (hex2ascii_data[hex]) #define hex2ascii(hex) (hex2ascii_data[hex])
#define toupper(c) ((c) - 0x20 * (((c) >= 'a') && ((c) <= 'z'))) #define toupper(c) ((c) - 0x20 * (((c) >= 'a') && ((c) <= 'z')))

View file

@ -15,8 +15,8 @@ volatile AT91PS_USART pUS1 = AT91C_BASE_US1;
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA; volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;
volatile AT91PS_PDC pPDC = AT91C_BASE_PDC_US1; volatile AT91PS_PDC pPDC = AT91C_BASE_PDC_US1;
uint32_t usart_baudrate = 0; uint32_t g_usart_baudrate = 0;
uint8_t usart_parity = 0; uint8_t g_usart_parity = 0;
/* /*
void usart_close(void) { void usart_close(void) {
// Reset the USART mode // Reset the USART mode
@ -41,8 +41,8 @@ void usart_close(void) {
static uint8_t us_inbuf1[USART_BUFFLEN]; static uint8_t us_inbuf1[USART_BUFFLEN];
static uint8_t us_inbuf2[USART_BUFFLEN]; static uint8_t us_inbuf2[USART_BUFFLEN];
uint8_t *usart_cur_inbuf = NULL; static uint8_t *usart_cur_inbuf = NULL;
uint16_t usart_cur_inbuf_off = 0; static uint16_t usart_cur_inbuf_off = 0;
static uint8_t us_rxfifo[USART_FIFOLEN]; static uint8_t us_rxfifo[USART_FIFOLEN];
static size_t us_rxfifo_low = 0; static size_t us_rxfifo_low = 0;
static size_t us_rxfifo_high = 0; static size_t us_rxfifo_high = 0;
@ -166,9 +166,9 @@ inline int usart_writebuffer_sync(uint8_t *data, size_t len) {
void usart_init(uint32_t baudrate, uint8_t parity) { void usart_init(uint32_t baudrate, uint8_t parity) {
if (baudrate != 0) if (baudrate != 0)
usart_baudrate = baudrate; g_usart_baudrate = baudrate;
if ((parity == 'N') || (parity == 'O') || (parity == 'E')) if ((parity == 'N') || (parity == 'O') || (parity == 'E'))
usart_parity = parity; g_usart_parity = parity;
// For a nice detailed sample, interrupt driven but still relevant. // For a nice detailed sample, interrupt driven but still relevant.
// See https://www.sparkfun.com/datasheets/DevTools/SAM7/at91sam7%20serial%20communications.pdf // See https://www.sparkfun.com/datasheets/DevTools/SAM7/at91sam7%20serial%20communications.pdf
@ -197,7 +197,7 @@ void usart_init(uint32_t baudrate, uint8_t parity) {
AT91C_US_NBSTOP_1_BIT | // 1 stop bit AT91C_US_NBSTOP_1_BIT | // 1 stop bit
AT91C_US_CHMODE_NORMAL; // channel mode: normal AT91C_US_CHMODE_NORMAL; // channel mode: normal
switch (usart_parity) { switch (g_usart_parity) {
case 'N': case 'N':
mode |= AT91C_US_PAR_NONE; // parity: none mode |= AT91C_US_PAR_NONE; // parity: none
break; break;
@ -227,9 +227,9 @@ void usart_init(uint32_t baudrate, uint8_t parity) {
// OVER = 1, -yes we are oversampling // OVER = 1, -yes we are oversampling
// baudrate == selected clock/8/CD --> this is ours // baudrate == selected clock/8/CD --> this is ours
// //
uint32_t brgr = MCK / (usart_baudrate << 3); uint32_t brgr = MCK / (g_usart_baudrate << 3);
// doing fp = round((mck / (usart_baudrate << 3) - brgr) * 8) with integers: // doing fp = round((mck / (g_usart_baudrate << 3) - brgr) * 8) with integers:
uint32_t fp = ((16 * MCK / (usart_baudrate << 3) - 16 * brgr) + 1) / 2; uint32_t fp = ((16 * MCK / (g_usart_baudrate << 3) - 16 * brgr) + 1) / 2;
pUS1->US_BRGR = (fp << 16) | brgr; pUS1->US_BRGR = (fp << 16) | brgr;

View file

@ -9,8 +9,8 @@
// Higher baudrates are pointless, only increasing overflow risk // Higher baudrates are pointless, only increasing overflow risk
extern uint32_t usart_baudrate; extern uint32_t g_usart_baudrate;
extern uint8_t usart_parity; extern uint8_t g_usart_parity;
void usart_init(uint32_t baudrate, uint8_t parity); void usart_init(uint32_t baudrate, uint8_t parity);
int usart_writebuffer_sync(uint8_t *data, size_t len); int usart_writebuffer_sync(uint8_t *data, size_t len);