📄 upsd_flash.c
字号:
function.
Note: The address that is passed in this function can be an address that
resides in any Flash segment that has a chip select. For example, if
fs0 and fs5 are used in the design, passing an address in this function
that resides in either fs0 or fs5 will invoke the bulk erase operation. */
unsigned char flash_erase_bulk(
volatile unsigned char xdata* flash_bulk_erase_address)
{
unsigned char done;
unsigned char poll;
unsigned char error;
unsigned char err;
done = FALSE;
err = FALSE;
// Note: the following constants (FLASH_COMMON_XXXX)
// are declared type volatile in the header file
// so they are not optimized away by the compiler
*(FLASH_COMMON_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
*(FLASH_COMMON_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
*(FLASH_COMMON_X555) = 0x80; // write 0x80 command to erase entire chip
*(FLASH_COMMON_X555) = 0xAA; // continue unlock sequence
*(FLASH_COMMON_XAAA) = 0x55; // continue unlock sequence
*(FLASH_COMMON_X555) = 0x10; // write 0x10 command to complete erase command
do // now use dat polling method to verify successful erase
{
poll = *(flash_bulk_erase_address); // read flash status from any address
// within the defined flash address space
error = poll & NVM_ERROR; // save timeout error bit at DQ5
poll = poll & NVM_DATA_POLL; // look at D7
if (poll == NVM_DATA_POLL) // compare DQ7
done = TRUE; // bulk erase OK,
// indicate successful exit criteria
else if (error == NVM_ERROR) // check for timeout error
err = TRUE; // indicate timeout error occurred
} while((done == FALSE) && (err == FALSE));
if (err == TRUE) // make sure timeout error and dat poll didn't
// occur simultaneously
{
poll = *(flash_bulk_erase_address); // Read flash status again
poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
if (poll == NVM_DATA_POLL) // compare DQ7
done = TRUE; // the flash erased OK at the same
// time timout error occured, indicate successful
// exit criteria
*(FLASH_COMMON_X555) = 0xF0; // reset the flash array (short reset instruction)
// now delay 3 msec per dat sheet
}
return(done); // a successful flash erase returns 1, timeout error returns 0
}
unsigned char flash_boot_erase_bulk(
volatile unsigned char xdata* flash_bulk_erase_address)
{
unsigned char done;
unsigned char poll;
unsigned char error;
unsigned char err;
done = FALSE;
err = FALSE;
// Note: the following constants (FLASH_COMMON_XXXX)
// are declared type volatile in the header file
// so they are not optimized away by the compiler
*(FLASH_BOOT_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
*(FLASH_BOOT_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
*(FLASH_BOOT_X555) = 0x80; // write 0x80 command to erase entire chip
*(FLASH_BOOT_X555) = 0xAA; // continue unlock sequence
*(FLASH_BOOT_XAAA) = 0x55; // continue unlock sequence
*(FLASH_BOOT_X555) = 0x10; // write 0x10 command to complete erase command
do // now use dat polling method to verify successful erase
{
poll = *(flash_bulk_erase_address); // read flash status from any address
// within the defined flash address space
error = poll & NVM_ERROR; // save timeout error bit at DQ5
poll = poll & NVM_DATA_POLL; // look at D7
if (poll == NVM_DATA_POLL) // compare DQ7
done = TRUE; // bulk erase OK,
// indicate successful exit criteria
else if (error == NVM_ERROR) // check for timeout error
err = TRUE; // indicate timeout error occurred
} while((done == FALSE) && (err == FALSE));
if (err == TRUE) // make sure timeout error and dat poll didn't
// occur simultaneously
{
poll = *(flash_bulk_erase_address); // Read flash status again
poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
if (poll == NVM_DATA_POLL) // compare DQ7
done = TRUE; // the flash erased OK at the same
// time timout error occured, indicate successful
// exit criteria
*(FLASH_BOOT_X555) = 0xF0; // reset the flash array (short reset instruction)
// now delay 3 msec per dat sheet
}
return(done); // a successful flash erase returns 1, timeout error returns 0
}
/*Module: flash_reset
Resets the main Flash memory to Read Array mode.
After this reset, the Flash memory may be read like a ROM device.
You'll need to include the header files generated by PSDsoft
Express. */
void flash_reset() // reset flash, read array mode
{
// Note: the following constants (FLASH_COMMON_XXXX)
// are declared type volatile in the header file
// so they are not optimized away by the compiler
*(FLASH_COMMON_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
*(FLASH_COMMON_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
*(FLASH_COMMON_X555) = 0xF0; // write 0xF0 command to reset
// Flash memory to Read Array Mode
// now delay 3 msec per dat sheet
}
/* Module: flash_read_id
Reads the Flash Identifier byte from main Flash memory. You'll need
to include the header files generated by PSDsoft Express.
Important: The address passed to this function should be independent
of memory paging or else the PSD page register value should be set to
the correct page prior to calling this function.
Note: The flash memory in the boot area of a PSD813F2 or PSD813F4 does
not provide an ID. Only the main Flash memory in all PSD813FX provides
an ID. */
unsigned char flash_read_id(flash_id_address) // read flash identifier
volatile unsigned char *flash_id_address;
{
unsigned char id;
// Note: the following constants (FLASH_COMMON_XXXX)
// are declared type volatile in the header file
// so they are not optimized away by the compiler
*(FLASH_COMMON_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
*(FLASH_COMMON_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
*(FLASH_COMMON_X555) = 0x90; // write 0x90 command to get ID
id = *(flash_id_address); // read flash status, address bit A6 = 0
// A1 = 0
// A0 = 1
*(FLASH_COMMON_X555) = 0xF0; // reset the flash array (short reset instruction)
// now delay 3 msec per dat sheet
return (id); // return byte ID value
}
/* Module: flash_erase_sector
Erases the specified sector in main Flash memory.
Need to include mapflash.h. Important: The address passed to this function
should be independent of memory paging or else the PSD page register should
be set to the correct page prior to calling this function. */
unsigned char flash_erase_sector(
volatile unsigned char xdata * sector_erase_address)
{
char done;
unsigned char poll;
unsigned char error;
unsigned char err;
done = FALSE;
*(FLASH_COMMON_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
*(FLASH_COMMON_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
*(FLASH_COMMON_X555) = 0x80; // write 0x80 command
*(FLASH_COMMON_X555) = 0xAA; // continue unlock sequence
*(FLASH_COMMON_XAAA) = 0x55; // continue unlock sequence
*(sector_erase_address) = 0x30; // write 0x30 command to indicate sector erase command
do // now use data polling method to verify successful erase
{
poll = *(sector_erase_address); // read flash status from any address
// within the flash address sector space
error = poll & NVM_ERROR; // save timeout error bit at DQ5
poll = poll & NVM_DATA_POLL; // look at D7
if (poll == NVM_DATA_POLL) // compare DQ7
done = TRUE; // erase OK,
// indicate successful exit criteria
else if (error == NVM_ERROR) // check for timeout error
err = TRUE; // indicate timeout error occurred
} while((done == FALSE) && (error == FALSE));
if (err == TRUE) // make sure timeout error and data poll didn't
// occur simultaneously
{
poll = *(sector_erase_address); // Read flash status again
poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
if (poll == NVM_DATA_POLL) // compare DQ7
done = TRUE; // the flash erased OK at the same
// time timout error occured, indicate successful
*(FLASH_COMMON_X555) = 0xF0; // reset the flash array (short reset instruction)
} // exit criteria
return(done); // a successful flash erase returns 1, timeout error returns 0
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -