Re: [PATCH] BMP085 : Change the macro to swap

From: Christoph Mair
Date: Fri Jun 25 2010 - 09:34:34 EST


On Fri, Jun 25, 2010 at 3:00 PM, Datta, Shubhrajyoti
<shubhrajyoti@xxxxxx> wrote:
>
>
>> -----Original Message-----
>> From: J.I. Cameron [mailto:jic23@xxxxxxxxxxxxxxxx] On Behalf Of Jonathan
>> Cameron
>> Sent: Thursday, June 24, 2010 6:23 PM
>> To: Datta, Shubhrajyoti
>> Cc: linux-kernel@xxxxxxxxxxxxxxx; Christoph Mair; Andrew Morton
>> Subject: Re: [PATCH] BMP085 : Change the macro to swap
>>
>> On 06/24/10 13:41, Datta, Shubhrajyoti wrote:
>> >
>> > Changing the macro to swap the bytes as the reason that the first byte
>> is the MSB and the next is LSB.
>> Are you sure on this one?
>
> The datasheet says the ÂE2PROM has the bytes as described in the comment below
> *
> * BMP085 Reg Addr
> * parameter   |    MSB   |    LSB
> * AC1 Â Â Â Â Â | Â Â Â 0xAA Â Â| Â Â Â 0xAB
> ...
>
> AA has MSB and AB has lsb so it has to be swapped. My idea is that it does not depend on the endianness of the CPU running the code. So I think that swap should happen unconditionally. The I2C reads a string of bytes and the first byte from AA and next from AB and hence an unconditional swap maybe needed.
>
> Am I missing something.
The data is read bytewise and stored in memory starting with
MSB-LSM-MSB-LSB-... If you have a big endian CPU, it expects a 16 Bit
word to be stored in exactly this format. A little endian CPU expects
the LSB to be stored at the lower memory address: LSB-MSB.
Therefore the bytes have to be swapped only for little-endian cpus.

Best regards,
Christoph
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/