mcBuildChecksum

ECU Measurement and Calibration Toolkit Help

Edition Date: October 2018

Part Number: 371602T-01

»View Product Info
Download Help (Windows Only)

Purpose

Calculates a checksum over a defined memory range within the ECU.

Format

mcTypeStatus mcBuildChecksum(
mcTypeTaskRef ECURefNum,
mcAddress Address,
u32 BlockSize,
u8 *ChecksumType,
u8 *SizeOfChecksum,
u32 *Checksum);

Input

ECURefNum

ECURefNum is the task reference which links to the selected ECU. This reference is originally returned from mcECUSelectEx.

Address

Configures the target address for the checksum operation in the ECU. mcAddress is a C struct consisting of:

Address

Specifies the address part of the target address.

Extension

Extension contains the extension part of the target address.

BlockSize

BlockSize determines the size of the block on which the checksum has to be calculated.

Output

ChecksumType

ChecksumType returns the type of the calculated checksum. For CCP, ChecksumType is 0xFF. For XCP, refer to the Description section.

SizeofChecksum

SizeofChecksum returns the size in bytes of the calculated checksum.

Checksum

Checksum is the calculated checksum.

Return Value

The return value indicates the status of the function call as a signed 32-bit integer. Zero means the function executed successfully. A negative value specifies an error, which means the function did not perform the expected behavior. A positive value specifies a warning, which means the function performed as expected, but a condition arose that may require attention.

Use the mcStatusToString function of the ECU M&C API to obtain a descriptive string for the return value.

Description

mcBuildChecksum is used to calculate the checksum of a specified memory block inside the ECU starting at the selected Address.

If you are using the CCP protocol, mcBuildChecksum implements the CCP BUILD_CHKSUM command. The checksum algorithm is not specified by CCP and the checksum algorithm may be different on different devices.

If you are using the XCP protocol, mcBuildChecksum implements the BUILD_CHECKSUM command of the XCP specification. The result of the checksum calculation is returned in Checksum regardless of the checksum type. The following values for ChecksumType are defined in the XCP specification:

TypeNameDescription
0x01XCP_ADD_11Add BYTE into a BYTE checksum, ignore overflows
0x02XCP_ADD_12Add BYTE into a WORD checksum, ignore overflows
0x03XCP_ADD_14Add BYTE into a DWORD checksum, ignore overflows
0x04XCP_ADD_22Add WORD into a WORD checksum, ignore overflows, blocksize must be modulo 2
0x05XCP_ADD_24Add WORD into a DWORD checksum, ignore overflows, blocksize must be modulo 2
0x06XCP_ADD_44Add DWORD into DWORD, ignore overflows, blocksize must be modulo 4
0x07XCP_CRC_16Refer to CRC error detection algorithms
0x08XCP_CRC_16_CITTRefer to CRC error detection algorithms
0x09XCP_CRC_32Refer to CRC error detection algorithms
0xFFXCP_USER_DEFINEDUser defined algorithm, in externally calculated function

With ChecksumType XCP_USER_DEFINED, the Slave may indicate that the Master which calculates the checksum must use a user-defined algorithm implemented in an externally calculated function (for instance, Win32 DLL, UNIX shared object file, etc.). The master retrieves the name of the external function file to be used for this slave from the ASAM MCD 2MC description file.

The CRC algorithms are specified by the following parameters:

NameWidthPolyInitRefinRefoutXORout
XCP_CRC_16160x80050x0000TRUETRUE0x0000
XCP_CRC16_CITT160x10210xFFFFFALSEFALSE0x0000
XCP_CRC_32 32320x04C11DB70xFFFFFFFFTRUETRUE0xFFFFFFFF

Name

The name of the algorithm. A string value starting with "XCP_".

Width

The width of the algorithm expressed in bits. This is one less than the width of the Poly.

Poly

The polynomial. This is a binary value specified as a hexadecimal number. The top bit of the Poly should be omitted. For example, if the Poly is 0x10110, you should specify 0x06. An important aspect of this parameter is that it represents the unreflected polynomial. The bottom of this parameter is always the least significant bit (LSB) of the divisor during the division, regardless of whether the algorithm is reflected.

Init

This parameter specifies the initial value of the register when the algorithm starts. This is the value to be assigned to the register in the direct table algorithm. In the table algorithm, we may think of the register always commencing with the value zero, and this value being XORed into the register after the nth bit iteration. This parameter should be specified as a hexadecimal number.

Refin

A Boolean parameter. If it is FALSE, input bytes are processed with bit 7 being treated as the most significant bit (MSB) and bit 0 being treated as the least significant bit. If this parameter is TRUE, each byte is reflected before being processed.

Refout

A Boolean parameter. If it is set to FALSE, the final value in the register is fed into the XORout stage directly. If this parameter is TRUE, the final register value is reflected first.

XORout

This is a width-bit value that should be specified as hexadecimal number. It is XORed to the final register value (after the Refout stage) before the value is returned as the official checksum.

For more detailed information about CRC algorithms, refer to:

http://www.repairfaq.org/filipg/LINK/F_crc_v34.html

WAS THIS ARTICLE HELPFUL?

Not Helpful