
Naw, I get some of it, not enough to write code from.
Edit;
I have noticed that there is a right bit shift in the calling routines ... one is asr (Arithmetic Shift Right), the other is lsr (Logical Shift Right), to d0 whatever is there ...
Code: Select all
///////////////////////////////////////////////////////////////////////////////
// Erase the given block.
///////////////////////////////////////////////////////////////////////////////
uint8_t Amd_EraseBlock(uint32_t address)
{
// Return zero if successful, anything else is an error code.
unsigned short status = 0;
uint16_t volatile * flashBase = (uint16_t*)address;
// Tell the chip to erase the given block.
+#if defined P12
+ SIM_CSOR0 |= 0x4;
+#else
SIM_CSOR0 = 0x7060;
+#endif
COMMAND_REG_AAA = 0xAAAA;
COMMAND_REG_554 = 0x5555;
COMMAND_REG_AAA = 0x8080;
COMMAND_REG_AAA = 0xAAAA;
COMMAND_REG_554 = 0x5555;
*flashBase = 0x3030;
uint16_t read1 = 0;
uint16_t read2 = 0;
for (int iterations = 0; iterations < 0x640000; iterations++)
{
read1 = *flashBase & 0x40;
ScratchWatchdog();
read2 = *flashBase & 0x40;
if (read1 == read2)
{
// Success!
break;
}
uint16_t read3 = *flashBase & 0x20;
if (read3 == 0)
{
continue;
}
status = 0xA0;
break;
}
if (status == 0xA0)
{
read1 = *flashBase & 0x40;
read2 = *flashBase & 0x40;
if (read1 != read2)
{
status = 0xB0;
}
else
{
// Success!
status = 0;
}
}
// Return to array mode.
*flashBase = 0xF0F0;
*flashBase = 0xF0F0;
+#if defined P12
+ SIM_CSOR0 = 0xA332;
+#else
SIM_CSOR0 = 0x1060;
+#endif
return status;
}
Code: Select all
///////////////////////////////////////////////////////////////////////////////
// Get the manufacturer and type of flash chip.
///////////////////////////////////////////////////////////////////////////////
uint32_t Amd_GetFlashId()
{
SIM_CSBAR0 = 0x0007;
SIM_CSORBT = 0x6820;
// Switch to flash into ID-query mode.
+#if defined P12
+ SIM_CSOR0 = 0xF322;
+#else
SIM_CSOR0 = 0x7060;
+#endif
COMMAND_REG_AAA = 0xAAAA;
COMMAND_REG_554 = 0x5555;
COMMAND_REG_AAA = 0x9090;
// Read the identifier from address zero.
//flashIdentifier = FLASH_IDENTIFIER;
uint16_t manufacturer = FLASH_MANUFACTURER;
uint16_t device = FLASH_DEVICE;
uint32_t id = ((uint32_t)manufacturer << 16) | device;
// Switch back to standard mode.
FLASH_BASE = READ_ARRAY_COMMAND;
+#if defined P12
+ SIM_CSOR0 = 0xA332;
+#else
SIM_CSOR0 = 0x1060;
+#endif
return id;
}
Code: Select all
///////////////////////////////////////////////////////////////////////////////
// Write data to flash memory.
// This is invoked by HandleWriteMode36 in common-readwrite.c
///////////////////////////////////////////////////////////////////////////////
uint8_t Amd_WriteToFlash(unsigned int payloadLengthInBytes, unsigned int startAddress, unsigned char *payloadBytes, int testWrite)
{
char errorCode = 0;
unsigned short status;
unsigned short* payloadArray = (unsigned short*) payloadBytes;
unsigned short* flashArray = (unsigned short*) startAddress;
for (unsigned index = 0; index < payloadLengthInBytes / 2; index++)
{
unsigned short volatile *address = &(flashArray[index]);
unsigned short value = payloadArray[index];
if (!testWrite)
{
+#if defined P12
+ SIM_CSOR0 |= 0x4;
+#else
SIM_CSOR0 = 0x7060;
+#endif
COMMAND_REG_AAA = 0xAAAA;
COMMAND_REG_554 = 0x5555;
COMMAND_REG_AAA = 0xA0A0;
*address = value;
}
char success = 0;
for(int iterations = 0; iterations < 0x1000; iterations++)
{
ScratchWatchdog();
uint16_t read = testWrite ? value : *address;
if (read == value)
{
success = 1;
break;
}
}
if (!success)
{
// Return flash to normal mode and return the error code.
errorCode = 0xAA;
if (!testWrite)
{
*address = 0xF0F0;
*address = 0xF0F0;
+#if defined P12
+ SIM_CSOR0 = 0xA332;
+#else
SIM_CSOR0 = 0x1060;
+#endif
}
return errorCode;
}
}
if (!testWrite)
{
// Return flash to normal mode.
unsigned short* address = (unsigned short*)startAddress;
*address = 0xF0F0;
*address = 0xF0F0;
+#if defined P12
+ SIM_CSOR0 = 0xA332;
+#else
SIM_CSOR0 = 0x1060;
+#endif
}
return 0;
}
Code: Select all
andi.w #$FEFF,(word_FFFFFA50).w
Code: Select all
move.w (word_FFFFFA7E).w,word_FFFFFFFC(a6)
bset #4,var_4(a6)
move.w var_4(a6),(word_FFFFFA7E).w
move.w (word_FFFFFA7C).w,dword_FFFFFFF8(a6)
andi.b #$F8,dword_FFFFFFF8+1(a6)
ori.b #5,dword_FFFFFFF8+1(a6)
move.w dword_FFFFFFF8(a6),(word_FFFFFA7C).
Code: Select all
loc_FFFF215C:
move.w #$AAAA,($AAA).w
move.w #$5555,($554).w
move.w #$A0A0,($AAA).w
move.w (a0),(a1)
move.w (a0),d5
Code: Select all
loc_FFFF2212:
addq.l #2,a1
addq.l #2,a0
subq.l #1,d1
bne.w loc_FFFF215C
Code: Select all
move.w (word_FFFFFA7E).w,var_4(a6)
bclr #4,var_4(a6)
move.w var_4(a6),(word_FFFFFA7E).w
Code: Select all
loc_FFFF2598:
moveq #1,d0
lsl.l #8,d0
move.w (word_FFFFFA50).w,d1
and.l #$100,d0
and.l #unk_FFFFFEFF,d1
or.l d0,d1
move.w d1,(word_FFFFFA50).w
Code: Select all
andi.w #$FEFF,(word_FFFFFA50).w
Code: Select all
move.w (word_FFFFFA7E).w,word_FFFFFFFC(a6)
bset #4,var_4(a6)
move.w var_4(a6),(word_FFFFFA7E).w
move.w (word_FFFFFA7C).w,dword_FFFFFFF8(a6)
andi.b #$F8,dword_FFFFFFF8+1(a6)
ori.b #5,dword_FFFFFFF8+1(a6)
move.w dword_FFFFFFF8(a6),(word_FFFFFA7C).
Code: Select all
move.w (word_FFFFFA7E).w,var_4(a6)
bclr #4,var_4(a6)
move.w var_4(a6),(word_FFFFFA7E).w
Code: Select all
///////////////////////////////////////////////////////////////////////////////
// Write data to flash memory.
// This is invoked by HandleWriteMode36 in common-readwrite.c
///////////////////////////////////////////////////////////////////////////////
uint8_t Amd_WriteToFlash(unsigned int payloadLengthInBytes, unsigned int startAddress, unsigned char *payloadBytes, int testWrite)
{
char errorCode = 0;
unsigned short status;
unsigned short saveFA50 = (*(unsigned short *)(0xFFFFFA50)); // Save value at FA50
unsigned short* payloadArray = (unsigned short*) payloadBytes;
unsigned short* flashArray = (unsigned short*) startAddress;
for (unsigned index = 0; index < payloadLengthInBytes / 2; index++)
{
unsigned short volatile *address = &(flashArray[index]);
unsigned short value = payloadArray[index];
if (!testWrite)
{
#if defined P12
(*(unsigned short *)(0xFFFFFA50)) &= 0xFEFF;
SIM_CSOR0 |= 0x4;
#else
SIM_CSOR0 = 0x7060;
#endif
COMMAND_REG_AAA = 0xAAAA;
COMMAND_REG_554 = 0x5555;
COMMAND_REG_AAA = 0xA0A0;
*address = value;
}
char success = 0;
for(int iterations = 0; iterations < 0x1000; iterations++)
{
ScratchWatchdog();
uint16_t read = testWrite ? value : *address;
if (read == value)
{
success = 1;
break;
}
}
if (!success)
{
// Return flash to normal mode and return the error code.
errorCode = 0xAA;
if (!testWrite)
{
*address = 0xF0F0;
*address = 0xF0F0;
#if defined P12
(*(unsigned short *)(0xFFFFFA50)) = saveFA50; // Restore with saved value
SIM_CSOR0 = 0xA332;
#else
SIM_CSOR0 = 0x1060;
#endif
}
return errorCode;
}
}
if (!testWrite)
{
// Return flash to normal mode.
unsigned short* address = (unsigned short*)startAddress;
*address = 0xF0F0;
*address = 0xF0F0;
#if defined P12
(*(unsigned short *)(0xFFFFFA50)) = saveFA50; // Restore with saved value
SIM_CSOR0 = 0xA332;
#else
SIM_CSOR0 = 0x1060;
#endif
}
return 0;
}
Where, inquiring minds would like to know!antus wrote:there is some code space optimisation to be had there