Jump to main content

##

# 2.21.2 CRC_CRCCalculate Function

## C

    void CRC_CRCCalculate

## Summary

Function to calculate CRC

## Description

It first configures the CRC engine data Width to 8-bit mode and then the initial seed value passed as argument. The user data from buffer will then be written in CRCDAT register.

This function returns the final CRC value once the computation is done

This function can be called repeatedly for multiple blocks of memory/data by using previously generated CRC value as seed.

## Parameters

Param | Description
--- | ---
buffer | Buffer on which the CRC has to be computed
length | Size of the buffer in bytes.
seed | CRC initial value (seed). It should be in direct form

## Returns

crc - Generated crc value

## Example

    #define BUFFER_SIZE 9

    const uint8_t srcBuffer[BUFFER_SIZE] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};

    CRC_SETUP crcSetup = {0};

    crcSetup.reverse_crc_input = true;
    crcSetup.polynomial_length = 32;
    crcSetup.polynomial = 0x04C11DB7;
    crcSetup.reverse_crc_output = true;
    crcSetup.final_xor_value = 0xFFFFFFFF;

    CRC_CRCSetup(crcSetup);

    // Expected CRC32 with above configurations and Input String - 0xCBF43926

    crc_32 = CRC_CRCCalculate((void *)srcBuffer, BUFFER_SIZE, 0xFFFFFFFF);

## Remarks

None