Пример #1
0
bool skynet_nv_write(NV_DATA_T* new_data) {
	__disable_irq();
	uint8_t r = 0;

	// prepare
	r += Chip_IAP_PreSectorForReadWrite(SECTOR_NUM, SECTOR_NUM);

	// erase
	r += Chip_IAP_EraseSector(SECTOR_NUM, SECTOR_NUM);

	// prepare again
	r += Chip_IAP_PreSectorForReadWrite(SECTOR_NUM, SECTOR_NUM);

	// write
	r += Chip_IAP_CopyRamToFlash(SECTOR_STARTADDR, (uint32_t *)new_data, sizeof(NV_DATA_T));

	// read again, just for sure
	skynet_nv_read(&read);

	__enable_irq();
	return (r == 0);
}
Пример #2
0
void flash_write(uint32_t f_dst, const uint32_t *src, uint32_t n_words) {
	uint8_t e;
	uint32_t Start = flash_get_sector_info(f_dst, NULL, NULL);
	uint32_t End = flash_get_sector_info(f_dst + (n_words - 1) * 4, NULL, NULL);
    __disable_irq();
	e = Chip_IAP_PreSectorForReadWrite(Start, End, BANK);
	F_ASSERT(e != IAP_CMD_SUCCESS, "Prepare for erase FAIL");
    DBG("Write Prepare ok %d:%d:%08X:%08Xx%d\n", Start, End, f_dst, src, n_words);
	e = Chip_IAP_CopyRamToFlash(f_dst, (uint32_t*) src, n_words * 4);
    F_ASSERT(e != IAP_CMD_SUCCESS, "Write FAIL");
    DBG("Write ok %d:%d:%08X:%08Xx%d\n", Start, End, f_dst, src, n_words);
    e = Chip_IAP_Compare(f_dst, (uint32_t) src, n_words * 4);
    F_ASSERT(e != IAP_CMD_SUCCESS, "Verify FAIL");
    DBG("Write Check ok %d:%d:%08X:%08Xx%d\n", Start, End, f_dst, src, n_words);
	__enable_irq();
}
Пример #3
0
void flash_erase(uint32_t f_dst, const uint32_t *src, uint32_t n_words) {
	uint8_t e;
	// check there is something to write
	if (n_words == 0) {
		return;
	}
	__disable_irq();

    // erase the sector(s)
	uint32_t Start = flash_get_sector_info(f_dst, NULL, NULL);
	uint32_t End = flash_get_sector_info(f_dst + 4 * n_words - 1, NULL, NULL);

    e = Chip_IAP_PreSectorForReadWrite(Start, End, BANK);
	F_ASSERT(e != IAP_CMD_SUCCESS, "Prepare for erase FAIL");
    DBG("ERASE Prepare ok %d:%d\n", Start, End);
    e = Chip_IAP_EraseSector(Start, End, BANK);
    F_ASSERT(e != IAP_CMD_SUCCESS, "Erase FAIL");
    DBG("ERASE Operation ok %d:%d\n", Start, End);
    e = Chip_IAP_BlankCheckSector(Start, End, BANK);
    F_ASSERT(e != IAP_CMD_SUCCESS, "Blank check FAIL");
    DBG("ERASE Check ok %d:%d\n", Start, End);
    __enable_irq();
}