Skip to content

Commit

Permalink
cardem: Report the VCC voltage (if supported)
Browse files Browse the repository at this point in the history
The SIMtrace2 protocol alwasy contained a field for the VCC voltage,
the cardem firmware just never populated that field, even on those
boards that use the ADC to determine its voltage.

Change-Id: Idcecad553fb36380e916378e1420488acbbfa8e3
  • Loading branch information
laf0rge committed Feb 14, 2022
1 parent 3a6f1ad commit 20bc014
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions firmware/libcommon/include/card_emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ void card_emu_uart_enable(uint8_t uart_chan, uint8_t rxtx);
void card_emu_uart_wait_tx_idle(uint8_t uart_chan);
void card_emu_uart_interrupt(uint8_t uart_chan);

int card_emu_get_vcc(uint8_t uart_chan);

struct cardemu_usb_msg_config;
int card_emu_set_config(struct card_handle *ch, const struct cardemu_usb_msg_config *scfg,
unsigned int scfg_len);
10 changes: 9 additions & 1 deletion firmware/libcommon/source/card_emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,10 @@ void card_emu_report_status(struct card_handle *ch, bool report_on_irq)
sts->flags |= CEMU_STATUS_F_CLK_ACTIVE;
if (ch->in_reset)
sts->flags |= CEMU_STATUS_F_RESET_ACTIVE;
/* FIXME: voltage + card insert */
#ifdef DETECT_VCC_BY_ADC
sts->voltage_mv = card_emu_get_vcc(ch->num);
#endif
/* FIXME: card insert */
sts->F_index = ch->F_index;
sts->D_index = ch->D_index;
sts->wi = ch->wi;
Expand Down Expand Up @@ -1102,7 +1105,12 @@ void card_emu_io_statechg(struct card_handle *ch, enum card_io io, int active)
card_set_state(ch, ISO_S_WAIT_POWER);
chg_mask |= CEMU_STATUS_F_VCC_PRESENT;
} else if (active == 1 && ch->vcc_active == 0) {
#ifdef DETECT_VCC_BY_ADC
TRACE_INFO("%u: VCC activated (%d mV)\r\n", ch->num,
card_emu_get_vcc(ch->num));
#else
TRACE_INFO("%u: VCC activated\r\n", ch->num);
#endif
card_set_state(ch, ISO_S_WAIT_CLK);
chg_mask |= CEMU_STATUS_F_VCC_PRESENT;
}
Expand Down
10 changes: 10 additions & 0 deletions firmware/libcommon/source/mode_cardemu.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ static void card_emu_uart_set_direction(uint8_t uart_chan, bool tx)
#endif
}

int card_emu_get_vcc(uint8_t uart_chan)
{
struct cardem_inst *ci = &cardem_inst[uart_chan];
#ifdef DETECT_VCC_BY_ADC
return ci->vcc_uv / 1000;
#else
return -1;
#endif
}

/* call-back from card_emu.c to enable/disable transmit and/or receive */
void card_emu_uart_enable(uint8_t uart_chan, uint8_t rxtx)
{
Expand Down

0 comments on commit 20bc014

Please sign in to comment.