119 lines
2.5 KiB
C
119 lines
2.5 KiB
C
//-------------------------------------------------------------------------------
|
||
// File Name: config.C
|
||
// Brief:
|
||
// Version: 1.1.0
|
||
// Create Date: 2021/07/20
|
||
// Create by: Marshal Lee
|
||
// Copyright:
|
||
// Copyright (c) 2021, Richpeace Co., LTD.
|
||
// All rights reserved.
|
||
//
|
||
// Modify by: Marshal Lee
|
||
// Modify Date: 2021/07/20
|
||
//-------------------------------------------------------------------------------
|
||
|
||
|
||
#define _IN_CONFIG_C
|
||
|
||
#include "config.h"
|
||
|
||
static const char VERSION_INFO[VERSION_LEN] =
|
||
{
|
||
VER_TYPE,
|
||
'-',
|
||
VER_PROD,
|
||
' ',
|
||
#if (CUR_VERSION == VERSION_DEBUG) // 调试版本
|
||
'D',
|
||
#elif (CUR_VERSION == VERSION_RELEASE) // 发布版本
|
||
'R',
|
||
#else
|
||
'V',
|
||
#endif
|
||
VER_CODE_M,
|
||
'.',
|
||
VER_CODE_S,
|
||
'.',
|
||
VER_CODE_D,
|
||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||
};
|
||
|
||
void GetCompileDateTime(char * datetime)
|
||
{
|
||
u8 i;
|
||
int month, year, day;
|
||
int hour, min, second;
|
||
|
||
const char *pMonth[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||
const char Date[12] = __DATE__; // 取编译日期
|
||
const char time[12] = __TIME__; // 取编译时间
|
||
|
||
month = 1;
|
||
for (i = 0; i < 12; i++)
|
||
{
|
||
if (memcmp(Date, pMonth[i], 3) == 0)
|
||
{
|
||
month = i + 1;
|
||
break;
|
||
}
|
||
}
|
||
year = (uint8_t)atoi(Date + 9); // Date[9]为2位年份,Date[7]为完整年份
|
||
day = (uint8_t)atoi(Date + 4);
|
||
|
||
hour = (uint8_t)atoi(time + 0);
|
||
min = (uint8_t)atoi(time + 3);
|
||
second = (uint8_t)atoi(time + 6);
|
||
|
||
if (datetime != NULL)
|
||
{
|
||
sprintf(datetime, "%02d%02d%02d%02d%02d%02d", year, month, day, hour, min, second);
|
||
}
|
||
}
|
||
|
||
void GetVersionStr(char * str)
|
||
{
|
||
if (str != NULL)
|
||
{
|
||
memcpy(str, VERSION_INFO, VERSION_LEN);
|
||
str[VERSION_LEN-1] = 0;
|
||
if (str[0] == 0xff)
|
||
{
|
||
str[0] = 0;
|
||
}
|
||
else
|
||
{
|
||
if (
|
||
str[VERSION_LEN-12] == 0xff &&
|
||
str[VERSION_LEN-11] == 0xff &&
|
||
str[VERSION_LEN-10] == 0xff &&
|
||
str[VERSION_LEN-9] == 0xff &&
|
||
str[VERSION_LEN-8] == 0xff &&
|
||
str[VERSION_LEN-7] == 0xff &&
|
||
str[VERSION_LEN-6] == 0xff &&
|
||
str[VERSION_LEN-5] == 0xff &&
|
||
str[VERSION_LEN-4] == 0xff &&
|
||
str[VERSION_LEN-3] == 0xff &&
|
||
str[VERSION_LEN-2] == 0xff &&
|
||
// str[VERSION_LEN-1] == 0xff &&
|
||
1 ) // 新写入的程序
|
||
{
|
||
u32 wrAddr;
|
||
char * vbuf = &(str[VERSION_LEN-12]);
|
||
GetCompileDateTime(vbuf);
|
||
wrAddr = (u32)VERSION_INFO;
|
||
wrAddr += VERSION_LEN-12;
|
||
|
||
// STMFlashWrite(wrAddr, (u16*)vbuf, 12/2, 3); // 写入flash中
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
void GetBuildStr(char * str)
|
||
{
|
||
sprintf(str, "Build: %s %s\r\n", __DATE__, __TIME__);
|
||
}
|
||
|
||
|