Jump to main content

# 1.2.5.4.1 SRV_PCRC_GetValue Function

## C

    uint32_t SRV_PCRC_GetValue(
        uint8_t *pData,
        size_t length,
        PCRC_HEADER_TYPE hdrType,
        PCRC_CRC_TYPE crcType,
        uint32_t initValue
    );

## Summary

Obtains the CRC for a data stream.

## Description

This routine gets the CRC value (8, 16 or 32 bits, depending on arguments) of the data stream provided as argument.

## Precondition

None.

## Parameters

Param | Description
--- | ---
pData | Pointer to buffer containing the data stream.
length | Length of the data stream.
hdrType | Header type to determine the method to obtain CRC. It is different for USI and PRIME packets (GENERIC, PROMOTION and BEACON).
crcType | CRC type (8, 16 or 32 bits). Used only in case of header type PCRC_HT_USI.
initValue | Initialization value for CRC computation. Used only in case of header type PCRC_HT_USI.

## Returns

If successful, the routine returns a valid CRC value. If an error occurs, the return value is PCRC_INVALID. Error can occur if hdrType or crcType are wrong. Returned CRC is always a 32-bit value, in case 8-bit or 16-bit CRC is calculated it is casted to 32-bit.

## Example

    uint32_t crc32;

    crc32 = SRV_PCRC_GetValue(pData, length, PCRC_HT_USI, PCRC_CRC32);

## Remarks

None.

Rev: G