//D:\GKOSON_BACK_GARDEN\TOUCH_CLASS\IAP-git\KEIL\MDK-ARM
#include "GW24Q64.h"
static G_SPIFlash_Type *flash=NULL;
void GprintHEX(char *tag,void* A,uint16_t len)
{
printf("[%s-%d]",tag,len);
for(uint16_t i=0;i<len;i++)
printf("%02X ",*( (unsigned char*)A+i ) );
printf("\r\n");
}
//测试范例:--数据结构
typedef struct
{
uint8_t level;
uint16_t len;
uint32_t count;
char mac[12+1];
uint16_t crc;
}ConfiginfoType;
ConfiginfoType cfginfo;
void sysCfginfo_print( void )
{
printy("[全体配置文件大小sizeof(ConfiginfoType)] =%d\r\n",sizeof(ConfiginfoType) );
printy("[offsetof(ConfiginfoType,level) ] =%d\r\n",offsetof(ConfiginfoType,level) );
printy("[offsetof(ConfiginfoType,len) ] =%d\r\n",offsetof(ConfiginfoType,len) );
printy("[offsetof(ConfiginfoType,count) ] =%d\r\n",offsetof(ConfiginfoType,count) );
printy("[offsetof(ConfiginfoType,mac) ] =%d\r\n",offsetof(ConfiginfoType,mac) );
printy("[offsetof(ConfiginfoType,crc) ] =%d\r\n",offsetof(ConfiginfoType,crc) );
GprintHEX("cfginfo",&cfginfo,sizeof(ConfiginfoType));
printy("[level = %2X]\r\n" , cfginfo.level);
printy("[len = %04X]\r\n" , cfginfo.len);
printy("[count = %08X]\r\n" , cfginfo.count);
printy("[蓝牙MAC = %s]\r\n" , cfginfo.mac);
printy("[crc = %04X]\r\n" , cfginfo.crc);
}
//测试范例:--数据结构
//用硬盘的第6个4K来保存
#define W24Q64_CFGINFO_ADD (4096*6)
void sys_cfginfo_clear(void)
{
flash->clearone(W24Q64_CFGINFO_ADD);
printf("W24Q64-格式化W24Q64_CFGINFO_ADD\r\n");
}
void sys_cfginfo_write_(void)
{
cfginfo.crc=0;
printf("sys_cfginfo_write即将操作CRC::");
GprintHEX("cfginfo",&cfginfo,sizeof(ConfiginfoType));
uint16_t savedcrc=crc16Check((uint8_t *)&cfginfo, sizeof(ConfiginfoType));
cfginfo.crc= savedcrc;
printy("\r\n--SAVE--\r\n");
printy("\r\n[FLASH-%04X][NOWCALC-%04X]\r\n",savedcrc,cfginfo.crc);
sys_cfginfo_clear();
flash->write( W24Q64_CFGINFO_ADD , (uint8_t *)&cfginfo , sizeof(ConfiginfoType) );
sysCfginfo_print();
}
void sys_cfginfo_write(ConfiginfoType *cfginfo)
{
cfginfo->crc=0;
printf("sys_cfginfo_write即将操作CRC::");
GprintHEX("cfginfo",&cfginfo,sizeof(ConfiginfoType));
uint16_t savedcrc=crc16Check((uint8_t *)&cfginfo, sizeof(ConfiginfoType));
cfginfo->crc= savedcrc;
printy("\r\n--SAVE--\r\n");
printy("\r\n[FLASH-%04X][NOWCALC-%04X]\r\n",savedcrc,cfginfo->crc);
sys_cfginfo_clear();
flash->write( W24Q64_CFGINFO_ADD , (uint8_t *)cfginfo , sizeof(ConfiginfoType) );
sysCfginfo_print();
}
void sys_cfginfo_read(ConfiginfoType *cfginfo)
{
flash->read( W24Q64_CFGINFO_ADD , (uint8_t *)cfginfo , sizeof(ConfiginfoType) );
}
//测试接口
void sys_cfginfo_test( void )
{
flash = &spiflash;
if(flash->init()) {NEVERSHOW; return;}
memset(&cfginfo , 0x00 , sizeof(ConfiginfoType));
sys_cfginfo_read(&cfginfo);
uint16_t temcrc=cfginfo.crc;
cfginfo.crc=0;
printf("即将操作CRC::");
GprintHEX("cfginfo",&cfginfo,sizeof(ConfiginfoType));
uint16_t savedcrc=crc16Check((uint8_t *)&cfginfo, sizeof(ConfiginfoType));
printy("\r\n[FLASH-%04X][NOWCALC-%04X]\r\n",temcrc,savedcrc);
sysCfginfo_print();
if(temcrc != savedcrc )
{
printf("\r\n新设备\r\n");
memset(&cfginfo , 0x00 , sizeof(ConfiginfoType));
cfginfo.count=0XAB;
sysCfginfo_print();
sys_cfginfo_write(&cfginfo);//----这个函数失败
//sys_cfginfo_write_();//----这个函数成功
soft_system_resert(__func__);
}
printf("\r\n旧设备\r\n");
sysCfginfo_print();
}
单独写的测试代码 看问题在阿里?
居然也可以
修改名字
不要撞车就很好了
void sys_cfginfo_write(ConfiginfoType *info)
{
info->crc=0;
printf("sys_cfginfo_write即将操作CRC::");
GprintHEX("cfginfo",&cfginfo,sizeof(ConfiginfoType));
uint16_t savedcrc=crc16Check((uint8_t *)&cfginfo, sizeof(ConfiginfoType));
info->crc= savedcrc;
sys_cfginfo_clear();
flash->write( W24Q64_CFGINFO_ADD , (uint8_t *)info , sizeof(ConfiginfoType) );
sysCfginfo_print();
}
但是KIL真实测试还是不行