use standard uintxx_t types
This commit is contained in:
parent
fb93bc5018
commit
f3cae7b757
|
@ -24,25 +24,25 @@
|
|||
#define mV_from_ADBMS6830(x) (((((int16_t) (x))) * 0.150) + 1500)
|
||||
|
||||
struct ADBMS6830_Internal_Status {
|
||||
uint16 CS_FLT : 16; //ADC fault - mismatch between S- and C-ADC
|
||||
uint16 : 3;
|
||||
uint16 CCTS : 13; //Conversion counter
|
||||
uint16 SMED : 1; //S-ADC multiple trim error (uncorrectable)
|
||||
uint16 SED : 1; //S-ADC single trim error (correctable)
|
||||
uint16 CMED : 1; //C-ADC multiple trim error (uncorrectable)
|
||||
uint16 CED : 1; //C-ADC single trim error (correctable)
|
||||
uint16 VD_UV : 1; //3V digital supply undervoltage
|
||||
uint16 VD_OV : 1; //3V digital supply overvoltage
|
||||
uint16 VA_UV : 1; //5V analog supply undervoltage
|
||||
uint16 VA_OV : 1; //5V analog supply overvoltage
|
||||
uint16 OSCCHK : 1; //Oscillator check
|
||||
uint16 TMODCHK : 1; //Test mode check
|
||||
uint16 THSD : 1; //Thermal shutdown
|
||||
uint16 SLEEP : 1; //Sleep mode previously entered
|
||||
uint16 SPIFLT : 1; //SPI fault
|
||||
uint16 COMPARE : 1; //Comparasion between S- and C-ADC active
|
||||
uint16 VDE : 1; //Supply voltage error
|
||||
uint16 VDEL : 1; //Latent supply voltage error
|
||||
uint16_t CS_FLT : 16; //ADC fault - mismatch between S- and C-ADC
|
||||
uint16_t : 3;
|
||||
uint16_t CCTS : 13; //Conversion counter
|
||||
uint16_t SMED : 1; //S-ADC multiple trim error (uncorrectable)
|
||||
uint16_t SED : 1; //S-ADC single trim error (correctable)
|
||||
uint16_t CMED : 1; //C-ADC multiple trim error (uncorrectable)
|
||||
uint16_t CED : 1; //C-ADC single trim error (correctable)
|
||||
uint16_t VD_UV : 1; //3V digital supply undervoltage
|
||||
uint16_t VD_OV : 1; //3V digital supply overvoltage
|
||||
uint16_t VA_UV : 1; //5V analog supply undervoltage
|
||||
uint16_t VA_OV : 1; //5V analog supply overvoltage
|
||||
uint16_t OSCCHK : 1; //Oscillator check
|
||||
uint16_t TMODCHK : 1; //Test mode check
|
||||
uint16_t THSD : 1; //Thermal shutdown
|
||||
uint16_t SLEEP : 1; //Sleep mode previously entered
|
||||
uint16_t SPIFLT : 1; //SPI fault
|
||||
uint16_t COMPARE : 1; //Comparasion between S- and C-ADC active
|
||||
uint16_t VDE : 1; //Supply voltage error
|
||||
uint16_t VDEL : 1; //Latent supply voltage error
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
@ -50,57 +50,57 @@ typedef struct {
|
|||
int16_t auxVoltages[MAXIMUM_AUX_VOLTAGES];
|
||||
|
||||
struct ADBMS6830_Internal_Status status;
|
||||
uint16 internalDieTemp;
|
||||
uint16 analogSupplyVoltage;
|
||||
uint16 digitalSupplyVoltage;
|
||||
uint16 sumOfCellMeasurements;
|
||||
uint16 refVoltage;
|
||||
uint16_t internalDieTemp;
|
||||
uint16_t analogSupplyVoltage;
|
||||
uint16_t digitalSupplyVoltage;
|
||||
uint16_t sumOfCellMeasurements;
|
||||
uint16_t refVoltage;
|
||||
|
||||
uint16 GPIO_Values[MAXIMUM_GPIO];
|
||||
uint16_t GPIO_Values[MAXIMUM_GPIO];
|
||||
|
||||
uint32 overVoltage;
|
||||
uint32 underVoltage;
|
||||
uint32_t overVoltage;
|
||||
uint32_t underVoltage;
|
||||
|
||||
} Cell_Module;
|
||||
|
||||
uint8 amsReset();
|
||||
uint8_t amsReset();
|
||||
|
||||
uint8 initAMS(SPI_HandleTypeDef* hspi);
|
||||
uint8 amsWakeUp();
|
||||
uint8_t initAMS(SPI_HandleTypeDef* hspi);
|
||||
uint8_t amsWakeUp();
|
||||
|
||||
uint8 amsCellMeasurement(Cell_Module* module);
|
||||
uint8 amsConfigCellMeasurement(uint8 numberofChannels);
|
||||
uint8_t amsCellMeasurement(Cell_Module* module);
|
||||
uint8_t amsConfigCellMeasurement(uint8_t numberofChannels);
|
||||
|
||||
uint8 amsAuxAndStatusMeasurement(Cell_Module* module);
|
||||
uint8 amsConfigAuxMeasurement(uint16 Channels);
|
||||
uint8_t amsAuxAndStatusMeasurement(Cell_Module* module);
|
||||
uint8_t amsConfigAuxMeasurement(uint16_t Channels);
|
||||
|
||||
uint8 amsConfigGPIO(uint16 gpios);
|
||||
uint8 amsSetGPIO(uint16 gpios);
|
||||
uint8 readGPIO(Cell_Module* module);
|
||||
uint8_t amsConfigGPIO(uint16_t gpios);
|
||||
uint8_t amsSetGPIO(uint16_t gpios);
|
||||
uint8_t readGPIO(Cell_Module* module);
|
||||
|
||||
uint8 amsConfigBalancing(uint32 Channels, uint8 dutyCycle);
|
||||
uint8 amsStartBalancing(uint8 dutyCycle);
|
||||
uint8 amsStopBalancing();
|
||||
uint8_t amsConfigBalancing(uint32_t Channels, uint8_t dutyCycle);
|
||||
uint8_t amsStartBalancing(uint8_t dutyCycle);
|
||||
uint8_t amsStopBalancing();
|
||||
|
||||
uint8 amsSelfTest();
|
||||
uint8_t amsSelfTest();
|
||||
|
||||
uint8 amsConfigOverUnderVoltage(uint16 overVoltage, uint16 underVoltage);
|
||||
uint8_t amsConfigOverUnderVoltage(uint16_t overVoltage, uint16_t underVoltage);
|
||||
|
||||
uint8 amsCheckUnderOverVoltage(Cell_Module* module);
|
||||
uint8 amsConfigOverVoltage(uint16 overVoltage);
|
||||
uint8_t amsCheckUnderOverVoltage(Cell_Module* module);
|
||||
uint8_t amsConfigOverVoltage(uint16_t overVoltage);
|
||||
|
||||
uint8 amscheckOpenCellWire(Cell_Module* module);
|
||||
uint8_t amscheckOpenCellWire(Cell_Module* module);
|
||||
|
||||
uint8 amsClearFlag();
|
||||
uint8 amsClearAux();
|
||||
uint8 amsClearCells();
|
||||
uint8_t amsClearFlag();
|
||||
uint8_t amsClearAux();
|
||||
uint8_t amsClearCells();
|
||||
|
||||
uint8 amsSendWarning();
|
||||
uint8 amsSendError();
|
||||
uint8_t amsSendWarning();
|
||||
uint8_t amsSendError();
|
||||
|
||||
uint8 amsClearWarning();
|
||||
uint8 amsClearError();
|
||||
uint8_t amsClearWarning();
|
||||
uint8_t amsClearError();
|
||||
|
||||
uint8 amsReadCellVoltages(Cell_Module* module);
|
||||
uint8_t amsReadCellVoltages(Cell_Module* module);
|
||||
|
||||
#endif /* INC_ADBMS_ABSTRACTION_H_ */
|
||||
|
|
|
@ -13,13 +13,8 @@
|
|||
#include <stdint.h>
|
||||
#define TARGET_STM32
|
||||
|
||||
#ifdef TARGET_STM32
|
||||
typedef uint8_t uint8;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint32;
|
||||
#endif
|
||||
|
||||
uint8 adbmsDriverInit(SPI_HandleTypeDef* hspi);
|
||||
uint8_t adbmsDriverInit(SPI_HandleTypeDef* hspi);
|
||||
|
||||
//2 command + 2 PEC + (data + 2 DPEC) per BMS
|
||||
#define CMD_BUFFER_SIZE(datalen) (4 + (N_BMS * (datalen + 2)))
|
||||
|
@ -61,7 +56,7 @@ uint8_t pollCMD(uint16_t command);
|
|||
void mcuAdbmsCSLow();
|
||||
void mcuAdbmsCSHigh();
|
||||
|
||||
uint8 wakeUpCmd();
|
||||
uint8_t wakeUpCmd();
|
||||
static inline void mcuDelay(uint16_t delay) { HAL_Delay(delay); };
|
||||
|
||||
#endif /* ADBMS_LL_DRIVER_H_ */
|
||||
|
|
|
@ -11,16 +11,16 @@
|
|||
#include "swo_log.h"
|
||||
#include <stddef.h>
|
||||
|
||||
extern uint8 numberofCells;
|
||||
extern uint8_t numberofCells;
|
||||
|
||||
#define CHECK_RETURN(x) \
|
||||
{ \
|
||||
uint8 status = x; \
|
||||
uint8_t status = x; \
|
||||
if (status != 0) \
|
||||
return status; \
|
||||
}
|
||||
|
||||
uint8 amsReset() {
|
||||
uint8_t amsReset() {
|
||||
amsWakeUp();
|
||||
readCMD(SRST, CMD_EMPTY_BUFFER, CMD_EMPTY_BUFFER_SIZE);
|
||||
|
||||
|
@ -54,24 +54,24 @@ uint8 amsReset() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint8 initAMS(SPI_HandleTypeDef* hspi) {
|
||||
uint8_t initAMS(SPI_HandleTypeDef* hspi) {
|
||||
adbmsDriverInit(hspi);
|
||||
return amsReset();
|
||||
}
|
||||
|
||||
uint8 amsWakeUp() {
|
||||
uint8_t amsWakeUp() {
|
||||
uint8_t buffer[CMD_BUFFER_SIZE(CFG_GROUP_A_SIZE)] = {0};
|
||||
return readCMD(RDCFGA, buffer, CMD_BUFFER_SIZE(CFG_GROUP_A_SIZE));
|
||||
}
|
||||
|
||||
uint8 amsCellMeasurement(Cell_Module* module) {
|
||||
uint8_t amsCellMeasurement(Cell_Module* module) {
|
||||
#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 amsReadCellVoltages(module);
|
||||
}
|
||||
|
||||
uint8 amsAuxAndStatusMeasurement(Cell_Module* module) {
|
||||
uint8 rxbuf[AUX_GROUP_A_SIZE] = {};
|
||||
uint8_t amsAuxAndStatusMeasurement(Cell_Module* module) {
|
||||
uint8_t rxbuf[AUX_GROUP_A_SIZE] = {};
|
||||
|
||||
CHECK_RETURN(readCMD(RDSTATC, rxbuf, STATUS_GROUP_C_SIZE));
|
||||
|
||||
|
@ -120,7 +120,7 @@ uint8 amsAuxAndStatusMeasurement(Cell_Module* module) {
|
|||
|
||||
module->auxVoltages[9] = mV_from_ADBMS6830(rxbuf[0] | (rxbuf[1] << 8));
|
||||
|
||||
uint8 rxbuffer[STATUS_GROUP_A_SIZE];
|
||||
uint8_t rxbuffer[STATUS_GROUP_A_SIZE];
|
||||
|
||||
CHECK_RETURN(readCMD(RDSTATA, rxbuffer, STATUS_GROUP_A_SIZE));
|
||||
|
||||
|
@ -136,9 +136,9 @@ uint8 amsAuxAndStatusMeasurement(Cell_Module* module) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint8 amsConfigBalancing(uint32 channels, uint8 dutyCycle) {
|
||||
uint8 buffer_a[PWM_GROUP_A_SIZE] = {};
|
||||
uint8 buffer_b[PWM_GROUP_B_SIZE] = {};
|
||||
uint8_t amsConfigBalancing(uint32_t channels, uint8_t dutyCycle) {
|
||||
uint8_t buffer_a[PWM_GROUP_A_SIZE] = {};
|
||||
uint8_t buffer_b[PWM_GROUP_B_SIZE] = {};
|
||||
CHECK_RETURN(readCMD(RDPWMA, buffer_a, CFG_GROUP_A_SIZE));
|
||||
CHECK_RETURN(readCMD(RDPWMB, buffer_b, CFG_GROUP_B_SIZE));
|
||||
|
||||
|
@ -164,14 +164,14 @@ uint8 amsConfigBalancing(uint32 channels, uint8 dutyCycle) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint8 amsStartBalancing(uint8 dutyCycle) { return writeCMD(UNMUTE, NULL, 0); }
|
||||
uint8_t amsStartBalancing(uint8_t dutyCycle) { return writeCMD(UNMUTE, NULL, 0); }
|
||||
|
||||
uint8 amsStopBalancing() { return writeCMD(MUTE, NULL, 0); }
|
||||
uint8_t amsStopBalancing() { return writeCMD(MUTE, NULL, 0); }
|
||||
|
||||
uint8 amsSelfTest() { return 0; }
|
||||
uint8_t amsSelfTest() { return 0; }
|
||||
|
||||
uint8 amsConfigOverUnderVoltage(uint16 overVoltage, uint16 underVoltage) {
|
||||
uint8 buffer[CFG_GROUP_A_SIZE];
|
||||
uint8_t amsConfigOverUnderVoltage(uint16_t overVoltage, uint16_t underVoltage) {
|
||||
uint8_t buffer[CFG_GROUP_A_SIZE];
|
||||
|
||||
if (underVoltage & 0xF000 || overVoltage & 0xF000) { // only 12 bits allowed
|
||||
return 1;
|
||||
|
@ -180,21 +180,21 @@ uint8 amsConfigOverUnderVoltage(uint16 overVoltage, uint16 underVoltage) {
|
|||
CHECK_RETURN(readCMD(RDCFGB, buffer, CFG_GROUP_A_SIZE));
|
||||
|
||||
//UV
|
||||
buffer[0] = (uint8) (underVoltage & 0xFF);
|
||||
buffer[0] = (uint8_t) (underVoltage & 0xFF);
|
||||
buffer[1] &= 0xF0;
|
||||
buffer[1] |= (uint8) ((underVoltage >> 8) & 0x0F);
|
||||
buffer[1] |= (uint8_t) ((underVoltage >> 8) & 0x0F);
|
||||
|
||||
//OV
|
||||
buffer[1] &= 0x0F;
|
||||
buffer[1] |= (uint8) (overVoltage << 4);
|
||||
buffer[2] = (uint8) (overVoltage >> 4);
|
||||
buffer[1] |= (uint8_t) (overVoltage << 4);
|
||||
buffer[2] = (uint8_t) (overVoltage >> 4);
|
||||
|
||||
return writeCMD(WRCFGB, buffer, CFG_GROUP_A_SIZE);
|
||||
}
|
||||
|
||||
uint8 amsCheckUnderOverVoltage(Cell_Module* module) {
|
||||
uint8 regbuffer[STATUS_GROUP_D_SIZE];
|
||||
uint32 ov_uv_data = 0;
|
||||
uint8_t amsCheckUnderOverVoltage(Cell_Module* module) {
|
||||
uint8_t regbuffer[STATUS_GROUP_D_SIZE];
|
||||
uint32_t ov_uv_data = 0;
|
||||
CHECK_RETURN(readCMD(RDSTATD, regbuffer, STATUS_GROUP_D_SIZE));
|
||||
ov_uv_data = (regbuffer[0] << 0) | (regbuffer[1] << 8) |
|
||||
(regbuffer[2] << 16) | (regbuffer[3] << 24);
|
||||
|
@ -210,23 +210,23 @@ uint8 amsCheckUnderOverVoltage(Cell_Module* module) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint8 amsClearFlag() {
|
||||
uint8 buffer[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
uint8_t amsClearFlag() {
|
||||
uint8_t buffer[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
return writeCMD(CLRFLAG, buffer, 6);
|
||||
}
|
||||
|
||||
uint8 amsClearAux() {
|
||||
uint8 buffer[6];
|
||||
uint8_t amsClearAux() {
|
||||
uint8_t buffer[6];
|
||||
return writeCMD(CLRAUX, buffer, 0);
|
||||
}
|
||||
|
||||
uint8 amsClearCells() {
|
||||
uint8 buffer[6];
|
||||
uint8_t amsClearCells() {
|
||||
uint8_t buffer[6];
|
||||
return writeCMD(CLRCELL, buffer, 0);
|
||||
}
|
||||
|
||||
uint8 amsReadCellVoltages(Cell_Module* module) {
|
||||
uint8 rxbuffer[CV_GROUP_A_SIZE];
|
||||
uint8_t amsReadCellVoltages(Cell_Module* module) {
|
||||
uint8_t rxbuffer[CV_GROUP_A_SIZE];
|
||||
CHECK_RETURN(readCMD(RDCVA, rxbuffer, CV_GROUP_A_SIZE));
|
||||
module->cellVoltages[0] = mV_from_ADBMS6830(rxbuffer[0] | (rxbuffer[1] << 8));
|
||||
module->cellVoltages[1] = mV_from_ADBMS6830(rxbuffer[2] | (rxbuffer[3] << 8));
|
||||
|
|
|
@ -49,7 +49,7 @@ static HAL_StatusTypeDef mcuSPITransmitReceive(uint8_t* rxbuffer, uint8_t* txbuf
|
|||
//CRC-15
|
||||
//x^15 + x^14 + x^10 + x^8 + x^7 + x^4 + x^3 + 1
|
||||
|
||||
static uint16 updateCommandPEC(uint16 currentPEC, uint8_t din) {
|
||||
static uint16_t updateCommandPEC(uint16_t currentPEC, uint8_t din) {
|
||||
din = (din >> 7) & 0x01;
|
||||
uint8_t in0 = din ^ ((currentPEC >> 14) & 0x01);
|
||||
uint8_t in3 = in0 ^ ((currentPEC >> 2) & 0x01);
|
||||
|
@ -59,7 +59,7 @@ static uint16 updateCommandPEC(uint16 currentPEC, uint8_t din) {
|
|||
uint8_t in10 = in0 ^ ((currentPEC >> 9) & 0x01);
|
||||
uint8_t in14 = in0 ^ ((currentPEC >> 13) & 0x01);
|
||||
|
||||
uint16 newPEC = 0;
|
||||
uint16_t newPEC = 0;
|
||||
|
||||
newPEC |= in14 << 14;
|
||||
newPEC |= (currentPEC & (0x01 << 12)) << 1;
|
||||
|
@ -81,7 +81,7 @@ static uint16 updateCommandPEC(uint16 currentPEC, uint8_t din) {
|
|||
}
|
||||
|
||||
static uint8_t calculateCommandPEC(uint8_t* data, uint8_t datalen) {
|
||||
uint16 currentpec = INITIAL_COMMAND_PEC;
|
||||
uint16_t currentpec = INITIAL_COMMAND_PEC;
|
||||
if (datalen >= 3) {
|
||||
for (int i = 0; i < (datalen - 2); i++) {
|
||||
for (int n = 0; n < 8; n++) {
|
||||
|
@ -103,7 +103,7 @@ static uint8_t checkCommandPEC(uint8_t* data, uint8_t datalen) {
|
|||
return 255;
|
||||
}
|
||||
|
||||
uint16 currentpec = INITIAL_COMMAND_PEC;
|
||||
uint16_t currentpec = INITIAL_COMMAND_PEC;
|
||||
|
||||
for (int i = 0; i < (datalen - 2); i++) {
|
||||
for (int n = 0; n < 8; n++) {
|
||||
|
@ -233,14 +233,14 @@ static crc F_CRC_CalculaCheckSum(uint8_t const AF_Datos[], uint16_t VF_nBytes) {
|
|||
return (VP_CRCTableValue ^ 0x0000);
|
||||
}
|
||||
|
||||
static uint16 updateDataPEC(uint16 currentPEC, uint8_t din) {
|
||||
static uint16_t updateDataPEC(uint16_t currentPEC, uint8_t din) {
|
||||
din = (din >> 7) & 0x01;
|
||||
uint8_t in0 = din ^ ((currentPEC >> 9) & 0x01);
|
||||
uint8_t in2 = in0 ^ ((currentPEC >> 1) & 0x01);
|
||||
uint8_t in3 = in0 ^ ((currentPEC >> 2) & 0x01);
|
||||
uint8_t in7 = in0 ^ ((currentPEC >> 6) & 0x01);
|
||||
|
||||
uint16 newPEC = 0;
|
||||
uint16_t newPEC = 0;
|
||||
|
||||
newPEC |= (currentPEC & (0x01 << 8)) << 1;
|
||||
newPEC |= (currentPEC & (0x01 << 7)) << 1;
|
||||
|
@ -262,7 +262,7 @@ HAL_StatusTypeDef ___writeCMD(uint16_t command, uint8_t * args, size_t arglen) {
|
|||
args[1] = (command) & 0xFF;
|
||||
|
||||
if (DEBUG_CHANNEL_ENABLED(LOG_LEVEL_NOISY)) {
|
||||
debug_log(LOG_LEVEL_NOISY, "%d W | %x %x ", HAL_GetTick(), args[0], args[1]);
|
||||
debug_log(LOG_LEVEL_NOISY, "%lu W | %x %x ", HAL_GetTick(), args[0], args[1]);
|
||||
|
||||
//print out data bytes
|
||||
for (size_t i = 0; i < N_BMS; i++) {
|
||||
|
@ -314,7 +314,7 @@ HAL_StatusTypeDef readCMD(uint16_t command, uint8_t * buffer, size_t buflen) {
|
|||
//TODO: check command counter?
|
||||
|
||||
if (DEBUG_CHANNEL_ENABLED(LOG_LEVEL_NOISY)) {
|
||||
debug_log(LOG_LEVEL_NOISY, "%u R | %x %x ", HAL_GetTick(), command >> 8, command & 0xFF);
|
||||
debug_log(LOG_LEVEL_NOISY, "%lu R | %x %x ", HAL_GetTick(), command >> 8, command & 0xFF);
|
||||
|
||||
//print out data bytes
|
||||
for (size_t i = 0; i < N_BMS; i++) {
|
||||
|
|
Loading…
Reference in New Issue