aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKévin Redon <kredon@sysmocom.de>2020-03-26 01:47:12 +0100
committerEric Wild <ewild@sysmocom.de>2020-04-10 02:09:21 +0200
commitb0d789e09dccbc1122ed6d5d00a14eba591c72f0 (patch)
tree0b9e330de1352c9c93afdd7e84bb8488e234f32e
parentae28d5a4c5fe3ab26eba09b1f861c0b67803200b (diff)
different voltage comparison on powerup
-rw-r--r--firmware/libcommon/source/mode_cardemu.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/firmware/libcommon/source/mode_cardemu.c b/firmware/libcommon/source/mode_cardemu.c
index 7a37317..1dbd2d3 100644
--- a/firmware/libcommon/source/mode_cardemu.c
+++ b/firmware/libcommon/source/mode_cardemu.c
@@ -62,6 +62,7 @@ struct cardem_inst {
const Pin pin_insert;
#ifdef DETECT_VCC_BY_ADC
uint32_t vcc_uv;
+ uint32_t vcc_uv_last;
#endif
bool vcc_active;
bool vcc_active_last;
@@ -197,6 +198,7 @@ int card_emu_uart_tx(uint8_t uart_chan, uint8_t byte)
/* FIXME: integrate this with actual irq handler */
static void usart_irq_rx(uint8_t inst_num)
{
+ OSMO_ASSERT(inst_num < ARRAY_SIZE(cardem_inst));
Usart *usart = get_usart_by_chan(inst_num);
struct cardem_inst *ci = &cardem_inst[inst_num];
uint32_t csr;
@@ -319,10 +321,14 @@ static int card_vcc_adc_init(void)
static void process_vcc_adc(struct cardem_inst *ci)
{
- if (ci->vcc_uv >= VCC_UV_THRESH_3V)
+ if (ci->vcc_uv >= VCC_UV_THRESH_3V &&
+ ci->vcc_uv_last < VCC_UV_THRESH_3V) {
ci->vcc_active = true;
- else
+ } else if (ci->vcc_uv < VCC_UV_THRESH_3V &&
+ ci->vcc_uv_last >= VCC_UV_THRESH_3V) {
ci->vcc_active = false;
+ }
+ ci->vcc_uv_last = ci->vcc_uv;
}
void ADC_IrqHandler(void)