diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index d1692e2ac..50b241ef2 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -314,6 +314,12 @@ uint32_t iso14a_get_timeout(void) { return iso14a_timeout - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / 128 - 2; } +void iso14a_rebase_transfer_time(void) { + //Restarting StartCountSspClk() resets NextTransferTime clock-counts to zero; retaining old value makes ReaderTransmit() wait stale time from previous APDU. + //Do not reset PCB or ATS state here. + NextTransferTime = 2 * DELAY_ARM2AIR_AS_READER; +} + //----------------------------------------------------------------------------- // Generate the parity value for a byte sequence //----------------------------------------------------------------------------- diff --git a/armsrc/iso14443a.h b/armsrc/iso14443a.h index 1f39be439..2b4f070fa 100644 --- a/armsrc/iso14443a.h +++ b/armsrc/iso14443a.h @@ -129,6 +129,8 @@ void setHf14aConfig(const hf14a_config_t *hc); hf14a_config_t *getHf14aConfig(void); void iso14a_set_timeout(uint32_t timeout); uint32_t iso14a_get_timeout(void); +// Rebase absolute reader-transfer schedule after a caller restarts the SSP clock counter. +void iso14a_rebase_transfer_time(void); void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *par); diff --git a/armsrc/sam_sc.c b/armsrc/sam_sc.c index 5bcd88395..d73cea345 100644 --- a/armsrc/sam_sc.c +++ b/armsrc/sam_sc.c @@ -366,6 +366,8 @@ static int sam_sc_card_api_loop(uint8_t *response, uint16_t *response_len, } if (iso14a) { switch_clock_to_countsspclk(); + //Keep absolute transfer scheduler in the same time base; so it doesn't wait on a stale timestamp from the preceding Card-API APDU. + iso14a_rebase_transfer_time(); int apdu_len = iso14_apdu((uint8_t *)op_value, op_len, false, nfc_rx, sizeof(nfc_rx), NULL); switch_clock_to_ticks();