北京中科昊芯科技有限公司

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 752|回复: 2

HX280025芯片VCRC模块crc16的使用

[复制链接]

7

主题

1

回帖

92

积分

注册会员

积分
92
发表于 2023-4-26 17:09:09 | 显示全部楼层 |阅读模式
本帖最后由 流心芝士鸡蛋仔 于 2023-4-26 17:17 编辑

HX280025 VCRC模块支持crc8、crc16、crc24、crc32和可配置多项式,均提供C版查表法和汇编算法。

对于crc16,其多项式包括 0x8005和0x1021,使用方法如下:

1. 使用前添加对应头文件
  1. #include "hx_vcrc.h"
  2. #include "crctable0x8005.h"
  3. #include "crctable0x8005reflected.h"
  4. #include "crctable0x1021.h"
  5. #include "crctable0x1021reflected.h"
复制代码

2. 将crc16算法文件 CRC_16_ASM.S 添加到工程中

3. CRC结构体定义
  1. //! \brief CRC structure
  2. //!
  3. typedef struct _CRC_Obj_{
  4.         uint32_t                seedValue;     //!< Initial value of the CRC calculation
  5.         uint16_t                nMsgBytes;    //!< the number of bytes in the message buffer
  6.         CRC_parity_e         parity;           //!< the location, in a word, of the first byte of the CRC calculation
  7.         uint32_t                crcResult;      //!< the calculated CRC
  8.         void                      *pMsgBuffer; //!< Pointer to the message buffer
  9.         void                      *pCrcTable;   //!< Pointer to the CRC lookup table
  10.         uint32_t                nMsgBits;      // provde the data size in bits if the CRC is to be computed bitwise
  11.         uint32_t                polynomial;   // added to ensure customized polynomial can be added by the user
  12.         uint16_t                polySize;      // provide the polynomial size for the customized polynomial
  13.         uint16_t                dataSize;
  14.         uint16_t                reflected;
  15.         void (*init)(void *);                  //!< Function pointer to CRC initialization routine
  16.         void (*run)(void *);                 //!< Function pointer to CRC computation routine

  17. }CRC_Obj;
复制代码
4. 结构体赋值及运算

  1. CRC_Obj    CRC;
  2. CRC_Handle handleCRC;

  3.     uint32_t crcResultC_1, crcResultC_2 ;

  4. ////////////////////////////////////////////////// C-16 /////////////////////////////////////////////////
  5.     // Step 2: Initialize the CRC object
  6.     CRC.seedValue    = INIT_CRC16;
  7.     CRC.nMsgBytes   = NBYTES;
  8.     CRC.parity          = CRC_parity_even;
  9.     CRC.crcResult     = 0;
  10.     CRC.pMsgBuffer  = (uint8_t *)&testInput_test2[0];
  11.     CRC.pCrcTable    = (uint16_t *)&crc16P1Table[0];
  12.     CRC.init         = (void (*)(void *))CRC_init16Bit;
  13.     CRC.run        = (void (*)(void *))CRC_run16BitTableLookupC;

  14.     // Step 3: Initialize the handle
  15.      handleCRC = &CRC;

  16.      // Step 4: Run the 16-bit table look-up CRC routine and save the first result
  17.      CRC.init(handleCRC);         //CRC_init16Bit
  18.      CRC.run(handleCRC);        //CRC_run16BitTableLookupC
  19.      crcResultC_1 = CRC.crcResult;           //=0x9331     16P1(0x8005)

  20.      // Step 5: Load the second lookup table and run the C routine
  21.      CRC.pCrcTable    = (uint16_t *)&crc16P2Table[0];
  22.      CRC.crcResult    = 0;
  23.      CRC.run(handleCRC);
  24.      crcResultC_2 = CRC.crcResult;          //=0x67fc     16P2(0x1021)
复制代码
5. 计算结果保存在 CRC.crcResult 中,读取即可。



所需文件及例程已经上传到附件中:





本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

14

主题

16

回帖

132

积分

注册会员

积分
132
发表于 2023-4-26 17:15:59 | 显示全部楼层
厉害,学习了

0

主题

6

回帖

41

积分

新手上路

积分
41
发表于 2023-4-26 17:19:19 | 显示全部楼层
干货满满啊!
我申请到昊芯的027ECD的核心板了,是从昊芯校企沟通微信群里申请的,申请很容易,收到核心板也快,已经开始按照昊芯官网的例程学习了。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|北京中科昊芯科技有限公司 ( 京ICP备19023330号-3 )

GMT+8, 2024-5-19 16:01 , Processed in 0.202518 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表