I have a lot of configuration data in EEPROM (4KB) which I read out in packed structures. Throughout my firmware I need to read/change these values very frequently, and performance of packed structures is not optimal, so I have a second struct which is exactly the same, only not packed. I have to copy each value one by one from the packed struct to the unpacked one, which is error-prone, because when I add a value to the packed structure I also have to remember to add it to the copy-function.
Is there a smarter way to do this?
This is the over-smart method of doing this, using the precompiler:
mydata-fields.h
mydata.h
UPDATE: With a bit of imagination you can even write a generic packed.h that receives the names of the struct and the fields file as parameters:
extract of packed.h
And then simply in the real file:
mydata.h
This will be useful if you have a lot of packed/unpacked structures and want to avoid some typing.
A not so evil solution would be to write a script (in Python!) that generates the code from the fields specification in some input text file.