Compare commits
2 Commits
aa16f093b1
...
96b8e12f9a
Author | SHA1 | Date | |
---|---|---|---|
96b8e12f9a | |||
37cec353ec |
@ -6,6 +6,10 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define MAX_PLAUSIBLE_TEMP 15000 // 150.0°C
|
||||
#define MIN_PLAUSIBLE_TEMP -4000 // -40.0°C
|
||||
#define MAX_ERRORED_TEMP 3 // number of implausible temperatures before panic (per BMS module)
|
||||
|
||||
#define ADBMS_NO_LOGGING_DEFS
|
||||
#include "ADBMS_Driver.h"
|
||||
|
||||
|
@ -17,11 +17,15 @@ typedef enum {
|
||||
#define CRITICAL_SECTION_ENTER(counter) do { __disable_irq(); } while(0)
|
||||
#define CRITICAL_SECTION_EXIT(counter) ({do { if (primask_##counter) __enable_irq(); } while(0);})
|
||||
|
||||
#define CRITICAL_SECTION() /* \
|
||||
CRITICAL_SECTION_VAR(__COUNTER__); \
|
||||
#define _CRITICAL_SECTION_IMPL(counter) \
|
||||
CRITICAL_SECTION_VAR(counter); \
|
||||
asm volatile ("dmb"); \
|
||||
CRITICAL_SECTION_ENTER(__COUNTER__); \
|
||||
for(int _cs_flag_##__COUNTER__ = 1; _cs_flag_##__COUNTER__; _cs_flag_##__COUNTER__ = 0, CRITICAL_SECTION_EXIT(__COUNTER__)) */
|
||||
CRITICAL_SECTION_ENTER(counter); \
|
||||
for(int _cs_flag_##counter = 1; _cs_flag_##counter; _cs_flag_##counter = 0, CRITICAL_SECTION_EXIT(counter))
|
||||
|
||||
#define CRITICAL_SECTION_IMPL(counter) _CRITICAL_SECTION_IMPL(counter)
|
||||
|
||||
#define CRITICAL_SECTION() CRITICAL_SECTION_IMPL(__COUNTER__)
|
||||
|
||||
[[maybe_unused, gnu::always_inline]]
|
||||
static inline void mcuAdbmsCSLow() {
|
||||
|
@ -135,9 +135,22 @@ HAL_StatusTypeDef battery_update() {
|
||||
}
|
||||
|
||||
// Process temperature values
|
||||
int failed_sensors = 0;
|
||||
|
||||
for (size_t j = 0; j < 10; j++) { // 10 GPIOs
|
||||
battery.module[i].cellTemps[j] = ntc_mv_to_celsius(bms_data[i].auxVoltages[j]);
|
||||
|
||||
if (battery.module[i].cellTemps[j] > MAX_PLAUSIBLE_TEMP || battery.module[i].cellTemps[j] < MIN_PLAUSIBLE_TEMP) {
|
||||
debug_log(LOG_LEVEL_ERROR, "Sensor %u on BMS %u has implausible temperature: %d0 mC", j, i,
|
||||
battery.module[i].cellTemps[j]);
|
||||
if (++failed_sensors >= MAX_ERRORED_TEMP) {
|
||||
// If too many implausible temperatures, panic
|
||||
debug_log(LOG_LEVEL_ERROR, "Too many implausible temperatures on BMS %u, erroring...", i);
|
||||
update_error_window(true, i);
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// For new battery struct
|
||||
if (battery.module[i].cellTemps[j] > battery.pack.max_temp) {
|
||||
battery.pack.max_temp = battery.module[i].cellTemps[j];
|
||||
|
Loading…
x
Reference in New Issue
Block a user