battery.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef BATTERY_H
  2. #define BATTERY_H
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #include <stdio.h>
  6. #include "ti/driverlib/dl_timerg.h"
  7. #include "src/config.h"
  8. //Battery Discharge Safety Check
  9. typedef enum: uint8_t{
  10. SLOT_STATE_OK= 0x00,
  11. SLOT_STATE_SOV= 0x01,
  12. SLOT_ERR_HOV= (0x02 | 0x80),
  13. SLOT_ERR_OVERTEMPERATURE= (0x03 | 0x80), // first bit indicates complete error
  14. // Control error states
  15. SLOT_WARN_LOWER_DAC_NOT_POSSIBLE=0x10,
  16. SLOT_WARN_HIGHER_DAC_NOT_POSSIBLE=0x11,
  17. SLOT_WARN_DAC_INVALID_VALUE=0x12,
  18. SLOT_WARN_LOWER_PWM_NOT_POSSIBLE=0x13,
  19. SLOT_WARN_HIGHER_PWM_NOT_POSSIBLE=0x14,
  20. SLOT_ERR_CONFIGBYTE = (0x25 | 0x80),
  21. SLOT_ERR_DAC_WRITE_FAILED= (0x26 | 0x80)
  22. } SlotState;
  23. typedef struct{
  24. uint16_t voltage;
  25. int16_t current;
  26. uint16_t temperature;
  27. SlotState state;
  28. } BatteryMeasurement;
  29. typedef struct {
  30. // for future extension of error states (overtemp etc): add here
  31. int16_t set_current;
  32. BatteryMeasurement measurement;
  33. uint16_t dac_value;
  34. uint16_t pwm_value;
  35. GPTIMER_Regs *timer;
  36. SlotState *state;
  37. int16_t high_side_voltage;
  38. uint8_t adc_addr;
  39. } BatterySlot;
  40. //global battery array declaration: extending visiblity of the variable to multiple source files: variable declaration
  41. extern BatterySlot slot;
  42. void slot_init(void);
  43. void slot_read_state(void);
  44. void slot_adjust_current(void);
  45. void slot_disable(void);
  46. #endif