465 lines
14 KiB
C
465 lines
14 KiB
C
#include "sys.h"
|
||
#include "CDZ_State.h"
|
||
//All rights reserved
|
||
//********************************************************************************
|
||
void NVIC_Configuration(void)
|
||
{
|
||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先
|
||
}
|
||
|
||
volatile uint32_t TickTimeCount_MS = 0;
|
||
|
||
const char ApplicationVersion[10] = Version(); //??????
|
||
|
||
|
||
/*初始化 SysTick*/
|
||
void SysTick_Init(void)
|
||
{
|
||
if(SysTick_Config(SystemCoreClock / 1000))
|
||
{
|
||
/* Capture error */
|
||
while (1);
|
||
}
|
||
}
|
||
volatile uint8_t SystickNum = 0; //节拍计数
|
||
volatile uint32_t SystemTimeHeart = 0;
|
||
volatile uint32_t SystemTimeCount= 0;
|
||
|
||
void SysTick_Handler(void)
|
||
{
|
||
SystemTimeHeart++;
|
||
TickTimeCount_MS++;
|
||
if(SystemTimeHeart%1000==1)SystemTimeCount++;
|
||
if(!SystickNum)
|
||
SystickNum = 1;
|
||
}
|
||
|
||
|
||
/******************************************************************************
|
||
????:TickOut
|
||
? ?:Alex
|
||
??????:Tick????,??????true ????
|
||
????:tick??,timeout ??(??)
|
||
????:bool
|
||
? ? ?:????
|
||
*******************************************************************************/
|
||
uint8_t TickOut(uint32_t *tick,uint32_t timeout)
|
||
{
|
||
uint32_t icount = 0;
|
||
if(timeout == 0)
|
||
{
|
||
*tick = SystemTimeHeart; //???????
|
||
return TRUE;
|
||
}
|
||
else
|
||
{
|
||
icount = SystemTimeHeart;
|
||
if(icount >= *tick) //?????
|
||
{
|
||
if( (icount - (*tick)) >= timeout)
|
||
{
|
||
return TRUE;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if( (0xFFFFFFFF - (*tick) + icount) >= timeout)
|
||
{
|
||
return TRUE;
|
||
}
|
||
}
|
||
return FALSE;
|
||
}
|
||
}
|
||
|
||
//????
|
||
uint8_t TickOutCycle(uint32_t *tick,uint32_t timeout)
|
||
{
|
||
uint32_t icount = 0;
|
||
if(timeout == 0)
|
||
{
|
||
*tick = SystemTimeHeart; //???????
|
||
return TRUE;
|
||
}
|
||
else
|
||
{
|
||
icount = SystemTimeHeart;
|
||
if(icount >= *tick) //?????
|
||
{
|
||
if( (icount - (*tick)) >= timeout)
|
||
{
|
||
*tick = SystemTimeHeart; //????
|
||
return TRUE;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if( (0xFFFFFFFF - (*tick) + icount) >= timeout)
|
||
{
|
||
*tick = SystemTimeHeart; //????
|
||
return TRUE;
|
||
}
|
||
}
|
||
return FALSE;
|
||
}
|
||
}
|
||
|
||
|
||
TimeTaskDatas TimeTaskData;
|
||
|
||
|
||
/**************************************************************************
|
||
* Function Name :
|
||
* Description : ????????
|
||
* Input : u8 time
|
||
* Output : none
|
||
**************************************************************************/
|
||
void TimeTaskDispatch_Flag(void)
|
||
{
|
||
if(SystickNum == 1)
|
||
{
|
||
TimeTaskData.F_Time_Count++;
|
||
|
||
TimeTaskData.F_Time_1MS = SET;
|
||
|
||
SystickNum = 0;
|
||
}
|
||
else //??1ms??
|
||
return;
|
||
|
||
if( (TimeTaskData.F_Time_Count % 5 == 0) && (TimeTaskData.F_Time_Count != 0 ) ) //5ms
|
||
{
|
||
TimeTaskData.F_Time_5MS = SET;
|
||
}
|
||
else //????5ms??
|
||
return;
|
||
if( (TimeTaskData.F_Time_Count % 10 == 0) && (TimeTaskData.F_Time_Count != 0 ) ) //10ms
|
||
{
|
||
TimeTaskData.F_Time_10MS = SET;
|
||
}
|
||
if( (TimeTaskData.F_Time_Count % 20 == 0) && (TimeTaskData.F_Time_Count != 0 ) ) //20ms
|
||
{
|
||
TimeTaskData.F_Time_20MS = SET;
|
||
}
|
||
if( (TimeTaskData.F_Time_Count % 50 == 0) && (TimeTaskData.F_Time_Count != 0 ) ) //50ms
|
||
{
|
||
TimeTaskData.F_Time_50MS = SET;
|
||
}
|
||
// else //????50ms??
|
||
// return;
|
||
if( (TimeTaskData.F_Time_Count % 100 == 0) && (TimeTaskData.F_Time_Count != 0 ) ) //100ms
|
||
{
|
||
TimeTaskData.F_Time_100MS = SET;
|
||
}
|
||
if( (TimeTaskData.F_Time_Count % 500 == 0) && (TimeTaskData.F_Time_Count != 0 ) ) //500ms
|
||
{
|
||
TimeTaskData.F_Time_500MS = SET;
|
||
}
|
||
if( (TimeTaskData.F_Time_Count % 1000 == 0) && (TimeTaskData.F_Time_Count != 0 ) ) //1000ms
|
||
{
|
||
TimeTaskData.F_Time_1000MS = SET;
|
||
}
|
||
if( (TimeTaskData.F_Time_Count % 1500 == 0) && (TimeTaskData.F_Time_Count != 0 ) ) //1500ms
|
||
{
|
||
TimeTaskData.F_Time_1500MS = SET;
|
||
}
|
||
if( (TimeTaskData.F_Time_Count % 2000 == 0) && (TimeTaskData.F_Time_Count != 0 ) ) //2000ms
|
||
{
|
||
TimeTaskData.F_Time_2000MS = SET;
|
||
}
|
||
|
||
if(TimeTaskData.F_Time_Count >= 6000)
|
||
TimeTaskData.F_Time_Count = 0; //??????
|
||
}
|
||
|
||
/**************************************************************************
|
||
* Function Name : Wait50us
|
||
* Description : This function wait 10 us . 72MHz
|
||
* Input : u8 time
|
||
* Output : none
|
||
**************************************************************************/
|
||
void Wait50us(uint8_t time)
|
||
{
|
||
uint8_t i;
|
||
for(;time>0;time--)
|
||
{
|
||
for(i = 50;i>0;i--)
|
||
{
|
||
__NOP(); // 1/72M=0.01389us
|
||
__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
|
||
__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
|
||
__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
|
||
__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
|
||
__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
|
||
__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
|
||
}
|
||
}
|
||
}
|
||
|
||
/********************************************************************************************************
|
||
* Function Name : Delay_MS
|
||
* Description : ??MS ??
|
||
* Input : u16 time
|
||
* Output : none
|
||
*********************************************************************************************************/
|
||
void Delay_MS(u16 time)
|
||
{
|
||
for(;time>0;time--)
|
||
{
|
||
Wait50us(20); //1MS
|
||
IWDG_Feed();
|
||
}
|
||
}
|
||
|
||
/**************************************************************************
|
||
* Function Name : SystemReboot
|
||
* Description : ????
|
||
* Input : none
|
||
* Output : none
|
||
**************************************************************************/
|
||
void SystemReboot(void)
|
||
{
|
||
// DEPRINT("System Reset!!!\r\n");
|
||
// WatchDog_Switch(0); //????
|
||
NVIC_SystemReset();
|
||
}
|
||
uint8_t SysStoreSysParmflag =0;
|
||
void SysWriteSysParm(void)
|
||
{
|
||
IWDG_Feed();
|
||
bsp_WriteCpuFlash(SysParaPileADDR,(unsigned char *)(&SysParaPileD),sizeof(SysParaPileD)); //
|
||
}
|
||
|
||
void SysStoreSysParm(void)
|
||
{
|
||
static uint8_t count =0;
|
||
if(SysStoreSysParmflag ==1)
|
||
{
|
||
if(count++ > 5)
|
||
{
|
||
SysWriteSysParm();
|
||
count =0;
|
||
SysStoreSysParmflag =0;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
count =0;
|
||
}
|
||
}
|
||
|
||
void SysWriteSocParm(void)
|
||
{
|
||
IWDG_Feed();
|
||
bsp_WriteCpuFlash(SOCParaPileADDR,(unsigned char *)(&SocCalculate),sizeof(SocCalculate)); //
|
||
}
|
||
RTCTimeS_D SysTime;
|
||
SysParaPile SysParaPileD;
|
||
Compensation_t SocCalculate;
|
||
|
||
|
||
void SocParaDataInit(void)
|
||
{
|
||
uint8_t i =0;
|
||
memset(&SocCalculate,0,sizeof(SocCalculate));
|
||
|
||
|
||
|
||
DEPRINT("======Hai Dun soc Parameter Init!======\r\n");
|
||
|
||
bsp_ReadCpuFlash(SOCParaPileADDR,(unsigned char *)(&SocCalculate),sizeof(SocCalculate)); //获取桩体参数信息
|
||
|
||
|
||
if( (SocCalculate.CalibrationEnable == 0x00) || (SocCalculate.CalibrationEnable == 0xff) )
|
||
{
|
||
memset(&SocCalculate,0,sizeof(SocCalculate));
|
||
DEPRINT("SocCalculate is default!\r\n");
|
||
}
|
||
if(SocCalculate.CalibrationEnable ==1)
|
||
{
|
||
//计算权值
|
||
for(i=0;i<SocCalculate.index;i++)
|
||
{
|
||
DEPRINT("SocCalculate is startVolt %f !\r\n",SocCalculate.data[i].startVolt);
|
||
DEPRINT("SocCalculate is endVolt %f \r\n",SocCalculate.data[i].endVolt);
|
||
DEPRINT("SocCalculate is startSoc %d \r\n",SocCalculate.data[i].startSoc);
|
||
DEPRINT("SocCalculate is endSoc %d \r\n",SocCalculate.data[i].endSoc);
|
||
DEPRINT("SocCalculate weight %f\r\n",SocCalculate.data[i].weight);
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
#include "dc300.h"
|
||
uint8_t ID_Flag;
|
||
extern u32 ChipUniqueID[3];
|
||
|
||
void SysParaDataInit(void)
|
||
{
|
||
vin_byte_t vin_code;
|
||
char *vin;
|
||
uint8_t data,check;
|
||
memset(&SysParaPileD,0,sizeof(SysParaPile));
|
||
DEPRINT("======Hai Dun Parameter Init!======\r\n");
|
||
bsp_ReadCpuFlash(SysParaPileADDR,(unsigned char *)(&SysParaPileD),sizeof(SysParaPile)); //获取桩体参数信息
|
||
|
||
if( (SysParaPileD.sn[0] == 0xff) || (SysParaPileD.sn[0] == 0) )
|
||
{
|
||
Delay_MS(10);
|
||
DEPRINT("bsp_ReadCpuFlash!\r\n");
|
||
bsp_ReadCpuFlash(SysParaPileADDR,(unsigned char *)(&SysParaPileD),sizeof(SysParaPileD)); //获取桩体参数信息
|
||
|
||
}
|
||
if( (SysParaPileD.sn[0] == 0xff) || (SysParaPileD.sn[0] == 0) )
|
||
{
|
||
Delay_MS(10);
|
||
DEPRINT("bsp_ReadCpuFlash 1\r\n");
|
||
bsp_ReadCpuFlash(SysParaPileADDR,(unsigned char *)(&SysParaPileD),sizeof(SysParaPileD)); //获取桩体参数信息
|
||
|
||
}
|
||
if( (SysParaPileD.sn[0] == 0xff) || (SysParaPileD.sn[0] == 0) )
|
||
{
|
||
Delay_MS(10);
|
||
DEPRINT("bsp_ReadCpuFlash 2\r\n");
|
||
bsp_ReadCpuFlash(SysParaPileADDR,(unsigned char *)(&SysParaPileD),sizeof(SysParaPileD)); //获取桩体参数信息
|
||
|
||
}
|
||
if( SysParaPileD.chargerstation[0] == 0xFF )
|
||
{
|
||
memset(SysParaPileD.chargerstation,0,sizeof(SysParaPileD.chargerstation));
|
||
}
|
||
if( (SysParaPileD.sn[0] == 0xff) || (SysParaPileD.sn[0] == 0) )
|
||
{
|
||
memset(SysParaPileD.sn,0,sizeof(SysParaPileD.sn));
|
||
SysParaPileD.registeredFlag =0;
|
||
//sprintf((char *)SysParaPileD.sn,"%s",DEFAULT_SN);
|
||
SysParaPileD.sn[0] ='H';
|
||
SysParaPileD.sn[1] ='Y';
|
||
SysParaPileD.sn[2] ='D';
|
||
SysParaPileD.sn[3] ='N';
|
||
SysParaPileD.sn[4] = '2';
|
||
SysParaPileD.sn[5] = '0';
|
||
SysParaPileD.sn[6] = '2';
|
||
SysParaPileD.sn[7] = '2';
|
||
|
||
|
||
vin_code.data = ChipUniqueID[2] >>24&0xff;
|
||
SysParaPileD.sn[8] = vin_code.bits.vode_h >0x0A? vin_code.bits.vode_h-0x0A+0x30:vin_code.bits.vode_h +0x30;
|
||
SysParaPileD.sn[9] = vin_code.bits.vode_l >0x0A? vin_code.bits.vode_l -0x0A+0x30:vin_code.bits.vode_l +0x30;
|
||
vin_code.data = ChipUniqueID[2] >>16&0xff;
|
||
SysParaPileD.sn[10] = vin_code.bits.vode_h >0x0A? vin_code.bits.vode_h-0x0A+0x30:vin_code.bits.vode_h +0x30;
|
||
SysParaPileD.sn[11] = vin_code.bits.vode_l >0x0A? vin_code.bits.vode_l -0x0A+0x30:vin_code.bits.vode_l +0x30;
|
||
vin_code.data = ChipUniqueID[2] >>8&0xff;
|
||
SysParaPileD.sn[12] = vin_code.bits.vode_h >0x0A? vin_code.bits.vode_h-0x0A+0x30:vin_code.bits.vode_h +0x30;
|
||
SysParaPileD.sn[13] = vin_code.bits.vode_l >0x0A? vin_code.bits.vode_l -0x0A+0x30:vin_code.bits.vode_l +0x30;
|
||
|
||
vin_code.data = ChipUniqueID[2]&0xff;
|
||
SysParaPileD.sn[14] = vin_code.bits.vode_h >0x0A? vin_code.bits.vode_h-0x0A+0x30:vin_code.bits.vode_h +0x30;
|
||
SysParaPileD.sn[15] = vin_code.bits.vode_l >0x0A? vin_code.bits.vode_l -0x0A+0x30:vin_code.bits.vode_l +0x30;
|
||
|
||
|
||
// SysParaPileD.sn[8] = ChipUniqueID[1] >>24&0xff;
|
||
// SysParaPileD.sn[9] = ChipUniqueID[1] >>16&0xff;
|
||
// SysParaPileD.sn[10] = ChipUniqueID[1] >>8&0xff;
|
||
// SysParaPileD.sn[11] = ChipUniqueID[1]&0xff;
|
||
//
|
||
// SysParaPileD.sn[12] = ChipUniqueID[2] >>24&0xff;
|
||
// SysParaPileD.sn[13] = ChipUniqueID[2] >>16&0xff;
|
||
// SysParaPileD.sn[14] = ChipUniqueID[2] >>8&0xff;
|
||
// SysParaPileD.sn[15] = ChipUniqueID[2]&0xff;
|
||
|
||
// memcpy((char *)SysParaPileD.sn, DEFAULT_SN, 16);
|
||
DEPRINT("sn is default!\r\n");
|
||
DEPRINT_ARRAY(SysParaPileD.sn,16);
|
||
SysParaPileD.device_type = 0;
|
||
// memcpy((char *)SysParaPileD.sn, DEFAULT_SN, 16);
|
||
// DEPRINT("sn is default!\r\n");
|
||
}
|
||
|
||
if( (SysParaPileD.Recordindex == 0xff) || (SysParaPileD.Recordindex > RECORD_NUM) )
|
||
{
|
||
SysParaPileD.Recordindex = 0;
|
||
DEPRINT("sn is default!\r\n");
|
||
}
|
||
|
||
if( (SysParaPileD.bluetooth_name[0] == 0xFF) || (SysParaPileD.bluetooth_name[0] == 0x00) )//无密码默认1234
|
||
{
|
||
memset(SysParaPileD.bluetooth_name,0,sizeof(SysParaPileD.bluetooth_name));
|
||
sprintf((char *)SysParaPileD.bluetooth_name,"%s",DEFAULT_BLUE_TOOTH_NAME);
|
||
DEPRINT("bluetooth_name is default!\r\n");
|
||
}
|
||
if( (SysParaPileD.bluetooth_passward[0] == 0xFF) || (SysParaPileD.bluetooth_passward[0] == 0x00) )
|
||
{
|
||
memset(SysParaPileD.bluetooth_passward,0,sizeof(SysParaPileD.bluetooth_passward));
|
||
sprintf((char *)SysParaPileD.bluetooth_passward,"%s",DEFAULT_BLUE_TOOTH_PASSWARD);
|
||
DEPRINT("bluetooth_passward is default!\r\n");
|
||
}
|
||
if( (SysParaPileD.manufacturer_name[0] == 0xFF) || (SysParaPileD.manufacturer_name[0] == 0x00) )
|
||
{
|
||
memset(SysParaPileD.manufacturer_name,0,sizeof(SysParaPileD.manufacturer_name));
|
||
sprintf((char *)SysParaPileD.manufacturer_name,"%s",DEFAULT_BLUE_TOOTH_NAME);
|
||
DEPRINT("bluetooth_passward is default!\r\n");
|
||
}
|
||
if( (SysParaPileD.OverTempValue[0] == 0xFFFF ) || (SysParaPileD.OverTempValue[0] == 0x00))
|
||
{
|
||
SysParaPileD.OverTempValue[0] = DEFAULT_OverTemperature1;
|
||
}
|
||
if( (SysParaPileD.OverTempValue[1] == 0xFFFF ) || (SysParaPileD.OverTempValue[1] == 0x00))
|
||
{
|
||
SysParaPileD.OverTempValue[1] = DEFAULT_OverTemperature2;
|
||
}
|
||
if( (SysParaPileD.OverTempValue[2] == 0xFFFF ) || (SysParaPileD.OverTempValue[2] == 0x00))
|
||
{
|
||
SysParaPileD.OverTempValue[2] = DEFAULT_OverTemperature3;
|
||
}
|
||
if( (SysParaPileD.VehichleInfo[0] == 0xFF ) || (SysParaPileD.VehichleInfo[0] == 0x00))
|
||
{
|
||
// memcpy(SysParaPileD.VehichleInfo,"LFV2A21K6A3092399",17);
|
||
|
||
strcpy((char*)&SysParaPileD.VehichleInfo[0],"LK6ADCE15LB408569");
|
||
// vin_code.data = ChipUniqueID[2] >>24&0xff;
|
||
// SysParaPileD.VehichleInfo[9] = vin_code.bits.vode_h >0x0A? vin_code.bits.vode_h-0x0A+0x30:vin_code.bits.vode_h +0x30;
|
||
// SysParaPileD.VehichleInfo[10] = vin_code.bits.vode_l >0x0A? vin_code.bits.vode_l -0x0A+0x30:vin_code.bits.vode_l +0x30;;
|
||
vin_code.data = ChipUniqueID[2] >>16&0xff;
|
||
SysParaPileD.VehichleInfo[11] = vin_code.bits.vode_h >0x0A? vin_code.bits.vode_h-0x0A+0x30:vin_code.bits.vode_h +0x30;
|
||
SysParaPileD.VehichleInfo[12] = vin_code.bits.vode_l >0x0A? vin_code.bits.vode_l -0x0A+0x30:vin_code.bits.vode_l +0x30;;
|
||
vin_code.data = ChipUniqueID[2] >>8&0xff;
|
||
SysParaPileD.VehichleInfo[13] = vin_code.bits.vode_h >0x0A? vin_code.bits.vode_h-0x0A+0x30:vin_code.bits.vode_h +0x30;
|
||
SysParaPileD.VehichleInfo[14] = vin_code.bits.vode_l >0x0A? vin_code.bits.vode_l -0x0A+0x30:vin_code.bits.vode_l +0x30;;
|
||
|
||
vin_code.data = ChipUniqueID[2]&0xff;
|
||
SysParaPileD.VehichleInfo[15] = vin_code.bits.vode_h >0x0A? vin_code.bits.vode_h-0x0A+0x30:vin_code.bits.vode_h +0x30;
|
||
SysParaPileD.VehichleInfo[16] = vin_code.bits.vode_l >0x0A? vin_code.bits.vode_l -0x0A+0x30:vin_code.bits.vode_l +0x30;;
|
||
vin = SysParaPileD.VehichleInfo;
|
||
VinCalc(vin,&check);
|
||
// data = VinTest();
|
||
SysParaPileD.VehichleInfo[8] = check +0x30;
|
||
SysParaPileD.device_type = 0;
|
||
// memset(SysParaPileD.VehichleInfo,0xFF,17);
|
||
}
|
||
memset(SysParaPileD.Reserved,0,sizeof(SysParaPileD.Reserved));
|
||
DEPRINT("\n\r SysParaPileD VehichleInfo %s\n\r",SysParaPileD.VehichleInfo);
|
||
}
|
||
|
||
void SYS_ENTER_CRITICAL(void)
|
||
{
|
||
// if ((critical_times++) == 0)
|
||
{
|
||
__disable_irq();//关闭总中断
|
||
}
|
||
}
|
||
|
||
void SYS_EXIT_CRITICAL(void)
|
||
{
|
||
// if (critical_times == 1)
|
||
{
|
||
// critical_times = 0;
|
||
__enable_irq();//开启总中断
|
||
}
|
||
// else
|
||
// {
|
||
// critical_times--;
|
||
// }
|
||
}
|