Change in simtrace2[master]: initialize VCC, RST, and VCC with actual values

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

tsaitgaist gerrit-no-reply at lists.osmocom.org
Thu Nov 14 18:54:12 UTC 2019


tsaitgaist has uploaded this change for review. ( https://gerrit.osmocom.org/c/simtrace2/+/16076 )


Change subject: initialize VCC, RST, and VCC with actual values
......................................................................

initialize VCC, RST, and VCC with actual values

previously the card RST, VCC, and CLK signal states have been initialized with
default values corresponding to an inactive reader.
this worked fine for actual inactive readers since the default values match
and would be updated when the signal changes (edge detection).
but if the reader is in another state, card activation detection could fail.
this is fixed since the actual signal values are now used during initialisation.

at the same time I changed the variable type from uint8_t to boolean since they
have only two possible states, and understanding the actual state when coding
is simpler (no need to check which integer corresponds to which state).

this change has been successfully tested on the 2 slots of OWHW board.

Change-Id: Ie9245d75d48ae93d16f97897d4fa5ad6cd402e73
---
M firmware/libcommon/include/card_emu.h
M firmware/libcommon/source/card_emu.c
M firmware/libcommon/source/mode_cardemu.c
M firmware/test/card_emu_tests.c
4 files changed, 27 insertions(+), 20 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/76/16076/1

diff --git a/firmware/libcommon/include/card_emu.h b/firmware/libcommon/include/card_emu.h
index a3c1cf2..e545593 100644
--- a/firmware/libcommon/include/card_emu.h
+++ b/firmware/libcommon/include/card_emu.h
@@ -29,8 +29,18 @@
 	CARD_IO_CLK,
 };
 
-struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan,
-				  uint8_t in_ep, uint8_t irq_ep);
+/** initialise card slot
+ *  @param[in] slot_num slot number (arbitrary number)
+ *  @param[in] tc_chan timer counter channel (to measure the ETU)
+ *  @param[in] uart_chan UART peripheral channel
+ *  @param[in] in_ep USB IN end point number
+ *  @param[in] irq_ep USB INTerrupt end point number
+ *  @param[in] vcc_active initial VCC signal state (true = on)
+ *  @param[in] in_reset initial RST signal state (true = reset asserted)
+ *  @param[in] clocked initial CLK signat state (true = active)
+ *  @return main card handle reference
+ */
+struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan, uint8_t in_ep, uint8_t irq_ep, bool vcc_active, bool in_reset, bool clocked);
 
 /* process a single byte received from the reader */
 void card_emu_process_rx_byte(struct card_handle *ch, uint8_t byte);
diff --git a/firmware/libcommon/source/card_emu.c b/firmware/libcommon/source/card_emu.c
index b7d0e1f..087867f 100644
--- a/firmware/libcommon/source/card_emu.c
+++ b/firmware/libcommon/source/card_emu.c
@@ -182,9 +182,9 @@
 	enum iso7816_3_card_state state;
 
 	/* signal levels */
-	uint8_t vcc_active;	/* 1 = on, 0 = off */
-	uint8_t in_reset;	/* 1 = RST low, 0 = RST high */
-	uint8_t clocked;	/* 1 = active, 0 = inactive */
+	bool vcc_active;	/*< if VCC is active (true = active/ON) */
+	bool in_reset;	/*< if card is in reset (true = RST low/asserted, false = RST high/ released) */
+	bool clocked;	/*< if clock is active ( true = active, false = inactive) */
 
 	/* timing parameters, from PTS */
 	uint8_t fi;
@@ -1126,8 +1126,7 @@
 
 static struct card_handle card_handles[NUM_SLOTS];
 
-struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan,
-				  uint8_t in_ep, uint8_t irq_ep)
+struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan, uint8_t in_ep, uint8_t irq_ep, bool vcc_active, bool in_reset, bool clocked)
 {
 	struct card_handle *ch;
 
@@ -1140,14 +1139,13 @@
 
 	INIT_LLIST_HEAD(&ch->uart_tx_queue);
 
-	/* initialize the card_handle with reasonable defaults */
 	ch->num = slot_num;
 	ch->irq_ep = irq_ep;
 	ch->in_ep = in_ep;
 	ch->state = ISO_S_WAIT_POWER;
-	ch->vcc_active = 0;
-	ch->in_reset = 1;
-	ch->clocked = 0;
+	ch->vcc_active = vcc_active;
+	ch->in_reset = in_reset;
+	ch->clocked = clocked;
 
 	ch->fi = 0;
 	ch->di = 1;
diff --git a/firmware/libcommon/source/mode_cardemu.c b/firmware/libcommon/source/mode_cardemu.c
index 98818e1..2d1a687 100644
--- a/firmware/libcommon/source/mode_cardemu.c
+++ b/firmware/libcommon/source/mode_cardemu.c
@@ -44,7 +44,7 @@
 static const Pin pin_usim1_vcc	= PIN_USIM1_VCC;
 
 #ifdef CARDEMU_SECOND_UART
-static const Pin pins_usim2[]    = {PINS_USIM2};
+static const Pin pins_usim2[]	= {PINS_USIM2};
 static const Pin pin_usim2_rst	= PIN_USIM2_nRST;
 static const Pin pin_usim2_vcc	= PIN_USIM2_VCC;
 #endif
@@ -357,14 +357,14 @@
 
 static void usim1_rst_irqhandler(const Pin *pPin)
 {
-	int active = PIO_Get(&pin_usim1_rst) ? 0 : 1;
+	bool active = PIO_Get(&pin_usim1_rst) ? false : true;
 	card_emu_io_statechg(cardem_inst[0].ch, CARD_IO_RST, active);
 }
 
 #ifndef DETECT_VCC_BY_ADC
 static void usim1_vcc_irqhandler(const Pin *pPin)
 {
-	int active = PIO_Get(&pin_usim1_vcc) ? 1 : 0;
+	bool active = PIO_Get(&pin_usim1_vcc) ? true : false;
 	card_emu_io_statechg(cardem_inst[0].ch, CARD_IO_VCC, active);
 	/* FIXME do this for real */
 	card_emu_io_statechg(cardem_inst[0].ch, CARD_IO_CLK, active);
@@ -374,14 +374,14 @@
 #ifdef CARDEMU_SECOND_UART
 static void usim2_rst_irqhandler(const Pin *pPin)
 {
-	int active = PIO_Get(&pin_usim2_rst) ? 0 : 1;
+	bool active = PIO_Get(&pin_usim2_rst) ? false : true;
 	card_emu_io_statechg(cardem_inst[1].ch, CARD_IO_RST, active);
 }
 
 #ifndef DETECT_VCC_BY_ADC
 static void usim2_vcc_irqhandler(const Pin *pPin)
 {
-	int active = PIO_Get(&pin_usim2_vcc) ? 1 : 0;
+	bool active = PIO_Get(&pin_usim2_vcc) ? true : false;
 	card_emu_io_statechg(cardem_inst[1].ch, CARD_IO_VCC, active);
 	/* FIXME do this for real */
 	card_emu_io_statechg(cardem_inst[1].ch, CARD_IO_CLK, active);
@@ -420,7 +420,7 @@
 	PIO_ConfigureIt(&pin_usim1_vcc, usim1_vcc_irqhandler);
 	PIO_EnableIt(&pin_usim1_vcc);
 #endif /* DETECT_VCC_BY_ADC */
-	cardem_inst[0].ch = card_emu_init(0, 2, 0, SIMTRACE_CARDEM_USB_EP_USIM1_DATAIN, SIMTRACE_CARDEM_USB_EP_USIM1_INT);
+	cardem_inst[0].ch = card_emu_init(0, 2, 0, SIMTRACE_CARDEM_USB_EP_USIM1_DATAIN, SIMTRACE_CARDEM_USB_EP_USIM1_INT, PIO_Get(&pin_usim1_vcc) ? true : false, PIO_Get(&pin_usim1_rst) ? false : true, PIO_Get(&pin_usim1_vcc) ? true : false);
 	sim_switch_use_physical(0, 1);
 
 #ifdef CARDEMU_SECOND_UART
@@ -435,10 +435,9 @@
 	PIO_ConfigureIt(&pin_usim2_vcc, usim2_vcc_irqhandler);
 	PIO_EnableIt(&pin_usim2_vcc);
 #endif /* DETECT_VCC_BY_ADC */
-	cardem_inst[1].ch = card_emu_init(1, 0, 1, SIMTRACE_CARDEM_USB_EP_USIM2_DATAIN, SIMTRACE_CARDEM_USB_EP_USIM2_INT);
+	cardem_inst[1].ch = card_emu_init(1, 0, 1, SIMTRACE_CARDEM_USB_EP_USIM2_DATAIN, SIMTRACE_CARDEM_USB_EP_USIM2_INT, PIO_Get(&pin_usim2_vcc) ? true : false, PIO_Get(&pin_usim2_rst) ? false : true, PIO_Get(&pin_usim2_vcc) ? true : false);
 	sim_switch_use_physical(1, 1);
 #endif /* CARDEMU_SECOND_UART */
-
 }
 
 /* called if config is deactivated */
diff --git a/firmware/test/card_emu_tests.c b/firmware/test/card_emu_tests.c
index 09b2e0d..fe1739b 100644
--- a/firmware/test/card_emu_tests.c
+++ b/firmware/test/card_emu_tests.c
@@ -397,7 +397,7 @@
 	struct card_handle *ch;
 	unsigned int i;
 
-	ch = card_emu_init(0, 23, 42, PHONE_DATAIN, PHONE_INT);
+	ch = card_emu_init(0, 23, 42, PHONE_DATAIN, PHONE_INT, false, true, false);
 	assert(ch);
 
 	usb_buf_init();

-- 
To view, visit https://gerrit.osmocom.org/c/simtrace2/+/16076
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-Change-Id: Ie9245d75d48ae93d16f97897d4fa5ad6cd402e73
Gerrit-Change-Number: 16076
Gerrit-PatchSet: 1
Gerrit-Owner: tsaitgaist <kredon at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191114/5b497c65/attachment.htm>


More information about the gerrit-log mailing list