#include #include #include "src/config.h" #ifndef BATTERY_H #define BATTERY_H #define INITIAL_PWM_VALUE (0) #define PWM_INCREMENT_VALUE (1) #define PWM_DECREMENT_VALUE (1) #define PWM_MAX_VALUE (1000) #define NUM_SLOTS (1) //Variables to read all the battery measurements from all the slots extern volatile bool scanInProgress; //Battery states read by Pi typedef enum{ STATE_EMPTY= 0x01, STATE_BATTERY_DETECTED= 0x02, STATE_WAITING_FOR_LIMITS= 0x03, STATE_MEASUREMENT_IN_PROGRESS= 0x04, STATE_MEASUREMENT_DONE= 0x04, STATE_OVERHEATING= 0x05, } BatteryState; //Battery Discharge Safety Check: when defined with type uint8_t takes only 1 byte otherwise takes 4 byte typedef enum: uint8_t{ SLOT_STATE_OK= 0x00, SLOT_STATE_SOV= 0x01, SLOT_ERR_HOV= (0x02 | 0x80), SLOT_ERR_OVERTEMPERATURE= (0x03 | 0x80), // first bit indicates complete error // Control error states SLOT_WARN_LOWER_DAC_NOT_POSSIBLE=0x10, SLOT_WARN_HIGHER_DAC_NOT_POSSIBLE=0x11, SLOT_WARN_DAC_INVALID_VALUE=0x12, SLOT_WARN_LOWER_PWM_NOT_POSSIBLE=0x13, SLOT_WARN_HIGHER_PWM_NOT_POSSIBLE=0x14, // I2C Slave Error states SLOT_ERR_NO_DAC = (0x20 | 0x80), SLOT_ERR_NO_ADC1 = (0x21 | 0x80), SLOT_ERR_NO_ADC2 = (0x22 | 0x80), SLOT_ERR_NO_ADC3 = (0x23 | 0x80), SLOT_ERR_NO_ADC4 = (0x24 | 0x80), SLOT_ERR_CONFIGBYTE = (0x25 | 0x80), SLOT_ERR_DAC_WRITE_FAILED= (0x26 | 0x80) } SlotState; typedef struct{ uint16_t voltage; int16_t current; uint16_t temperature; SlotState slot_state; }BatteryMeasurement; typedef enum __attribute__((__packed__)){ STATE_IDLE, STATE_PRE_CHARGE, STATE_CC_CHARGING, STATE_CV_CHARGING, STATE_DISCHARGING, STATE_FINAL_DISCHARGE, STATE_ERROR, }BatteryChargingState; typedef struct{ uint8_t slot_id; uint16_t pwm_value; //for Power Burning PWM int16_t charge_discharge; BatteryState battery_state; BatteryMeasurement battery_measurement; uint16_t min_voltage; uint16_t max_voltage; uint8_t cut_off_current; uint16_t capacitance; uint8_t charge_fraction; uint8_t cycle_number; BatteryChargingState battery_charging_state; bool batteryLimitReceived; } BatteryInfo; extern BatteryInfo battery_data[NUM_SLOTS]; void Battery_Init(); void Battery_StateCondition(uint8_t slot_id); #endif