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/TMS320F28035: define variable in assembly and access the variable in C

Part Number: TMS320F28035

Tool/software: TI C/C++ Compiler

Hi, I'm testing the ILPFC project and it's written in assembly and C.

Below codes are in "ADCDRV_1ch.asm"

ADCDRV_1ch_INIT .macro n
;================================
_ADCDRV_1ch_Rlt:n: .usect "ADCDRV_1ch_Section",2,1,1 ; 2 means 2 words, 32bits

; publish Terminal Pointers for access from the C environment
.def _ADCDRV_1ch_Rlt:n:

MOVL XAR2, #ZeroNet ; "ZeroNet" is initialised to 0 in ISR
MOVW DP, #_ADCDRV_1ch_Rlt:n:
MOVL @_ADCDRV_1ch_Rlt:n:, XAR2 ; zero output terminal pointer
.endm

Together with the code below, we defined 11 variable ADCDRV_1ch_Rlt1-ADCDRV_1ch_Rlt11, these variables' size are 2 words.

ADCDRV_1ch_INIT 1 ; Ipfc//these codes are in ILPFC-DPL-ISR.asm
ADCDRV_1ch_INIT 2 ; Ipfc
ADCDRV_1ch_INIT 3 ; Ipfc
ADCDRV_1ch_INIT 4 ; Ipfc
ADCDRV_1ch_INIT 5 ; Ipfc
ADCDRV_1ch_INIT 6 ; Ipfc
ADCDRV_1ch_INIT 7 ; Ipfc
ADCDRV_1ch_INIT 8 ; Ipfc
ADCDRV_1ch_INIT 9 ; Vpfc
ADCDRV_1ch_INIT 10 ; VL_fb
ADCDRV_1ch_INIT 11 ; VN_fb

In ILPFC-main.c, there are codes below.

// ADC Driver Macro. Ipfc is oversampled 8 times.
extern volatile long *ADCDRV_1ch_Rlt1; // instance #1, Ipfc
extern volatile long *ADCDRV_1ch_Rlt2; // instance #2, Ipfc
extern volatile long *ADCDRV_1ch_Rlt3; // instance #3, Ipfc
extern volatile long *ADCDRV_1ch_Rlt4; // instance #4, Ipfc
extern volatile long *ADCDRV_1ch_Rlt5; // instance #5, Ipfc
extern volatile long *ADCDRV_1ch_Rlt6; // instance #6, Ipfc
extern volatile long *ADCDRV_1ch_Rlt7; // instance #7, Ipfc
extern volatile long *ADCDRV_1ch_Rlt8; // instance #4, Ipfc
extern volatile long *ADCDRV_1ch_Rlt9; // instance #5, Vbus
extern volatile long *ADCDRV_1ch_Rlt10; // instance #6, VL_fb
extern volatile long *ADCDRV_1ch_Rlt11; // instance #7, VN_fb

My question is that:

Is it the code "extern volatile long *ADCDRV_1ch_Rlt1" makes the variable "ADCDRV_1ch_Rlt1" a pointer?

And I can also write "extern volatile long ADCDRV_1ch_Rlt1" to make the variable "ADCDRV_1ch_Rlt1" a long number, right?

But I cannot write "extern volatile int ADCDRV_1ch_Rlt1" to make the variable "ADCDRV_1ch_Rlt1" a short number, because short number is 16bits, and in assembly "ADCDRV_1ch_Rlt1" are allocated 32 bits, right?

  • The only C declaration which makes sense is "extern volatile long ADCDRV_1ch_Rlt1".  It's not a pointer.  It's a long value.

    Thanks and regards,

    -George

  • Accessing a hand-coded-assembly field from C code is tricky.  You are better off defining the object in C code and accessing it from assembly, for two reasons:

    1. You can first create a dummy C function to do what you want the assembly code to do, and then pattern your own hand-coded assembly off of what the compiler generates.  This will show you the best addressing mode to use in your hand-coded assembly.
    2. Compiler symbols represent objects; when you use a compiler symbol, you actually get the contents of that object.  However, assembler symbols represent addresses; when you use an assembler symbol, you actually get the address of that symbol.  It is easier to "fake out" the assembler to read C objects than it is to "fake out" the compiler to read assembler symbols.

  • But this sentence are written in the example project.

    extern volatile long *ADCDRV_1ch_Rlt1; // instance #1, Ipfc

    Besides.
    The only C declaration which makes sense is "extern volatile long ADCDRV_1ch_Rlt1", is it because it's 32 bit number? And any 32 bit data type makes sense, right?
  • Does ADCDRV_1ch_Rlt1 contain an integer or does it contain a pointer? Given that the declaration is a pointer, and the macro talks about "terminal pointers," this suggests to me that that is in ADCDRV_1ch_Rlt1 is a large model data pointer. Large model data pointers are 32 bits, so the size makes sense.

    What problem are you having that makes you question whether the code is correct?
  • I don't doubt it, George's answer says:
    The only C declaration which makes sense is "extern volatile long ADCDRV_1ch_Rlt1". It's not a pointer. It's a long value.

    What I doubt is that for a variable defined in assembly, we can not specify the data type in assembly code, we can only specify the length, and only in C we can specify the data type to int or long or float or pointer, right?
  • You are correct, it is not possible to specify a C type for an assembly symbol. Assembly symbols do not have any particular type.