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.
This commit is contained in:
Harald Welte
2016-02-29 10:09:46 +01:00
parent 99f62a6def
commit 47ee283d14

View File

@@ -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;