-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Switch SAMD21 ticks to PER event #5100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I tested this PR using pulsein for a DHT11 on a Metro M0 Express. It consistently failed with too few pulses (between 69 and 73). The protocol is expecting 81 pulses. I will see if I can determine the cause. |
It looks like the issue is that the line: |
Why does the duration of setting interrupt after tick matter? It should be interruptable by the pulsein code. |
The time it takes to set and synchronize the COMP register is longer than some incoming pulses; and does not seem to be interruptible. This means we cannot afford to do that while an incoming pulse is taking place. As painful as it is, I think we need a way to simply avoid the COMP setting while in a pulse. I did some testing with a boolean flag that returns from port_interrupt_after_ticks() in supervisor/port.c before hitting the COMP statement. It is set in pulsein_interrupt_handler( ) in PulseIn.c when self->first_edge is true (i.e. at the very start of a pulse) and then is reset in common_hal_pulseio_pulsein_popleft() and common_hal_pulseio_pulsein_get_len() when self->len is 0 (i.e. as soon as possible at the the end of a pulse). This seems to work, allowing auto-reloads to work. I realize that there may be a slight delay if the reload gets scheduled while we're in the midst of an incoming pulse; but that window is ~4ms for a DHT and ~68ms for an irremote. |
The EVSYS is used to generate an interrupt from the event. This simplifies timing used in pulseio that conflicted with the auto-reload countdown. Fixes micropython#3890
9a8ae69
to
f0859ac
Compare
Ok, @DavePutz. I added back the COMP set disable. I couldn't find a way to make it not stall the interrupt processing. It doesn't impact ticks anymore though because they use a separate EVSYS interrupt now. |
I have found that moving the rtc_start_pulse from common_hal_pulseio_pulsein_construct to the pulsein_interrupt_handler
Other than that the PR looks good. |
Adds CIRCUITPY_BUSIO_UART to disable UART by raising ValueError that no pins work.
@DavePutz I don't want to move it to the interrupt handler because it could be delayed by a sleep. I did add a start/stop in resume/pause so that sleep will be allowed when pulsein is paused. |
This leaves much more space on SAMD21 builds that aren't "full builds". These are new APIs that we don't need to add to old boards. Also, tweak two Arduino boards to save space on them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! No testing performed.
The EVSYS is used to generate an interrupt from the event. This
simplifies timing used in pulseio that conflicted with the
auto-reload countdown.
Fixes #3890