#ifndef BATTERY_H #define BATTERY_H #include #include #include #include "ti/driverlib/dl_timerg.h" #include "src/config.h" //Battery Discharge Safety Check 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, 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 state; } BatteryMeasurement; typedef struct { // for future extension of error states (overtemp etc): add here int16_t set_current; BatteryMeasurement measurement; uint16_t dac_value; uint16_t pwm_value; GPTIMER_Regs *timer; SlotState *state; int16_t high_side_voltage; uint8_t adc_addr; } BatterySlot; //global battery array declaration: extending visiblity of the variable to multiple source files: variable declaration extern BatterySlot slot; void slot_init(void); void slot_read_state(void); void slot_adjust_current(void); void slot_disable(void); #endif