Skip to content

Separate RadioLib ISR events from main radio mode#2062

Open
robekl wants to merge 1 commit intomeshcore-dev:devfrom
robekl:fix-radiolib-isr-state-handoff
Open

Separate RadioLib ISR events from main radio mode#2062
robekl wants to merge 1 commit intomeshcore-dev:devfrom
robekl:fix-radiolib-isr-state-handoff

Conversation

@robekl
Copy link
Contributor

@robekl robekl commented Mar 17, 2026

Summary

This fixes the RadioLib wrapper ISR handoff by separating interrupt events from the main radio mode state.

Problem

RadioLibWrapper currently shares a single volatile uint8_t state between ISR and normal code:

  • the RadioLib interrupt callback does state |= STATE_INT_READY
  • main code repeatedly overwrites that same variable with assignments like state = STATE_IDLE, state = STATE_RX, and state = STATE_TX_WAIT

That is not an atomic synchronization scheme. volatile only prevents caching; it does not make read-modify-write operations safe. An interrupt can arrive between the load and store of one of those assignments, causing a completion event to be lost.

That can show up as missed send-complete / receive-complete notifications and inconsistent mode transitions.

Fix

This PR removes the overloaded shared state byte and splits the responsibilities:

  • radio_mode is now main-context only and tracks IDLE, RX, or TX_WAIT
  • pending_interrupt_events is ISR-owned and only records completion events
  • the ISR only increments the pending-event counter
  • main code claims and clears pending events atomically inside a very short interrupt-disabled section

The wrapper now reasons about:

  • mode transitions using radio_mode
  • interrupt completion using the claimed event count

instead of trying to encode both into one shared variable.

Why this fixes it

Main code no longer overwrites an ISR-owned bitfield. The ISR publishes completion events into its own channel, and the main loop claims them explicitly before acting.

That removes the lost-interrupt window that existed when the code mixed plain assignments and ISR-side bit-setting on the same byte.

Validation

Built successfully:

  • Heltec_v3_repeater

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant