Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-02

Place of elements in record

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Koenraad Lelong

Hi,

I'm developping a arm-embedded project. I need to store some variables to EEPROM. What I'm doing now is manually give each variable an address and then I use that address to store the variable in EEPROM. Unfortunately, that's not easy. Yesterday I spent some hours trying to see why the code I wrote does not work. This morning I thought of a possible reason, and I think I'm right : I was overlapping some variables.

So I'm trying to find a simpler way to have the relative position of variables to use as an address in an EEPROM.
I'm tinking about using a record. Is there a way to get the relative position of a record-element ?
Some psuedo-code :

EEPROM_Content : record of
  Var1 : byte;
  Var2 : word;
  Var3 : byte;
end{EEPROM_Content};
EEPROM_WriteByte(<position of Var1 in EEPROM_Content>,EEPROM_Content.Var1);
//<position of Var1 in EEPROM_Content> should be 0
EEPROM_WriteWord(<position of Var2 in EEPROM_Content>,EEPROM_Content.Var2);
//<position of Var2 in EEPROM_Content> should be 1
EEPROM_WriteByte(<position of Var3 in EEPROM_Content>,EEPROM_Content.Var3);
//<position of Var3 in EEPROM_Content> should be 4

I think I could use
@
@
@
as those positions, but is this computed at compile-time, or at run-time ? Am I right if I assume EEPROM_Content.Var1 is at relative position 0 in the record ?
I prefer to have the individual variables written to EEPROM, but maybe writing the whole record in one go would be possible also. Then I don't need to hassle with the positions. I mean, it _is_ possible to do that but if it's suited for the project I don't know yet.

Other solutions ?

Mmm, writing things out clears the mind. I think it would be better to write the whole record.

Thanks for your input.

Regards,

Koenraad Lelong

Reply by email

Ludo Brands
to Koenraad Lelong
Koenraad Lelong wrote
Other solutions ?
type
  EEPROM_Content= record
   Var1 : byte;
   Var2 : word;
   Var3 : byte;
  end;

...

@EEPROM_Content(nil^).Var2 gives you the relative address of Var2 in the record. Calculated at compile time.

Ludo

Reply by email

Mark Morgan Lloyd
to Koenraad Lelong: I'm developping a arm-embedded project. I need to store some variables to EEPROM. What…
Koenraad Lelong wrote 13 lines
Hi, I'm developping a arm-embedded project. I need to store some variables to EEPROM. What I'm doing now is manually give each variable an address and then I use that address to store the variable in EEPROM. Unfortunately, that's not easy. Yesterday I spent some hours trying to see why the code I wrote does not work. This morning I thought of a possible reason, and I think I'm right : I was overlapping some variables. So I'm trying to find a simpler way to have the relative position of variables to use as an address in an EEPROM. I'm tinking about using a record. Is there a way to get the relative position of a record-element ?

..

Mmm, writing things out clears the mind. I think it would be better to write the whole record.

I'd suggest that this depends in part on the semiconductor technology. You might be best transferring individual fields for old-fashioned EEPROMs, or defining a larger block with a magic number for more "RAM-like" devices particularly if they have load-levelling.

I've had to deal with the mess left by a contractor who was pathologically incapable of keeping NVR layout consistent across versions, and it wasn't pleasant.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Koenraad Lelong
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 5 lines
I'd suggest that this depends in part on the semiconductor technology. You might be best transferring individual fields for old-fashioned EEPROMs, or defining a larger block with a magic number for more "RAM-like" devices particularly if they have load-levelling.

Hi,

I'm using "old-fashioned" EEPROM (1 kilobyte). In the device every write-cycle takes about 3ms. So writing individual variables each takes 3ms. But writing the whole record would also take 3ms (I think, I have to verify this). So it's tempting to do that. But a whole record could cross memory-pages, then the record needs to be split in two (or more) cycles. But at the moment I'm saving less than 20 variables, so splitting will be for later.

Thanks for your input, same for you Ludo.

Regards,

Koenraad Lelong.

Reply by email