Hi Anand
Thank you for the example.
I have something to clarify
for(address=CFM1StartAddress;address<=CFM1EndAddress;address=address+4)
{
scanf("%2x%2x%2x%2x",&receivedHex[0],&receivedHex[1],&receivedHex[2],&receivedHex[3]); /*Get 4 bytes from UART Terminal*/
for(byte=0; byte<4; byte++)
{
receivedHex[byte] = (((receivedHex[byte] & 0xaa)>>1)|((receivedHex[byte] & 0x55)<<1)); /*Swap LSB with MSB before write into CFM*/
receivedHex[byte] = (((receivedHex[byte] & 0xcc)>>2)|((receivedHex[byte] & 0x33)<<2));
receivedHex[byte] = (((receivedHex[byte] & 0xf0)>>4)|((receivedHex[byte] & 0x0f)<<4));
}
word = (receivedHex[0]<<24)|(receivedHex[1]<<16)|(receivedHex[2]<<8)|(receivedHex[3]); /*Combine 4 bytes to become 1 word before write operation*/
IOWR_32DIRECT(ONCHIP_FLASH_0_DATA_BASE, address, word); /*Command to write into On-Chip Flash IP*/
byte = 0;
word = 0x0;
while((IORD(ONCHIP_FLASH_0_CSR_BASE, 0) & 0x0b) == 0x02)
{
printf("Writing CFM1(%d)\n",address);
}
if((IORD(ONCHIP_FLASH_0_CSR_BASE, 0) & 0x0b) == 0x00)
{
printf("Write to %d failed\n", address);
state=20;
address = 700000;
}
if((IORD(ONCHIP_FLASH_0_CSR_BASE, 0) & 0x0b) == 0x08)
{
}
}
This part
for(byte=0; byte<4; byte++)
{
/*Swap LSB with MSB before write into CFM*/
receivedHex[byte] = (((receivedHex[byte] & 0xaa)>>1)|((receivedHex[byte] & 0x55)<<1));
receivedHex[byte] = (((receivedHex[byte] & 0xcc)>>2)|((receivedHex[byte] & 0x33)<<2));
receivedHex[byte] = (((receivedHex[byte] & 0xf0)>>4)|((receivedHex[byte] & 0x0f)<<4));
}
I shouldn't do if I have Big-Indian option or I should swap MSB and LSB anyway?