📄 custom.c
字号:
FLASH_ALLOW_READ = FALSE;
//printf("\n asdf");
if (report_verbose)
{
print("Erasing Block [%X] ...\n", (unsigned int) block) ;
}
InputCodedSequence((ULONG) FLASH_1_BASE) ; /* Enter preliminary coded cycles */
ptr_to_b = (UINT16 *) (FLASH_1_BASE | COMMAND_ADDR); /* pointer to 29F400T boot_block */
*ptr_to_b = ERASE_SETUP; /* write erase_setup command for block */
InputCodedSequence((ULONG) FLASH_1_BASE) ; /* Enter preliminary coded cycles */
ptr_to_b = (UINT16 *) block; /* point to block_start_add for erase */
*ptr_to_b = B_ERASE_CONFIRM;
task_delay(1);
while (eraseprogressing)
{
lastreading = *ptr_to_b;
if ((lastreading & 0x80) == 0x80)
{
/* Poll DQ7 until erase completed */
eraseprogressing = 0;
erasefailed = 0;
}
else if ((lastreading & 0x20) == 0x20) /* test s_reg erase_error_flag */
{
eraseprogressing = 0;
}
}
if (erasefailed)
{
if ((*ptr_to_b & 0x80) != 0x80)
{
print("Erase Failure\n") ;
*ptr_to_b = READ_ARRAY; /* write read/reset command to reset P/E.C. */
/* and error flag */
FLASH_ALLOW_READ = TRUE;
return 0;
}
}
FLASH_ALLOW_READ = TRUE;
return 1;
}
/*=======================================================================================*/
/*=========================================================================================*/
int FlashWrite(int entries, UINT32 address, unsigned char *data)
{
volatile UINT16 *addr;
UINT16 flashdata = *(UINT16 *) data;
UINT16 const flashdata_dq7 = flashdata & 0x80;
UINT16 lastreading;
int icount = 0;
// InputCodedSequence((ULONG)FLASH_1_BASE) ; /* Enter preliminary coded cycles */
ptr_to_b = (device_U16_t *) (0x7fc0aaaa); /* pointer to 29F400T boot_block */
*ptr_to_b = (device_U16_t) CODEDCYCLE_1;
ptr_to_b = (device_U16_t *) (0x7fc05555); /* pointer to 29F400T boot_block */
*ptr_to_b = (device_U16_t) CODEDCYCLE_2;
addr = (UINT16 *) (FLASH_1_BASE | COMMAND_ADDR);
*addr = PROGRAM_SETUP; /* setup write word */
addr = (UINT16 *) (address & 0x7fffffff);
*addr = flashdata; /* write word to addressed location */
while (icount < 8)
{
icount++;
lastreading = *addr;
if ((lastreading & 0x80) == flashdata_dq7) /* Poll DQ7 until programming comples */
{
return 1;
}
else
{
if ((lastreading & 0x20) == 0x20) /* test s_reg progr_error_flag */
{
lastreading = *addr ;
if ((lastreading & 0x80) == flashdata_dq7) /* Poll DQ7 until programming comples */
{
return 1;
}
else
{
return 0;
}
}
}
}
if (icount == 16)
{
return 0;
}
else
{
return 1;
}
}
void RomClearupMiCo(void)
{
}
/************************************************************************
Function : VerifyFlash
Description : Verifies a block of flash memory. For simplicity it verifies
on a pbyte by byte basis.
Returns : Returns False - failed, True - OK;
************************************************************************/
int VerifyFlashMiCo(UINT32 flash_addr, UBYTE *source_data_p, int length)
{
volatile UINT32 *fpl = (UINT32 *) flash_addr; /* ptr to position in flash */
volatile UBYTE *fp = (UBYTE *) flash_addr; /* ptr to position in flash */
volatile UBYTE *sp = (UBYTE *) source_data_p; /* ptr to the source data */
*fpl = READ_ARRAY;
if (length > 0)
{
/* length must be 1 or above */
for (; length > 0 ; length -= 1)
{
if (*fp != *sp)
{
print("verify FAILED for address 0x%2X: read 0x%x : expected 0x%2X\n\n",
(unsigned int)
fp,
*fp,
*sp);
return FALSE ;
}
sp++;
fp++;
} /* each byte */
} /* for length */
return TRUE ;
}
int FlashVerify(int entries, UINT32 address, unsigned char *data)
{
volatile UINT16 *addr;
UINT16 lastreading;
UINT16 flashdata = *(UINT16 *) data;
addr = (UINT16 *) (address & 0x7fffffff);
lastreading = *addr ;
if ((lastreading & 0x80) == (flashdata & 0x80))
{
return 1;
}
else
{
// Don't add debugmessage in this line,it can cause unknow problems
return 0;
}
}
int ProgramFlashMiCo(UINT32 flash_addr, UBYTE *source_data_p_old, int length)
{
int i;
UBYTE *source_data_p;
source_data_p = source_data_p_old;
write_error = 0;
FLASH_ALLOW_READ = FALSE;
while (length > 0)
{
i = 0;
while (i < 3)
{
i++;
// task_delay(1); // Don't delete this line
task_lock();
#if 0
if (!FlashWrite((int) length, flash_addr, source_data_p))
{
write_error++;
}
task_unlock();
if (!FlashVerify((int) length, flash_addr, source_data_p))
{
verify_error++;
continue;
}
break;
#else
if (!FlashWrite((int) length, flash_addr, source_data_p))
{
write_error++;
task_unlock();
continue;
}
task_unlock();
break;
#endif
}
if (i == 3)
{
print("fatal error ! ==> Retry write flash failed at address 0x%lx,bytes 0x%x\n",
flash_addr,
(UBYTE) * source_data_p);
FLASH_ALLOW_READ = TRUE;
return 0;
}
flash_addr += 2;
length -= 2;
source_data_p += 2;
FLASH_NWRITED += 2;
}
/* Return to read array mode after programming*/
RESET_FLASH_1;
FLASH_ALLOW_READ = TRUE;
return 1;
}
int EraseAppBlock(void)
{
return 0;
}
int ProgramAppBlock(void)
{
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -