mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 18:48:13 -07:00
armsrc: clarify static vars vs global vars
This commit is contained in:
parent
fbaf634779
commit
3e7512a5d5
20 changed files with 101 additions and 102 deletions
|
@ -73,7 +73,7 @@ int ToSendMax = -1;
|
|||
static int ToSendBit;
|
||||
struct common_area common_area __attribute__((section(".commonarea")));
|
||||
int button_status = BUTTON_NO_CLICK;
|
||||
bool allow_send_wtx = false;
|
||||
static bool allow_send_wtx = false;
|
||||
|
||||
inline void send_wtx(uint16_t wtx) {
|
||||
if (allow_send_wtx) {
|
||||
|
@ -385,12 +385,12 @@ static void SendStatus(void) {
|
|||
static void SendCapabilities(void) {
|
||||
capabilities_t capabilities;
|
||||
capabilities.version = CAPABILITIES_VERSION;
|
||||
capabilities.via_fpc = reply_via_fpc;
|
||||
capabilities.via_usb = reply_via_usb;
|
||||
capabilities.via_fpc = g_reply_via_fpc;
|
||||
capabilities.via_usb = g_reply_via_usb;
|
||||
capabilities.baudrate = 0; // no real baudrate for USB-CDC
|
||||
#ifdef WITH_FPC_USART
|
||||
if (reply_via_fpc)
|
||||
capabilities.baudrate = usart_baudrate;
|
||||
if (g_reply_via_fpc)
|
||||
capabilities.baudrate = g_usart_baudrate;
|
||||
#endif
|
||||
|
||||
#ifdef WITH_FLASH
|
||||
|
@ -701,8 +701,8 @@ static void PacketReceived(PacketCommandNG *packet) {
|
|||
case CMD_BREAK_LOOP:
|
||||
break;
|
||||
case CMD_QUIT_SESSION: {
|
||||
reply_via_fpc = false;
|
||||
reply_via_usb = false;
|
||||
g_reply_via_fpc = false;
|
||||
g_reply_via_usb = false;
|
||||
break;
|
||||
}
|
||||
// emulator
|
||||
|
|
|
@ -13,9 +13,8 @@
|
|||
|
||||
#include "common.h"
|
||||
|
||||
extern int rsamples; // = 0;
|
||||
extern uint8_t trigger;
|
||||
extern bool allow_send_wtx;
|
||||
extern int g_rsamples; // = 0;
|
||||
extern uint8_t g_trigger;
|
||||
|
||||
// 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
|
||||
|
|
34
armsrc/cmd.c
34
armsrc/cmd.c
|
@ -36,11 +36,11 @@
|
|||
#include "string.h"
|
||||
|
||||
// Flags to tell where to add CRC on sent replies
|
||||
bool reply_with_crc_on_usb = false;
|
||||
bool reply_with_crc_on_fpc = true;
|
||||
bool g_reply_with_crc_on_usb = false;
|
||||
bool g_reply_with_crc_on_fpc = true;
|
||||
// "Session" flag, to tell via which interface next msgs should be sent: USB or FPC USART
|
||||
bool reply_via_fpc = false;
|
||||
bool reply_via_usb = false;
|
||||
bool g_reply_via_fpc = 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) {
|
||||
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;
|
||||
// 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));
|
||||
}
|
||||
|
||||
if (reply_via_fpc) {
|
||||
if (g_reply_via_fpc) {
|
||||
#ifdef WITH_FPC_USART_HOST
|
||||
resultfpc = usart_writebuffer_sync((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
|
||||
#else
|
||||
|
@ -80,9 +80,9 @@ int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *d
|
|||
#endif
|
||||
}
|
||||
// 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
|
||||
if (reply_via_fpc && (resultfpc != PM3_SUCCESS)) return resultfpc;
|
||||
if (g_reply_via_fpc && (resultfpc != PM3_SUCCESS)) return resultfpc;
|
||||
#endif
|
||||
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);
|
||||
// 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;
|
||||
compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(PacketResponseNGPreamble) + len, &first, &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;
|
||||
// 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);
|
||||
}
|
||||
if (reply_via_fpc) {
|
||||
if (g_reply_via_fpc) {
|
||||
#ifdef WITH_FPC_USART_HOST
|
||||
resultfpc = usart_writebuffer_sync((uint8_t *)&txBufferNG, txBufferNGLen);
|
||||
#else
|
||||
|
@ -138,9 +138,9 @@ static int reply_ng_internal(uint16_t cmd, int16_t status, uint8_t *data, size_t
|
|||
#endif
|
||||
}
|
||||
// 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
|
||||
if (reply_via_fpc && (resultfpc != PM3_SUCCESS)) return resultfpc;
|
||||
if (g_reply_via_fpc && (resultfpc != PM3_SUCCESS)) return resultfpc;
|
||||
#endif
|
||||
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)
|
||||
return PM3_EIO;
|
||||
}
|
||||
reply_via_usb = usb;
|
||||
reply_via_fpc = fpc;
|
||||
g_reply_via_usb = usb;
|
||||
g_reply_via_fpc = fpc;
|
||||
} else { // Old style command
|
||||
PacketCommandOLD rx_old;
|
||||
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))
|
||||
return PM3_EIO;
|
||||
|
||||
reply_via_usb = usb;
|
||||
reply_via_fpc = fpc;
|
||||
g_reply_via_usb = usb;
|
||||
g_reply_via_fpc = fpc;
|
||||
rx->ng = false;
|
||||
rx->magic = 0;
|
||||
rx->crc = 0;
|
||||
|
|
|
@ -37,11 +37,11 @@
|
|||
#include "pm3_cmd.h"
|
||||
|
||||
// Flags to tell where to add CRC on sent replies
|
||||
extern bool reply_with_crc_on_usb;
|
||||
extern bool reply_with_crc_on_fpc;
|
||||
extern bool g_reply_with_crc_on_usb;
|
||||
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
|
||||
extern bool reply_via_fpc;
|
||||
extern bool reply_via_usb;
|
||||
extern bool g_reply_via_fpc;
|
||||
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_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len);
|
||||
|
|
|
@ -15,31 +15,31 @@
|
|||
#include "ansi.h"
|
||||
|
||||
#define Dbprintf_usb(...) {\
|
||||
bool tmpfpc = reply_via_fpc;\
|
||||
bool tmpusb = reply_via_usb;\
|
||||
reply_via_fpc = false;\
|
||||
reply_via_usb = true;\
|
||||
bool tmpfpc = g_reply_via_fpc;\
|
||||
bool tmpusb = g_reply_via_usb;\
|
||||
g_reply_via_fpc = false;\
|
||||
g_reply_via_usb = true;\
|
||||
Dbprintf(__VA_ARGS__);\
|
||||
reply_via_fpc = tmpfpc;\
|
||||
reply_via_usb = tmpusb;}
|
||||
g_reply_via_fpc = tmpfpc;\
|
||||
g_reply_via_usb = tmpusb;}
|
||||
|
||||
#define Dbprintf_fpc(...) {\
|
||||
bool tmpfpc = reply_via_fpc;\
|
||||
bool tmpusb = reply_via_usb;\
|
||||
reply_via_fpc = true;\
|
||||
reply_via_usb = false;\
|
||||
bool tmpfpc = g_reply_via_fpc;\
|
||||
bool tmpusb = g_reply_via_usb;\
|
||||
g_reply_via_fpc = true;\
|
||||
g_reply_via_usb = false;\
|
||||
Dbprintf(__VA_ARGS__);\
|
||||
reply_via_fpc = tmpfpc;\
|
||||
reply_via_usb = tmpusb;}
|
||||
g_reply_via_fpc = tmpfpc;\
|
||||
g_reply_via_usb = tmpusb;}
|
||||
|
||||
#define Dbprintf_all(...) {\
|
||||
bool tmpfpc = reply_via_fpc;\
|
||||
bool tmpusb = reply_via_usb;\
|
||||
reply_via_fpc = true;\
|
||||
reply_via_usb = true;\
|
||||
bool tmpfpc = g_reply_via_fpc;\
|
||||
bool tmpusb = g_reply_via_usb;\
|
||||
g_reply_via_fpc = true;\
|
||||
g_reply_via_usb = true;\
|
||||
Dbprintf(__VA_ARGS__);\
|
||||
reply_via_fpc = tmpfpc;\
|
||||
reply_via_usb = tmpusb;}
|
||||
g_reply_via_fpc = tmpfpc;\
|
||||
g_reply_via_usb = tmpusb;}
|
||||
|
||||
|
||||
void DbpString(const char *str);
|
||||
|
|
|
@ -35,7 +35,7 @@ static uint32_t felica_lasttime_prox2air_start;
|
|||
static void iso18092_setup(uint8_t fpga_minor_mode);
|
||||
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);
|
||||
bool WaitForFelicaReply(uint16_t maxbytes);
|
||||
static bool WaitForFelicaReply(uint16_t maxbytes);
|
||||
|
||||
static void iso18092_set_timeout(uint32_t timeout) {
|
||||
felica_timeout = timeout + (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / (16 * 8) + 2;
|
||||
|
|
|
@ -48,8 +48,8 @@ static bool bCrypto;
|
|||
// Is in auth stage
|
||||
static bool bAuthenticating;
|
||||
// Successful password auth
|
||||
bool bSelecting;
|
||||
bool bCollision;
|
||||
static bool bSelecting;
|
||||
static bool bCollision;
|
||||
static bool bPwd;
|
||||
static bool bSuccessful;
|
||||
|
||||
|
@ -89,14 +89,14 @@ static uint8_t password[4];
|
|||
static uint8_t NrAr[8];
|
||||
static uint8_t key[8];
|
||||
static uint8_t writedata[4];
|
||||
uint8_t logdata_0[4], logdata_1[4];
|
||||
uint8_t nonce[4];
|
||||
bool key_no;
|
||||
static uint8_t logdata_0[4], logdata_1[4];
|
||||
static uint8_t nonce[4];
|
||||
static bool key_no;
|
||||
static uint64_t cipher_state;
|
||||
|
||||
int16_t blocknr;
|
||||
size_t flipped_bit = 0;
|
||||
uint32_t byte_value = 0;
|
||||
static int16_t blocknr;
|
||||
static size_t flipped_bit = 0;
|
||||
static uint32_t byte_value = 0;
|
||||
|
||||
static int hitag2_reset(void) {
|
||||
tag.state = TAG_STATE_RESET;
|
||||
|
@ -997,7 +997,7 @@ void SniffHitag2(void) {
|
|||
|
||||
lf_init(false, false);
|
||||
|
||||
logging = false;
|
||||
g_logging = false;
|
||||
|
||||
size_t periods = 0;
|
||||
uint8_t periods_bytes[4];
|
||||
|
@ -1031,8 +1031,8 @@ void SniffHitag2(void) {
|
|||
|
||||
// Test if we detected the first reader modulation edge
|
||||
if (periods != 0) {
|
||||
if (logging == false) {
|
||||
logging = true;
|
||||
if (g_logging == false) {
|
||||
g_logging = true;
|
||||
LED_D_ON();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
#define READP0CMD "1100000111"
|
||||
#define ERROR_RESPONSE "F402889C"
|
||||
|
||||
extern const uint8_t Hitag2Sync[5];
|
||||
extern bool CryptoActive;
|
||||
extern Hitag_State Hitag_Crypto_State;
|
||||
static const uint8_t Hitag2Sync[5];
|
||||
static bool CryptoActive;
|
||||
static Hitag_State Hitag_Crypto_State;
|
||||
|
||||
// hitag2_crack implements the first crack algorithm described in the paper,
|
||||
// Gone In 360 Seconds by Verdult, Garcia and Balasch.
|
||||
|
|
|
@ -48,8 +48,7 @@ static int temp2 = 0;
|
|||
static int sof_bits; // number of start-of-frame bits
|
||||
static uint8_t pwdh0, pwdl0, pwdl1; // password bytes
|
||||
static uint32_t rnd = 0x74124485; // randomnumber
|
||||
size_t blocknr;
|
||||
bool end = false;
|
||||
static bool end = false;
|
||||
//#define SENDBIT_TEST
|
||||
|
||||
/* array index 3 2 1 0 // bytes in sim.bin file are 0 1 2 3
|
||||
|
|
|
@ -1802,7 +1802,7 @@ static void ReaderTransmitIClass_ext(uint8_t *frame, int len, int wait) {
|
|||
TransmitIClassCommand(ToSend, ToSendMax, &wait);
|
||||
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) {
|
||||
ReaderTransmitIClass_ext(frame, len, 330);
|
||||
|
@ -1867,7 +1867,7 @@ static int ReaderReceiveIClass(uint8_t *receivedAnswer) {
|
|||
if (GetIClassAnswer(receivedAnswer, 0, NULL) == false)
|
||||
return 0;
|
||||
|
||||
LogTrace(receivedAnswer, Demod.len, rsamples, rsamples, NULL, false);
|
||||
LogTrace(receivedAnswer, Demod.len, g_rsamples, g_rsamples, NULL, false);
|
||||
return Demod.len;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,9 +31,9 @@ static uint32_t iso14a_timeout;
|
|||
// if iso14443a not active - transmit/receive dont try to execute
|
||||
static bool hf_field_active = false;
|
||||
|
||||
uint8_t colpos = 0;
|
||||
int rsamples = 0;
|
||||
uint8_t trigger = 0;
|
||||
static uint8_t colpos = 0;
|
||||
int g_rsamples = 0;
|
||||
uint8_t g_trigger = 0;
|
||||
// the block number for the ISO14443-4 PCB
|
||||
static uint8_t iso14_pcb_blocknum = 0;
|
||||
|
||||
|
@ -123,7 +123,7 @@ static uint32_t LastProxToAirDuration;
|
|||
#define SEC_Z 0xc0
|
||||
|
||||
void iso14a_set_trigger(bool enable) {
|
||||
trigger = enable;
|
||||
g_trigger = enable;
|
||||
}
|
||||
|
||||
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);
|
||||
// Send command to tag
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1150,7 +1150,7 @@ static void CodeAndTransmit14443bAsReader(const uint8_t *cmd, int len) {
|
|||
|
||||
TransmitFor14443b_AsReader();
|
||||
|
||||
if (trigger) LED_A_ON();
|
||||
if (g_trigger) LED_A_ON();
|
||||
|
||||
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) {
|
||||
trigger = enable;
|
||||
g_trigger = enable;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -25,13 +25,18 @@
|
|||
// T0 = timer/carrier = 1500kHz/125kHz = 1500000/125000 = 6
|
||||
//#define HITAG_T0 3
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Exported global variables
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool g_logging = true;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Global variables
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool rising_edge = false;
|
||||
bool logging = true;
|
||||
bool reader_mode = false;
|
||||
static bool rising_edge = false;
|
||||
static bool reader_mode = false;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
periods++;
|
||||
|
||||
if (logging) logSampleSimple(adc_val);
|
||||
if (g_logging) logSampleSimple(adc_val);
|
||||
|
||||
// Only test field changes if state of adc values matter
|
||||
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 (logging) logSampleSimple(0xFF);
|
||||
if (g_logging) logSampleSimple(0xFF);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -223,7 +228,7 @@ void lf_init(bool reader, bool simulate) {
|
|||
uint32_t bufsize = 10000;
|
||||
|
||||
// use malloc
|
||||
if (logging) initSampleBufferEx(&bufsize, true);
|
||||
if (g_logging) initSampleBufferEx(&bufsize, true);
|
||||
|
||||
lf_sample_mean();
|
||||
}
|
||||
|
@ -269,7 +274,7 @@ size_t lf_detect_field_drop(size_t max) {
|
|||
periods++;
|
||||
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) {
|
||||
rising_edge = false;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "util.h"
|
||||
#include "string.h"
|
||||
|
||||
extern bool logging;
|
||||
extern bool g_logging;
|
||||
|
||||
void lf_sample_mean(void);
|
||||
bool lf_test_periods(size_t expected, size_t count);
|
||||
|
|
|
@ -15,10 +15,6 @@
|
|||
|
||||
#include "pm3_cmd.h" // struct
|
||||
|
||||
extern uint8_t decimation;
|
||||
extern uint8_t bits_per_sample ;
|
||||
extern bool averaging;
|
||||
|
||||
void AcquireRawAdcSamples125k(int divisor);
|
||||
void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint32_t period_1, uint8_t *command);
|
||||
void ReadTItag(void);
|
||||
|
|
|
@ -27,7 +27,7 @@ Default LF config is set to:
|
|||
samples_to_skip = 0
|
||||
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) {
|
||||
uint32_t d = config.divisor;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#define RECEIVE_SIZE 64
|
||||
|
||||
// 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
|
||||
static uint8_t deselect_cmd[] = {0xc2, 0xe0, 0xb4};
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ typedef int ssize_t;
|
|||
|
||||
#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 toupper(c) ((c) - 0x20 * (((c) >= 'a') && ((c) <= 'z')))
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ volatile AT91PS_USART pUS1 = AT91C_BASE_US1;
|
|||
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;
|
||||
volatile AT91PS_PDC pPDC = AT91C_BASE_PDC_US1;
|
||||
|
||||
uint32_t usart_baudrate = 0;
|
||||
uint8_t usart_parity = 0;
|
||||
uint32_t g_usart_baudrate = 0;
|
||||
uint8_t g_usart_parity = 0;
|
||||
/*
|
||||
void usart_close(void) {
|
||||
// Reset the USART mode
|
||||
|
@ -41,8 +41,8 @@ void usart_close(void) {
|
|||
|
||||
static uint8_t us_inbuf1[USART_BUFFLEN];
|
||||
static uint8_t us_inbuf2[USART_BUFFLEN];
|
||||
uint8_t *usart_cur_inbuf = NULL;
|
||||
uint16_t usart_cur_inbuf_off = 0;
|
||||
static uint8_t *usart_cur_inbuf = NULL;
|
||||
static uint16_t usart_cur_inbuf_off = 0;
|
||||
static uint8_t us_rxfifo[USART_FIFOLEN];
|
||||
static size_t us_rxfifo_low = 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) {
|
||||
|
||||
if (baudrate != 0)
|
||||
usart_baudrate = baudrate;
|
||||
g_usart_baudrate = baudrate;
|
||||
if ((parity == 'N') || (parity == 'O') || (parity == 'E'))
|
||||
usart_parity = parity;
|
||||
g_usart_parity = parity;
|
||||
|
||||
// For a nice detailed sample, interrupt driven but still relevant.
|
||||
// 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_CHMODE_NORMAL; // channel mode: normal
|
||||
|
||||
switch (usart_parity) {
|
||||
switch (g_usart_parity) {
|
||||
case 'N':
|
||||
mode |= AT91C_US_PAR_NONE; // parity: none
|
||||
break;
|
||||
|
@ -227,9 +227,9 @@ void usart_init(uint32_t baudrate, uint8_t parity) {
|
|||
// OVER = 1, -yes we are oversampling
|
||||
// baudrate == selected clock/8/CD --> this is ours
|
||||
//
|
||||
uint32_t brgr = MCK / (usart_baudrate << 3);
|
||||
// doing fp = round((mck / (usart_baudrate << 3) - brgr) * 8) with integers:
|
||||
uint32_t fp = ((16 * MCK / (usart_baudrate << 3) - 16 * brgr) + 1) / 2;
|
||||
uint32_t brgr = MCK / (g_usart_baudrate << 3);
|
||||
// doing fp = round((mck / (g_usart_baudrate << 3) - brgr) * 8) with integers:
|
||||
uint32_t fp = ((16 * MCK / (g_usart_baudrate << 3) - 16 * brgr) + 1) / 2;
|
||||
|
||||
pUS1->US_BRGR = (fp << 16) | brgr;
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
// Higher baudrates are pointless, only increasing overflow risk
|
||||
|
||||
extern uint32_t usart_baudrate;
|
||||
extern uint8_t usart_parity;
|
||||
extern uint32_t g_usart_baudrate;
|
||||
extern uint8_t g_usart_parity;
|
||||
|
||||
void usart_init(uint32_t baudrate, uint8_t parity);
|
||||
int usart_writebuffer_sync(uint8_t *data, size_t len);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue