123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #include "includes.h"
- HGS_POC_DEF hgs_poc_type;
- SUT_PRODUCT_PARA sutProductPara;
- char DEV_HARDID[16];
- //读取指定地址的半字(16位数据)
- //faddr:读地址(此地址必须为2的倍数!!)
- //返回值:对应数据
- u16 STMFLASH_ReadHalfWord(u32 faddr)
- {
- return *(vu16*)faddr;
- }
- /**********************************************************************************************************
- *写页数据,擦除整页2048字节,并写入Byte数据,数据可少于2048Btye,但必须是偶数。
- ************************************************************************************************************/
- void WritePageData(unsigned long WriteAddr,unsigned char *pData,unsigned short DataLen)
- {
- unsigned short i;
- unsigned short temp;
- FLASH_Status status;
-
- if(WriteAddr<FLASH_BASE || (WriteAddr>=(FLASH_BASE+1024*STM32_FLASH_SIZE)))return;//非法地址
- if(WriteAddr&0x0000003ff)return;//非页首地址
-
- FLASH_Unlock(); //解锁
- status=FLASH_ErasePage(WriteAddr);//擦除这个扇区
-
- if(status!=FLASH_COMPLETE){
- return;
- }
-
- //写入
- for(i = 0; i < DataLen; i+=2)
- {
- //数据8位融合为16位
- temp = (((unsigned short)pData[i+1])<<8) + ((unsigned short)pData[i]);
- FLASH_ProgramHalfWord((WriteAddr+i),temp);
- }
- FLASH_Lock();//上锁
- }
- void ReadFlashData(unsigned long ReadAddr,unsigned char *pData,unsigned short DataLen)
- {
- int i,j;
- unsigned short temp;
- j=0;
- for(i=0;i<DataLen;i+=2){
- temp=STMFLASH_ReadHalfWord(ReadAddr+i);
- pData[j++]=(unsigned char)(temp&0xff);
- pData[j++]=(temp>>8)&0xff;
- }
- }
- /**********************************************************************************************************
- SaveProductParaToFlash
- ************************************************************************************************************/
- void SaveProductParaToFlash()
- {
- uint32_t tick;
- //char recBuf[60];
-
- PWR_EN_HIGH;
- // if(sutProductPara.takeNoteFlag)
- // {
- // //记录保存相关信息到SPI FLASH
- // tick=RTC_GetCounter();
- // //时间 位置 机型 序列号
- // snprintf(recBuf, sizeof(recBuf), "[rec]%d,%s,%s,%08x|\r\n",tick,recoreInfo,sutProductPara.ProductName,sutProductPara.PSN);
- // sFlash_Write(recBuf, RECORD_INFO_ADDRESS, sizeof(recBuf));
- // SlwTrace(INF, recBuf, 0);
- // }
- ////////////////////////
- WritePageData(MAIN_CONFIG_ADDR,(unsigned char *)&sutProductPara,sizeof(SUT_PRODUCT_PARA));
- //DelayMs(100);
- //WritePageData(BACKUP_CONFIG_ADDR,(unsigned char *)&sutProductPara,sizeof(SUT_PRODUCT_PARA));
-
- //PWR_EN_LOW;//软按键不需要
-
- }
- /********************************************************************
- *SaveParaToFlash
- 将sutNetPara重要参数保存到FLASH
- *********************************************************************/
- #define MIN_PSN_NUM 1000000
- #define MAX_PSN_NUM 4200000000
- void ReadProductParaFromFlash(void)
- {
- char needsave=0;
- char needsleep=0;
- //1、读取主区参数
- ReadFlashData(MAIN_CONFIG_ADDR,(unsigned char *)&sutProductPara,sizeof(SUT_PRODUCT_PARA));
- if(sutProductPara.PSN < MIN_PSN_NUM || sutProductPara.PSN > MAX_PSN_NUM){
- printf("PSN invalid:%x\r\n",sutProductPara.PSN);
- sutProductPara.PSN=1990595007;
- }
- if(sutProductPara.ProductVersion != PRODUCT_VERSION){
- sutProductPara.ProductVersion=PRODUCT_VERSION;
- needsave=1;
- }
- if(0!=strcmp(sutProductPara.ProductName, PRODUCT_NAME)){
- strcpy(sutProductPara.ProductName, PRODUCT_NAME);
- needsave=1;
- }
-
- if(newPara.PF1Status>1){
- newPara.PF1Status=0;
- needsave=1;
- }
-
-
- if(sutProductPara.SleepFlag==1){
- needsave=1;
- needsleep=1;
- sutProductPara.SleepFlag=0;
- }
-
- if(needsave!=0) SaveProductParaToFlash();
- if(needsleep) Sleeping();
- }
- void GpsTimeUpdate(void)
- {
-
- newPara.gpsTimeIndex=0;// ZT260不支持GPS
-
- if(GPS_TimeTable[newPara.gpsTimeIndex])//判断GPS是否已关,根据上传时间来算
- {
- //GPS_PWREN_HIGH;
- g_uiGpsStat=1;
-
- }
- else{
- //GPS_PWREN_LOW;
- g_uiGpsStat=0;
- sutGpsInfo.isGpsWork=0;
- }
-
- printf("newPara.gpsTimeIndex===%d,%d\r\n",newPara.gpsTimeIndex,g_uiGpsStat);
-
- }
|