#include "board.h" #include "global.h" /** * 读取硬件参数保存部分,要求数据指针地址是4字节对齐 * * @author lxz (2019/5/30/周四) * * @param data * * @return int */ int hw_flash_data_read(uint32_t pos, void * data,uint32_t length) { st_flash_read(pos,(uint32_t *)data,length / 4); //hw_24cxx_read(pos,data,length); return length; } /** * 写入硬件参数部分,要求数据指针地址是4字节对齐 * * @author lxz (2019/5/30/周四) * * @param data * * @return int */ int hw_flash_data_write(uint32_t pos, void * data,uint32_t length) { //开始编写参数 st_flash_write(pos, (uint32_t *)data, length / 4); //hw_24cxx_write(pos,data,length); return length; } /** * * * @author lxz * * @param pos */ void hw_flash_data_erase(uint32_t pos) { st_flash_unlock(); st_flash_erase_secotr(st_flash_addr_to_sector_no(pos)); st_flash_lock(); } /** * 检查指定的空间是否能写入 * * @author lxz (2019/5/31/周五) * * @param pos 必须保证32字节对齐的地址 * @param length * * @return int */ int hw_flash_data_check_empty(uint32_t pos,uint32_t length) { length = (length + 3) / 4; while (length > 0) { if (st_flash_read_word(pos) != 0xFFFFFFFF) { break; } length--; pos+= 4; } return length; } void ManualSaveData(void) { hw_flash_data_erase(MANUAL_SAVE_ADDRESS); hw_flash_data_write(MANUAL_SAVE_ADDRESS,&user_datas[POWEROFF_SAVE_BLOCK_SIZE / 2],MANUAL_SAVE_BLOCK_SIZE); } void ManualReadData(void) { hw_flash_data_read(MANUAL_SAVE_ADDRESS, &user_datas[POWEROFF_SAVE_BLOCK_SIZE / 2],MANUAL_SAVE_BLOCK_SIZE); }