Hi, Everyone!
I have rather simple code, but it doesn't work correct. I use MSP430f5419 in IAR WorkBench.
#define SWAP8(x) (((x&0xFFFFFFFF)<<32)|((x>>32)&0xFFFFFFFF))
unsigned long long TestFun(unsigned long long inValue)
{ return SWAP8(inValue); }
void SimpleCode(unsigned char *buf, unsigned int len)
{
unsigned int i;
unsigned long long *ptr;
for (i=0; i<len;i+=8)
{
ptr = (unsigned long long*)&buf[i];
*ptr = TestFun(*ptr);
}
}
....
unsigned char Packet[512] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
unsigned int DataSize = 8;
SimpleCode(Packet, DataSize)
I expected such result:
Packet = {0x55, 0x66, 0x77, 0x88, 0x11 ,0x22, 0x33, 0x44};
But I get this:
Packet = {0x55, 0x66, 0x77, 0x00, 0x11 ,0x22, 0x33, 0x88};
I think the problem is in data alignment.
For example, if array "Packet" starts with abstract address 0x11, and was not align to 4-multiple address. Then pointer "ptr" get address 0x10 (Am I right?) here:
ptr = (unsigned long long*)&buf[i];
Then variable "inValue" is 0x0011223344556677
After SWAP8 will get 0x4455667700112233
Then Packet will have {0x55, 0x66, 0x77, 0x00, 0x11 ,0x22, 0x33, 0x88};
If this right, how can I align "Packet" to 4-multiple address?
Or there's some other error?
Best Regards, Mikhail.