STM32G0 MCAL 0.0.1
Tiny MCAL for educational purpose.
Loading...
Searching...
No Matches
Crc.h File Reference

This file contains the API and the configuration of the AUTOSAR Basic Software module CRC. More...

Go to the source code of this file.

Functions

uint8 Crc_CalculateCRC8 (const uint8 *Crc_DataPtr, uint32 Crc_Length, uint8 Crc_StartValue8, boolean Crc_IsFirstCall)
 Calculate a CRC of 8 bits
 
uint8 Crc_CalculateCRC8H2F (const uint8 *Crc_DataPtr, uint32 Crc_Length, uint8 Crc_StartValue8H2F, boolean Crc_IsFirstCall)
 Calculate a CRC of 8 bits with other polynomial 0x2F
 
uint16 Crc_CalculateCRC16 (const uint8 *Crc_DataPtr, uint32 Crc_Length, uint16 Crc_StartValue16, boolean Crc_IsFirstCall)
 Calculate a CRC of 16 bits and polynomial of 0x1021
 
uint16 Crc_CalculateCRC16ARC (const uint8 *Crc_DataPtr, uint32 Crc_Length, uint16 Crc_StartValue16, boolean Crc_IsFirstCall)
 Calculate a CRC of 16 bits and polynomial of 0xA001
 
uint32 Crc_CalculateCRC32 (const uint8 *Crc_DataPtr, uint32 Crc_Length, uint32 Crc_StartValue32, boolean Crc_IsFirstCall)
 Calculate a CRC of 32 bits and polynomial of 0x04C11DB7
 
uint32 Crc_CalculateCRC32P4 (const uint8 *Crc_DataPtr, uint32 Crc_Length, uint32 Crc_StartValue32, boolean Crc_IsFirstCall)
 Calculate a CRC of 32 bits and polynomial of F4’AC’FB’13h
 
uint64 Crc_CalculateCRC64 (const uint8 *Crc_DataPtr, uint32 Crc_Length, uint64 Crc_StartValue64, boolean Crc_IsFirstCall)
 Calculate a CRC of 64 bits and polynomial of 42’F0’E1’EB’A9’EA’36’93h
 
uint8 Crc_GetVersionInfo (Std_VersionInfoType *Versioninfo)
 Fuunction to assign values to VersionInfo structure
 

Detailed Description

This file contains the API and the configuration of the AUTOSAR Basic Software module CRC.

The Crc library contains the following routines for CRC calculation • CRC8: SAEJ1850 • CRC8H2F: CRC8 0x2F polynomial • CRC16 • CRC32 • CRC32P4: CRC32 0xF4ACFB13 polynomial • CRC64: CRC-64-ECMA

This library was designed like a Runtime calculation: Slower execution, but small code size (no ROM table)

Function Documentation

◆ Crc_CalculateCRC16()

uint16 Crc_CalculateCRC16 ( const uint8 * Crc_DataPtr,
uint32 Crc_Length,
uint16 Crc_StartValue16,
boolean Crc_IsFirstCall )

Calculate a CRC of 16 bits and polynomial of 0x1021

The function calculates the a 16 bit CRC according to the standard of AUTOSAR with their respective paramters.

First is necessary to know if is the first time to use the function and it is assigned a value for our CRC calculation. The function calculates the CRC through a for cycle, one of them is to know what of all bytes is in the calculation and the other is to move the bit of the respective byte.

The function uses bit shift to calculate the CRC according with the process.

Parameters
Crc_DataPtrPointer to start address of data block to be calculated.
Crc_LengthLength of data block to be calculated in bytes.
Crc_StartValue16Start value when the algorithm starts.
Crc_IsFirstCallboolean variable to know if is the first time that we used the function.
Return values
crcValuethe value of crc (16 bits) according with parameters and specifications of this function
Requirement
SWS_Crc_00019, SWS_Crc_00015

< Polynomial of CRC16

< Value of CRC if is first call

< Number of shift bits on crc calculation

< Number of bits of a byte

< Most significant bit of 2 bytes

◆ Crc_CalculateCRC16ARC()

uint16 Crc_CalculateCRC16ARC ( const uint8 * Crc_DataPtr,
uint32 Crc_Length,
uint16 Crc_StartValue16,
boolean Crc_IsFirstCall )

Calculate a CRC of 16 bits and polynomial of 0xA001

