-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
Fix esp8266 timer1 testing #2709
Conversation
…time. The is because a callback interrupt routine hasn't been set on the timer. This doesn't affect normal code which accesses the timer via HardwareTimer which contains logic to ensure this doesn't happen.
This is because it's only a 23-bit timer which limits maximum to about 1.7 seconds (test duration is 2 seconds). Fixed by restricting duration to timer maximum.
Check whether timer is an UP or DOWN counter Use timer maximum tick value to ensure counter wraps correctly
Runs more slowly on Host
PR Summary
|
@slaff Must remember to run HostTests on all chips (esp8266, rp2040, esp32, esp32c3, esp32s2 and esp32s3 if available) to catch stuff like this! Certainly before a major/minor release I think? |
Looking again at this today I've found an issue with Timer1 on the esp8266, for exactly the reason I gave above.
We expect the LED to toggle once then stop, but instead it keeps flashing at ~1.7s intervals. This is because the timer is still enabled and just keeps wrapping. Confirmed using So timer needs to be explicitly disabled in the callback. Adding this to the driver code is going to add latency, so will need to take a closer look at this. Suggestions welcome! |
@mikee47 ping me when this PR is ready. |
@slaff OK, done with this PR. |
This PR fixes an issue with `HostTests` which hangs consistently when testing Timer1 (used by HardwareTimer) on the Esp8266. The problem occurs whilst checking each timer for consistency against system time. This happens because the test code doesn't set a callback interrupt routine. It is only a problem on the Esp8266 because the callback routine is set directly on the interrupt vector. Other architectures use indirection and so do nothing if the callback isn't set. NB. Doing this with the Esp8266 would increase interrupt latency which would affect PWM timing, etc. Normal code uses the `HardwareTimer` class which contains logic to ensure this doesn't happen during setup. Timer1 has only a 23-bit counter so fails test with /16 divisor as it wraps at around 1.7s (test duration is 2 seconds). Fixed by restricting duration to timer maximum (less 1ms). Elapsed tick calculation check also improved by first checking whether timer is an UP or DOWN counter, and using timer maximum tick value to handle wraps correctly. This PR also reduces the number of test loops on the Host (from 2000 to 50). Note: Bug was introduced in #2456. Timer1 needed to be correctly configured (but inactive) to produce correct result for Esp32.
This PR fixes an issue with
HostTests
which hangs consistently when testing Timer1 (used by HardwareTimer) on the Esp8266.The problem occurs whilst checking each timer for consistency against system time.
This happens because the test code doesn't set a callback interrupt routine.
It is only a problem on the Esp8266 because the callback routine is set directly on the interrupt vector.
Other architectures use indirection and so do nothing if the callback isn't set.
NB. Doing this with the Esp8266 would increase interrupt latency which would affect PWM timing, etc.
Normal code uses the
HardwareTimer
class which contains logic to ensure this doesn't happen during setup.Timer1 has only a 23-bit counter so fails test with /16 divisor as it wraps at around 1.7s (test duration is 2 seconds).
Fixed by restricting duration to timer maximum (less 1ms).
Elapsed tick calculation check also improved by first checking whether timer is an UP or DOWN counter,
and using timer maximum tick value to handle wraps correctly.
This PR also reduces the number of test loops on the Host (from 2000 to 50).
Note: Bug was introduced in #2456. Timer1 needed to be correctly configured (but inactive) to produce correct result for Esp32.