Blame view

app/app-prime-modbus/include/fanet/crc.h 2.68 KB
8c2952457   김태훈   응용 프로그램 추가
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  /***********************************************************************CHDR**
   * NAME:      crc.h
   *
   * PURPOSE:   Provides functions for calculating Cyclic Redundancy Checks
   *            (CRCs).
   *
   *****************************************************************************/
  
  #ifndef	INCLUDED_CRC
  #define	INCLUDED_CRC
  
  /*****************************************************************************
   * Internal constants
   *****************************************************************************/
  #define	CRC_BITS_BYTE	8
  #define	CRC_BYTE_MASK	0xFF
  #define	CRC_UCHAR_MAX	255
  
  /***********************************************************************EXDT**
   * NAME:      CRC_VAL
   *
   * PURPOSE:   Holds the CRC 'register' during calculation and can be cast to
   *            an integer for output
   *
   *****************************************************************************/
  typedef unsigned int	CRC_VAL;
  
  /***********************************************************************EXDT**
   * NAME:      CRC_BOOL
   *
   * PURPOSE:   True / false boolean value
   *
   *****************************************************************************/
  typedef int	CRC_BOOL;
  #define	CRC_TRUE	1
  #define	CRC_FALSE	0
  
  /***********************************************************************EXDT**
   * NAME:      CRC_TBL
   *
   * PURPOSE:   Stores CRC the parameters and look-up table required for doing
   *            the CRC calculation
   *
   *****************************************************************************/
  typedef struct crc_tbl
  {
    CRC_VAL pre_calc[CRC_UCHAR_MAX + 1];
    int width;
    CRC_VAL poly;
    CRC_VAL init_val;
    CRC_VAL xor_out;
    CRC_BOOL is_rev;
  } CRC_TBL;
  
  /***********************************************************************EXCN**
   * NAME:      CRC_STD_*
   *
   * PURPOSE:   Constants to identify standard varieties of CRCs
   *
   *****************************************************************************/
  #define CRC_STD_CRC16     0
  #define CRC_DNP_CRC16     1
  #define CRC_MOD_CRC16     2
  #define CRC_STD_XMODEM    3
  #define CRC_STD_ZMODEM16  4
  #define CRC_STD_CRC32     5
  #define CRC_STD_JAM       6
  
  /*****************************************************************************
   * Function prototypes
   *****************************************************************************/
  CRC_BOOL	crc_mk_tbl(CRC_TBL*, int, CRC_VAL, CRC_VAL, CRC_VAL, int);
  CRC_BOOL	crc_mk_std_tbl(CRC_TBL*, int);
  CRC_VAL		crc_final(CRC_VAL*, CRC_TBL*);
  
  void		crc_init(CRC_VAL*, CRC_TBL*);
  void		crc_add_chr(CRC_VAL*, CRC_TBL*, unsigned char, int);
  void		crc_add_str(CRC_VAL*, CRC_TBL*, unsigned char*);
  void		crc_add_data(CRC_VAL*, CRC_TBL*, unsigned char*, int);
  
  #endif