If your IC sends MSB first but the destination receives LSB first, transformation of the data has to be taken.
ex:
We send 0x41 (0100 0001), but the receiver will receive 0x82 (1000 0010).
So before the sending, we have to transform 0x41 to 0x82 first.
That's why this routine exists.
static inline uint8_t MSB_LSB( uint8_t indata )
{
int i = 0, shifts = 0;
int max_shift = 7;
uint8_t tmp_var, outdata = 0;
for (i = 0; i < max_shift + 1; ++i)
{
tmp_var = indata & (0x01 << i);
shifts = max_shift - (i << 1);
if (shifts > 0)
tmp_var <<= shifts;
else
{
shifts = (i << 1) - max_shift;
tmp_var >>= shifts;
}
outdata |= tmp_var;
}
printk("MSB_LSB(0x%x) -> 0x%x\n", indata, outdata);
return outdata;
}
2006年7月24日 星期一
MSB/LSB issue
標籤:
Uncategoried
延伸閱讀:
- 青藏鐵路 - 2006-07-04
- DDR 記憶體之 Q&A - 2006-06-16
- 2.5 吋硬碟與 USB 的愛恨情仇 - 2006-06-15
- MSN Bot - 2006-06-14
- What Do You Got by Bon Jovi - 2011-01-03
訂閱:
張貼留言 (Atom)
It's a Big-Endian or Little-Endian ?
回覆刪除maybe it depends on hardware circuit~
sometimes, we always can use hardware-strapping to decide which
type we needed~
版主回覆:(07/06/2012 02:56:31 PM)