cardem: use TC_ETU to trigger ATR sending

this changes how ATR is handled.
the ATR is also printed when set (as important debug information).
the test is also updated to correspond to the new mechanism (
simulating the timeout before sending the ATR)

Change-Id: I69df797e2feadffa9f5f977cb71b69386cee7cd0
diff --git a/firmware/libcommon/source/mode_cardemu.c b/firmware/libcommon/source/mode_cardemu.c
index 57d541b..76b3a01 100644
--- a/firmware/libcommon/source/mode_cardemu.c
+++ b/firmware/libcommon/source/mode_cardemu.c
@@ -1,6 +1,7 @@
 /* card emulation mode
  *
  * (C) 2015-2017 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2018 by sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -98,15 +99,11 @@
 
 static Usart *get_usart_by_chan(uint8_t uart_chan)
 {
-	switch (uart_chan) {
-	case 0:
-		return USART1;
-#ifdef CARDEMU_SECOND_UART
-	case 1:
-		return USART0;
-#endif
+	if (uart_chan < ARRAY_SIZE(cardem_inst)) {
+		return cardem_inst[uart_chan].usart_info.base;
+	} else {
+		return NULL;
 	}
-	return NULL;
 }
 
 /***********************************************************************
@@ -244,6 +241,20 @@
 	return 0;
 }
 
+/* call-back from card_emu.c to force a USART interrupt */
+void card_emu_uart_interrupt(uint8_t uart_chan)
+{
+	Usart *usart = get_usart_by_chan(uart_chan);
+	if (!usart) {
+		return;
+	}
+	if (USART0 == usart) {
+		NVIC_SetPendingIRQ(USART0_IRQn);
+	} else if (USART1 == usart) {
+		NVIC_SetPendingIRQ(USART1_IRQn);
+	}
+}
+
 /***********************************************************************
  * ADC for VCC voltage detection
  ***********************************************************************/