• AVR Freaks

Hot!EEPROM Object placement vs. declaration order

Author
sjb741
Super Member
  • Total Posts : 834
  • Reward points : 0
  • Joined: 2010/01/25 08:45:39
  • Location: 0
  • Status: offline
2020/06/17 07:14:43 (permalink)
0

EEPROM Object placement vs. declaration order

XC8 UG, 50002737C-page 102: 5.4.5.1 EEPROM Variables

I declared three initialised "__eeprom" objects. The first two are structures, the final one is a byte array.

I thought the EEPROM layout would reflect declaration sequence (OBJECT_1,OBJECT_2,OBJECT_3). In fact, I see from the EEPROM view that the placement has (for some reason) been chosen by the compiler (or is that linker..?) as (OBJECT_2,OBJECT_3,OBJECT_1).


__eeprom TpwmCfg gPwm0Defaults[N_CONFIGS] =
{
   #include "DEF_VALUES_PWM0.c"
};
__eeprom TpwmCfg gPwm1Defaults[N_CONFIGS] =
{
   #include "DEF_VALUES_PWM1.c"
};
__eeprom uint8_t gPresetClockIdxs[N_CONFIGS] =
{
   #include "DEF_VALUES_CLOCK_IDX.c"
};

 
MAP file
_gPwm1Defaults idataEEDATA 00000
_gPresetClockIdxs idataEEDATA 0002C
_gPwm0Defaults idataEEDATA 00030

The initialised structs and the byte array hold preset values which the user can recall & modify if desired.
 
I need to know the sequencing for subsequent reads (& occasional updates) "in the field".
 
Would it be best to amalgmate all objects into one structure? Also, do I have to worry about alignment, packing etc?

PS What does the forum option "Toggle Reward Point Option" do?
post edited by sjb741 - 2020/06/17 08:16:26
#1

4 Replies Related Threads

    mad_c
    Super Member
    • Total Posts : 1243
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re: EEPROM Object placement vs. declaration order 2020/06/17 13:52:48 (permalink)
    +1 (1)
    sjb741
    I thought the EEPROM layout would reflect declaration sequence (OBJECT_1,OBJECT_2,OBJECT_3).

    The C standard does not specify the ordering of objects in memory based on where they are defined, so you should not make assumptions as to their final location.

    Would it be best to amalgmate all objects into one structure?

    That is the only way in which you can dictate the order in which the objects will appear, so this might be your solution.

    Also, do I have to worry about alignment, packing etc?

    Not with XC8, as there is no alignment needed or performed, but on other compilers and device architectures, alignment might be more optimal or required.
     
    Jeff.
    #2
    Aussie Susan
    Super Member
    • Total Posts : 3724
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: EEPROM Object placement vs. declaration order 2020/06/17 19:15:31 (permalink)
    +1 (1)
    sjb741
    I need to know the sequencing for subsequent reads (& occasional updates) "in the field".

    Why? Just refer to the to the variable names and let the compiler/linker to the work of sorting out the references for you.
    sjb741
    Would it be best to amalgmate all objects into one structure?

    If you need to have a specific relationship between the separate structures then, as others have said, you will need to set that up yourself.
    Susan
    #3
    ric
    Super Member
    • Total Posts : 27652
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: EEPROM Object placement vs. declaration order 2020/06/17 20:11:32 (permalink)
    +1 (1)
    I suspect they want to access the EEPROM directly using a programmer.
    Otherwise your suggestion is how they SHOULD be doing it.
    I've previously tried to place EEPROM objects at absolute addresses with the "@" operator in v1.xx, and it wouldn't let you set an initial value.
    I don't know if the __at() operator in v2.xx will let you force the eeprom objects to a fixed location, AND let you set an initial value. Must try it someday. :)
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    1and0
    Access is Denied
    • Total Posts : 10906
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: EEPROM Object placement vs. declaration order 2020/06/17 21:13:56 (permalink)
    0
    ric
    I've previously tried to place EEPROM objects at absolute addresses with the "@" operator in v1.xx, and it wouldn't let you set an initial value.

    I've never understood why EEPROM variables cannot be located at absolute addresses. pink: pink
    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5