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.

TMS320F280037: Trying to understand ctrlfuncs memcpy syntax

Part Number: TMS320F280037

Tool/software:

In the TI code, loadSize_ctrlfuncs is declared as existing externally as a uint32_t defined 'somewhere'.  It is used in a memcpy() as shown below.  When I run static-analysis I get an error on parameter 3 because it's attempting to convert a unint32_t* to an unsigned long.  On the surface this seems like bad/incorrect C-syntax, but I am assuming that the compiler/linker is doing something special in order to convert (size_t)&loadSize_ctrlfuncs into the actual size of the region to copy, or I am failing to understand how the C-syntax works in this case.  I am just trying to understand how that works, because I need to suppress the MISRA violation for this line if it is truly working as designed.  This same pattern is repeated for other sections which are mem-copied, so I assume it is done purposefully. 


extern uint32_t loadSize_ctrlfuncs;
memcpy(&runStart_ctrlfuncs, &loadStart_ctrlfuncs, (size_t)&loadSize_ctrlfuncs);

thanks,
Jeremy
  • Hi Jeremy,

    The size_t data type is used to represent the size of a data type in bytes. Usually it would be used in a statement like this:

    size_t int32bytes = sizeof(uint32_t);

    Then you could pass this variable into the third parameter of your memcpy function. In your case, it sounds like you can just use loadSize_ctrlfuncs directly if the value of this variable is already representing the number of bytes you want to copy.

    memcpy(&runStart_ctrlfuncs, &loadStart_ctrlfuncs, loadSize_ctrlfuncs);
    Let me know if I am misunderstanding.
    Best Regards,
    Delaney
  • Hi Delaney - I believe I found my answer in the TMS320C28x Assembly Language Tools v22.6.0.LTS User's Guide:


    8.6.2 Linker-Defined Integer Values

    To access linker symbols that represent integer values, use the _symval built-in operator, which is essentially a cast operation. For example, the linker symbol __TI_STACK_SIZE evaluates to a plain integer. To get the symbol's value as an integer in C/C++ code, use the following syntax:

    extern void __TI_STACK_SIZE;

    size_t get_stack_size() { return _symval(&__TI_STACK_SIZE); }

    The type in such extern declarations does not matter, because only the address of the symbol is needed. In strict ANSI mode, you cannot declare this variable with a type of void, so use unsigned char instead.