What does this Declaration means???

Thread Starter

embpic

Joined May 29, 2013
189
volatile BDT_ENTRY BDT[BDT_NUM_ENTRIES] BDT_BASE_ADDR_TAG;

here are some defination.
Rich (BB code):
#define BDT_NUM_ENTRIES      ((USB_MAX_EP_NUMBER + 1) * 4)
#define USB_MAX_EP_NUMBER	    2
#define BDT_BASE_ADDR   0x2000
#define BDT_BASE_ADDR_TAG @ BDT_BASE_ADDR


typedef union __BDT
{
    struct
    {
        BD_STAT STAT;
        BYTE CNT;
        BYTE ADRL;                      //Buffer Address Low
        BYTE ADRH;                      //Buffer Address High
    };
    struct
    {
        unsigned filler1:8;
        unsigned filler2:8;
        WORD     ADR;                      //Buffer Address
    };
    DWORD Val;
    BYTE v[4];
} BDT_ENTRY;
upto this, it is ok.
but here,
volatile BDT_ENTRY BDT[BDT_NUM_ENTRIES] BDT_BASE_ADDR_TAG;

it shows three part BDT_ENTRY is typedef of union and BDT[BDT_NUM_ENTRIES] is array of BDT_ENTRY.
This is also ok but again there is third part of BDT_BASE_ADDR_TAG.
what is doing here???

is it for address??
that is to locate this variable at that position??
 

JohnInTX

Joined Jun 26, 2012
4,787
is it for address??
that is to locate this variable at that position??
Looks like it.

'volatile' tells the compiler that other things can modify the variable e.g. a hardware peripheral and that it must not move it, share it or optimize it out.

If you walk back through the defines you'll see that
volatile BDT_ENTRY BDT[BDT_NUM_ENTRIES] BDT_BASE_ADDR_TAG;

where BDT_BASE_ADDR_TAG evaluates to @ 0x2000, declares an array of structs of type BDT_ENTRY named BDT containing some computed number of structures at the absolute, non relocatable address 2000h (presumably a set of hardware buffers or pointers to them)
 
Top