|
Okay...
First I create a union called EEpromStruct. In the union all the members are located at the same address. Inside this union there are two members: the EEpromBytes array and the Settings structure.
The members of a structure are sequentially placed in memory, thus first comes the FloatVal, next ByteVal etc.
Because the EEpromBytes array and Settings structure are within a union, their base address is the same. So FloatVal is located at EEpromBytes[0...3], ByteVal at EEpromBytes[4], SomeMore at EEpromBytes[5...6] etc.
The size of the union has always the size of the largest member, so it's for this example 16 bytes. That is intentionally matched with the size of one row. (the EEPROM_Write always writes one full row of 16 bytes).
Notice that the union has a typedef in it's declaration. This means it does not actually reserve memory but it tells the compiler about the memory layout of the union (or structure).
Next, I define a compiler directive called SettingsAddress and set it to the start of the PSoCs EEprom base location (CYDEV_EE_BASE).
The actual placement of the EEpromStruct union at the EEprom area is done at: volatile EEpromStruct xdata EEpromData _at_ SettingsAddress;
Then I also place the same EEpromStruct to RAM by: EEpromStruct RAMcopy;
Now everything is set for the compiler to work with. Next we can use the struct and it's members to read and write to.
By RAMcopy = EEpromData; the contents of the EEpromData struct (resides at PSOCs EEprom location) is placed to the RAMcopy structure. The compiler just copies the complete structure for you to RAM.
By RAMcopy.Settings.FloatVal += FloatTest; you are just accessing the FloatVal member of the RAM structure and increasing it with FloatTest.
The EEPROM_Write next writes the 16 bytes RAM structure to Row 0. Row 0 is located at CYDEV_EE_BASE. You can use Row 1 also by using (CYDEV_EE_BASE + 16). The (const uint8 *) &RAMcopy is casting the base address (&RAMcopy) to a const uint8 pointer as this is what the library function would accept.
At least I showed that it's also possible to just use a member of the EEprom structure and copy it to RAM.
You can also directy use the EEprom location within your program like: if (EEpromData.Settings.ByteVal > 0x10) FloatTest += 0x10;
Hope this helps you!
Regards,
Rolf
|