CELIS/SYSTEM/sys/sys.h

349 lines
10 KiB
C
Raw Normal View History

#ifndef __SYS_H
#define __SYS_H
#include "stm32f10x.h"
//////////////////////////////////////////////////////////////////////////////////
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
//0,<2C><>֧<EFBFBD><D6A7>ucos
//1,֧<><D6A7>ucos
#define SYSTEM_SUPPORT_UCOS 0 //<2F><><EFBFBD><EFBFBD>ϵͳ<CFB5>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Ƿ<EFBFBD>֧<EFBFBD><D6A7>UCOS
//λ<><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><CAB5>51<35><31><EFBFBD>Ƶ<EFBFBD>GPIO<49><4F><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>˼<EFBFBD><CBBC>,<2C>ο<EFBFBD><<CM3Ȩ<33><C8A8>ָ<EFBFBD><D6B8>>><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(87ҳ~92ҳ).
//IO<49>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EAB6A8>
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
//IO<49>ڵ<EFBFBD>ַӳ<D6B7><D3B3>
#define GPIOA_ODR_Addr (GPIOA_BASE+12) //0x4001080C
#define GPIOB_ODR_Addr (GPIOB_BASE+12) //0x40010C0C
#define GPIOC_ODR_Addr (GPIOC_BASE+12) //0x4001100C
#define GPIOD_ODR_Addr (GPIOD_BASE+12) //0x4001140C
#define GPIOE_ODR_Addr (GPIOE_BASE+12) //0x4001180C
#define GPIOF_ODR_Addr (GPIOF_BASE+12) //0x40011A0C
#define GPIOG_ODR_Addr (GPIOG_BASE+12) //0x40011E0C
#define GPIOA_IDR_Addr (GPIOA_BASE+8) //0x40010808
#define GPIOB_IDR_Addr (GPIOB_BASE+8) //0x40010C08
#define GPIOC_IDR_Addr (GPIOC_BASE+8) //0x40011008
#define GPIOD_IDR_Addr (GPIOD_BASE+8) //0x40011408
#define GPIOE_IDR_Addr (GPIOE_BASE+8) //0x40011808
#define GPIOF_IDR_Addr (GPIOF_BASE+8) //0x40011A08
#define GPIOG_IDR_Addr (GPIOG_BASE+8) //0x40011E08
//IO<49>ڲ<EFBFBD><DAB2><EFBFBD><>Ե<EFBFBD>һ<EFBFBD><D2BB>IO<49><4F>!
//ȷ<><C8B7>n<EFBFBD><6E>ֵС<D6B5><D0A1>16!
#define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define TRUE 1
#define FALSE 0
void SysTick_Init(void);
void NVIC_Configuration(void);
uint8_t TickOut(uint32_t *tick,uint32_t timeout);
//????
uint8_t TickOutCycle(uint32_t *tick,uint32_t timeout);
void Get_ChipID(void);
typedef struct
{
FlagStatus F_Time_1MS;
FlagStatus F_Time_5MS;
FlagStatus F_Time_10MS;
FlagStatus F_Time_20MS;
FlagStatus F_Time_50MS;
FlagStatus F_Time_100MS;
FlagStatus F_Time_500MS;
FlagStatus F_Time_1000MS;
FlagStatus F_Time_1500MS;
FlagStatus F_Time_2000MS;
uint32_t F_Time_Count; // uint16_t
}TimeTaskDatas;
extern TimeTaskDatas TimeTaskData;
void TimeTaskDispatch_Flag(void);
uint8_t TickOut(uint32_t *tick,uint32_t timeout);
uint8_t TickOutCycle(uint32_t *tick,uint32_t timeout);
//------------------<2D><><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD>------------------------------------------------------
#define DEBUG //<2F><><EFBFBD>Կ<EFBFBD><D4BF><EFBFBD>
#ifdef DEBUG
//<2F><><EFBFBD>Դ<EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>
#define DEPRINT(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define dbg_printf(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define DEPRINT_ARRAY(buf, len) {\
unsigned char byteCount;\
for(byteCount = 0; byteCount < len; byteCount++) { \
DEPRINT("%c ", buf[byteCount]);\
}\
}
// #define DEPRINT_ARRAY(buf, len) // DEPRINT("%02x ", buf[byteCount]);
#else
#define DEPRINT(fmt, ...)
#define DEPRINT_ARRAY(buf, len)
#endif
#define DEVICE_TYPE 0x11
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
/* <20><><EFBFBD>Ե<EFBFBD>FLASH<53><48>ַ - PAGE SIZE = 2K<32>ֽ<EFBFBD> */
#define TEST_ADDR (0x08000000 + 0x20000 - 0x1000)
//flash <20><>ַ<EFBFBD><D6B7>0~2K һ<><D2BB><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>Byte,16Kbit = 4Kbyte
#define SOCParaPileADDR (0x08000000 + 0x20000 - 0x2000) //<2F><><EFBFBD><EFBFBD>
#define SysParaPileADDR (0x08000000 + 0x20000 - 0x1000)
#define EndParaADDR (0x08000000 + 0x20000) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
#define CALIBRATION_NUM 32
#define RECORD_NUM 10
#pragma pack (1) /*ָ<><D6B8><EFBFBD><EFBFBD>1<EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD>*/
typedef struct
{
uint8_t index;
uint8_t date[7];
uint16_t power;
uint16_t chargingtime;
}record_t;
typedef struct
{
float startVolt;
uint16_t startSoc;
float endVolt;
uint16_t endSoc;
uint16_t offset;
float weight;
}calibration_t;
typedef struct
{
//soc <20><><EFBFBD><EFBFBD>У׼<D0A3><D7BC><EFBFBD><EFBFBD>
uint8_t checksum;//Ԥ<><D4A4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
uint8_t CalibrationEnable;//Ԥ<><D4A4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
uint8_t index;//Ԥ<><D4A4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
calibration_t data[CALIBRATION_NUM];
}Compensation_t;
//0~4096Byte 4K ׮<><D7AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
typedef struct
{
uint8_t sn[16]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t bluetooth_name[16];
uint8_t bluetooth_passward[8];
uint8_t manufacturer_name[16];
uint8_t chargerstation[20];
uint8_t device_type;
uint16_t OverTempValue[3];
uint16_t OverPower;
uint16_t OverVolt;
uint16_t OverCurrent; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD>Դ<EFBFBD>Ϊ<EFBFBD><CEAA>
uint16_t BmsMaxVolt; //<2F><><EFBFBD>ض<D8B6><EEB6A8>ѹ==<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ BatMaxTotalChargeVol
uint16_t BmsMaxCurrent;
uint16_t TotalVoltage;//<2F><><EFBFBD>ض<D8B6><EEB6A8>ѹ
uint16_t TotalCapacity; //<2F><><EFBFBD>ض<D8B6><EEB6A8><EFBFBD><EFBFBD>
uint16_t BatMaxChargeCur;
uint16_t uBatMaxEnergy; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint16_t BatMaxTotalChargeVol; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD>ѹ
uint16_t fTotalBatVol;
/*------------------------------------*/
uint16_t HeartBeatTime;
uint8_t ProtocolType;
//ע<><D7A2><EFBFBD><EFBFBD>
uint8_t registeredCode[10];
uint8_t registeredFlag;
uint32_t ChipUniqueID[3];
uint16_t BmRequireVolt;
uint16_t BmsRequireCurrent;
uint8_t QuickChargeEnable; //<2F><><EFBFBD>߿<EFBFBD><DFBF><EFBFBD><E4BFAA>
uint8_t OfflineQuickChargeCount; //<2F><><EFBFBD>߿<EFBFBD><DFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t trickleChargingSocEnable; //soc<6F><63><EFBFBD><EFBFBD> ʹ<><CAB9>
uint8_t trickleChargingSoc; //<2F><><EFBFBD><EFBFBD>soc<6F><63><EFBFBD><EFBFBD>ֵ
uint8_t tricklepower; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t tricklecurrent; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t ChargingMode; // 2<><EFBFBD><E2B9A6>--1<><31><EFBFBD><EFBFBD>ģʽ
uint16_t StopVoltage;
uint16_t RequirePower; //<2F><EFBFBD><E3B9A6>ʱ<EFBFBD>Դ˱<D4B4><CBB1><EFBFBD>Ϊ<EFBFBD><CEAA>
uint8_t SignalLossFlag;
uint8_t RequireVoltageDifference;
uint8_t StartChargeCount; //<2F><><EFBFBD><EFBFBD>750V ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>
uint8_t VehichleInfo[17]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6>Ϣ VIN<49><4E>
uint16_t SimulatedCurrentBatVolt;
uint8_t Debug_Page_function;
uint8_t Reserved[7];//Ԥ<><D4A4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD> 10-3
/********<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>*********/
uint8_t ucBatType; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint16_t BatMaxChargeVol; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ(0.00~24.00V) 0.01V
uint16_t BatRatedVoltage; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<D8B6><EEB6A8>ѹ 0.1V
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD> */
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEB6A8>ѹ
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEB6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ϵͳ<CFB5><EFBFBD><EEB6A8>ѹ
//ϵͳ<CFB5><EFBFBD><EEB6A8><EFBFBD><EFBFBD>
//ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t uBatMaxTempPlus50; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(-50~200<30><30>)
uint8_t uBatMinTempPlus50; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint16_t BatCount; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>
/**********<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>**********/
uint8_t Recordindex;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼
record_t chargeRecord[RECORD_NUM]; // 10<31><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼
/**********<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>**********/
uint8_t Offline_qcharge_switch;//<2F><><EFBFBD>߿<EFBFBD><DFBF><EFBFBD><E4BFAA>
uint8_t Offline_reserve;//<2F><><EFBFBD>߿<EFBFBD><DFBF><EFBFBD><E4BFAA>
uint8_t reserved[64]; //Ԥ<><D4A4>128<32>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
/**********<2A><>ѹBMS<4D><53>DCDC<44><43><EFBFBD><EFBFBD>**********/
uint8_t WorkModel;
uint16_t DCRequireVolt;
uint16_t DCRequireCurrent;
uint16_t DCMaxPower; // <20><><EFBFBD><EFBFBD>
/**************DC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>******************/
uint8_t DC_InductanceTemp;
uint8_t DC_IGBTTemp;
uint16_t DCMaxVolt; //DCDC<44><43>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint16_t DCMaxCurrent;
uint8_t CapacitanceTemp1;
uint8_t DCBoxTemp2;
uint16_t reserved2[2];
/**************<2A>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD>******************/
uint8_t VIN_Enable; // VIN<49>Ƿ<EFBFBD><C7B7>ϱ<EFBFBD>
uint8_t BlueSignalLoss; //<2F><><EFBFBD><EFBFBD><EFBFBD>źŶ<C5BA>ʧ
uint8_t ChargeMode; //<2F><><EFBFBD>ʽ
uint16_t ChargeParam; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t HighVoltageModule; //<2F><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3> 1<><31> 0<><30>
int8_t HighVoltageOffset; //<2F><>ѹ300VУ׼
uint16_t HighVoltageReal; //300Vʵ<56>ʵ<EFBFBD>ѹ
uint8_t DoubleBatteryMode;
uint8_t reserved6[6];
uint8_t SocSimulaType; //SOC<4F><43><EFBFBD>ʽ 1-can<61><6E>ȡ 2-socģ<63><C4A3> 3-SOCУ׼
uint16_t SocSimulaMaxVolt; //SOCģ<43><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
uint16_t SocSimulaMinVolt; //SOCģ<43><C4A3><EFBFBD><EFBFBD>С<EFBFBD><D0A1>ѹ
uint16_t SocCalibrationVolt[16]; //SOCУ׼<D0A3><D7BC>ѹ
uint16_t SocCalibrationData[16]; //SOC
uint8_t reservebyte[128]; //Ԥ<><D4A4>256<35>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
uint8_t Product_Code[32]; //DCU<43><55>Ʒ<EFBFBD><C6B7>
}SysParaPile;
#pragma pack() /*ȡ<><C8A1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>ȱʡ<C8B1><CAA1><EFBFBD><EFBFBD>*/
extern SysParaPile SysParaPileD;
extern Compensation_t SocCalculate;
#define DEFAULT_BLUE_TOOTH_NAME ("HEYDN")
#define DEFAULT_SN ("HEYDN20230208008")
#define DEFAULT_BLUE_TOOTH_PASSWARD ("1234")
#define DEFAULT_MANU_NAME ("HaiDun")
#define DEFAULT_POWER (110) //Ĭ<>Ϲ<EFBFBD><CFB9><EFBFBD>5k
#define DEFAULT_OverTemperature3 (85)
#define DEFAULT_OverTemperature1 (85)
#define DEFAULT_OverTemperature2 (85)
#define DEFAULT_DownpowerTemperature (75)
#define DEFAULT_OVER_CURRENT (450) //45A
#define DEFAULT_OVER_VOLT (4000) //400V
#define DEFAULT_OVER_VOLT1 (4000) //400V
#define DEFAULT_OVER_VOLT2 (4000) //400V
typedef struct
{
uint8_t EPO_Button_Flag; //<2F><>ͣ<EFBFBD><CDA3>ť<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD> "S"<22><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9> "N" <20><><EFBFBD><EFBFBD>
uint8_t A_Gun_Insulation_Flag; //Aǹ<41><C7B9>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <09><>"N"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"G"<22><><EFBFBD><EFBFBD>
uint8_t AInsulation_Timeout_Flag; //<2F><>Ե<EFBFBD><D4B5><EFBFBD>ⳬʱ<E2B3AC><CAB1><EFBFBD>ϣ<EFBFBD>"N"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"G"<22><><EFBFBD><EFBFBD>
}FaultStates;
extern FaultStates FaultStateD;
void Charger_ProtectCheck(void);
extern const char ApplicationVersion[10]; //??????
void SysParaDataInit(void);
uint16_t Calculate_Absolute_Value(uint16_t data1,uint16_t data2);
extern void SysStoreSysParm(void);
extern uint8_t SysStoreSysParmflag;
typedef struct
{
uint8_t Year;
uint8_t Month;
uint8_t Day;
// uint8_t WeekDay;
uint8_t Hour;
uint8_t Minute;
uint8_t Second;
}RTCTimeS_D;
extern RTCTimeS_D SysTime;
void Delay_MS(u16 time);
void SysWriteSysParm(void);
#define TRUE 1
#define FALSE 0
typedef union
{
uint8_t data;
struct{
uint8_t vode_l:4;
uint8_t vode_h:4;
}bits;
}vin_byte_t;
uint16_t Get_Min_Value(uint16_t data1,uint16_t data2);
uint16_t Get_Max_Value(uint16_t data1,uint16_t data2);
uint16_t determine_interval(uint16_t value);
void SYS_ENTER_CRITICAL(void);//<2F>ر<EFBFBD><D8B1><EFBFBD><EFBFBD>ж<EFBFBD>
void SYS_EXIT_CRITICAL(void); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
extern const char ApplicationVersion[10];
#endif