Yahoo Groups archive

Lpc2000

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

Message

RE: [lpc2000] Re: Bit set/clear w/ gcc

2006-01-12 by Joel Winarske

> The LED2 = 1 instruction will not be an atomic instruction when done
> using bit fields.
> Use:
> 
>     #define LED2 (1<<12)
>     port0_set = LED2
> 
> makes use of the special I/O set register. This is faster (it saves a
> read from port0_reg) and atomic


This may be informative for some.  I compiled two lines of the same code
that lie at the start of a function. 

#define LED31_BIT 		  31
#define LED31_BIT_MSK 	0x80000000

(Bit Field Method as referenced in earlier post)
LED1 = LED_OFF;
        LDR         R4,??main_0+0xC    ;; port_reg
        LDR         R0,[R4, #+0]
        MVN         R1,#+0x2000
        LDR         R2,[R0, #+0]
        AND         R2,R1,R2
        STR         R2,[R0, #+0]
LED1 = LED_OFF;
        LDR         R2,[R0, #+0]
        AND         R1,R1,R2
        STR         R1,[R0, #+0]


FIO0PIN |= (1 << LED31_BIT);		// read and write
        MVN         R0,#-1073741781
        BIC         R0,R0,#+0x3FC0
        LDR         R1,[R0, #+0]
        ORR         R1,R1,#-2147483648
        STR         R1,[R0, #+0]
FIO0PIN |= (1 << LED31_BIT);
        LDR         R1,[R0, #+0]
        ORR         R1,R1,#-2147483648
        STR         R1,[R0, #+0]


FIO0PIN |= LED31_BIT_MSK;		// read and write
        MVN         R0,#-1073741781
        BIC         R0,R0,#+0x3FC0
        LDR         R1,[R0, #+0]
        ORR         R1,R1,#-2147483648
        STR         R1,[R0, #+0]
FIO0PIN |= LED31_BIT_MSK;
        LDR         R1,[R0, #+0]
        ORR         R1,R1,#-2147483648
        STR         R1,[R0, #+0]


FIO0SET = (1 << LED31_BIT);		// write only
        MVN         R0,#-1073741785
        BIC         R0,R0,#+0x3FC0
        MOV         R1,#-2147483648
        STR         R1,[R0, #+0]
FIO0SET = (1 << LED31_BIT);
        STR         R1,[R0, #+0]


FIO0SET = LED31_BIT_MSK;		// write only
        MVN         R0,#-1073741785
        BIC         R0,R0,#+0x3FC0
        MOV         R1,#-2147483648
        STR         R1,[R0, #+0]
FIO0SET = LED31_BIT_MSK;
        STR         R1,[R0, #+0]


Joel

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.