-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Only include timer0 overflow ISR and initialization when it is actually used. #320
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
base: master
Are you sure you want to change the base?
Conversation
This moves all timer0-related code into a new file wiring_systick.c. This is a preparation for a next commit, to allow this code to be included only when linked. The delayMicroseconds function is not included in this file, since it does not actually use the timer but does cycle counting (but for consistency, it is moved into its own file instead). This commit only moves code and fixes some whitespace in the process, it does not actually change anything else.
This prevents pulling in wiring_systick.c, thus omitting timer0 setup and ISR, unless any of delay(), millis(), or micros() are actually used.
@facchinm, did you guys have some script to do a bulk compile of all examples or something similar? I think it would be nice to see the impact of this change against a number of examples or real-world sketches. I wrote a script for that a long time ago, but that's probably out of date now (should maybe be updated to arduino-cli, but no point in that if there is something out there already). |
This is very clever indeed, thanks you very much for submitting it! I'll forward this to the cloud team for a mass compile against Create examples. |
Ah, ther's a cloud-based mass compile tool there, nice! Any of that open? And does it allow comparing things (like compilation failures or sketch sizes with/without a PR applied)? |
@facchinm, any idea about whether this has bee ndone? Would be nice to move this change forward. |
No ETA yet, sorry 😞 |
This applies the same trick we used for HardwareSerial to the timer0-related functions. With this PR, if none of
delay
,millis
ormicros
is used, the timer0 overlow ISR is not included and enabled.This has two advantages:
Note that delayMicroseconds is not included in the above list, since it does not use timer0 but does cycle counting, so can still be used without pulling in the timer0 ISR.
This is implemented by putting the timer0 related code in a separate .c file, which is only pulled in if any of these functions are referenced (this happens because the core is linked through an .a file). To prevent the (new)
init_systick()
initialization function, which is called frominit()
inwiring.c
to pull in the file, a weak definition ofinit_systick()
is included inwiring.c
which is replaced by the real definition fromwiring_systick.c
if any of the timer functions are used.Without this PR, compiling the bare minimum sketch gives:
With this PR applied, the result is:
This PR is the result of some discussion in the #arduino IRC channel between @rlcamp and myself. @rlcamp implemented most of this PR, I reviewed it and made some perfectioning changes.