I am trying to create host usb drivers for a printer device using the PIC32mx series . I am using the Microchip Library Application sample example . Wherein iI see that in order to send the BDT, the below mentioned structure is used. Now the BDT should be in all 8 bytes as documented in the Application note , But when I check the size of the BD_ENTRY union variable I see that it is different- 12 bytes. It should be 8 bytes if i am right. I tried to compile this particular part of the same code using Mikroc and simulated it using proteus and I find the byte length (sizeof) to be 8 bytes.
I am a bit confused, also I am new to the world of pointers, structures and unions.
typedef union _BD_STAT {
BYTE Val;
struct {
//If the CPU owns the buffer then these are the values
unsigned BC8:1; //bit 8 of the byte count
unsigned BC9:1; //bit 9 of the byte count
unsigned BSTALL:1; //Buffer Stall Enable
unsigned DTSEN:1; //Data Toggle Synch Enable
unsigned INCDIS:1; //Address Increment Disable
unsigned KEN:1; //BD Keep Enable
unsigned DTS:1; //Data Toggle Synch Value
unsigned UOWN:1; //USB Ownership
};
struct {
//if the USB module owns the buffer then these are
// the values
unsigned :2;
unsigned PID0:1; //Packet Identifier
unsigned PID1:1;
unsigned PID2:1;
unsigned PID3:1;
unsigned :1;
};
struct {
unsigned :2;
unsigned PID:4; //Packet Identifier
unsigned :2;
};
} BD_STAT;
typedef union __attribute__ ((packed))__BDT {
//typedef union __BDT{
struct __attribute__ ((packed)) {
//struct
BD_STAT STAT;
WORD CNT:10;
WORD ADR;
WORD ADRH;
};
struct __attribute__ ((packed)) {
//struct
DWORD res :16;
DWORD count:10;
};
DWORD w[2];
WORD v[4];
QWORD Val;
} BDT_ENTRY;