I am trying to create usb drivers for a printer device using the PIC32mx series. I am using a sample Microchip library application. In this case, I see that the structure below is used to send the BDT. Now the BDT should be in all 8 bytes, as described in the note to the application, But when I check the size of the BD_ENTRY union variable, I see that it is different from 12 bytes. It should be 8 bytes if I am right. I tried to compile this part of the same code with Mikroc and simulate it with protus, and I find that the byte length (sizeof) is 8 bytes.
I am a little confused, also I am new to the world of pointers, structures and unions.
typedef union _BD_STAT {
BYTE Val;
struct {
unsigned BC8:1;
unsigned BC9:1;
unsigned BSTALL:1;
unsigned DTSEN:1;
unsigned INCDIS:1;
unsigned KEN:1;
unsigned DTS:1;
unsigned UOWN:1;
};
struct {
unsigned :2;
unsigned PID0:1;
unsigned PID1:1;
unsigned PID2:1;
unsigned PID3:1;
unsigned :1;
};
struct {
unsigned :2;
unsigned PID:4;
unsigned :2;
};
} BD_STAT;
typedef union __attribute__ ((packed))__BDT {
struct __attribute__ ((packed)) {
BD_STAT STAT;
WORD CNT:10;
WORD ADR;
WORD ADRH;
};
struct __attribute__ ((packed)) {
DWORD res :16;
DWORD count:10;
};
DWORD w[2];
WORD v[4];
QWORD Val;
} BDT_ENTRY;
source
share