fix timer overflow?

This commit is contained in:
2026-04-15 11:00:48 +03:00
parent 8631f23b53
commit 8daff9c46a
7 changed files with 89 additions and 50 deletions

View File

@ -161,7 +161,9 @@ class SimState:
def first_rx(st: SimState) -> None:
"""IR_DecoderRaw::firstRX сброс буфера; isRecive/isReciveRaw в прошивке здесь не меняются."""
"""Аналог IR_DecoderRaw::firstRX: сброс буфера битов, преамбулы, счётчиков ошибок по битам.
В прошивке isRecive / isReciveRaw сбрасывают вызывающие пути (listenStart, checkTimeout, конец кадра);
затем firstRX() обнуляет буфер и preambleResetToIdle()."""
st.is_preamb = True
st.is_wrong_pack = False
st.is_buffer_overflow = False
@ -188,11 +190,18 @@ def tick(
rise_max = rise_sync_time + TOLERANCE_US
irmax = IR_TIMEOUT # упрощ.: без подстройки riseSyncTime в timeout
# listenStart: обрыв незавершённого приёма
if st.is_recive_raw and (t_us - st.prev_rise) > irmax * 2:
# listenStart: как IR_DecoderRaw — пауза по lastEdgeTime (между обработанными фронтами), не по prevRise.
if st.last_edge > 0 and st.is_recive_raw and (t_us - st.last_edge) > irmax * 2:
st.is_recive_raw = False
first_rx(st)
# checkTimeout: как IR_DecoderRaw после фикса — isReciveRaw=0 и firstRX(), иначе залипание FSM.
if st.last_edge > 0 and st.is_recive and (t_us - st.last_edge) > irmax * 2:
st.is_recive = False
st.is_recive_raw = False
first_rx(st)
# Не подставлять last_edge = t_us здесь: как IR_DecoderRaw после фикса.
st.last_edge = t_us
skip_rest = False
@ -307,6 +316,7 @@ def tick(
if st.is_buffer_overflow or st.is_preamb or st.is_wrong_pack:
st.is_recive = False
st.is_recive_raw = False
first_rx(st)
return
if st.buf_bit_pos == st.next_control_bit:
st.next_control_bit += SYNC_BITS if st.is_data else BIT_PER_BYTE
@ -345,7 +355,7 @@ def tick(
st.packets.append((ok, st.pack_size, bytes(st.data_buffer[: st.pack_size])))
st.is_recive = False
st.is_recive_raw = False
# буфер не чистят здесь — как в IR_DecoderRaw; firstRX по listenStart
# Как в IR_DecoderRaw: буфер не чистят на успешном CRC; сброс по listenStart/checkTimeout/firstRX
if around_rise_period(st.rise_period, rise_sync_time):
if st.high_time > st.low_time: