Endianess Question

Discussion to talk about software related topics only.
Post Reply
DBrunermer
Posts: 67
Joined: Thu Apr 21, 2011 7:06 am
Location: Pittsburgh, PA

Endianess Question

Post by DBrunermer »

Hey all, I'm sorry but I have a big-endian question or concern that I can't seem to wrap my head around. (MOD 5272)

I have this CPLD that I originally designed as an 8-bit accessible device, and endianess wasn't such a big deal, because I could talk to the thing a byte at a time anyway, so it was fine. I'm transferring 32-bit values, but like I say, it was a byte at a time so ordering it was easy enough.

Now I'm changing it to a sixteen(16) bit device and I'm feeling really uncertain about what is going to happen. What I mean is, what will be on which data line?

Say I'm transferring a 32-bit value into the 16- bit device.
Address 0 still has the MSB, but will it still be in D(31-24)? Will D(23-16) have the same data as D(31-24) at Address 1 when in 8 bit mode?

I'm not sure this question even makes sense, or if I'm over-thinking it. But thanks. Dan B.
User avatar
pbreed
Posts: 1091
Joined: Thu Apr 24, 2008 3:58 pm

Re: Endianess Question

Post by pbreed »

8 bit bus transfers happen on D31..D24 with address lines A0..An having meaning.


16 bit bus transfers happen on D31..D16 with address lines A1..An having meaning, IE A0 selects the byte, so with 16 bit transfer it is not used.


32 bit bus transfers happen on D31..D0 and A0,A1 are both unused....


Now writing a 32 bit value to a sixteen bit bus....

suppose you are writing 32 bits 0x12345678 to Address 0x80000000.... that is maped to a 16 bit hardware device...

First it will write:

0x1234 on D31..D16 with Address = 0x80000000
then it will write
0x5678 on D31..D16 with Address = 0x80000002

Reads are similar... reading 32 bits from address 0x80000000 on a 16 bit interface will be:

Read MSW with address bus = 0x80000000
Read LSW with Address bus = 0x80000002

Reading/Writing 16 bits is straight forward....

Reading a byte is simple....
A Byte read will read from the 16 bit port with the address the encompasses that byte..

Suppose you want to read a byte from address 0x80000003
on the 16 bit port mapped to 0x80000000...

The system will perform a 16 bit read of address 0x80000002
Suppose it read 0x1122 from that 16 bit read...
Since you asked for a byte from address 3 it would return 0x22....
If you had tried to do a byte read from address 2 the same 16 bit read would happen and it would instead return the 0x11 part of the read.


Lastly to be complet doing a byte write to a 16 bit address... (You will or should probably never do this but its possible..)

Say we are writing 0x99 to address 0x80000003
The system will address the 16 bit port as follows...
A 16 bit write of 0x??99 to Address 0x80000002... with the BE3 strobe low and the BE2 strobe high...

Say we are writing 0x44 to address 0x80000002
The system will address the 16 bit port as follows...
A 16 bit write of 0x44?? to Address 0x80000002... with the BE3 strobe high and the BE2 strobe low..

Add of this is covered in detail in the freescale manual....with pretty pictures and diagrams much easier to understand than my random text.

Paul
Post Reply