mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-08 17:18:10 +08:00
timeout reconfiguration: flag was never cleared and some more changes:
* clear newtimeout_pending flag * fix initial newtimeout_pending flag value on win32 * remove all _atomic as anyway a load+clear wouldn't be atomic and we're not in a critical situation: just one writer seldomly called on reconnect * move new timeout poll to uart_recv for faster deployment * remove redundant uart_reconfigure_timeouts(UART_FPC_CLIENT_RX_TIMEOUT_MS);
This commit is contained in:
parent
9b85f80321
commit
b5e4a60a15
3 changed files with 14 additions and 17 deletions
|
@ -623,16 +623,13 @@ int TestProxmark(void) {
|
|||
|
||||
PrintAndLogEx(INFO, "Communicating with PM3 over %s", conn.send_via_fpc_usart ? _YELLOW_("FPC UART") : _YELLOW_("USB-CDC"));
|
||||
|
||||
int res;
|
||||
if (conn.send_via_fpc_usart) {
|
||||
PrintAndLogEx(INFO, "UART Serial baudrate: " _YELLOW_("%u") "\n", conn.uart_speed);
|
||||
res = uart_reconfigure_timeouts(UART_FPC_CLIENT_RX_TIMEOUT_MS);
|
||||
} else {
|
||||
res = uart_reconfigure_timeouts(UART_USB_CLIENT_RX_TIMEOUT_MS);
|
||||
}
|
||||
|
||||
if (res != PM3_SUCCESS) {
|
||||
return res;
|
||||
int res = uart_reconfigure_timeouts(UART_USB_CLIENT_RX_TIMEOUT_MS);
|
||||
if (res != PM3_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ bool newtimeout_pending = false;
|
|||
|
||||
int uart_reconfigure_timeouts(uint32_t value) {
|
||||
newtimeout_value = value;
|
||||
__atomic_test_and_set(&newtimeout_pending, __ATOMIC_SEQ_CST);
|
||||
newtimeout_pending = true;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -243,6 +243,10 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
|
|||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
|
||||
if ( newtimeout_pending ) {
|
||||
timeout.tv_usec = newtimeout_value * 1000;
|
||||
newtimeout_pending = false;
|
||||
}
|
||||
// Reset the output count
|
||||
*pszRxLen = 0;
|
||||
do {
|
||||
|
@ -303,10 +307,6 @@ int uart_send(const serial_port sp, const uint8_t *pbtTx, const uint32_t len) {
|
|||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
|
||||
bool shall_update = __atomic_load_n(&newtimeout_pending, __ATOMIC_SEQ_CST);
|
||||
if ( shall_update )
|
||||
timeout.tv_usec = newtimeout_value * 1000;
|
||||
|
||||
while (pos < len) {
|
||||
// Reset file descriptor
|
||||
FD_ZERO(&rfds);
|
||||
|
|
|
@ -49,18 +49,18 @@ typedef struct {
|
|||
} serial_port_windows;
|
||||
|
||||
uint32_t newtimeout_value = 0;
|
||||
bool newtimeout_pending = true;
|
||||
bool newtimeout_pending = false;
|
||||
|
||||
int uart_reconfigure_timeouts(uint32_t value) {
|
||||
newtimeout_value = value;
|
||||
__atomic_test_and_set(&newtimeout_pending, __ATOMIC_SEQ_CST);
|
||||
newtimeout_pending = true;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int uart_reconfigure_timeouts_polling(serial_port sp) {
|
||||
bool shall_update = __atomic_load_n(&newtimeout_pending, __ATOMIC_SEQ_CST);
|
||||
if ( shall_update == false )
|
||||
if ( newtimeout_pending == false )
|
||||
return PM3_SUCCESS;
|
||||
newtimeout_pending = false;
|
||||
|
||||
serial_port_windows *spw;
|
||||
spw = (serial_port_windows *)sp;
|
||||
|
@ -174,6 +174,7 @@ uint32_t uart_get_speed(const serial_port sp) {
|
|||
}
|
||||
|
||||
int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uint32_t *pszRxLen) {
|
||||
uart_reconfigure_timeouts_polling(sp);
|
||||
int res = ReadFile(((serial_port_windows *)sp)->hPort, pbtRx, pszMaxRxLen, (LPDWORD)pszRxLen, NULL);
|
||||
if (res)
|
||||
return PM3_SUCCESS;
|
||||
|
@ -190,7 +191,6 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
|
|||
}
|
||||
|
||||
int uart_send(const serial_port sp, const uint8_t *p_tx, const uint32_t len) {
|
||||
uart_reconfigure_timeouts_polling(sp);
|
||||
DWORD txlen = 0;
|
||||
int res = WriteFile(((serial_port_windows *)sp)->hPort, p_tx, len, &txlen, NULL);
|
||||
if (res)
|
||||
|
|
Loading…
Reference in a new issue