46 lines
1.4 KiB
C
46 lines
1.4 KiB
C
#pragma once
|
|
#ifndef __BATTERY_H
|
|
#define __BATTERY_H
|
|
#include "config_ADBMS6830.h"
|
|
#include "stm32h7xx_hal.h"
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
#define ADBMS_NO_LOGGING_DEFS
|
|
#include "ADBMS_Driver.h"
|
|
|
|
extern struct {
|
|
struct {
|
|
float soc;
|
|
uint16_t min_voltage;
|
|
uint16_t max_voltage;
|
|
uint16_t min_temp;
|
|
uint16_t max_temp;
|
|
} pack;
|
|
struct {
|
|
BMS_Chip * chip;
|
|
int16_t cellTemps[10];
|
|
struct {
|
|
uint8_t min_v_idx : 4; uint8_t max_v_idx : 4; // cell index: 0-15
|
|
uint8_t min_t_idx : 4; uint8_t max_t_idx : 4; // used like this: battery->module[i].chip->cellVoltages[min_v_idx]
|
|
};
|
|
} module[N_BMS];
|
|
} battery;
|
|
|
|
//Helper for getting min/max values
|
|
static inline struct { uint16_t min_v; uint16_t max_v; int16_t min_t; int16_t max_t; } getModuleMinMax(int i) {
|
|
return (typeof(getModuleMinMax(0))) {
|
|
.min_v = battery.module[i].chip->cellVoltages[battery.module[i].min_v_idx],
|
|
.max_v = battery.module[i].chip->cellVoltages[battery.module[i].max_v_idx],
|
|
.min_t = battery.module[i].cellTemps[battery.module[i].min_t_idx],
|
|
.max_t = battery.module[i].cellTemps[battery.module[i].max_t_idx]
|
|
};
|
|
}
|
|
|
|
HAL_StatusTypeDef battery_init(SPI_HandleTypeDef* hspi);
|
|
HAL_StatusTypeDef battery_update();
|
|
|
|
void print_battery_info();
|
|
void print_master_status();
|
|
|
|
#endif // __BATTERY_H
|