EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

GPIO on LPC24XX with IAR EWB

Started by "mats.sernfalt" March 27, 2009
Hi!

Acording to the LPC24XX manual clear/set of GPIO registers allow a single instruction but when I look at the resulting assembler code there are several instruction. How do I write the C code (for IAR) to force the compiler to make one instruction out of a set or clear of a GPIO port??

__IO_REG8( X_FIO2SET1, 0x3FFFC059,__READ_WRITE);
X_FIO2SET1 = 4; //This C-instruction results in the following 4 machine instructions:

00000D08 E3E0019B MVN R0, #0xC0000026
00000D0C E3C00DFE BIC R0, R0, #0x3F80
00000D10 E3A01004 MOV R1, #0x4
00000D14 E5C01000 STRB R1, [R0, #+0]

An Engineer's Guide to the LPC2100 Series

On Fri, 27 Mar 2009 10:15:03 -0000, you wrote:

>Hi!
>
>Acording to the LPC24XX manual clear/set of GPIO registers allow a single instruction but when I look at the resulting assembler code there are several instruction. How do I write the C code (for IAR) to force the compiler to make one instruction out of a set or clear of a GPIO port??

>__IO_REG8( X_FIO2SET1, 0x3FFFC059,__READ_WRITE);
> X_FIO2SET1 = 4; //This C-instruction results in the following 4 machine instructions:
>
> 00000D08 E3E0019B MVN R0, #0xC0000026
> 00000D0C E3C00DFE BIC R0, R0, #0x3F80
> 00000D10 E3A01004 MOV R1, #0x4
> 00000D14 E5C01000 STRB R1, [R0, #+0]

The first 2 instructions are generating the address of the FIO2SET register.
The last instruction is doing the bit-set.
--- In l..., Mike Harrison wrote:
>
> On Fri, 27 Mar 2009 10:15:03 -0000, you wrote:
>
> >Hi!
> >
> >Acording to the LPC24XX manual clear/set of GPIO registers allow a single instruction but when I look at the resulting assembler code there are several instruction. How do I write the C code (for IAR) to force the compiler to make one instruction out of a set or clear of a GPIO port??
>
> >__IO_REG8( X_FIO2SET1, 0x3FFFC059,__READ_WRITE);
> >
> >
> > X_FIO2SET1 = 4; //This C-instruction results in the following 4 machine instructions:
> >
> > 00000D08 E3E0019B MVN R0, #0xC0000026
> > 00000D0C E3C00DFE BIC R0, R0, #0x3F80
> > 00000D10 E3A01004 MOV R1, #0x4
> > 00000D14 E5C01000 STRB R1, [R0, #+0]
>
> The first 2 instructions are generating the address of the FIO2SET register.
> The last instruction is doing the bit-set.
>

Yes, but the question remains: How do I write the C code (for IAR) to force the compiler to make one instruction out of set or clear of a GPIO port??

Hi,

> > > 00000D08 E3E0019B MVN R0, #0xC0000026
> > > 00000D0C E3C00DFE BIC R0, R0, #0x3F80
> > > 00000D10 E3A01004 MOV R1, #0x4
> > > 00000D14 E5C01000 STRB R1, [R0, #+0]
> >
> > The first 2 instructions are generating the address of the FIO2SET
> register.
> > The last instruction is doing the bit-set.
> > Yes, but the question remains: How do I write the C code (for IAR) to
force
> the compiler to make one instruction out of set or clear of a GPIO port??

YOU CAN'T. The compiler needs to form an address, load a bit mask, and then
issue a SINGLE INSTRUCTION to set a bit in a port. The manual refers to the
fact that writing to the SET port atomically sets the bit, rather than using
three instructions to read-modify-write.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors


The 2024 Embedded Online Conference