CELIS/SYSTEM/sys/sys.h
2024-08-09 14:24:48 +08:00

350 lines
9.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __SYS_H
#define __SYS_H
#include "stm32f10x.h"
//////////////////////////////////////////////////////////////////////////////////
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
//0,不支持ucos
//1,支持ucos
#define SYSTEM_SUPPORT_UCOS 0 //定义系统文件夹是否支持UCOS
//位带操作,实现51类似的GPIO控制功能
//具体实现思想,参考<<CM3权威指南>>第五章(87页~92页).
//IO口操作宏定义
#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口地址映射
#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口操作,只对单一的IO口!
//确保n的值小于16!
#define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出
#define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入
#define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出
#define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入
#define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出
#define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入
#define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出
#define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入
#define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出
#define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入
#define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出
#define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入
#define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出
#define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入
#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);
//------------------调试部分------------------------------------------------------
#define DEBUG //调试开关
#ifdef DEBUG
//调试打印控制部分
#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
/*参数定义*/
/* 测试的FLASH地址 - PAGE SIZE = 2K字节 */
#define TEST_ADDR (0x08000000 + 0x20000 - 0x1000)
//flash 地址从0~2K 一个地址以Byte,16Kbit = 4Kbyte
#define SOCParaPileADDR (0x08000000 + 0x20000 - 0x2000) //参数
#define SysParaPileADDR (0x08000000 + 0x20000 - 0x1000)
#define Product_CodeADDR (0x08000000 + 0x20000 - 0x800) //最后2k
#define Order_CodeADDR (0x08000000 + 0x20000 - 0x1000) //最后4k
#define EndParaADDR (0x08000000 + 0x20000) //参数最后地址
#define CALIBRATION_NUM 32
#define RECORD_NUM 10
#pragma pack (1) /*指定按1字节对齐*/
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 设置校准数组
uint8_t checksum;//预留一部分内存
uint8_t CalibrationEnable;//预留一部分内存
uint8_t index;//预留一部分内存
calibration_t data[CALIBRATION_NUM];
}Compensation_t;
//0~4096Byte 4K 桩体参数
typedef struct
{
uint8_t sn[16]; //语言设置
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; //恒流时以此为主
uint16_t BmsMaxVolt; //电池额定电压==最大充电电压 BatMaxTotalChargeVol
uint16_t BmsMaxCurrent;
uint16_t TotalVoltage;//电池额定电压
uint16_t TotalCapacity; //电池额定容量
uint16_t BatMaxChargeCur;
uint16_t uBatMaxEnergy; //电池最大容量
uint16_t BatMaxTotalChargeVol; //电池最大充电总电压
uint16_t fTotalBatVol;
/*------------------------------------*/
uint16_t HeartBeatTime;
uint8_t ProtocolType;
//注册码
uint8_t registeredCode[10];
uint8_t registeredFlag;
uint32_t ChipUniqueID[3];
uint16_t BmRequireVolt;
uint16_t BmsRequireCurrent;
uint8_t QuickChargeEnable; //离线快充开关
uint8_t OfflineQuickChargeCount; //离线快充次数
uint8_t trickleChargingSocEnable; //soc涓流 使能
uint8_t trickleChargingSoc; //涓流soc启动值
uint8_t tricklepower; //涓流功率
uint8_t tricklecurrent; //涓流电流
uint8_t ChargingMode; // 2衡功率--1恒流模式
uint16_t StopVoltage;
uint16_t RequirePower; //恒功率时以此变量为主
uint8_t SignalLossFlag;
uint8_t RequireVoltageDifference;
uint8_t StartChargeCount; //超过750V 时启动电压次数
uint8_t VehichleInfo[17]; //车辆辨识信息 VIN码
uint16_t SimulatedCurrentBatVolt;
uint8_t Debug_Page_function;
uint8_t Reserved[7];//预留一部分内存 10-3
/********电池相关参数*********/
uint8_t ucBatType; //电池类型
uint16_t BatMaxChargeVol; //单体蓄电池最高允许充电电压(0.00~24.00V) 0.01V
uint16_t BatRatedVoltage; //单体电池额定电压 0.1V
/* 充电配置参数 */
//单体额定电压
//单体额定满电电压
//单体数量
//系统额定电压
//系统额定容量
//系统满电电压
//最高温度
//最低温度
//电池类型
uint8_t uBatMaxTempPlus50; //蓄电池模块最高允许的温度(-50~200℃)
uint8_t uBatMinTempPlus50; //最低温度
uint16_t BatCount; //单体电池个数
/**********充电记录数据**********/
uint8_t Recordindex;//充电记录
record_t chargeRecord[RECORD_NUM]; // 10组充电记录
/**********新增功能字段**********/
uint8_t Offline_qcharge_switch;//离线快充开关
uint8_t Offline_reserve;//离线快充开关
uint8_t reserved[64]; //预留128字节数据
/**********高压BMS和DCDC参数**********/
uint8_t WorkModel;
uint16_t DCRequireVolt;
uint16_t DCRequireCurrent;
uint16_t DCMaxPower; // 功率
/**************DC保护条件******************/
uint8_t DC_InductanceTemp;
uint8_t DC_IGBTTemp;
uint16_t DCMaxVolt; //DCDC电压电流参数
uint16_t DCMaxCurrent;
uint8_t CapacitanceTemp1;
uint8_t DCBoxTemp2;
uint16_t reserved2[2];
/**************优化设置******************/
uint8_t VIN_Enable; // VIN是否上报
uint8_t BlueSignalLoss; //蓝牙信号丢失
uint8_t ChargeMode; //充电方式
uint16_t ChargeParam; //充电参数
uint8_t HighVoltageModule; //高压辅助模块 1开 0关
int8_t HighVoltageOffset; //高压300V校准
uint16_t HighVoltageReal; //300V实际电压
uint8_t DoubleBatteryMode;
uint8_t reserved6[6];
uint8_t SocSimulaType; //SOC计算方式 1-can读取 2-soc模拟 3-SOC校准
uint16_t SocSimulaMaxVolt; //SOC模拟最大电压
uint16_t SocSimulaMinVolt; //SOC模拟最小电压
uint16_t SocCalibrationVolt[16]; //SOC校准电压
uint16_t SocCalibrationData[16]; //SOC
uint8_t reservebyte[128]; //预留256字节数据
}SysParaPile;
#pragma pack() /*取消指定对齐,恢复缺省对齐*/
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) //默认功率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; //急停按钮是否按下 "S"按下停止, "N" 正常
uint8_t A_Gun_Insulation_Flag; //A枪绝缘检测故障 "N"正常,"G"故障
uint8_t AInsulation_Timeout_Flag; //绝缘检测超时故障,"N"正常,"G"故障
}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);//关闭总中断
void SYS_EXIT_CRITICAL(void); //开启总中断
extern const char ApplicationVersion[10];
#endif