| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #ifndef BATTERY_H
- #define BATTERY_H
- #include <stdint.h>
- #include <stdbool.h>
- #include <stdio.h>
- #include "ti/driverlib/dl_timerg.h"
- //define macro to be used by multiple files in the program witout the variable being overwritten
- //for testing
- #define NUM_SLOTS (1)
- //Battery Tolerance
- // how much tolerance do we allow if we charge / discharge before we
- // trigger the control loop to adjust the value
- #define BATTERY_CURRENT_THRESHOLD (5)
- // for i2c communication to know battery health
- #define SOV_THRESHOLD_MV (6000)
- #define HOV_THRESHOLD_MV (8000)
- #define TEMPERATURE_MAX_C (60)
- //Battery Discharge Safety Check
- typedef enum{
- SLOT_STATE_OK= 0x00,
- SLOT_STATE_SOV= 0x01,
- SLOT_STATE_HOV= 0x02,
- SLOT_WARN_OVERTEMPERATURE = 0x03,
- SLOT_ERR_OVERTEMPERATURE= (0x04 | 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 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;
- } BatterySlot;
- //global battery array declaration: extending visiblity of the variable to multiple source files: variable declaration
- extern BatterySlot battery_slots[NUM_SLOTS];
- typedef struct {
- void (*init)();
- void (*read_state)(uint8_t slot_id);
- void (*adjust_current)(uint8_t slot_id);
- void (*disable)(uint8_t slot_id);
- } BatterySlotManager;
- extern BatterySlotManager battery_slotmgr;
- #endif
|