aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/src/simtrace/iso7816_uart.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2014-11-11 22:31:27 +0100
committerHarald Welte <laforge@gnumonks.org>2014-11-11 22:31:27 +0100
commit5a40e2fed18ed75c7b8d62f52cf4a7c660a8e026 (patch)
treebce986dd5ab366dd141456f842c887868b73db7a /firmware/src/simtrace/iso7816_uart.c
parent3c85f8de8d394eaea5ed7f6e2675201d079e227b (diff)
parentb6caca4b64a73d8d3ab4ce6b51cea71b8f1a54b0 (diff)
Merge branch 'minxu-fixes'
Diffstat (limited to 'firmware/src/simtrace/iso7816_uart.c')
-rw-r--r--firmware/src/simtrace/iso7816_uart.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/firmware/src/simtrace/iso7816_uart.c b/firmware/src/simtrace/iso7816_uart.c
index 52522c0..9e8ace9 100644
--- a/firmware/src/simtrace/iso7816_uart.c
+++ b/firmware/src/simtrace/iso7816_uart.c
@@ -125,6 +125,20 @@ static const u_int8_t di_table[] = {
12, 20, 2, 4, 8, 16, 32, 64,
};
+void iso_uart_report_errors(void)
+{
+ 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)
{
DEBUGPCRF("no_rctx: %u, rctx_sent: %u, rst: %u, pps: %u, bytes: %u, "
@@ -567,6 +581,26 @@ 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 &&
+ req_ctx_count(RCTX_STATE_UDP_EP2_PENDING) == 0 &&
+ (isoh.sh.flags & SIMTRACE_FLAG_ATR) == 0) {
+ 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;
@@ -610,9 +644,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++;
@@ -675,6 +713,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 */