This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TMS320F28335: Two or More Variables Sharing an Address

Part Number: TMS320F28335

Tool/software: TI C/C++ Compiler

Hello,

I'm implementing code that interfaces with external devices using the external interface on the TMS320F28335. One of the addresses has two uses depending on whether it is a read or a write operation. Writing to the address controls a relay. Reading from the address gets the device version. 

All of the other locations are being configured using a linker command file. While I can do this here, by having code to abstract an address based on the read or write operation, I'd rather pragma two variables to the same address; one a const that when read is the device version, while the other can be written to to set the relay state. Is this possible?

Thanks,

Jonathan

  • I think you would have to make it a method or property of a class.
  • Jonathan Riger said:
    I'd rather pragma two variables to the same address; one a const that when read is the device version, while the other can be written to to set the relay state. Is this possible?

    I can't think of a way to do it from C or C++.  But I can think of a way to do it in a linker command file.  In your linker command file, you need statements similar to ...

    _read_variable  = 0x1234;
    _write_variable = _read_variable;

    In C or C++, declare (not define) these variables similar to ...

    volatile extern int write_variable;
    volatile extern int read_variable;

    Note how the names start with underscore in the linker command file, but not in C.  That is because C2000 tools use the older COFF ABI.  To adapt this technique to the newer EABI, never use the leading underscore.  

    Thanks and regards,

    -George