From 47ee283d14c94d65e84e40410b8fcbf6c924508d Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 29 Feb 2016 10:09:46 +0100 Subject: [PATCH] card_emu_io_statechg(): properly determine edges from levels The caller might not have edge triggering and just gives us the current state. we have to use that informtaion to determine the edges when something is actually switched on or off. --- firmware/src_simtrace/card_emu.c | 35 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/firmware/src_simtrace/card_emu.c b/firmware/src_simtrace/card_emu.c index 55d227ff..cf3f87b5 100644 --- a/firmware/src_simtrace/card_emu.c +++ b/firmware/src_simtrace/card_emu.c @@ -772,27 +772,38 @@ void card_emu_io_statechg(struct card_handle *ch, enum card_io io, int active) { switch (io) { case CARD_IO_VCC: - if (active == 0) { + if (active == 0 && ch->vcc_active == 1) { + TRACE_DEBUG("VCC deactivated\n\r"); tc_etu_disable(ch->tc_chan); card_set_state(ch, ISO_S_WAIT_POWER); - } else if (active == 1 && ch->vcc_active == 0) + } else if (active == 1 && ch->vcc_active == 0) { + TRACE_DEBUG("VCC activated\n\r"); card_set_state(ch, ISO_S_WAIT_CLK); + } ch->vcc_active = active; break; case CARD_IO_CLK: - if (active == 1 && ch->state == ISO_S_WAIT_CLK) - card_set_state(ch, ISO_S_WAIT_RST); + if (active == 1 && ch->clocked == 0) { + TRACE_DEBUG("CLK activated\n\r"); + if (ch->state == ISO_S_WAIT_CLK) + card_set_state(ch, ISO_S_WAIT_RST); + } else if (active == 0 && ch->clocked == 1) { + TRACE_DEBUG("CLK deactivated\n\r"); + } ch->clocked = active; break; case CARD_IO_RST: - if (active == 0 && ch->in_reset && - ch->vcc_active && ch->clocked) { - /* enable the TC/ETU counter once reset has been released */ - tc_etu_enable(ch->tc_chan); - card_set_state(ch, ISO_S_WAIT_ATR); - /* FIXME: wait 400 to 40k clock cycles before sending ATR */ - card_set_state(ch, ISO_S_IN_ATR); - } else if (active) { + if (active == 0 && ch->in_reset) { + TRACE_DEBUG("RST released\n\r"); + if (ch->vcc_active && ch->clocked) { + /* enable the TC/ETU counter once reset has been released */ + tc_etu_enable(ch->tc_chan); + card_set_state(ch, ISO_S_WAIT_ATR); + /* FIXME: wait 400 to 40k clock cycles before sending ATR */ + card_set_state(ch, ISO_S_IN_ATR); + } + } else if (active && !ch->in_reset) { + TRACE_DEBUG("RST asserted\n\r"); tc_etu_disable(ch->tc_chan); } ch->in_reset = active;