Gast
#644362
Hallo,
ich habe folgende Programmcode und weiss leider nicht, was ich machen
soll.
In der Zeile " *((_attribute_ ((packed)) DWORD *)pData) = USBRxData;"
sollen der Werte "0x01006080", der in USBRxData steht, geschrieben
werden. Der pDATA steht aber auf einer ungeraden Adresse. Wenn nun die
Zeile "*((_attribute_ ((packed)) DWORD *)pData) = USBRxData;" kommt,
wird aber der Wert nicht auf ungerade Adresse geschrieben, sondern auf
die nächste gerade Adresse. In diesem Fall eine Adresse tiefer.
Wie kann ich dieses dem Compiler mitteilen, dass er auch auf eine
ungerade Adresse schreiben soll?
Gruss
Harry
Folgender Programmcode:
typedef union {
WORD W;
struct {
BYTE L;
BYTE H;
} _attribute_ ((packed)) WB;
} _attribute_ ((packed)) WORD_BYTE;
/* bmRequestType Definition */
typedef union _REQUEST_TYPE {
struct _BM {
BYTE Recipient : 5;
BYTE Type : 2;
BYTE Dir : 1;
} _attribute_ ((packed)) BM;
BYTE B;
} _attribute_ ((packed)) REQUEST_TYPE;
/* USB Default Control Pipe Setup Packet */
typedef struct _USB_SETUP_PACKET {
REQUEST_TYPE bmRequestType;
BYTE bRequest;
WORD_BYTE wValue;
WORD_BYTE wIndex;
WORD wLength;
} _attribute_ ((packed)) USB_SETUP_PACKET;
USB_SETUP_PACKET SetupPacket;
USB_ReadEP(0x00, (BYTE *)&SetupPacket);
DWORD USB_ReadEP (DWORD EPNum, BYTE *pData) {
DWORD cnt, n;
USBCtrl = ((EPNum & 0x0F) << 2) | CTRL_RD_EN;
do {
cnt = USBRxPLen;
} while ((cnt & PKT_RDY) == 0);
cnt &= PKT_LNGTH_MASK;
for (n = 0; n < (cnt + 3) / 4; n++) {
*((_attribute_ ((packed)) DWORD *)pData) = USBRxData;
pData += 4;
}
......
Struktur:
typedef union {
WORD W;
struct {
BYTE L;
BYTE H;
} _attribute_ ((packed)) WB;
} _attribute_ ((packed)) WORD_BYTE;
/* bmRequestType Definition */
typedef union _REQUEST_TYPE {
struct _BM {
BYTE Recipient : 5;
BYTE Type : 2;
BYTE Dir : 1;
} _attribute_ ((packed)) BM;
BYTE B;
} _attribute_ ((packed)) REQUEST_TYPE;
/* USB Default Control Pipe Setup Packet */
typedef struct _USB_SETUP_PACKET {
REQUEST_TYPE bmRequestType;
BYTE bRequest;
WORD_BYTE wValue;
WORD_BYTE wIndex;
WORD wLength;
} _attribute_ ((packed)) USB_SETUP_PACKET;