The function calculates the a 16 bit CRC with data reflected according to the standard of AUTOSAR with their respective paramters.

In this case AUTOSAR specify a 0x8005 polynomial but the function need that the input data are relfected so the reflected data of 0x8005 is 0xA001.

First is necessary to know if is the first time to use the function and it is assigned a value for our CRC calculation. The function calculates the CRC through a for cycle, one of them is to know what of all bytes is in the calculation and the other is to move the bit of the respective byte.

The function uses bit shift to calculate the CRC according with the process.

Parameters
Crc_DataPtrPointer to start address of data block to be calculated.
Crc_LengthLength of data block to be calculated in bytes.
Crc_StartValue16Start value when the algorithm starts.
Crc_IsFirstCallboolean variable to know if is the first time that we used the function.
Return values
crcValuethe value of crc (16 bits) according with parameters and specifications of this function
Requirement
SWS_Crc_00071, SWS_Crc_00069

< Polynomial of CRC16ARC

< Less significant bit

◆ Crc_CalculateCRC32()

uint32 Crc_CalculateCRC32 ( const uint8 * Crc_DataPtr,
uint32 Crc_Length,
uint32 Crc_StartValue32,
boolean Crc_IsFirstCall )

Calculate a CRC of 32 bits and polynomial of 0x04C11DB7

The function calculates the a 32 bit CRC with data reflected according to the standard of AUTOSAR with their respective paramters.

In this case AUTOSAR specify a 0x04C11DB7 polynomial but the function need that the input data are relfected so the reflected data of 0x04C11DB7 is 0xEDB88320.

First is necessary to know if is the first time to use the function and it is assigned a value for our CRC calculation. The function calculates the CRC through a for cycle, one of them is to know what of all bytes is in the calculation and the other is to move the bit of the respective byte.

The function uses bit shift to calculate the CRC according with the process.

Parameters
Crc_DataPtrPointer to start address of data block to be calculated.
Crc_LengthLength of data block to be calculated in bytes.
Crc_StartValue32Start value when the algorithm starts.
Crc_IsFirstCallboolean variable to know if is the first time that we used the function.
Return values
crcValuethe value of crc (32 bits) according with parameters and specifications of this function
Requirement
SWS_Crc_00020, SWS_Crc_00016

< Polynomial of CRC32

< Value of CRC if is first call

< Value of CRC if is first call

< Less significant bit

< Value of CRC if is first call

◆ Crc_CalculateCRC32P4()

uint32 Crc_CalculateCRC32P4 ( const uint8 * Crc_DataPtr,
uint32 Crc_Length,
uint32 Crc_StartValue32,
boolean Crc_IsFirstCall )

Calculate a CRC of 32 bits and polynomial of F4’AC’FB’13h

The function calculates the a 32 bit CRC with data reflected according to the standard of AUTOSAR with their respective paramters.

In this case AUTOSAR specify a F4’AC’FB’13h polynomial but the function need that the input data are relfected so the reflected and is needed to assign the first CRC value the value of their XOR in this case 0xFFFFFFFF.

First is necessary to know if is the first time to use the function and it is assigned a value for our CRC calculation. The function calculates the CRC through a for cycle, one of them is to know what of all bytes is in the calculation and the other is to move the bit of the respective byte.

The function uses bit shift to calculate the CRC according with the process.

Parameters
Crc_DataPtrPointer to start address of data block to be calculated.
Crc_LengthLength of data block to be calculated in bytes.
Crc_StartValue32Start value when the algorithm starts.
Crc_IsFirstCallboolean variable to know if is the first time that we used the function.
Return values
crcValuethe value of crc (32 bits) according with parameters and specifications of this function
Requirement
SWS_Crc_00058, SWS_Crc_00059

< Value of CRC if is first call

< Value of CRC if is first call

< Less significant bit

< Polynomial of CRC32P4

< Value of CRC if is first call

◆ Crc_CalculateCRC64()

uint64 Crc_CalculateCRC64 ( const uint8 * Crc_DataPtr,
uint32 Crc_Length,
uint64 Crc_StartValue64,
boolean Crc_IsFirstCall )

Calculate a CRC of 64 bits and polynomial of 42’F0’E1’EB’A9’EA’36’93h

The function calculates the a 32 bit CRC with data reflected according to the standard of AUTOSAR with their respective paramters.

