avr-libc icon indicating copy to clipboard operation
avr-libc copied to clipboard

[bug #38192] eeprom_update_byte does not use bitwise AND

Open avrs-admin opened this issue 3 years ago • 0 comments

Tue 29 Jan 2013 12:23:56 PM CET

As described in AVR103, there is no need of erase cycle if new value match bitwise AND between the old value and the new value.

Patch below uses this functionality, eeprom endurance is higher and update time is reduced too.

% diff -u eeupd_byte.S.orig eeupd_byte.S
--- eeupd_byte.S.orig   2013-01-29 10:54:43.000000000 +0100
+++ eeupd_byte.S        2013-01-29 12:02:25.000000000 +0100
@@ -88,8 +88,14 @@
breq    2f

# if    defined (EEPM0) && defined (EEPM1)
-       ; Set programming mode: erase and write.
+       ; Set programming mode: write only
out **SFR_IO_ADDR (EECR), __zero_reg_**
+       sbi     _SFR_IO_ADDR (EECR),EEPM1
+       ;test bitwise AND
+       and __tmp_reg__, r18
+       cpse __tmp_reg__, r18
+       ; final value different, set programing mode: erase and write
+       cbi     _SFR_IO_ADDR (EECR),EEPM1
# elif  defined (EEPM0) || defined (EEPM1)
#  error       /* Unknown EECR register.       */
# endif

This issue was migrated from https://savannah.nongnu.org/bugs/?38192

avrs-admin avatar Jan 31 '22 01:01 avrs-admin