mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
107 lines
4.0 KiB
C
107 lines
4.0 KiB
C
/*********************************************************************************************************************
|
||
* COPYRIGHT NOTICE
|
||
* Copyright (c) 2020,<2C><><EFBFBD>ɿƼ<C9BF>
|
||
* All rights reserved.
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>QQȺ<51><C8BA><EFBFBD><EFBFBD>Ⱥ<EFBFBD><C8BA>824575535
|
||
*
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC><EFBFBD><EFBFBD>У<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5>;<EFBFBD><CDBE>
|
||
* <20><>ӭ<EFBFBD><D3AD>λʹ<CEBB>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>뱣<EFBFBD><EBB1A3><EFBFBD><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC>İ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
*
|
||
* @file eeprom(Dflash)
|
||
* @company <09>ɶ<EFBFBD><C9B6><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC><EFBFBD><EFBFBD><EFBFBD>˾
|
||
* @author <09><><EFBFBD>ɿƼ<C9BF>(QQ3184284598)
|
||
* @version <09>鿴doc<6F><63>version<6F>ļ<EFBFBD> <20>汾˵<E6B1BE><CBB5>
|
||
* @Software ADS v1.2.2
|
||
* @Target core TC264D
|
||
* @Taobao https://seekfree.taobao.com/
|
||
* @date 2020-3-23
|
||
********************************************************************************************************************/
|
||
|
||
|
||
#include "IfxScuWdt.h"
|
||
#include "IfxFlash.h"
|
||
#include "zf_assert.h"
|
||
#include "zf_eeprom.h"
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief У<><D0A3>FLASH<53>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
// @param sector_num <09><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ0-11
|
||
// @param page_num <09><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ҳ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ0-1023
|
||
// @return <09><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD>0û<30><C3BB><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
// @since v1.0
|
||
// Sample usage: flash_check(0,0);//У<><D0A3>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0ҳ<30>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
uint8 flash_check(uint32 sector_num, uint32 page_num)
|
||
{
|
||
ZF_ASSERT(EEPROM_SECTOR_NUM>sector_num);
|
||
ZF_ASSERT(EEPROM_SECTOR_PAGE_NUM>page_num);
|
||
uint32 sector_addr = IfxFlash_dFlashTableEepLog[sector_num].start;
|
||
uint32 page_addr = sector_addr + page_num * IFXFLASH_DFLASH_PAGE_LENGTH;
|
||
|
||
uint32 temp = *(uint32 *)page_addr;
|
||
if(0 != temp) return 1;
|
||
|
||
return 0;
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
// @param sector_num <09><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ0-11
|
||
// @return void
|
||
// @since v1.0
|
||
// Sample usage: eeprom_erase_sector(0);
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
void eeprom_erase_sector(uint32 sector_num)
|
||
{
|
||
ZF_ASSERT(EEPROM_SECTOR_NUM>sector_num);
|
||
|
||
uint32 flash = 0;
|
||
uint16 end_init_sfty_pw;
|
||
uint32 sector_addr = IfxFlash_dFlashTableEepLog[sector_num].start;
|
||
|
||
end_init_sfty_pw = IfxScuWdt_getSafetyWatchdogPassword();
|
||
|
||
IfxScuWdt_clearSafetyEndinit(end_init_sfty_pw);
|
||
IfxFlash_eraseSector(sector_addr);
|
||
IfxScuWdt_setSafetyEndinit(end_init_sfty_pw);
|
||
|
||
IfxFlash_waitUnbusy(flash, IfxFlash_FlashType_D0);
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief <20><><EFBFBD><EFBFBD>һҳ
|
||
// @param sector_num <09><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ0-11
|
||
// @param page_num <09><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ0-1023
|
||
// @param buf <09><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ַ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>Ϊuint32
|
||
// @return void
|
||
// @since v1.0
|
||
// Sample usage: eeprom_page_program(0,0, &buf);
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
void eeprom_page_program(uint32 sector_num, uint32 page_num, uint32 *buf)
|
||
{
|
||
ZF_ASSERT(EEPROM_SECTOR_NUM>sector_num);
|
||
ZF_ASSERT(EEPROM_SECTOR_PAGE_NUM>page_num);
|
||
|
||
uint32 errors = 0;
|
||
uint32 flash = 0;
|
||
uint16 end_init_sfty_pw;
|
||
uint32 sector_addr = IfxFlash_dFlashTableEepLog[sector_num].start;
|
||
|
||
end_init_sfty_pw = IfxScuWdt_getSafetyWatchdogPassword();
|
||
|
||
uint32 page_addr = sector_addr + page_num * IFXFLASH_DFLASH_PAGE_LENGTH;
|
||
errors = IfxFlash_enterPageMode(page_addr);
|
||
ZF_ASSERT(0 == errors);
|
||
|
||
IfxFlash_waitUnbusy(flash, IfxFlash_FlashType_D0);
|
||
|
||
IfxFlash_loadPage(page_addr, buf[0], 0);
|
||
|
||
IfxScuWdt_clearSafetyEndinit(end_init_sfty_pw);
|
||
IfxFlash_writePage(page_addr);
|
||
IfxScuWdt_setSafetyEndinit(end_init_sfty_pw);
|
||
|
||
IfxFlash_waitUnbusy(flash, IfxFlash_FlashType_D0);
|
||
}
|
||
|