In this case AUTOSAR specify a 42’F0’E1’EB’A9’EA’36’93h polynomial but the function need that the input data are relfected so the reflected and is needed to assign the first CRC value the value of their XOR in this case 0xFFFFFFFFFFFFFFFF.

First is necessary to know if is the first time to use the function and it is assigned a value for our CRC calculation. The function calculates the CRC through a for cycle, one of them is to know what of all bytes is in the calculation and the other is to move the bit of the respective byte.

The function uses bit shift to calculate the CRC according with the process.

Parameters
Crc_DataPtrPointer to start address of data block to be calculated.
Crc_LengthLength of data block to be calculated in bytes.
Crc_StartValue64Start value when the algorithm starts.
Crc_IsFirstCallboolean variable to know if is the first time that we used the function.
Return values
crcValuethe value of crc (64 bits) according with parameters and specifications of this function
Requirement
SWS_Crc_00061, SWS_Crc_00064

< Value of CRC if is first call

< Value of CRC if is first call

< Less significant bit

< Polynomial of CRC64

< Value of CRC if is first call

◆ Crc_CalculateCRC8()

uint8 Crc_CalculateCRC8 ( const uint8 * Crc_DataPtr,
uint32 Crc_Length,
uint8 Crc_StartValue8,
boolean Crc_IsFirstCall )

Calculate a CRC of 8 bits

The function calculates the a 8 bit CRC according to the standard of AUTOSAR with their respective paramters.

First is necessary to know if is the first time to use the function and it is assigned a value for our CRC calculation. The function calculates the CRC through a for cycle, one of them is to know what of all bytes is in the calculation and the other is to move the bit of the respective byte.

The function uses bit shift to calculate the CRC according with the process.

Parameters
Crc_DataPtrPointer to start address of data block to be calculated.
Crc_LengthLength of data block to be calculated in bytes.
Crc_StartValue8Start value when the algorithm starts.
Crc_IsFirstCallboolean variable to know if is the first time that we used the function.
Return values
crcValuethe value of crc (8 bits) according with parameters and specifications of this function
Requirement
SWS_Crc_00031, SWS_Crc_00032

< Polynomial of CRC8_SAEJ1850

< Value of CRC if is first call

< Number of bits of a byte

< Most significant bit of a byte

◆ Crc_CalculateCRC8H2F()

uint8 Crc_CalculateCRC8H2F ( const uint8 * Crc_DataPtr,
uint32 Crc_Length,
uint8 Crc_StartValue8H2F,
boolean Crc_IsFirstCall )

Calculate a CRC of 8 bits with other polynomial 0x2F

The function calculates the a 8 bit CRC according to the standard of AUTOSAR with their respective paramters.

First is necessary to know if is the first time to use the function and it is assigned a value for our CRC calculation. The function calculates the CRC through a for cycle, one of them is to know what of all bytes is in the calculation and the other is to move the bit of the respective byte.

The function uses bit shift to calculate the CRC according with the process.

Parameters
Crc_DataPtrPointer to start address of data block to be calculated.
Crc_LengthLength of data block to be calculated in bytes.
Crc_StartValue8H2FStart value when the algorithm starts.
Crc_IsFirstCallboolean variable to know if is the first time that we used the function.
Return values
crcValuethe value of crc (8 bits) according with parameters and specifications of this function
Requirement
SWS_Crc_00043, SWS_Crc_00044

< Polynomial of CRC8H2F

< Value of CRC if is first call

< Number of bits of a byte

< Most significant bit of a byte

◆ Crc_GetVersionInfo()

uint8 Crc_GetVersionInfo ( Std_VersionInfoType * Versioninfo)

Fuunction to assign values to VersionInfo structure

This service returns the version information of this module.

The function assign values to VersionInfo structure to know the vendorID, moduleID, sw_major_version, sw_minor_version and sw_patch_version.

The function returns a TRUE if the members of structure have a value this part of code is inly for test porpuses.

Parameters
VersioninfoVariable that locates the version information of CRC.
Return values
status
Requirement
SWS_Crc_00021

< CRC Vendor ID VALUE

< CRC MODULE ID VALUE

< CRC_SW_MAJOR_VERSION ID VALUE

< CRC_SW_MINOR_VERSION ID VALUE

< CRC_SW_PATCH_VERSION ID VALUE