If I have a hardware device that has, say, battery backed SRAM, is there a way that I can access it using variables rather than addresses? (I have the code for reading and writing the BB sram already, of course).
To clarify, imagine Arduino EEPROM. Most people use it like this:
#include EEPROM.h uint8_t v = 10; EEPROM.write (0, 10); // write to EEPROM address zero v = EEPROM.read (0); // read back from EEPROM address 0 // v should read back as "10"
However, the proper way to use EEPROM is:
uint8_t n EEMEM; // place n in eeprom uint8_t v = 10; eeprom_write_byte (&n, v); // write v to n (in eeprom) v = eeprom_read_byte (&n); // read eeprom n into v // v should read back as "10"
By using EEMEM, I don't need to worry WHERE "n" is, nor do I need to worry what size it is (8 bit, 16 bit, etc...)
Now, I want to do the same thing with MY "memory". Say I have functions to read and write data to battery backed SRAM on an RTC clock chip like this:
value = sram_read_byte (uint8_t addr);
sram_write_byte (uint8_t addr, uint8_t value);
I would like do do something like this:
#define SRAM __attribute__((section(".sram")))
... and then be able to use it in my program:
uint8_t n SRAM; uint8_t v = 10; sram_write_byte (&n, v); // write v to n (in RTC sram) v = sram_read_byte (&n); // read RTC sram n into v // v should read back as "10"
I've looked through the source for AVR-LIBC (both eeprom and progmem code) and can't seem to figure out how it's done.
Any ideas or help will be appreciated!