See Cyclic Redundancy Code (CRC) for detailed documentation.

License#

Copyright 2018 Silicon Laboratories Inc. www.silabs.com

The licensor of this software is Silicon Laboratories Inc. Your use of this software is governed by the terms of Silicon Labs Master Software License Agreement (MSLA) available at www.silabs.com/about-us/legal/master-software-license-agreement. This software is distributed to you in Source Code format and is governed by the sections of the MSLA applicable to Source Code.

/***************************************************************************/
#ifndef __CRC_H__
#define __CRC_H__

/***************************************************************************/
uint16_t halCommonCrc16(uint8_t newByte, uint16_t prevResult);

uint32_t halCommonCrc32(uint8_t newByte, uint32_t prevResult);

// Commonly used initial and expected final CRC32 values
#define INITIAL_CRC             0xFFFFFFFFL        
#define CRC32_START             INITIAL_CRC        
#define CRC32_END               0xDEBB20E3L  

#endif //__CRC_H__

Macros#

#define
INITIAL_CRC 0xFFFFFFFFL

initial crc

#define
CRC32_START INITIAL_CRC

crc32 start

#define
CRC32_END 0xDEBB20E3L

For CRC32 POLYNOMIAL run LSB-MSB.

Functions#

uint16_t
halCommonCrc16(uint8_t newByte, uint16_t prevResult)

Calculates 16-bit cyclic redundancy code (CITT CRC 16).

uint32_t
halCommonCrc32(uint8_t newByte, uint32_t prevResult)

Calculates 32-bit cyclic redundancy code.

 

Function Documentation#

halCommonCrc16#

uint16_t halCommonCrc16 (uint8_t newByte, uint16_t prevResult)

Calculates 16-bit cyclic redundancy code (CITT CRC 16).

Parameters
TypeDirectionArgument NameDescription
uint8_tN/AnewByte

The new byte to be run through CRC.

uint16_tN/AprevResult

The previous CRC result.

Applies the standard CITT CRC 16 polynomial to a single byte. It should support being called first with an initial value, then repeatedly until all data is processed.

Returns

  • The new CRC result.


halCommonCrc32#

uint32_t halCommonCrc32 (uint8_t newByte, uint32_t prevResult)

Calculates 32-bit cyclic redundancy code.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/AnewByte

The new byte to be run through CRC.

uint32_tN/AprevResult

The previous CRC result.

Note

  • On some radios or micros, the CRC for error detection on packet data is calculated in hardware.

Applies a CRC32 polynomial to a single byte. It should support being called first with an initial value, then repeatedly until all data is processed.

Returns

  • The new CRC result.