135 lines
4.3 KiB
C
135 lines
4.3 KiB
C
/****************************************************************************
|
|
|
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
|
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
be copied by any method or incorporated into another program without
|
|
the express written consent of Aerospace C.Power. This Information or any portion
|
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
liability for its use in any way and conveys no license or title under
|
|
any patent or copyright and makes no representation or warranty that this
|
|
Information is free from patent or copyright infringement.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef IOT_CRC_API_H
|
|
#define IOT_CRC_API_H
|
|
|
|
/* os shim includes */
|
|
#include "os_types_api.h"
|
|
#include "os_mem_api.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define IOT_CRC_DBG_ENABLE (0)
|
|
/* define crc16 type */
|
|
#define IOT_CRC16_TYPE_CCITT (0)
|
|
#define IOT_CRC16_TYPE_CCITT_FALSE (1)
|
|
#define IOT_CRC16_TYPE_XMODEM (2)
|
|
#define IOT_CRC16_TYPE_X25 (3)
|
|
#define IOT_CRC16_TYPE_BT (4)
|
|
|
|
/** \defgroup MISC_APIs MISC APIs
|
|
* @brief MISC APIs
|
|
*
|
|
*
|
|
*/
|
|
|
|
/** @addtogroup MISC_APIs
|
|
* @{
|
|
*
|
|
*/
|
|
|
|
/**
|
|
* brief: get 32bit CRC value from a byte stream with init vector
|
|
* @param init_vect: the init vector
|
|
* @param buffer: buffer with data for crc calculating
|
|
* @param len: length of the buffer
|
|
* @retval: the CRC of data in buffer
|
|
*/
|
|
uint32_t iot_getcrc32_update(uint32_t init_vect, uint8_t *buffer, uint32_t len);
|
|
|
|
/**
|
|
* brief: get 32bit CRC value from a byte stream
|
|
* @param buffer: buffer with data for crc calculating
|
|
* @param len: length of the buffer
|
|
* @retval: the CRC of data in buffer
|
|
*/
|
|
uint32_t iot_getcrc32(uint8_t *buffer, uint32_t len);
|
|
|
|
/**
|
|
* brief: get high 16 bits value of the 32bit CRC value from a byte stream
|
|
* @param buffer: buffer with data for crc calculating
|
|
* @param len: length of the buffer
|
|
* @retval: high 16 bits value of the 32bit CRC
|
|
*/
|
|
uint16_t iot_getcrc32_h16(uint8_t *buffer, uint32_t len);
|
|
|
|
/**
|
|
* brief: get 24bit CRC value from a byte stream with init vector
|
|
* @param init_vect: the init vector
|
|
* @param buffer: buffer with data for crc calculating
|
|
* @param len: length of the buffer
|
|
* @retval: the CRC of data in buffer
|
|
*/
|
|
uint32_t iot_getcrc24_update(uint32_t init_vect, uint8_t *buffer, uint32_t len);
|
|
|
|
/**
|
|
* brief: get 24bit CRC value from a byte stream
|
|
* @param buffer: buffer with data for crc calculating
|
|
* @param len: length of the buffer
|
|
* @retval: the CRC of data in buffer
|
|
*/
|
|
uint32_t iot_getcrc24(uint8_t *buffer, uint32_t len);
|
|
|
|
/**
|
|
* brief: get 16bit crc_xmodem value from a byte stream with init vector
|
|
* @param init_vect: the init vector
|
|
* @param buffer: buffer with data for crc calculating
|
|
* @param len: length of the buffer
|
|
* @param reverse_flag: reverse buffer data
|
|
* @retval: the CRC of data in buffer
|
|
*/
|
|
uint16_t iot_getcrc16_update(uint16_t init_vect, uint8_t *buffer,
|
|
uint32_t len, uint8_t reverse_flag);
|
|
|
|
/**
|
|
* brief: get 16bit crc_xmodem value from a byte stream
|
|
* @param buffer: buffer with data for crc calculating
|
|
* @param len: length of the buffer
|
|
* @param crc16_type: crc16 type see - IOT_CRC16_TYPE_XXX
|
|
* @retval: the CRC of data in buffer
|
|
*/
|
|
uint16_t iot_getcrc16(uint8_t *buffer, uint32_t len, uint8_t crc16_type);
|
|
|
|
/**
|
|
* brief: get 8bit CRC value from a byte stream with init vector
|
|
* @param init_vect: the init vector
|
|
* @param buffer: buffer with data for crc calculating
|
|
* @param len: length of the buffer
|
|
* @retval: the CRC of data in buffer
|
|
*/
|
|
uint8_t iot_getcrc8_update(uint8_t init_vect, uint8_t *buffer, uint32_t len);
|
|
|
|
/**
|
|
* brief: get 8bit CRC value from a byte stream
|
|
* @param buffer: buffer with data for crc calculating
|
|
* @param len: length of the buffer
|
|
* @retval: the CRC of data in buffer
|
|
*/
|
|
uint8_t iot_getcrc8(uint8_t *buffer, uint32_t len);
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* IOT_CRC_API_H */
|