# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# General CRC Syndrome Detector HDL Optimized

Detect errors in input data using CRC, optimized for HDL code generation

## Library

Communications System Toolbox > Error Correction and Detection > CRC (`commcrc2`)

Communications System Toolbox HDL Support > Error Correction and Detection > CRC (`commhdlcrc`)

## Description

This hardware-friendly CRC detector block performs a cyclic redundancy check (CRC) on data and compares the resulting checksum with the appended checksum. If the two checksums do not match, the block reports an error. Instead of processing an entire frame at once, the block accepts and returns a data sample stream with accompanying control signals. The control signals indicate the validity of the samples and the boundaries of the frame. To achieve higher throughput, the block accepts vector data up to the CRC length, and implements a parallel architecture.

### Signal Attributes

PortDirectionDescriptionData Type
`dataIn`InputMessage data plus checksum. Data can be a column vector of binary values, or a scalar integer representing several bits. For example, vector input [0 0 0 1 0 0 1 1] is equivalent to uint8 input 19. The data width must be less than or equal to the CRC length, and the CRC length must be divisible by the data width. For example, for CRC-CCITT/CRC-16, the valid data widths are 16, 8, 4, 2, and 1.

Vector: double, Boolean, or fixdt(0,1,0)

Scalar: unsigned integer (uint8/16/32) or fixdt(0,N,0)

`startIn`InputIndicates the start of a frame of data, including checksum.Boolean or fixdt(0,1,0)
`endIn`InputIndicates the end of a frame of data. Boolean or fixdt(0,1,0)
`validIn`InputIndicates that input data is valid. Boolean or fixdt(0,1,0)
`dataOut`OutputMessage data. The output data has the same width as the input data.Same as `dataIn`
`startOut`OutputIndicates the start of a frame of data. Boolean or fixdt(0,1,0)
`endOut`OutputIndicates the end of a frame of data. Boolean or fixdt(0,1,0)
`validOut`OutputIndicates that output data is valid. Boolean or fixdt(0,1,0)
`err`OutputIndicates the corruption of the received data, when `err` is high(1).Boolean or fixdt(0,1,0)

## Parameters

Polynomial

A double, Boolean, or fixdt(0,1) row or column vector specifying the polynomial, in descending order of powers. The CRC length is length(polynomial) – 1. The default value is `[1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1]`.

Initial state

A double, Boolean, or fixdt(0,1) scalar or vector of length equal to the CRC length, specifying the initial state of the internal shift register. The default value is 0.

Direct method
• When this parameter is selected, the block uses the direct algorithm for CRC checksum calculations.

• When this parameter is not selected, the block uses the nondirect algorithm for CRC checksum calculations.

The parameter is cleared by default.

To learn about the direct and non-direct algorithms, see Cyclic Redundancy Check Codes.

Reflect input

The input data width must be a multiple of 8.

• When this parameter is selected, each input byte is flipped before entering the shift register.

• When this parameter is not selected, the message data is passed to the shift register unchanged.

The parameter is cleared by default.

Reflect CRC checksum

The CRC length must be a multiple of 8.

• When this parameter is selected, each checksum byte is flipped before it is passed to the final XOR stage.

• When this parameter is not selected, the checksum byte is passed to the final XOR stage unchanged.

The parameter is cleared by default.

Final XOR value

The value that the CRC checksum is XORed with before it is appended to the input data. This parameter can be a double, Boolean, or fixdt(0,1) scalar or vector of length equal to the CRC length. The default value is 0.

## Algorithm

When you use vector or integer input, the block implements a parallel CRC algorithm [1].

To provide high throughput for modern communications systems, the CRC algorithm is implemented with a parallel architecture. This architecture recursively calculates M bits of CRC checksum for each W input bits. At the end of the frame, the final checksum result is appended to the message. For a polynomial length of M, the recursive checksum calculation for W bits in parallel is:

`${X}^{\text{'}}={F}_{W}\left(×\right)X\left(+\right)D$`
FW is an M-by-M matrix that selects elements of the current state for the polynomial calculation with the new input bits. D is an M-sample vector that provides the new input bits, ordered in relation to the polynomial and padded with zeroes. (×) is implemented with logical AND, and (+) is implemented with logical XOR.

### Timing Diagram

This waveform shows streaming data and the accompanying control signals for a CRC16 block with 8-bit binary vector input. The input frames are contiguous, and the output frames show space between them because the detector block removes the checksum word.

### Initial Delay

The General CRC Syndrome Detector HDL Optimized block introduces a latency on the output. This latency can be computed with the following equation:

`initialdelay = (3 * CRC length/input data width) + 2`

## HDL Code Generation

This block supports HDL code generation using HDL Coder™. HDL Coder provides additional configuration options that affect HDL implementation and synthesized logic. For more information on implementations, properties, and restrictions for HDL code generation, see General CRC Syndrome Detector HDL Optimized in the HDL Coder documentation.

## References

[1] Campobello, Giuseppe, Giuseppe Patane, and Marco Russo. "Parallel CRC Realization." IEEE Transactions on Computers. Vol. 52, No. 10, October 2003, pp. 1312–1319.