This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Place constant at fixed code memory address

Hi,

I'm confused about the existings threads regarding this topic, so please excuse this new thread.

I'd like to put some calibration data into my (OTP) memory of C164-CA. The software would have some declaration for a few constants located at the end of the code space for example. These constants would get their value coded to zero for example. Before burning the otp the real calibration data would be placed into the programmers hex-file by modifying the selected values.

Does anybody have an idea of how to place these constants to a fixed location in memory ?

Thanks in advance
Thomas

Parents
  • The _at_ keyword is the easy way.

    If for some reason you want to avoid extended features, you can use the linker to place a segment in a particular place. Put your constants in their own file, and use the CODE / DATA / PDATA / XDATA (BL51) or SEGMENTS (LX51) linker directives to put the segment created by that file whereever you need it.

Reply
  • The _at_ keyword is the easy way.

    If for some reason you want to avoid extended features, you can use the linker to place a segment in a particular place. Put your constants in their own file, and use the CODE / DATA / PDATA / XDATA (BL51) or SEGMENTS (LX51) linker directives to put the segment created by that file whereever you need it.

Children
  • I thought the _at_ keyword wasn't available anymore in C166 ? In C51 is it, surely..

  • By following the advice described in the knowledgebase article I'm able to redirect the const variable to a specific address in the NCONST segment.

    I have the impression that the variable itself is located to a RAM address, whereas only the value for initialisation is placed into ROM and loaded into the RAM variable at startup.

    Is there a possibility to make the compiler only address the ROM when reading this constant ? I would like to save the extra RAM space ...

  • Just to see if it works I did the whole thing myself.
    Created the file test.c and included it in the project:

    const int i=0x1234;
    
    void main(void)
    {
        static int huge* ptr;
        ptr = &i;
    }
    
    Added the followin line to the User sections in the L166 locator settings dialog box:
    ?NC?TEST%NCONST(0x000300)
    
    After building the project everything looked as expected:
    MAP file:
    
    START     STOP      LENGTH    TYPE  RTYP  ALIGN  TGR  GRP  COMB  CLASS   SECTION NAME
    =====================================================================================
    ...
    000300H   000301H   000002H   DATA  REL   WORD   ---    3  PUBL  NCONST  ?NC?TEST
    ...
    
    Intel HEX file:
    ...
    :020300003412B5
    ...
    
    Disassembly of main():
    00020000 E6F40003  MOV      R4,#0x0300
    00020004 E6F50000  MOV      R5,#0x0000
    00020008 F6F40012  MOV      DPP0:0x1200,R4
    0002000C F6F50212  MOV      DPP0:0x1202,R5
    00020010 CB00      RET
    

    It shows that the constant has been located at the specified address (0x300,) the value of the constant can be seen in the HEX file where it is supposed to be (at 0x300,) and the address of the variable showing up in code is 0x300 as expected.
    So everything worked as expected.

    - mike