At 12:06 PM 3/17/05 -0300, Leonardo Santos wrote:
>Hello All:
> I'm working with a LPC2106 using the GCC 3.4.4 toolchain (GCC +
> binutils 2.15
>+ newlib 1.13). I wrote a union and a structure to access the P0 pins
>individually, like this:
>
>typedef struct {
> int p0 : 1;
> int p1 : 1;
> int p2 : 1;
>(...)
> int p30 : 1;
> int p31 : 1;
>}port_t;
>
>typedef union {
> port_t pins;
> unsigned int reg;
>} ioreg;
>
>typedef struct {
> ioreg iopin;
> ioreg ioset;
> ioreg iodir;
> ioreg ioclr;
>}gpio_t;
>
>So I declare a pinter like
>
> volatile gpio_t *gpio = 0xE0028000;
>
>If I access the registers using
>
> if( gpio->iopin.reg & 0x01 )
>
>or
>
> gpio->ioset.reg |= 0x00008000;
>
>Everithing works fine! But if I try a code like this:
>
> gpio->ioset.pins.p15 = 1;
P15 is a 1 bit int so its only values are 0 and -1 but I don't think that's
the problem. Provided your bit order is correct I don't see any reason
they shouldn't give the same result. I'd use unsigned int for bitfields
unless you wanted them to be signed for some particular purpose.
>To set P0.15, P0.23 and P0.31 are set too! I had tried this code in my Linux
>workstaion and it works just fine. The compiles setting I'm using are
Hmm, those are 8 bits apart. Have you taken a look at the assembly output
for the two cases? They should be similar if not identical. Unless the
compiler is getting confused by some sort of sign extension issue? Seems a
stretch though.
Robert
" 'Freedom' has no meaning of itself. There are always restrictions, be
they legal, genetic, or physical. If you don't believe me, try to chew a
radio signal. " -- Kelvin Throop, III
http://www.aeolusdevelopment.com/Message
Re: [lpc2000] C union not working
2005-03-17 by Robert Adsett
Attachments
- No local attachments were found for this message.