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.

LAUNCHXL-F280039C: How to read RPC to the C variable right in C-source file, avoiding creating a separate .asm file.

Part Number: LAUNCHXL-F280039C

Dear colleagues,

I would like to clarify how it is possible to read the RPС CPU register into a local variable inside a C function? At the same time, avoiding the creation of a separate .asm file, probably bypassing only _asm() commands.

Thanks in advance!

BR,

Kostiantyn Rudenko

  • Hello Kostiantyn,

    In assembly the way to read the RPC register is by pushing it to the stack and popping it into a register. I am not aware of a way to do this in using only C; you could try to find the address of the RPC register in memory, but I don't believe there is access to this in C code.

    Best regards,

    Omer Amir

  • Perhaps I didn't phrase my question very clearly :)
    It goes without saying that the capabilities of the C language are insufficient, it needs to use assembler commands :)
    But, I would like to clarify whether this can be done without creating a separate .asm file, that is, by placing these asm-commands directly in the C code using _asm("..."), in C- function, or, maybe in C-inline function.

    Thanks!

  • Hello Kostiantyn,

    You should be able to use the push/pop method using _asm(), I don't see a problem with doing this. I have used the assembly inline function before, it works fine. I recommend trying this on your device to check.

    Best regards,

    Omer Amir

  • Here 
    https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/693819/ccs-tms320f280049-how-to-read-rpc 
    I saw an example of how this can be wrapped in an asm function. But my knowledge in assembler is still very weak, therefore, could you please suggest how to modify this to save directly in C variable? And I suppose in this case the ".global _getRPC" and "LRETR" commands will not be needed.

    ; assembly stub to get RPC

    .global _getRPC

    _getRPC:
    PUSH   RPC
    POP     ACC
    LRETR

    Thanks.

  • I also tried like this:
    1) Defined global variable:

    volatile unsigned int VAR;

    2) Inside C-function, I put this code:

    _asm(" .global VAR");
    _asm(" PUSH RPC");
    _asm(" POP ACC");
    _asm(" MOVL @VAR,ACC");

    But, the variable VAR is kept unchanged. There is probably something wrong here.

  • Hello Kostiantyn,

    I tested the following code on a different device, but it should work the same for you:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    #include "driverlib.h"
    #include "device.h"
    uint32_t temp();
    void main(void)
    {
    uint32_t value = temp();
    while(1);
    }
    uint32_t temp()
    {
    __asm(" PUSH RPC");
    __asm(" POP ACC");
    return;
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    There will be a warning that 'temp' is not returning a value, but the ACC register is what is returned when a function is called. I tested this on my side and got the proper value of RPC.

    Best regards,

    Omer Amir

  • Thanks a lot!:))
    Btw, it is possible to avoid the warning by modifying the return like this:
     

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    uint32_t getRPC(void)
    {
    __asm(" PUSH RPC");
    __asm(" POP ACC");
    __asm(" LRETR");
    return 0;
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


    I just checked it on my target - it works, and even without warnings.