Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

RE: [lpc2000] UBYTE alignment problem in structure

2005-11-09 by Gromann, Klaus

attribute packed should help.
But take care, the ARM7 processor can't access 32-bit wide to an address
that is not 32-bit aligned.
If you try to read 32 bit from the address 0x83000002, you don't get the
expected result, but without any error message or exception.

Klaus

-----Original Message-----
From: lpc2000@yahoogroups.com [mailto:lpc2000@yahoogroups.com] On Behalf
Of lehmannjluc
Sent: Wednesday, November 09, 2005 11:55 AM
To: lpc2000@yahoogroups.com
Subject: [lpc2000] UBYTE alignment problem in structure


I have the following structure definition: =========================
#define PTR_ATTR                
#define VPC3_PTR                PTR_ATTR *
typedef struct
{
    UBYTE int_req1;
    UBYTE int_req2;
    union
    {
        struct
        {
            UBYTE int_reg1;
            UBYTE int_reg2;
            UBYTE status_L;
            UBYTE status_H;
        } (ULONG rd);
        struct
        {
            UBYTE int_ack1;
            UBYTE int_ack2;
            UBYTE int_mask_L;
            UBYTE int_mask_H;
        } wr;
    } isreg;
    UBYTE mode_reg0_L;
    //....and so on with various union and sub-structure.
}  VPC3_STRUC;
#define VPC3_STRUC_PTR    VPC3_STRUC    VPC3_PTR
extern VPC3_STRUC_PTR     p_Vpc3;
=========================
This structure is used to point to a real hardware address.
And the code is:
=========================
#define EM_START_ADDR_BANK3	(0x83000000)
#define VPC3_ASIC_ADDRESS	(EM_START_ADDR_BANK3 + 0x0000)
    p_Vpc3 = (VPC3_STRUC VPC3_PTR)VPC3_ASIC_ADDRESS;
========================= But when we compile using the Ashling dev
tools with GNU compiler 
version 3.4.2 for a LPC2214 ARM, I have an alignment problem.
&p_Vpc3->int_req1 points to 0x83000000 (which is correct) but whereas 
I would expect &p_Vpc3->isreg.rd.int_reg1 to point to 0x83000002, it 
points to 0x83000004 (same for &p_Vpc3->mode_reg0_L which points to 
0x83000008 rather than the expected 0x83000006) and so on with the 
following byte of the structure.  
It looks like the compiler aligns the union on 32 bits, so drop an 
empty 2 bytes after int_req2 element.
I searched the archive for similar problem, but also I found some 
alignment questions, none matched my problem or where even close.

I am using a library supplied by the hardware chip manufacturer and I 
cannot just rewrite the whole library.
What could be done to force the compiler to point byte after byte and 
not align to 32-bit ARM word ? If it can be done at all...

Thanks in advance for any help you can provide,
Jean-Luc Lehmann






 
Yahoo! Groups Links

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.