[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] RFC: avr/bits.h

From: Nicolas Schodet
Subject: Re: [avr-libc-dev] RFC: avr/bits.h
Date: Tue, 1 Mar 2005 21:58:17 +0100
User-agent: Mutt/1.5.6+20040907i


About bit manipulations, I had a bad experience last week. On some
registers, bit manipulation can be tricky:

TWCR &= ~(_BV (TWSTA) | _BV (TWSTO));

The interrupt flag bit is read as 1, and writen at 1, this clear the
interrupt bit! A warning could be added to the manual.

Another question about bit manipulation: what is the best way to read 4
bytes into a double word? This could also be included in the bit
manipulation header. This code seems to compile quite bad and generate
useless operations:

uint32_t a;
uint8_t b[4];

a = (uint32_t) b[0] << 24 | (uint32_t) b[1] << 16
    | (uint32_t) b[2] << 8 | (uint32_t) b[3] << 0;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]