C
CptDondo
I am working on an embedded platform which has a block of battery-backed
RAM. I need to store various types of data in this block of memory -
for example, bitmapped data for control registers, strings for logging,
and structures for data points.
I want to use one function to read data from this block and one function
to write data, for example:
sram_read(OBJECT_IDENTIFIER) would return a pointer to the appriate
object and
sram_write(OBJECT_IDENTIFIER, &object) would write the object to the memory
I have to do this in a way that is portable across architectures - we
support two platforms, one is ARM based and the other is x86 based.
Sometimes the object might be a string, sometimes a char, sometimes a
structure.....
What is the correct way to declare these functions?
Also, and a somewhat more difficult problem (for me at least) is the
actual storage mechanism....
One of the objects I have to store is a structure like this:
struct AnalogPoint {
float value;
float alarm_hi, alarm_low;
float average, avg_weight;
int log_freq;
int hyst_timer;
char ctrl_reg;
};
I've been kicking around various ways to store this structure. Figure
that I have to store 16 of these. I could store an array of 16
structures and return pointers to them. But then I see potential
problems; if the software is upgraded the newly compiled versions may
not put the same data in the same place, so I'd have garbage when the
new software tried to read the data saved by the older software.
I could 'unpack' the structure and store all of the elements as linear
arrays and build a structure on the fly and return a pointer to it, but
then I have problems with the data area being overwritten on the next call.
So.... Any suggestions? Stability is more important than speed.
Thanks,
--Yan
RAM. I need to store various types of data in this block of memory -
for example, bitmapped data for control registers, strings for logging,
and structures for data points.
I want to use one function to read data from this block and one function
to write data, for example:
sram_read(OBJECT_IDENTIFIER) would return a pointer to the appriate
object and
sram_write(OBJECT_IDENTIFIER, &object) would write the object to the memory
I have to do this in a way that is portable across architectures - we
support two platforms, one is ARM based and the other is x86 based.
Sometimes the object might be a string, sometimes a char, sometimes a
structure.....
What is the correct way to declare these functions?
Also, and a somewhat more difficult problem (for me at least) is the
actual storage mechanism....
One of the objects I have to store is a structure like this:
struct AnalogPoint {
float value;
float alarm_hi, alarm_low;
float average, avg_weight;
int log_freq;
int hyst_timer;
char ctrl_reg;
};
I've been kicking around various ways to store this structure. Figure
that I have to store 16 of these. I could store an array of 16
structures and return pointers to them. But then I see potential
problems; if the software is upgraded the newly compiled versions may
not put the same data in the same place, so I'd have garbage when the
new software tried to read the data saved by the older software.
I could 'unpack' the structure and store all of the elements as linear
arrays and build a structure on the fly and return a pointer to it, but
then I have problems with the data area being overwritten on the next call.
So.... Any suggestions? Stability is more important than speed.
Thanks,
--Yan