only:mre_f4
This commit is contained in:
Andrey 2023-03-04 16:00:44 -05:00
parent 32e8de134f
commit e9da0eeed2
5 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,41 @@
#include <stddef.h>
#include <stdint.h>
#include "crc8hondak.h"
static inline uint8_t crc_init(void)
{
return 0xff;
}
static inline uint8_t crc_next(uint8_t crc, uint8_t data)
{
uint8_t eor;
unsigned int i = 8;
crc ^= data;
do {
/* This might produce branchless code */
eor = crc & 1 ? 0xb8 : 0;
crc >>= 1;
crc ^= eor;
} while (--i);
return crc;
}
static inline uint8_t crc_final(uint8_t crc)
{
return ~crc;
}
uint8_t crc_hondak_calc(const uint8_t *data, size_t len)
{
uint8_t crc = crc_init();
if (len) do {
crc = crc_next(crc, *data++);
} while (--len);
return crc_final(crc);
}

View File

@ -0,0 +1,19 @@
/*
* crc8hondak.h
*
* Code generated by universal_crc by Danjel McGougan
*
* matches CRC8_EBU with 0xFF OutXor
*
* CRC parameters used:
* bits: 8
* poly: 0x1d
* init: 0xff
* xor: 0xff
* reverse: true
* non-direct: false
*
* CRC of the string "123456789" is 0x68
*/
uint8_t crc_hondak_calc(const uint8_t *data, size_t len);

View File

@ -12,6 +12,7 @@ UTILSRC_CPP = \
$(UTIL_DIR)/math/error_accumulator.cpp \
$(UTIL_DIR)/math/efi_pid.cpp \
$(UTIL_DIR)/math/interpolation.cpp \
$(UTIL_DIR)/math/crc8hondak.cpp \
$(PROJECT_DIR)/util/datalogging.cpp \
$(PROJECT_DIR)/util/loggingcentral.cpp \
$(PROJECT_DIR)/util/cli_registry.cpp \

View File

@ -0,0 +1,15 @@
#include "pch.h"
#include "crc8hondak.h"
TEST(util, crc8hondak) {
const uint8_t data[] = {0x1, 0, 0};
ASSERT_EQ(140, crc_hondak_calc(data, 3));
}
// https://rusefi.com/forum/viewtopic.php?p=47283#p47283
TEST(util, crc8hondak_2) {
const uint8_t data[] = {0, 0xD0, 0x06, 0};
ASSERT_EQ(0x62, crc_hondak_calc(data, 4));
}

View File

@ -3,6 +3,7 @@
CPPSRC += $(PROJECT_DIR)/../unit_tests/tests/util/test_buffered_writer.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_error_accumulator.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_exp_average.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_honda_crc.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_hash.cpp \
INCDIR += $(PROJECT_DIR)/controllers/system