These EEPROM functions originate from AVR libc. Some AVRs can actually map the EEPROM address space into data or program memory (which may or may not be the reason for the signature).As I read this code - it will take the passed in memory address and use that as the offset?
Code:void eeprom_write_word([U]uint16_t *addr[/U], uint16_t value) { uint32_t offset = (uint32_t)addr; if (offset >= EEPROM_SIZE-1) return; // ... *(uint16_t *)(&FlexRAM[offset]) = value; // ...
It seems to me all of these should just be expecting the EEPROM address (i.e. offset) - not some pointer?::
void eeprom_write_word(uint16_t addr, uint16_t value)
If you agree I can change the code and test - but I didn't bother before and now I remember why.
For Teensy, just think of the EEPROM as a separate address space starting at 0 and passing in an address makes some sense.
You don't want to change the signature, that will break code. Adding new functions like:
void eeprom_write_word(size_t offset, uint16_t value)
that cast offset to a "uint16_t*" and call
void eeprom_write_word(uint16_t *addr, uint16_t value)
may make sense. An inline function would get optimized away.
That wouldn't be C-compatible though (overloaded function), I don't know if that is a requirement.
Last edited: