From aac131508723edc9c74b95e8c4de3f99634201bb Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 18 Jul 2023 17:52:56 +0200 Subject: [PATCH] LF EM: make sure to sample the field only during the last no-mod half bit of a series of ID broadcasts --- .../src/rfid/nfctag/lf/lf_tag_em.c | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/firmware/application/src/rfid/nfctag/lf/lf_tag_em.c b/firmware/application/src/rfid/nfctag/lf/lf_tag_em.c index d32252d..8163425 100644 --- a/firmware/application/src/rfid/nfctag/lf/lf_tag_em.c +++ b/firmware/application/src/rfid/nfctag/lf/lf_tag_em.c @@ -125,6 +125,7 @@ uint64_t em410x_id_to_memory64(uint8_t id[5]) { } void timer_ce_handler(nrf_timer_event_t event_type, void* p_context) { + bool mod; switch (event_type) { // 因为我们配置的是使用CC通道2,所以事件回调 // 函数中判断NRF_TIMER_EVENT_COMPARE0事件 @@ -133,29 +134,30 @@ void timer_ce_handler(nrf_timer_event_t event_type, void* p_context) { if (GETBIT(m_id_bit_data, m_bit_send_position)) { // 发送 1 的第一个沿 ANT_TO_MOD(); + mod = true; } else { // 发送 0 的第一个沿 ANT_NO_MOD(); + mod = false; } m_is_send_first_edge = false; // 下次发送第二个沿 } else { if (GETBIT(m_id_bit_data, m_bit_send_position)) { // 发送 1 的第二个沿 ANT_NO_MOD(); + mod = false; } else { // 发送 0 的第二个沿 ANT_TO_MOD(); + mod = true; } m_is_send_first_edge = true; // 下次发送第一个沿 - if (++m_bit_send_position >= LF_125KHZ_EM410X_BIT_SIZE) { - m_bit_send_position = 0; // 广播一次成功,bit位置归零 - ++m_send_id_count; // 统计广播次数 - } } - // 如果广播次数超过上限次数,则重新比较场状态,根据新的场状态选择是否继续模拟标签 - if (m_send_id_count >= LF_125KHZ_BORADCAST_MAX) { - m_send_id_count = 0; // 广播次数达到上限,重新识别场状态并且重新统计广播次数 + // measure field only during no-mod half of last bit of last broadcast + if ((! mod) && + (m_bit_send_position + 1 >= LF_125KHZ_EM410X_BIT_SIZE) && + (m_send_id_count + 1 >= LF_125KHZ_BORADCAST_MAX)) { nrfx_timer_disable(&m_timer_send_id); // 关闭广播场的定时器 // 我们不需要任何的事件,仅仅需要检测一下场的状态 NRF_LPCOMP->INTENCLR = LPCOMP_INTENCLR_CROSS_Msk | LPCOMP_INTENCLR_UP_Msk | LPCOMP_INTENCLR_DOWN_Msk | LPCOMP_INTENCLR_READY_Msk; @@ -172,6 +174,15 @@ void timer_ce_handler(nrf_timer_event_t event_type, void* p_context) { NRF_LOG_INFO("LF FIELD LOST"); } } + + if (m_is_send_first_edge == true) { // 下次发送第一个沿 + if (++m_bit_send_position >= LF_125KHZ_EM410X_BIT_SIZE) { + m_bit_send_position = 0; // 广播一次成功,bit位置归零 + if (++m_send_id_count >= LF_125KHZ_BORADCAST_MAX) { + m_send_id_count = 0; // 广播次数达到上限,重新识别场状态并且重新统计广播次数 + } + } + } break; } default: {