aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKévin Redon <kredon@sysmocom.de>2020-03-26 01:47:12 +0100
committerHarald Welte <laforge@osmocom.org>2021-04-06 02:17:39 +0200
commitb6e421bcbede4750ed59bc7a87a36b0b9370a685 (patch)
tree0def5f73da588a7bf095c1a6f511b43ab5e157e2
parente145a7aed4b109ce1dc3b8907dbed52611ce6ed4 (diff)
card_emu: use edge-triggered VCC ADC logic
Before this patch, we used to st ci->vcc_active depending on the instantaneous ADC reading of VCC. Is it > .5v, we claim VCC is active, and if it's below, VCC is inactive. With this patch we move to an edge triggered approach: Only change ci->vcc_active if the previous reading was different from the current reading. FIXME: why? Change-Id: I71b703162219484e43638f1f2f692e9dd554ef55
-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 127556c..2930e73 100644
--- a/firmware/libcommon/source/mode_cardemu.c
+++ b/firmware/libcommon/source/mode_cardemu.c
@@ -70,6 +70,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;
@@ -233,6 +234,7 @@ static uint16_t compute_next_timeout(struct cardem_inst *ci)
* \param[in] inst_num Instance number, range 0..1 (some boards only '0' permitted) */
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;
@@ -441,10 +443,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)