diff --git a/AMS_Master_Code/Core/Inc/config_ADBMS6830.h b/AMS_Master_Code/Core/Inc/config_ADBMS6830.h index dedb364..2fdaa6a 100644 --- a/AMS_Master_Code/Core/Inc/config_ADBMS6830.h +++ b/AMS_Master_Code/Core/Inc/config_ADBMS6830.h @@ -4,13 +4,17 @@ #include "main.h" #define N_BMS 1 +#define N_CELLS 16 #define ADBMS_MAX_CHIP_TEMP 110 // max temperature of ADBMS6830B (not battery) in C +#define ADBMS_SPI_TIMEOUT 50 // Timeout in ms -[[maybe_unused]] static inline void mcuAdbmsCSLow() { +[[maybe_unused, gnu::always_inline]] +static inline void mcuAdbmsCSLow() { HAL_GPIO_WritePin(AMS_CS_GPIO_Port, AMS_CS_Pin, GPIO_PIN_RESET); } -[[maybe_unused]] static inline void mcuAdbmsCSHigh() { +[[maybe_unused, gnu::always_inline]] +static inline void mcuAdbmsCSHigh() { HAL_GPIO_WritePin(AMS_CS_GPIO_Port, AMS_CS_Pin, GPIO_PIN_SET); } diff --git a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/ADBMS_HighLevel.h b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/ADBMS_HighLevel.h index 2222503..ced8255 100644 --- a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/ADBMS_HighLevel.h +++ b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/ADBMS_HighLevel.h @@ -30,6 +30,4 @@ extern Cell_Module modules[N_BMS]; extern uint32_t balancedCells; extern bool BalancingActive; -extern uint8_t numberofCells; - #endif /* INC_AMS_HIGHLEVEL_H_ */ diff --git a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_Abstraction.c b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_Abstraction.c index 4db1611..bd3f2f1 100644 --- a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_Abstraction.c +++ b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_Abstraction.c @@ -12,8 +12,6 @@ #include "swo_log.h" #include -extern uint8_t numberofCells; - static const char* const HAL_Statuses[] = {"HAL_OK", "HAL_ERROR", "HAL_BUSY", "HAL_TIMEOUT"}; #define CHECK_RETURN(x) \ @@ -275,8 +273,7 @@ HAL_StatusTypeDef amsCheckUnderOverVoltage(Cell_Module (*module)[N_BMS]) { (*module)[i].overVoltage = 0; (*module)[i].underVoltage = 0; - for (size_t j = 0; j < numberofCells; - j++) { // ov/uv flags are 1-bit flags for each cell C0UV, C0OV, C1UV, C1OV, ... + for (size_t j = 0; j < N_CELLS; j++) { // ov/uv flags are 1-bit flags for each cell C0UV, C0OV, C1UV, C1OV, ... (*module)[i].underVoltage |= (ov_uv_data >> (j * 2)) & 0x01; (*module)[i].overVoltage |= (ov_uv_data >> (j * 2 + 1)) & 0x01; } diff --git a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_HighLevel.c b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_HighLevel.c index 6fb50f7..afd150f 100644 --- a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_HighLevel.c +++ b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_HighLevel.c @@ -18,8 +18,6 @@ Cell_Module modules[N_BMS] = {}; uint32_t balancedCells = 0; bool balancingActive = false; -uint8_t numberofCells = 16; - uint8_t packetChecksumFails = 0; #define MAX_PACKET_CHECKSUM_FAILS 5 @@ -37,7 +35,7 @@ static constexpr ADBMS_DetailedStatus NO_ERROR = {ADBMS_NO_ERROR}; ADBMS_DetailedStatus AMS_Init(SPI_HandleTypeDef* hspi) { debug_log(LOG_LEVEL_INFO, "ADBMS6830B HAL - configured for %d controllers and %d cells per controller...", N_BMS, - numberofCells); + N_CELLS); if (initAMS(hspi) != HAL_OK) { debug_log(LOG_LEVEL_ERROR, "ADBMS6830B HAL - initialization failed"); return (ADBMS_DetailedStatus){ADBMS_INTERNAL_BMS_FAULT, -1};