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 Insert

CAN Message Utilities: CRC Insert — Computes and Inserts a CRC

Library

Simulink Real-Time - Speedgoat

Description

The CRC Insert block inserts a CRC value of a certain bit width at a certain bit position inside the data payload of a CAN or CAN-FD frame. In the block mask, the user selects the CRC Type to be computed and the location where it should be inserted in the data payload. The block computes the CRC over the entire payload after excluding the bits where the CRC will be inserted. For example, if the user wants to compute an 8-bit wide CRC over the array [1 2 3 4 5 6 7 8] and insert the computed CRC at the first byte, then the block will only perform the calculation over the array [2 3 4 5 6 7 8], assuming that the first byte is pre-allocated to store the CRC value. The first byte is therefore excluded from the calculation.

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 must 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 inserting the CRC into 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 modify the input message and it mirrors it directly to the message output port. If Enable is not 0 the block inserts the CRC value in the message data payload according to the other parameters.

Outputs
Message Port

This output port is always available and its datatype (either CAN_MESSAGE_BUS, CAN_FD_MESSAGE_BUS or a uint8 array with a length inherited from the input) is configured by the Protocol parameter in the block mask. The CAN message, CAN-FD message or uint8 array with the payload modified by CRC insertion is output on this port.

CRC

Select CRC Port in the mask to enable this input port. This port outputs the CRC value that is computed internally. The datatype is inherited from the CRC Type selected in the CRC Type mask parameter, or from the double datatype for custom CRC algorithms.

Parameters

Enable Port

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

CRC Type

Use this parameter 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, where the CRC is inserted in the payload. Bit Location is expressed in 0-based indexing (e.g., if the user wants to insert the CRC in the 2nd byte, this parameter should be configured to the value 8). This location must match the start bit for where the CRC value is pre-allocated in 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 length of the CRC value pre-allocated in 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.