refactor: code cleanup, update .gitignore
This commit is contained in:
parent
4860a35390
commit
eb2dba0106
|
@ -1,6 +1,7 @@
|
|||
/.vscode/
|
||||
/build/
|
||||
/.cache/
|
||||
/.idea/
|
||||
.clangd
|
||||
TouchGFX/build
|
||||
compile_commands.json
|
||||
|
|
|
@ -72,7 +72,7 @@ HAL_StatusTypeDef amsCellMeasurement(Cell_Module (*module)[N_BMS]);
|
|||
|
||||
HAL_StatusTypeDef amsAuxAndStatusMeasurement(Cell_Module (*module)[N_BMS]);
|
||||
|
||||
HAL_StatusTypeDef amsConfigBalancing(uint32_t channels[N_BMS], uint8_t dutyCycle);
|
||||
HAL_StatusTypeDef amsConfigBalancing(const uint32_t channels[static N_BMS], uint8_t dutyCycle);
|
||||
HAL_StatusTypeDef amsStartBalancing(uint8_t dutyCycle);
|
||||
HAL_StatusTypeDef amsStopBalancing();
|
||||
|
||||
|
|
|
@ -24,19 +24,6 @@ uint8_t adbmsDriverInit(SPI_HandleTypeDef* hspi);
|
|||
#define CMD_EMPTY_BUFFER ((uint8_t[CMD_BUFFER_SIZE(0)]){0})
|
||||
#define CMD_EMPTY_BUFFER_SIZE CMD_BUFFER_SIZE(0)
|
||||
|
||||
//macro to function for better type checking (access attribute)
|
||||
[[gnu::access(read_only, 4, 1)]]
|
||||
static inline void __modify_writeCMD_args(size_t arglen, uint8_t args[static restrict N_BMS * (arglen + 2)], uint8_t bms, uint8_t * restrict data) {
|
||||
for (uint8_t i = 0; i < arglen; i++) {
|
||||
args[(bms * (arglen + 2)) + i] = data[i];
|
||||
}
|
||||
}
|
||||
|
||||
#define modify_writeCMD_args(args, bms, data) \
|
||||
static_assert(bms < N_BMS, "bms out of range"); \
|
||||
__modify_writeCMD_args(args.arglen, args.args + 4, bms, data)
|
||||
|
||||
|
||||
HAL_StatusTypeDef ___writeCMD(uint16_t command, uint8_t * args, size_t arglen);
|
||||
|
||||
[[gnu::access(read_write, 2, 4), gnu::nonnull(2), gnu::always_inline]] //add dummy size variable for bounds checking, should be optimized out
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
extern uint8_t numberofCells;
|
||||
|
||||
#define CHECK_RETURN(x) \
|
||||
{ \
|
||||
do { \
|
||||
HAL_StatusTypeDef status = x; \
|
||||
if (status != 0) \
|
||||
return status; \
|
||||
}
|
||||
} while (0)
|
||||
|
||||
HAL_StatusTypeDef amsReset() {
|
||||
amsWakeUp();
|
||||
|
@ -71,7 +71,7 @@ HAL_StatusTypeDef amsWakeUp() {
|
|||
HAL_StatusTypeDef amsCellMeasurement(Cell_Module (*module)[N_BMS]) {
|
||||
#warning check conversion counter to ensure that continous conversion has not been stopped
|
||||
#warning check for OW conditions: ADSV | ADSV_OW_0 / ADSV_OW_1
|
||||
return HAL_ERROR; //amsReadCellVoltages(module);
|
||||
return amsReadCellVoltages(module);
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef amsAuxAndStatusMeasurement(Cell_Module (*module)[N_BMS]) {
|
||||
|
@ -153,7 +153,7 @@ HAL_StatusTypeDef amsAuxAndStatusMeasurement(Cell_Module (*module)[N_BMS]) {
|
|||
return HAL_OK;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef amsConfigBalancing(uint32_t channels[N_BMS], uint8_t dutyCycle) {
|
||||
HAL_StatusTypeDef amsConfigBalancing(const uint32_t channels[static N_BMS], uint8_t dutyCycle) {
|
||||
if (dutyCycle > 0x0F) {
|
||||
return HAL_ERROR; // only 4 bits are allowed for dutyCycle
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ HAL_StatusTypeDef amsReadCellVoltages(Cell_Module (*module)[N_BMS]) {
|
|||
}
|
||||
|
||||
//Each selected BMS must have a corresponding address, and the data array for that BMS must be at least datalens[i] bytes long
|
||||
HAL_StatusTypeDef amsSendI2C(uint8_t addresses[static N_BMS], uint8_t * data[static N_BMS], uint8_t datalens[static N_BMS], uint32_t bms_mask) {
|
||||
HAL_StatusTypeDef amsSendI2C(const uint8_t addresses[static N_BMS], uint8_t * data[static N_BMS], const uint8_t datalens[static N_BMS], uint32_t bms_mask) {
|
||||
uint8_t buffer[CMD_BUFFER_SIZE(COMM_GROUP_SIZE)] = {};
|
||||
|
||||
//COMM register works in 3 bytes max per go, interleaved with control information
|
||||
|
@ -351,7 +351,7 @@ HAL_StatusTypeDef amsSendI2C(uint8_t addresses[static N_BMS], uint8_t * data[sta
|
|||
|
||||
if (i == 0) {
|
||||
buffer[offset + 0] = I2C_SEND_START;
|
||||
buffer[offset + 1] = addresses[j];
|
||||
buffer[offset + 1] = addresses[j] << 1; //shift the address left by 1 to make space for the R/W bit
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -390,7 +390,7 @@ HAL_StatusTypeDef amsSendI2C(uint8_t addresses[static N_BMS], uint8_t * data[sta
|
|||
return HAL_OK;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef amsReadI2C(uint8_t addresses[static N_BMS], uint8_t * data[static N_BMS], uint8_t datalens[static N_BMS], uint32_t bms_mask) {
|
||||
HAL_StatusTypeDef amsReadI2C(const uint8_t addresses[static N_BMS], uint8_t * data[static N_BMS], const uint8_t datalens[static N_BMS], uint32_t bms_mask) {
|
||||
uint8_t buffer[CMD_BUFFER_SIZE(COMM_GROUP_SIZE)] = {};
|
||||
|
||||
uint8_t max_datalen = 0;
|
||||
|
@ -422,7 +422,7 @@ HAL_StatusTypeDef amsReadI2C(uint8_t addresses[static N_BMS], uint8_t * data[sta
|
|||
|
||||
if (i == 0) {
|
||||
buffer[offset + 0] = I2C_SEND_START;
|
||||
buffer[offset + 1] = addresses[j];
|
||||
buffer[offset + 1] = addresses[j] << 1 | 0x01; // shift the address left by 1 to make space for the R/W bit
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -441,7 +441,7 @@ HAL_StatusTypeDef amsReadI2C(uint8_t addresses[static N_BMS], uint8_t * data[sta
|
|||
}
|
||||
|
||||
// case 3: we are still receiving data
|
||||
buffer[offset + ((i % 3) * 2)] = I2C_RECV_ACK;
|
||||
buffer[offset + ((i % 3) * 2)] = I2C_SEND_ACK;
|
||||
}
|
||||
|
||||
// send the command data
|
||||
|
|
|
@ -6,11 +6,9 @@
|
|||
*/
|
||||
|
||||
#include "ADBMS_LL_Driver.h"
|
||||
#include "ADBMS_CMD_MAKROS.h"
|
||||
#include "config_ADBMS6830.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "swo_log.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <strings.h>
|
||||
|
||||
|
@ -132,7 +130,7 @@ static uint8_t checkDataPEC(uint8_t* data, uint8_t len) {
|
|||
}
|
||||
|
||||
HAL_StatusTypeDef ___writeCMD(uint16_t command, uint8_t * args, size_t arglen) {
|
||||
HAL_StatusTypeDef ret = HAL_OK;
|
||||
HAL_StatusTypeDef ret;
|
||||
if (arglen > 0) {
|
||||
args[0] = (command >> 8) & 0xFF;
|
||||
args[1] = (command) & 0xFF;
|
||||
|
|
|
@ -43,8 +43,8 @@ void AMS_Init(SPI_HandleTypeDef* hspi) {
|
|||
|
||||
#define any(x) ({ \
|
||||
bool any = false; \
|
||||
for (size_t i = 0; i < N_BMS; i++) { \
|
||||
Cell_Module module = modules[i]; \
|
||||
for (size_t __any_intern_i = 0; __any_intern_i < N_BMS; __any_intern_i++) { \
|
||||
Cell_Module module = modules[__any_intern_i]; \
|
||||
any |= (x); \
|
||||
} \
|
||||
any; \
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#include "errors.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
SlaveErrorData error_data[NUM_ERROR_KINDS] = {};
|
||||
uint32_t error_sources = 0;
|
||||
|
|
Loading…
Reference in New Issue