arduino / arduino/ArduinoCore-avr
attachInterrupt safety
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
The `attachInterrupt` function changes a 16 bit function address, which requires multiple processor instructions. If the interrupt fires halfway through this address change, the processor will jump to an invalid address.
This is only an issue if the interrupt is already enabled.
The way I see it, this issue can be solved by:
- Disabling the interrupt while changing the address
- Documenting that it is not safe to call `attachInterrupt` multiple times on the same interrupt without calling `detachInterrupt` between. Or documenting that it can be done, but only if one disables interrupts while performing the action.
If I am wrong and the AVR has an atomic 16 bit memory write operation of which I am unaware, I would love to be enlightened.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the attachInterrupt implementation in ArduinoCore-avr and trace how the 16-bit function address is updated when an interrupt is already enabled. Check the AVR interrupt and memory-write constraints, then review the related detachInterrupt behavior and documentation. Done means the safety behavior or its documented usage is unambiguous and covers repeated attachment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100