relax the timeouts
High baud rates lead to incredibly small wait times that are infeasible
as long as software timers are being used, but this is not really a
problem - they can just be increased to a reasonable value.
At the end of the day the timers need to take the latency of the
firmware into account, and timeouts only occur on powerup with wrong
voltages/dead cards, or in rare error cases.
The actual timeout value does therefore not really matter that much.
Change-Id: Icb733f2d46f45c1a7dcd2abe6bc292bd41d6b9c2
diff --git a/ccid_common/cuart.c b/ccid_common/cuart.c
index 1d777f9..7094a86 100644
--- a/ccid_common/cuart.c
+++ b/ccid_common/cuart.c
@@ -52,9 +52,16 @@
if(!cuart->current_wtime_byte)
return;
+ int etu_in_us = get_etu_in_us(cuart) + 1;
+ cuart->wtime_etu = cuart->wtime_etu ? cuart->wtime_etu : 1;
+
/* timemout is wtime * ETU + expected number of bytes * (12ETU+1 slack)ETU */
- usecs = get_etu_in_us(cuart) * cuart->wtime_etu +
- get_etu_in_us(cuart) * cuart->current_wtime_byte * (12+1);
+ usecs = etu_in_us * cuart->wtime_etu +
+ etu_in_us * cuart->current_wtime_byte * (12+1);
+
+ /* limit lower wait time to reasonable value */
+ usecs = usecs < 300000 ? 300000 : usecs;
+
if (usecs > 1000000) {
secs = usecs / 1000000;
usecs = usecs % 1000000;