initial commit

first build, test
This commit is contained in:
Артём Чамайкин
2024-07-23 18:21:48 +03:00
parent 2d07e5f52e
commit a5b0b7db8d
157 changed files with 134706 additions and 0 deletions

209
Core/Inc/charger_gbt.h Normal file
View File

@@ -0,0 +1,209 @@
/*
* charger_gbt.h
*
* Created on: Apr 18, 2024
* Author: colorbass
*/
#ifndef INC_CHARGER_GBT_H_
#define INC_CHARGER_GBT_H_
#include "main.h"
typedef enum{
GBT_CC_UNKNOWN,
GBT_CC_12V,
GBT_CC_6V,
GBT_CC_4V,
GBT_CC_2V,
}gbtCcState_t;
typedef enum{
GBT_DISABLED,
GBT_S0_UNCONNECTED, //СС1 12V/6V СС2 12V
GBT_S1_CONNECTED, //СС1 4V СС2 4V (6V)
GBT_S2_LOCKED, //
GBT_S3_STARTED, // 12V AUX
GBT_S4_ISOTEST, // testing isolation, send CHM receive BHM
GBT_S5_BAT_INFO, // identifying BMS, send CRM receive BRM (long)
GBT_S6_BAT_STAT, // send CRM(AA), receive BCP (long)
GBT_S7_BMS_WAIT, // wait for BMS, send CTS+CML receive BRO(00), next BRO(AA)
GBT_S8_INIT_CHARGER,// starting power modules, send CRO(00)
GBT_S9_WAIT_BCL, // waiting for BCL (requested voltage), send CRO(00)
GBT_S10_CHARGING, // charging, contactor ON, send CCS, receiving BCL+BCS+BSM
GBT_STOP, // stop
//TODO: after stop send BSD state
}gbtState_t;
#pragma pack(push, 1)
typedef struct {
uint16_t maxOutputVoltage;
}GBT_BHM_t;
typedef struct {
uint8_t bmsIdentified;
char chargerNumber[4];
char chargerLocation[3];
}GBT_CRM_t;
typedef struct {
uint16_t maxOutputVoltage;
uint16_t minOutputVoltage;
uint16_t maxOutputCurrent;
uint16_t minOutputCurrent;
}GBT_CML_t;
typedef struct{
uint8_t version[3]; //GB/T version
uint8_t batteryType; //battery type
uint16_t batteryCapacity; // 0.1Ah/bit
uint16_t batteryVoltage; // 0.1V/bit
uint8_t batteryVendor[4]; // Battery vendor (ASCII string)
uint32_t batterySN; // int
uint8_t batteryManuY; // year (offset 1985)
uint8_t batteryManuM; // month
uint8_t batteryManuD; // day
uint32_t batteryCycleCount:24; //uint24_t
uint8_t ownAuto; // 0 = lizing, 1 = own auto
uint8_t rsvd0;
uint8_t EVIN[17]; //EVIN
uint8_t EV_SW_VER[8];
}GBT_BRM_t;
typedef struct {
uint16_t maxCellVoltage; // 0.01v/bit
uint16_t maxChargingCurrent; // 0.1A/bit
uint16_t totalEnergy; // 0.1kWh
uint16_t maxChargingVoltage; // 0.1V/ bit
uint8_t maxTemp; // 1C/bit, -50C offset
uint16_t SOC; // 0.1%/bit , 0..100%
uint16_t measVoltage; // 0.1V/bit
}GBT_BCP_t;
typedef struct {
uint16_t requestedVoltage; // 0.1V/bit
uint16_t requestedCurrent; // 0.1A/bit
uint8_t chargingMode; // 0x01 - CV, 0x02 - CC
}GBT_BCL_t;
typedef struct {
uint16_t measuredChargingVoltage;
uint16_t measuredChargingCurrent;
uint16_t highestVoltageOfBatteryCell;
uint8_t groupNrOfCellWithHighestVoltage;
uint16_t currentChargeState;
uint16_t estimatedRemainingChargingTime;
}GBT_BCS_t;
typedef struct {
uint8_t singleBatteryHighestVoltageSerNo;// SINGLE_BATTERY_HIGHEST_VOLTAGE_SER_NO
uint8_t batteryHighestTemp; //BATTERY_HIGHEST_TEMP
uint8_t batteryHighestTempSerNo;//BATTERY_HIGHEST_TEMP_SER_NO
uint8_t batteryLowestTemp;//BATTERY_LOWEST_TEMP
uint8_t batteryLowestTempSerNo;//BATTERY_LOWEST_TEMP_SER_NO
uint8_t batteryCellVoltageState;//BATTERY_CELL_VOLTAGE_STATE
uint8_t batteryStatus;//BATTERY_STATUS[bit-mask];
}GBT_BSM_t;
typedef struct {
uint16_t outputVoltage;
uint16_t outputCurrent;
uint16_t chargingTime;
uint16_t chargingPermissible;
}GBT_CCS_t;
typedef struct {
uint8_t enablePSU;
uint16_t requestedVoltage; // 0.1V/bit
uint16_t requestedCurrent; // 0.1A/bit
uint8_t chargingMode; // 0x01 - CV, 0x02 - CC
uint8_t chargingPercentage; //
uint16_t chargingRemainingTimeMin; //
uint16_t chargingElapsedTimeMin; //
uint8_t chargingElapsedTimeSec; //
}GBT_EDCAN_Output_t;
typedef struct {
uint8_t PSU_Status;
uint16_t measuredVoltage; // 0.1V/bit
uint16_t measuredCurrent; // 0.1A/bit
}GBT_EDCAN_Input_t;
/* 500 - Power Supply
TX
* PSU_ENABLE
* BMS_STATUS
* BMS_ERRORS
* PSU_REQUESTED_VOLTAGE[2]
* PSU_REQUESTED_CURRENT[2]
* BMS_CHARGE_PERCENTAGE
// BMS_MIN_CURRENT
* CHARGE_REMAINING_TIME_MIN
* CHARGE_REMAINING_TIME_SEC
* CHARGE_ELAPSED_TIME[1]
RX
* MEASURED_VOLTAGE[2]
* MEASURED_CURRENT[2]
// MAX_VOLTAGE[2]
// MAX_CURRENT[2]
// MAX_POWER[2]
* PSU_STATUS
*
*/
#pragma pack(pop)
extern ADC_HandleTypeDef hadc1;
extern GBT_BRM_t GBT_EVInfo;
extern GBT_BCP_t GBT_BATStat;
extern GBT_BCS_t GBT_ChargingStatus;
extern GBT_BCL_t GBT_ReqPower;
extern GBT_CML_t GBT_MaxLoad;
extern GBT_CCS_t GBT_ChargerCurrentStatus;
extern GBT_CRM_t GBT_ChargerInfo;
extern GBT_BSM_t GBT_BatteryStatus;
extern uint8_t GBT_BRO;
void GBT_Init();
void GBT_Start();
void GBT_Stop();
void GBT_Stop1();
void GBT_ChargerTask();
float GBT_CC_GetAdc();
void ADC_Select_Channel(uint32_t ch);
uint8_t GBT_CC_GetState();
void GBT_SwitchState(gbtState_t state);
void GBT_Delay(uint32_t delay);
uint32_t GBT_StateTick();
void J_SendPacket(uint32_t PGN, uint8_t pri, uint8_t DLC, uint8_t *data);
void GBT_SendCCS();
void GBT_SendCST();
void GBT_SendCRO(uint8_t state);
void GBT_SendCML();
void GBT_SendCTS();
void GBT_SendCHM();
void GBT_SendCRM(uint8_t state);
#endif /* INC_CHARGER_GBT_H_ */