123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- /********************************************************************************
- * File Name: ProductPara.c
- * Function Describe:
- * Explain:
- * Writer: ShiLiangWen
- * Date: 2015-7-6
- *******************************************************************************/
- #define THIS_FILE_ID 6
- //-----------------------------------------------------------------------------
- #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;
- }
- //从指定地址开始读出指定长度的数据
- //ReadAddr:起始地址
- //pBuffer:数据指针
- //NumToWrite:半字(16位)数
- void STMFLASH_Read(u32 ReadAddr,u16 *pBuffer,u16 NumToRead)
- {
- u16 i;
- for(i=0;i<NumToRead;i++)
- {
- pBuffer[i]=STMFLASH_ReadHalfWord(ReadAddr);//读取2个字节.
- ReadAddr+=2;//偏移2个字节.
- }
- }
- /**********************************************************************************************************
- *写页数据,擦除整页2048字节,并写入Byte数据,数据可少于2048Btye,但必须是偶数。
- ************************************************************************************************************/
- void WritePageData(unsigned long WriteAddr,unsigned char *pData,unsigned short DataLen)
- {
- unsigned short i;
- unsigned short temp;
- FLASH_Status status;
-
- RunMake(THIS_FILE_ID);
-
- if(WriteAddr<STM32_FLASH_BASE || (WriteAddr>=(STM32_FLASH_BASE+1024*STM32_FLASH_SIZE)))return;//非法地址
- if(WriteAddr&0x0000003ff)return;//非页首地址
- RunMake(THIS_FILE_ID);
- FLASH_Unlock(); //解锁
- RunMake(THIS_FILE_ID);
- status=FLASH_ErasePage(WriteAddr);//擦除这个扇区
- if(status!=FLASH_COMPLETE){
- RunMake(THIS_FILE_ID);
- return;
- }
- RunMake(THIS_FILE_ID);
-
- //写入
- 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);
- }
- RunMake(THIS_FILE_ID);
- FLASH_Lock();//上锁
- RunMake(THIS_FILE_ID);
- }
- /**********************************************************************************************************
- ************************************************************************************************************/
- 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;
- }
- }
- void printfATHCODE(void)
- {
- char buf[3], buf2[50];
-
- // unsigned char i;
- // for(i=0;i<7;i++)
- // {
- // sprintf(buf, "%02x", sutProductPara.AutH[i]);
- // strcat(buf2, buf);
- // }
- // strcat(buf2, "\r\n");
- // SlwTrace(INF , buf2);
-
- //snprintf(buf2, sizeof(buf2), "index=%d,time=%d",sutProductPara.m_GPS_TimeIndex,sutGpsInfo.GPS_UploadTime);
- //SlwTrace(INF, buf2,1);
- }
- /**********************************************************************************************************
- 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;
-
- }
- #if 0
- void ResetFip(void)
- {
- sutProductPara.MFotaIP[0]=FOTA_IAP_IP0;
- sutProductPara.MFotaIP[1]=FOTA_IAP_IP1;
- sutProductPara.MFotaIP[2]=FOTA_IAP_IP2;
- sutProductPara.MFotaIP[3]=FOTA_IAP_IP3;
- sutProductPara.MFotaPort=FOTA_IAP_PORT;
- }
- void FotaIpCheck(void)
- {
- char resetflag;
-
- resetflag=0;
- if(sutProductPara.ProductVersion != PRODUCT_VERSION)
- {
- if((sutProductPara.MFotaIP[0] == 0xFF &&
- sutProductPara.MFotaIP[1] == 0xFF &&
- sutProductPara.MFotaIP[2] == 0xFF &&
- sutProductPara.MFotaIP[3] == 0xFF) ||
- sutProductPara.MFotaPort == 0xFFFF)
- {
- resetflag=1;
- }
-
- if(sutProductPara.ProductVersion <= 107 && PRODUCT_VERSION >= 108)
- {
- resetflag=2;
- }
- if(resetflag) ResetFip();
- }
- }
- #endif
- /********************************************************************
- *SaveParaToFlash
- 将sutNetPara重要参数保存到FLASH
- *********************************************************************/
- #define MIN_PSN_NUM 1000000
- #define MAX_PSN_NUM 4200000000
- void ReadProductParaFromFlash(void)
- {
- char needsave=0;
- IWDG_ReloadCounter();
- //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=0;
- }
- 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(needsave!=0) SaveProductParaToFlash();
- }
- void GpsTimeUpdate(void)
- {
- if(GPS_TimeTable[newPara.gpsTimeIndex])//判断GPS是否已关,根据上传时间来算
- {
- GPS_PWREN_HIGH;
- printf("gpsOpening===%d\r\n",newPara.gpsTimeIndex);
- g_uiGpsStat=1;
- }
- else{
- printf("gpsDown====%d\r\n",newPara.gpsTimeIndex);
- GPS_PWREN_LOW;
- g_uiGpsStat=0;
- sutGpsInfo.isGpsWork=0;
- sutGpsInfo.isGpsValid=0;
- sutGpsInfo.GpsInactiveCt=0;
- g_usUart3RecvLen=0;
- }
- }
- /************************************file begin*******************************/
|