From fa85b08504eda7045b4b7d50fee1b75c4f5e5dd2 Mon Sep 17 00:00:00 2001
From: pwpiwi <pwpiwi@users.noreply.github.com>
Date: Mon, 11 Dec 2017 20:40:09 +0100
Subject: [PATCH] fix iso14a_set_timeout() adjustment

---
 armsrc/iso14443a.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c
index 0a9f7c03..94ca52f5 100644
--- a/armsrc/iso14443a.c
+++ b/armsrc/iso14443a.c
@@ -189,13 +189,14 @@ void iso14a_set_trigger(bool enable) {
 
 
 void iso14a_set_timeout(uint32_t timeout) {
-	iso14a_timeout = timeout - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER)/(16*8) + 2;
+	// adjust timeout by FPGA delays and 2 additional ssp_frames to detect SOF
+	iso14a_timeout = timeout + (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER)/(16*8) + 2;
 	if(MF_DBGLEVEL >= 3) Dbprintf("ISO14443A Timeout set to %ld (%dms)", timeout, timeout / 106);
 }
 
 
 uint32_t iso14a_get_timeout(void) {
-	return iso14a_timeout + (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER)/(16*8) - 2;
+	return iso14a_timeout - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER)/(16*8) - 2;
 }
 
 //-----------------------------------------------------------------------------
-- 
2.39.5