Skip to content

Commit

Permalink
Improve checksum per gnea#158
Browse files Browse the repository at this point in the history
 Per gnea#158  The logical OR squashes the previous checksum down to 1 bit of information, resulting in the final checksum being either the last character written, or one plus the last character written.

This change switches to the bitwise-or to convert the squashing into a 1-bit roll to the left.
  • Loading branch information
drf5n authored Apr 11, 2022
1 parent df87b36 commit ccae213
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions grbl/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void eeprom_put_char( unsigned int addr, unsigned char new_value )
void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size) {
unsigned char checksum = 0;
for(; size > 0; size--) {
checksum = (checksum << 1) || (checksum >> 7);
checksum = (checksum << 1) | (checksum >> 7);
checksum += *source;
eeprom_put_char(destination++, *(source++));
}
Expand All @@ -141,7 +141,7 @@ int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, uns
unsigned char data, checksum = 0;
for(; size > 0; size--) {
data = eeprom_get_char(source++);
checksum = (checksum << 1) || (checksum >> 7);
checksum = (checksum << 1) | (checksum >> 7);
checksum += data;
*(destination++) = data;
}
Expand Down

0 comments on commit ccae213

Please sign in to comment.