Skip to content
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

Avoid using floating point in the heartbeat code #132

Merged
merged 1 commit into from
Jan 5, 2021

Conversation

toofishes
Copy link
Contributor

Prior work in 2015 in this repository (commit 1c8ae71 and 52f3151)
had removed all uses of floating point, saving the flash memory needed
for floating point software routines.

More recently, floating point is used if HEARTBEAT_SUPERVISION is
enabled. By making a few small changes and adjusting things to use
integer math, we can save 600+ bytes of flash.

This also removes the deprecated function HsDeactivate which isn't
called from anywhere.

Before (with HEARTBEAT_SUPERVISION defined):

RAM:   [======    ]  65.0% (used 1331 bytes from 2048 bytes)
Flash: [========= ]  92.0% (used 30134 bytes from 32768 bytes)

After (with HEARTBEAT_SUPERVISION defined):

RAM:   [======    ]  65.0% (used 1331 bytes from 2048 bytes)
Flash: [========= ]  90.1% (used 29526 bytes from 32768 bytes)

Let me know if you want this script I used below- I can PR and include it in the repository! It is based off of https://github.com/torvalds/linux/blob/master/scripts/bloat-o-meter and tailored to work for platformio and C++ symbols. Here it is showing that several floating point functions were included before, and 608 bytes have been trimmed.

$ ./bloat-o-meter development_heartbeat_2020_12_09.elf .pio/build/openevse/firmware.elf
add/remove: 0/11 grow/shrink: 0/1 up/down: 0/-608 (-608)
function                                     old     new   delta
main                                        6276    6274      -2
__fp_nan                                       6       -      -6
__divsf3                                       8       -      -8
__fp_inf                                      12       -     -12
__fp_zero                                     14       -     -14
__fp_pscB                                     14       -     -14
__fp_pscA                                     14       -     -14
__fp_round                                    34       -     -34
__fp_split3                                   68       -     -68
__fixunssfsi                                  94       -     -94
__floatunsisf                                122       -    -122
__divsf3x                                    220       -    -220

int rc=1;
if ((m_HsInterval != 0) && (sinceLastPulse > m_HsInterval)) { //HEARTBEAT_SUPERVISION is currently active and the Heartbeat interval has timed out
if (m_HsInterval != 0 && sinceLastPulse > (m_HsInterval * 1000)) { //HEARTBEAT_SUPERVISION is currently active and the Heartbeat interval has timed out
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely double check my work here- by not dividing by 1000 on line 2093, we can multiply the other side of our comparison by 1000 on line 2095 and the logic is equivalent.

Prior work in 2015 in this repository (commit 1c8ae71 and 52f3151)
had removed all uses of floating point, saving the flash memory needed
for floating point software routines.

More recently, floating point is used if HEARTBEAT_SUPERVISION is
enabled. By making a few small changes and adjusting things to use
integer math, we can save 600+ bytes of flash.

This also removes the deprecated function `HsDeactivate` which isn't
called from anywhere.
@lincomatic lincomatic merged commit dd50ea9 into lincomatic:development Jan 5, 2021
@lincomatic
Copy link
Owner

thanks again for another great PR. Yes, the bloat-o-meter would be great. you can add it to the util directory

@toofishes toofishes deleted the no-floating-point branch May 2, 2021 17:15
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.

2 participants