| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #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,
- // 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_ADC = 0x20,
- SLOT_ERR_NO_DAC = 0x21,
- SLOT_ERR_CONFIGBYTE = 0x22,
- SLOT_ERR_DAC_WRITE_FAILED=0x23,
- } 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);
- } BatterySlotManager;
- extern BatterySlotManager battery_slotmgr;
- #endif
|