chg: reconfigure uart timeouts when compiled for FPC and connecting over USB.
This commit is contained in:
@@ -105,5 +105,8 @@ bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed);
|
||||
*/
|
||||
uint32_t uart_get_speed(const serial_port sp);
|
||||
|
||||
/* Reconfigure timeouts
|
||||
*/
|
||||
bool uart_reconfigure_timeouts(serial_port *sp, uint32_t value );
|
||||
#endif // _UART_H_
|
||||
|
||||
|
||||
@@ -67,17 +67,16 @@ typedef struct {
|
||||
term_info tiNew; // Terminal info during the transaction
|
||||
} serial_port_unix;
|
||||
|
||||
// Receiving from USART need more than 30ms as we used on USB
|
||||
// else we get errors about partial packet reception
|
||||
// FTDI 9600 hw status -> we need 20ms
|
||||
// FTDI 115200 hw status -> we need 50ms
|
||||
// FTDI 460800 hw status -> we need 30ms
|
||||
// BT 115200 hf mf fchk 1 dic -> we need 140ms
|
||||
// see usb_cmd.h
|
||||
struct timeval timeout = {
|
||||
.tv_sec = 0, // 0 second
|
||||
.tv_usec = 200000 // 200 000 micro seconds
|
||||
.tv_sec = 0, // 0 second
|
||||
.tv_usec = UART_FPC_CLIENT_RX_TIMEOUT_US
|
||||
};
|
||||
|
||||
bool uart_reconfigure_timeouts(serial_port *sp, uint32_t value ) {
|
||||
timeout.usec = value * 1000;
|
||||
}
|
||||
|
||||
serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
serial_port_unix *sp = calloc(sizeof(serial_port_unix), sizeof(uint8_t));
|
||||
if (sp == 0) return INVALID_SERIAL_PORT;
|
||||
@@ -92,7 +91,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
timeout.tv_usec = 300000; // 300 000 micro seconds
|
||||
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_US;
|
||||
|
||||
char *colon = strrchr(addrstr, ':');
|
||||
const char *portstr;
|
||||
|
||||
@@ -48,6 +48,24 @@ typedef struct {
|
||||
COMMTIMEOUTS ct; // Serial port time-out configuration
|
||||
} serial_port_windows;
|
||||
|
||||
bool uart_reconfigure_timeouts(serial_port *sp, uint32_t value) {
|
||||
|
||||
serial_port_windows *spw = (serial_port_windows*)sp;
|
||||
spw->ct.ReadIntervalTimeout = value;
|
||||
spw->ct.ReadTotalTimeoutMultiplier = 0;
|
||||
spw->ct.ReadTotalTimeoutConstant = value;
|
||||
spw->ct.WriteTotalTimeoutMultiplier = value;
|
||||
spw->ct.WriteTotalTimeoutConstant = 0;
|
||||
|
||||
if (!SetCommTimeouts(spw->hPort, &spw->ct)) {
|
||||
uart_close(spw);
|
||||
printf("[!] UART error while setting comm time outs\n");
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
PurgeComm(spw->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
|
||||
}
|
||||
|
||||
serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
char acPortName[255] = {0};
|
||||
serial_port_windows *sp = calloc(sizeof(serial_port_windows), sizeof(uint8_t));
|
||||
@@ -84,30 +102,8 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
printf("[!] UART error while setting com state\n");
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
// all zero's configure: no timeout for read/write used.
|
||||
// took settings from libnfc/buses/uart.c
|
||||
#ifdef WITH_FPC
|
||||
// Still relevant?
|
||||
sp->ct.ReadIntervalTimeout = 150; //200;
|
||||
sp->ct.ReadTotalTimeoutMultiplier = 0;
|
||||
sp->ct.ReadTotalTimeoutConstant = 150; //200;
|
||||
sp->ct.WriteTotalTimeoutMultiplier = 150; //200;
|
||||
sp->ct.WriteTotalTimeoutConstant = 0;
|
||||
#else
|
||||
sp->ct.ReadIntervalTimeout = 30;
|
||||
sp->ct.ReadTotalTimeoutMultiplier = 0;
|
||||
sp->ct.ReadTotalTimeoutConstant = 30;
|
||||
sp->ct.WriteTotalTimeoutMultiplier = 30;
|
||||
sp->ct.WriteTotalTimeoutConstant = 0;
|
||||
#endif
|
||||
|
||||
if (!SetCommTimeouts(sp->hPort, &sp->ct)) {
|
||||
uart_close(sp);
|
||||
printf("[!] UART error while setting comm time outs\n");
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
PurgeComm(sp->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
|
||||
uart_reconfigure_timeouts(sp, UART_FPC_CLIENT_RX_TIMEOUT_MS);
|
||||
|
||||
if (!uart_set_speed(sp, speed)) {
|
||||
// trying some fallbacks automatically
|
||||
@@ -154,6 +150,7 @@ bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) {
|
||||
PurgeComm(spw->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
|
||||
if (result)
|
||||
conn.uart_speed = uiPortSpeed;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user