From 7fcc62940d35ae31bdf5e5ebdd5ca55c8f4429c2 Mon Sep 17 00:00:00 2001 From: Min Xu Date: Sat, 25 Oct 2014 20:13:23 +0200 Subject: simtrace: Add heartbeat message to debug console --- firmware/src/simtrace/iso7816_uart.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'firmware/src/simtrace/iso7816_uart.c') diff --git a/firmware/src/simtrace/iso7816_uart.c b/firmware/src/simtrace/iso7816_uart.c index 52522c0..611ccfb 100644 --- a/firmware/src/simtrace/iso7816_uart.c +++ b/firmware/src/simtrace/iso7816_uart.c @@ -125,6 +125,14 @@ static const u_int8_t di_table[] = { 12, 20, 2, 4, 8, 16, 32, 64, }; +void iso_uart_report_overrun(void) +{ + static unsigned lastOverrun = 0; + if (isoh.stats.overrun != lastOverrun) { + DEBUGPCR("UART overrun: %u", lastOverrun = isoh.stats.overrun); + } +} + void iso_uart_stats_dump(void) { DEBUGPCRF("no_rctx: %u, rctx_sent: %u, rst: %u, pps: %u, bytes: %u, " @@ -675,6 +683,8 @@ void iso_uart_init(void) { DEBUGPCR("USART Initializing"); + memset(&isoh, 0, sizeof(isoh)); + refill_rctx(&isoh); /* make sure we get clock from the power management controller */ -- cgit v1.2.3 From ab325fc295a23d04f27cc7300b12d2564e4d83e6 Mon Sep 17 00:00:00 2001 From: Min Xu Date: Sat, 25 Oct 2014 20:55:01 +0200 Subject: Ensure to transmit current req_ctx on RESET/VCC events When any of the following events occur: * VCC_PHONE off * nRST * RST we tranmsit the current req_ctx, if there is data pending. This ensures that for any successive data, the ATR flag in the next req_ctx containing the data, not in the previous req_ctx. It also ensures that the ATR is aligned at 0 offset in the new req_ctx, which is an assumption the host software makes but the previous code didn't ensure. Furthermore, we introduce a periodic flushing of any pending but incomplete req_ctx. --- firmware/src/simtrace/iso7816_uart.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'firmware/src/simtrace/iso7816_uart.c') diff --git a/firmware/src/simtrace/iso7816_uart.c b/firmware/src/simtrace/iso7816_uart.c index 611ccfb..780340f 100644 --- a/firmware/src/simtrace/iso7816_uart.c +++ b/firmware/src/simtrace/iso7816_uart.c @@ -575,6 +575,23 @@ void iso7816_wtime_expired(void) set_state(&isoh, ISO7816_S_WAIT_APDU); } +void iso_uart_flush(void) +{ + send_rctx(&isoh); +} + +void iso_uart_idleflush(void) +{ + static struct req_ctx *last_req = NULL; + static u_int16_t last_len = 0; + + if (last_req == isoh.rctx || last_len == isoh.rctx->tot_len) { + send_rctx(&isoh); + } + last_req = isoh.rctx; + last_len = isoh.rctx->tot_len; +} + static __ramfunc void usart_irq(void) { u_int32_t csr = usart->US_CSR; @@ -618,9 +635,13 @@ static __ramfunc void usart_irq(void) static void reset_pin_irq(u_int32_t pio) { if (!AT91F_PIO_IsInputSet(AT91C_BASE_PIOA, pio)) { + /* make sure to flush pending req_ctx */ + iso_uart_flush(); DEBUGPCR("nRST"); set_state(&isoh, ISO7816_S_RESET); } else { + /* make sure to flush pending req_ctx */ + iso_uart_flush(); DEBUGPCR("RST"); set_state(&isoh, ISO7816_S_WAIT_ATR); isoh.stats.rst++; -- cgit v1.2.3 From 7e3c9959e1e140753738be9b6d4142f6c2068e3d Mon Sep 17 00:00:00 2001 From: Min Xu Date: Sat, 25 Oct 2014 21:18:03 +0200 Subject: iso_uart: Print more errors, not just overruns --- firmware/src/simtrace/iso7816_uart.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'firmware/src/simtrace/iso7816_uart.c') diff --git a/firmware/src/simtrace/iso7816_uart.c b/firmware/src/simtrace/iso7816_uart.c index 780340f..e37deba 100644 --- a/firmware/src/simtrace/iso7816_uart.c +++ b/firmware/src/simtrace/iso7816_uart.c @@ -125,12 +125,18 @@ static const u_int8_t di_table[] = { 12, 20, 2, 4, 8, 16, 32, 64, }; -void iso_uart_report_overrun(void) +void iso_uart_report_errors(void) { - static unsigned lastOverrun = 0; + static unsigned lastOverrun = 0, lastParity = 0, lastFrame = 0; if (isoh.stats.overrun != lastOverrun) { DEBUGPCR("UART overrun: %u", lastOverrun = isoh.stats.overrun); } + if (isoh.stats.frame_err != lastFrame) { + DEBUGPCR("UART frame error: %u", lastFrame = isoh.stats.frame_err); + } + if (isoh.stats.parity_err != lastParity) { + DEBUGPCR("UART parity error: %u", lastParity = isoh.stats.parity_err); + } } void iso_uart_stats_dump(void) -- cgit v1.2.3 From 6bafd0cfb40c2d201f8723a3678dd4f04b380842 Mon Sep 17 00:00:00 2001 From: Min Xu Date: Sat, 25 Oct 2014 21:25:54 +0200 Subject: Don't split req_ctx with ATR payload The codnition for flushing a req_ctx on UART idle is fixed to flush only if 1) There has been no new data since last check, and 2) There are no req_ctx currently pending to be transmitted to USB, and 3) We did NOT just got a reset and waiting for ATR I saw an ATR split in two different req_ctx prior, presumably flush decided to send req_ctx after ATR but got a new character just before sent). If we did get a RESET, let original logic decide to send the req_ctx -- presumably when ATR data is fully received. --- firmware/src/simtrace/iso7816_uart.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'firmware/src/simtrace/iso7816_uart.c') diff --git a/firmware/src/simtrace/iso7816_uart.c b/firmware/src/simtrace/iso7816_uart.c index e37deba..9e8ace9 100644 --- a/firmware/src/simtrace/iso7816_uart.c +++ b/firmware/src/simtrace/iso7816_uart.c @@ -591,7 +591,10 @@ void iso_uart_idleflush(void) static struct req_ctx *last_req = NULL; static u_int16_t last_len = 0; - if (last_req == isoh.rctx || last_len == isoh.rctx->tot_len) { + if (last_req == isoh.rctx && + last_len == isoh.rctx->tot_len && + req_ctx_count(RCTX_STATE_UDP_EP2_PENDING) == 0 && + (isoh.sh.flags & SIMTRACE_FLAG_ATR) == 0) { send_rctx(&isoh); } last_req = isoh.rctx; -- cgit v1.2.3