cleanup
This commit is contained in:
parent
c7be10b37f
commit
c9c9ac06d3
@ -8,10 +8,7 @@
|
|||||||
#ifndef INC_ADBMS_ABSTRACTION_H_
|
#ifndef INC_ADBMS_ABSTRACTION_H_
|
||||||
#define INC_ADBMS_ABSTRACTION_H_
|
#define INC_ADBMS_ABSTRACTION_H_
|
||||||
|
|
||||||
#include "ADBMS_CMD_MAKROS.h"
|
|
||||||
#include "ADBMS_Driver.h"
|
#include "ADBMS_Driver.h"
|
||||||
#include "ADBMS_LL_Driver.h"
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#define mV_from_ADBMS6830(x) (((((int16_t)(x))) * 0.150) + 1500)
|
#define mV_from_ADBMS6830(x) (((((int16_t)(x))) * 0.150) + 1500)
|
||||||
|
|
||||||
|
@ -9,9 +9,7 @@
|
|||||||
#define ADBMS_LL_DRIVER_H_
|
#define ADBMS_LL_DRIVER_H_
|
||||||
|
|
||||||
#include "config_ADBMS6830.h"
|
#include "config_ADBMS6830.h"
|
||||||
#include "stm32h7xx_hal.h"
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#define TARGET_STM32
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t adbmsDriverInit(SPI_HandleTypeDef* hspi);
|
uint8_t adbmsDriverInit(SPI_HandleTypeDef* hspi);
|
||||||
|
@ -15,6 +15,13 @@
|
|||||||
#define INITIAL_COMMAND_PEC 0x0010
|
#define INITIAL_COMMAND_PEC 0x0010
|
||||||
#define INITIAL_DATA_PEC 0x0010
|
#define INITIAL_DATA_PEC 0x0010
|
||||||
|
|
||||||
|
// CRC polynomial constants
|
||||||
|
#define CRC15_POLY 0xC599
|
||||||
|
#define CRC10_POLY 0x8F
|
||||||
|
#define CRC15_REMAINDER_MASK 0x4000
|
||||||
|
#define CRC10_REMAINDER_MASK 0x200
|
||||||
|
#define CRC10_RESULT_MASK 0x3FF
|
||||||
|
|
||||||
SPI_HandleTypeDef* adbmsspi;
|
SPI_HandleTypeDef* adbmsspi;
|
||||||
|
|
||||||
uint8_t adbmsDriverInit(SPI_HandleTypeDef* hspi) {
|
uint8_t adbmsDriverInit(SPI_HandleTypeDef* hspi) {
|
||||||
@ -49,8 +56,8 @@ static uint16_t computeCRC15(const uint8_t* data, size_t length) {
|
|||||||
for (size_t i = 0; i < length; i++) {
|
for (size_t i = 0; i < length; i++) {
|
||||||
remainder ^= (data[i] << 7);
|
remainder ^= (data[i] << 7);
|
||||||
for (int b = 0; b < 8; b++) {
|
for (int b = 0; b < 8; b++) {
|
||||||
if (remainder & 0x4000) {
|
if (remainder & CRC15_REMAINDER_MASK) {
|
||||||
remainder = (uint16_t)((remainder << 1) ^ 0xC599);
|
remainder = (uint16_t)((remainder << 1) ^ CRC15_POLY);
|
||||||
} else {
|
} else {
|
||||||
remainder <<= 1;
|
remainder <<= 1;
|
||||||
}
|
}
|
||||||
@ -81,13 +88,12 @@ static uint8_t checkCommandPEC(uint8_t* data, uint8_t datalen) {
|
|||||||
|
|
||||||
static uint16_t computeCRC10(const uint8_t* data, size_t length, bool rx_cmd) {
|
static uint16_t computeCRC10(const uint8_t* data, size_t length, bool rx_cmd) {
|
||||||
uint16_t remainder = INITIAL_DATA_PEC;
|
uint16_t remainder = INITIAL_DATA_PEC;
|
||||||
const uint16_t poly = 0x8F;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < length; i++) {
|
for (size_t i = 0; i < length; i++) {
|
||||||
remainder ^= (uint16_t)(data[i] << 2);
|
remainder ^= (uint16_t)(data[i] << 2);
|
||||||
for (int b = 0; b < 8; b++) {
|
for (int b = 0; b < 8; b++) {
|
||||||
if (remainder & 0x200) {
|
if (remainder & CRC10_REMAINDER_MASK) {
|
||||||
remainder = (uint16_t)((remainder << 1) ^ poly);
|
remainder = (uint16_t)((remainder << 1) ^ CRC10_POLY);
|
||||||
} else {
|
} else {
|
||||||
remainder <<= 1;
|
remainder <<= 1;
|
||||||
}
|
}
|
||||||
@ -98,14 +104,14 @@ static uint16_t computeCRC10(const uint8_t* data, size_t length, bool rx_cmd) {
|
|||||||
if (rx_cmd) {
|
if (rx_cmd) {
|
||||||
remainder ^= (uint16_t)((data[length] & 0xFC) << 2);
|
remainder ^= (uint16_t)((data[length] & 0xFC) << 2);
|
||||||
for (int b = 0; b < 6; b++) {
|
for (int b = 0; b < 6; b++) {
|
||||||
if (remainder & 0x200) {
|
if (remainder & CRC10_REMAINDER_MASK) {
|
||||||
remainder = (uint16_t)((remainder << 1) ^ poly);
|
remainder = (uint16_t)((remainder << 1) ^ CRC10_POLY);
|
||||||
} else {
|
} else {
|
||||||
remainder <<= 1;
|
remainder <<= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (uint16_t)(remainder & 0x3FF);
|
return (uint16_t)(remainder & CRC10_RESULT_MASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t calculateDataPEC(uint8_t* data, uint8_t datalen) {
|
static uint8_t calculateDataPEC(uint8_t* data, uint8_t datalen) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user