Documentation search search close
CONTENTS
https://www.speedgoat.com/help/slrt/page/icon_documentation.jpg
v10.0.1.x for R2026a
View other versions

CAN Message Utilities: CRC Validation

CAN Message Utilities: CRC Validation — Extracts a CRC value from a CAN or CAN-FD data payload and validates it against a reference CRC value

Library

Simulink Real-Time - Speedgoat

Description

The CRC Validation block extracts a CRC value of a certain bit width from a certain bit position from the data payload of a CAN or CAN-FD frame and compares it against a computed CRC. The computed CRC is computed by the block itself. In the block mask, the user selects the CRC Type to be computed and the block computes the CRC over the entire payload after having removed the bits holding the embedded CRC value. For example, if the user wants to validate an 8-bit wide CRC inserted at the first byte in the data payload [123 2 3 4 5 6 7 8], the block will extract the '123' value and store it internally as an extracted CRC. It will then calculate the computed CRC value over the [2 3 4 5 6 7 8] array. Subsequently, it compares the two CRC values and output the result of the comparison on the CRC Valid output port.

The CRC value is computed internally by the block using any of the CRC algorithms provided, or a custom CRC algorithm. For the CRCs provided, the CRC is calculated using a lookup table to optimize real-time performance. When using a custom CRC algorithm, please refer to the usage notes for more detailed information.

The following CRC algorithms are currently available:

  • CRC8-SAEJ1850

  • CRC8-0x2F

  • CRC8-0x07

  • CRC16-CCITT-FALSE

  • CRC16-ARC

  • CRC32-Ethernet

  • CRC32-0xF4ACFB13

The block inherits the sample time from the CAN or CAN-FD message line connected to its input.

The user needs to pay particular attention to the configuration of the CRC width and the CRC location to ensure that no overflow or truncation occur when computing and extracting the CRC from the data payload.

Ports

Which input and output ports are available depends on the settings configuration in the block mask

Input
Message Port

This input port is always available and its datatype (either CAN_MESSAGE_BUS, CAN_FD_MESSAGE_BUS or a uint8 array with a maximum length of 256 bytes) is configured by the Protocol parameter in the block mask.

Enable

Select Enable Port in the mask to enable this input port. The datatype is double. When the Enable input signal is 0, the block does not perform any action and all the output ports are set to 0.

Outputs
Computed CRC

Select Computed CRC port in the mask to enable this input port. The datatype is inherited from the CRC Type selected in the CRC Type mask parameter, or is a double datatype for custom CRC algorithms.

Extracted CRC

Select Extracted CRC port in the mask to enable this input port. The block puts the value of the extracted CRC on the port. The datatype is inherited from the CRC Type selected in the CRC Type mask parameter, or is a double datatype for custom CRC algorithms.

CRC Valid

Select CRC Valid Port in the mask to enable this input port. This port provides the result of the comparison of the computed CRC and the extracted CRC.

Parameters

Enable Port

Adds an "Enable" input port to enable/disable the CRC Validation block at runtime.

Computed CRC Port

Adds a "Computed CRC" output port to allow the computed CRC value to be used in the model.

Extracted CRC Port

Adds an "Extracted CRC" output port providing the Extracted CRC value.

CRC Valid Port

Adds a "CRC Valid" port providing the result of the comparison of computed CRC against extracted CRC.

CRC Type

Use this to select one of the following CRC computation methods: CRC8-SAEJ1850, CRC8-0x2F, CRC8-0x07, CRC16-CCITT-FALSE, CRC16-ARC, CRC32-Ethernet, CRC32-0xF4ACFB13, Custom.

Bit Location

The location, expressed in bits, from where the CRC is extracted from the payload. Bit Location is expressed in 0-based indexing (e.g., if the user wants to extract the CRC from the 2nd byte, this parameter should be configured to the value 8). This location must match the start bit for the CRC value extracted from the payload sent through the Message Port input.

Custom CRC Bit Width

Available when the CRC Type option is set to Custom. This parameter is the width (expressed in bits) of the CRC value generated by the custom CRC algorithm. The width must match the bit length of the CRC value extracted from the payload sent through the Message Port input.

Custom CRC Function File

Available when the CRC Type option is set to Custom. This parameter is the .c or .cpp source file in which the custom CRC algorithm is defined. The file is specified by name and must be located on the MATLAB path. A single file can define multiple CRC algorithms.

Custom CRC Function Name

Available when the CRC Type option is set to Custom. This parameter is the name of the function that defines the custom CRC algorithm to be applied.

Protocol

This parameter determines the datatype of the block's input port.