Skip to content

Commit

Permalink
Merge pull request #4 from samuelyhsu/master
Browse files Browse the repository at this point in the history
给头文件添加extern "C"保护,以便在c++环境也能正常使用
  • Loading branch information
qiyongzhong0 authored Dec 4, 2023
2 parents 2e6cc54 + 4e3abd9 commit 5b16da5
Show file tree
Hide file tree
Showing 28 changed files with 999 additions and 849 deletions.
165 changes: 165 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@

# Kconfig file for package crclib

menuconfig PKG_USING_CRCLIB
bool "crclib : A library of functions with 8-bit ,16-bit ,32-bit crc check calculations."
default n

if PKG_USING_CRCLIB

config PKG_CRCLIB_PATH
string
default "/packages/misc/crclib"

config CRCLIB_USING_CRC8
bool "using 8 bit crc"
default y

if CRCLIB_USING_CRC8
config CRC8_USING_CONST_TABLE
bool "using const table"
default y

choice
prompt "crc8 polynome"
default CRC8_POLY_8C
help
Select crc8 polynome
config CRC8_POLY_8C
bool "x8+x5+x4+1"
config CRC8_POLY_D9
bool "x8+x7+x4+x3+x+1"
config CRC8_POLY_CUSTOM
bool "custom value"
endchoice

if CRC8_POLY_CUSTOM
config CRC8_POLY_CUSTOM_STRING
int "crc8 polynome value (int)"
default 0
endif

config CRC8_POLY
int
default 140 if CRC8_POLY_8C
default 217 if CRC8_POLY_D9
default CRC8_POLY_CUSTOM_STRING if CRC8_POLY_CUSTOM
endif

config CRCLIB_USING_CRC16
bool "using 16 bit crc"
default y

if CRCLIB_USING_CRC16
config CRC16_USING_CONST_TABLE
bool "using const table"
default y

choice
prompt "crc16 polynome"
default CRC16_POLY_A001
help
Select crc16 polynome
config CRC16_POLY_A001
bool "x16+x15+x2+1 (MODBUS,IBM,SDLC)"
config CRC16_POLY_8404
bool "x16+x12+x5+1 (CCITT,ISO,HDLC,ITUX25,PPP-FCS)"
config CRC16_POLY_CUSTOM
bool "custom value"
endchoice

if CRC16_POLY_CUSTOM
config CRC16_POLY_CUSTOM_STRING
int "crc16 polynome value (int)"
default 0
endif

config CRC16_POLY
int
default 40961 if CRC16_POLY_A001
default 33800 if CRC16_POLY_8404
default CRC16_POLY_CUSTOM_STRING if CRC16_POLY_CUSTOM
endif

config CRCLIB_USING_CRC32
bool "using 32 bit crc"
default y

if CRCLIB_USING_CRC32
config CRC32_USING_CONST_TABLE
bool "using const table"
default y

choice
prompt "crc32 polynome"
default CRC32_POLY_EDB88320
help
Select crc32 polynome
config CRC32_POLY_EDB88320
bool "x32+x26+x23+...+x2+x+1 (ZIP,RAR,IEEE,LAN/FDDI,PPP-FCS)"
config CRC32_POLY_82F63B78
bool "x32+x28+x27+...+x8+x6+1 (SCTP)"
config CRC32_POLY_CUSTOM
bool "custom value"
endchoice

if CRC32_POLY_CUSTOM
config CRC32_POLY_CUSTOM_STRING
int "crc32 polynome value (int)"
default 0
endif

config CRC32_POLY
int
default 3988292384 if CRC32_POLY_EDB88320
default 2197175160 if CRC32_POLY_82F63B78
default CRC32_POLY_CUSTOM_STRING if CRC32_POLY_CUSTOM
endif

config CRCLIB_USING_CRC8_EX
bool "using 8 bit crc expand"
default n

config CRCLIB_USING_CRC16_EX
bool "using 16 bit crc expand"
default n

config CRCLIB_USING_CRC32_EX
bool "using 32 bit crc expand"
default n

config CRCLIB_USING_CRC16_EX_SAMPLE
bool "using 16 bit crc expand sample"
default n

config CRCLIB_USING_CRC_HW
bool "using hardware crc"
default n

config CRCLIB_USING_CRC_HW_SAMPLE
bool "using hardware crc sample"
default n

choice
prompt "Version"
default PKG_USING_CRCLIB_V102
help
Select the package version
config PKG_USING_CRCLIB_LATEST_VERSION
bool "latest"
config PKG_USING_CRCLIB_V102
bool "v1.02"
config PKG_USING_CRCLIB_V101
bool "v1.01"
config PKG_USING_CRCLIB_V100
bool "v1.00"
endchoice

config PKG_CRCLIB_VER
string
default "latest" if PKG_USING_CRCLIB_LATEST_VERSION
default "v1.02" if PKG_USING_CRCLIB_V102
default "v1.01" if PKG_USING_CRCLIB_V101
default "v1.00" if PKG_USING_CRCLIB_V100

endif
8 changes: 4 additions & 4 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ from building import *

cwd = GetCurrentDir()
path = [cwd+'/inc']
src = Glob('src/*.c')

