2025-04-26 16:03:23 +08:00

81 lines
1.9 KiB
C

/**
******************************************************************************
* @file
* @author
* @version
* @date
* @brief
* @function List:
******************************************************************************
* @attention
*
*
* <h2><center>&copy; COPYRIGHT 2021 </center></h2>
******************************************************************************
* @History:
* @Author:
* @Data:
* @Version:
*/
#ifndef _CRC_H_
#define _CRC_H_
#include "common_types.h"
#include "common_cfg.h"
//#define CRC8_ID_FOR_SBC 0
#define CRC8_ID_FOR_E2E_L1 0u
#define CRC8_ID_FOR_E2E_L2 1u
#define CRC8_ID_MAX 2u
//{8, 0x1d, 0x00, 0, 0, 0x00}, //CRC8_SAE J1850
#define CRC8_L1_INIT_VALUE 0XFFu //调试的板子是H
#define CRC8_L1_POLY_VALUE 0x1Du
#define CRC8_L1_XOR_VALUE 0XFFu
#define CRC8_L2_INIT_VALUE 0X00u //调试的板子是H
#define CRC8_L2_POLY_VALUE 0x1Du
#define CRC8_L2_XOR_VALUE 0X00u
#define CRC_TABLE_IS_CONST 1u //crc 表,固定数组值
#if 0
/*immo crc校验常数自定义*/
#define CRC8_CPOLYNOME (0x7u)
#define POLYNOMINAL 0x8408
#define PRESET_VALUE 0x3791
#define CHECK_VALUE 0x0000
#define CRC16_Make 0x01
#define CRC16_Check 0x00
//extern u16 crc16_make_check(u8 *buffer, u8 size);
unsigned int crc16_make_check(unsigned char *Buffer, unsigned char size, unsigned char Calc_CRC);
unsigned int crc16_make(unsigned char *Buffer, unsigned char size);
uint8_t crc8_make(uint8_t *pu8Data, uint8_t u8Len);
#endif
u8 crc_8_for_sa3f(u8 *p_data,u8 len);
#if 0 //def RAM_OPTIMIZE_EN
#define CRC_USE_TABLE 1 //不用表格,直接用算法
u8 crc_8_make_l1(u8 *u8_data,u8 u8_len);
u8 crc_8_make_l2(u8 *u8_data,u8 u8_len);
#ifdef ASIL_EN
void crc_init(void);
#endif
#else
#define CRC_USE_TABLE 1 //利用生成表格
void crc8_table_init(u8 id);
u8 crc8_make_by_table(u8 id,u8 *p_data,u8 len);
u8 crc8_table_set_init_value(u8 id,u8 value);
#ifdef ASIL_EN
void crc_init(void);
#endif
#endif
#endif