group = DefineGroup('crclib', src, depend = ['PKG_USING_CRCLIB'], CPPPATH = path)
src = Glob('src/*.c')

Return('group')
group = DefineGroup('crclib', src, depend=['PKG_USING_CRCLIB'], CPPPATH=path)

Return('group')
17 changes: 11 additions & 6 deletions inc/crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@
#ifndef __CRC_H__
#define __CRC_H__

#include <crc8.h>
#ifdef __cplusplus
extern "C" {
#endif

#include <crc16.h>
#include <crc32.h>
#include <crc8_ex.h>
#include <crc16_ex.h>
#include <crc32.h>
#include <crc32_ex.h>
#include <crc_hw_stm32.h>
#include <crc8.h>
#include <crc8_ex.h>
#include <crc_hw_hc32.h>
#include <crc_hw_n32.h>

#include <crc_hw_stm32.h>
#ifdef __cplusplus
}
#endif
#endif

28 changes: 17 additions & 11 deletions inc/crc16.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,44 @@
#ifndef __CRC16_H__
#define __CRC16_H__

#include "typedef.h"
#ifdef __cplusplus
extern "C" {
#endif

#include "crc_cfg.h"
#include "typedef.h"

#ifdef CRCLIB_USING_CRC16

#if (!defined(CRC16_USING_CONST_TABLE) || ((CRC16_POLY != 0xA001) && (CRC16_POLY != 0x8408)))
/*
#if (!defined(CRC16_USING_CONST_TABLE) || \
((CRC16_POLY != 0xA001) && (CRC16_POLY != 0x8408)))
/*
* @brief cyclic initialize crc table
* @param none
* @retval none
*/
void crc16_table_init(void);
#endif

/*
/*
* @brief cyclic calculation crc check value
* @param init_val - initial value
* @param pdata - datas pointer
* @param len - datas len
* @retval calculated result
* @retval calculated result
*/
u16 crc16_cyc_cal(u16 init_val, u8 *pdata, u32 len);
uint16_t crc16_cyc_cal(uint16_t init_val, uint8_t *pdata, uint32_t len);

/*
/*
* @brief calculation crc check value, initial is 0xFFFF
* @param pdata - datas pointer
* @param len - datas len
* @retval calculated result
* @retval calculated result
*/
u16 crc16_cal(u8 *pdata, u32 len);
uint16_t crc16_cal(uint8_t *pdata, uint32_t len);

#endif

#ifdef __cplusplus
}
#endif
#endif

28 changes: 17 additions & 11 deletions inc/crc16_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,50 @@
#ifndef __CRC16_EX_H__
#define __CRC16_EX_H__

#include "typedef.h"
#ifdef __cplusplus
extern "C" {
#endif

#include "crc_cfg.h"
#include "typedef.h"

#ifdef CRCLIB_USING_CRC16_EX

#define CRC16_EX_INIT_VAL 0xFFFF
#define CRC16_EX_INIT_VAL 0xFFFF

typedef struct{
u16 table[256];
}crc16_inst_t;
typedef struct {
u16 table[256];
} crc16_inst_t;

/*
/*
* @brief initialize crc instance
* @param hinst - instance handle
* @param poly - polynomial of crc
* @retval none
*/
void crc16_ex_init(crc16_inst_t *hinst, u16 poly);

/*
/*
* @brief cyclic calculation crc check value
* @param hinst - instance handle
* @param init_val - initial value
* @param pdata - datas pointer
* @param len - datas len
* @retval calculated result
* @retval calculated result
*/
u16 crc16_ex_cyc_cal(crc16_inst_t *hinst, u16 init_val, u8 *pdata, u32 len);

/*
/*
* @brief calculation crc check value, initial is 0xFFFF
* @param hinst - instance handle
* @param pdata - datas pointer
* @param len - datas len
* @retval calculated result
* @retval calculated result
*/
u16 crc16_ex_cal(crc16_inst_t *hinst, u8 *pdata, u32 len);

#endif
#ifdef __cplusplus
}
#endif
#endif

16 changes: 12 additions & 4 deletions inc/crc16_ex_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@
#ifndef __CRC16_EX_SAMPLE_H__
#define __CRC16_EX_SAMPLE_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <crc.h>

#ifdef CRCLIB_USING_CRC16_EX
#ifdef CRCLIB_USING_CRC16_EX_SAMPLE

#define CRC16_EX_SAMPLE_POLY 0xA001
#define CRC16_EX_SAMPLE_POLY 0xA001

extern crc16_inst_t crc16_ex_sample_inst;

#define CRC16_EX_SAMPLE_CYC_CAL(init, pd, len) crc16_ex_cyc_cal(&crc16_ex_sample_inst, init, pd, len)
#define CRC16_EX_SAMPLE_CAL(pd, len) crc16_ex_cal(&crc16_ex_sample_inst, pd, len)
#define CRC16_EX_SAMPLE_CYC_CAL(init, pd, len) \
crc16_ex_cyc_cal(&crc16_ex_sample_inst, init, pd, len)
#define CRC16_EX_SAMPLE_CAL(pd, len) \
crc16_ex_cal(&crc16_ex_sample_inst, pd, len)

#endif
#endif
#ifdef __cplusplus
}
#endif
#endif

Loading

0 comments on commit 5b16da5

Please sign in to comment.