3.5 CRC Driver

Overview

The 32-bit programmable Cyclic Redundancy Check (CRC) generator provides a hardware implemented method of quickly generating checksums for various networking and security applications.

Features

  • User-Programmable CRC Polynomial Equation, up to 32 Bits.
  • Programmable Shift Direction (little or big-endian).
  • Supports seeding with Direct and Indirect methods.
  • Supports CRC Simulator in UI.

3.5.1 Module Documentation

3.5.1.1 CRC Driver

32-bit Programmable Cyclic Redundancy Check generator using dsPIC MCUs

3.5.1.1.1 Module description

32-bit Programmable Cyclic Redundancy Check generator using dsPIC MCUs

Data structures
  • struct CRC_INTERFACE

    Structure containing the function pointers of CRC driver.

Enumerations
Functions
  • void CRC_Initialize (void)

    Initializes the CRC module. This function sets the polynomial and data width; data and seed shift; updates the polynomial and shifts the seed value. After the function is called, the CRC module is ready to calculate the CRC of a data buffer.

  • void CRC_Deinitialize (void)

    Deinitializes CRC to POR values.

  • void CRC_SeedSet (uint32_t seed, enum CRC_SEED_METHOD seedMethod, enum CRC_SEED_DIRECTION seedDirection)

    Sets the CRC seed with method and direction.

  • void CRC_CalculateBufferStart (void *buffer, uint32_t sizeBytes)

    CRC module calculation on a buffer in data space.

  • void CRC_CalculateProgramStart (uint32_t startAddr, uint32_t sizeBytes)

    Starts the CRC calculation on a buffer in program space.

  • void CRC_EventCallbackRegister (void(*handler)(void))

    This function can be used to override default callback and to define custom callback for CRC Event event.

  • void CRC_EventCallback (void)

    This is the default callback with weak attribute. The user can override and implement the default callback without weak attribute or can register a custom callback function using  

    CRC_EventCallbackRegister.

  • void CRC_Tasks (void)

    This function cycles through the CRC calculations.  

    This function will load the CRC module FIFO with the buffer data.

  • bool CRC_CalculationIsDone (void)

    Returns the CRC calculation complete status  

  • uint32_t CRC_CalculationResultGet (bool reverse, uint32_t xorValue)

    Gets the CRC result if the calculation is done.

  • uint32_t CRC_CalculationResultRawGet (void)

    Gets the CRC raw result if the calculation is done.

  • uint32_t CRC_CalculationResultReverseGet (void)

    Gets the CRC reversed value of result if the calculation is done.

  • uint32_t CRC_CalculationResultXORGet (uint32_t xorValue)

    Gets the CRC XOR'd value of the result if the calculation is done.

Variables
  • const struct CRC_INTERFACE CRC

    Structure object of type CRC_INTERFACE with the custom name given by the user in the Melody Driver User interface. The default name e.g. CRC can be changed by the user in the CRC user interface. This allows defining a structure with application specific name using the 'Custom Name' field. Application specific name allows the API Portability.

3.5.1.1.2 Function Documentation

CRC_CalculateBufferStart()

void CRC_CalculateBufferStart (void * buffer, uint32_t sizeBytes)

CRC module calculation on a buffer in data space.

Precondition:

The CRC module needs to be initialized with the desired settings

Parameters:
in buffer

- Address of the desired data in data space

in sizeBytes

- Size of the buffer  

Returns:

none  

CRC_CalculateProgramStart()

void CRC_CalculateProgramStart (uint32_t startAddr, uint32_t sizeBytes)

Starts the CRC calculation on a buffer in program space.

Precondition:

The CRC module needs to be initialized with the desired settings.

Parameters:
in startAddr

- Starting address of the program space, Each program instruction is 3 bytes, the caller should account for that in the size.

in sizeBytes

- Size of the buffer in multiple of 3  

Returns:

none  

CRC_CalculationIsDone()

bool CRC_CalculationIsDone (void )

Returns the CRC calculation complete status  

Precondition:

The CRC module needs to be initialized with the desired settings. CRC_CalculateBufferStart or CRC_CalculateProgramStart must be called for the associated function to work.

Parameters:
none
Returns:

true - the CRC calculation is complete and result is available in CRC_CalculationResultRawGet

false - the CRC calculation in progress

CRC_CalculationResultGet()

uint32_t CRC_CalculationResultGet (bool reverse, uint32_t xorValue)

Gets the CRC result if the calculation is done.

Precondition:

The CRC module needs to be initialized with the desired settings. CRC_CalculationIsDone must be called for the associated function to work.

Parameters:
in reverse

- Reverses the CRC calculated value if true

in xorValue

- Set the value that will be XOR'd with the CRC result after reversed if desired

Returns:

Returns the CRC result for the module

CRC_CalculationResultRawGet()

uint32_t CRC_CalculationResultRawGet (void )

Gets the CRC raw result if the calculation is done.

Precondition:

The CRC module needs to be initialized with the desired settings.  

CRC_CalculationIsDone must be called for the associated function to work.

Parameters:
none
Returns:

Returns the CRC result for the module  

CRC_CalculationResultReverseGet()

uint32_t CRC_CalculationResultReverseGet (void )

Gets the CRC reversed value of result if the calculation is done.

Precondition:

The CRC module needs to be initialized with the desired settings.  

CRC_CalculationIsDone must be called for the associated function to work.

Parameters:
none
Returns:

Returns the CRC result for the module  

CRC_CalculationResultXORGet()

uint32_t CRC_CalculationResultXORGet (uint32_t xorValue)

Gets the CRC XOR'd value of the result if the calculation is done.

Precondition:

The CRC module needs to be initialized with the desired settings.  

CRC_CalculationIsDone must be called for the associated function to work.

Parameters:
in xorValue

- A value that will be XOR'd with the CRC result after reversed if desired

Returns:

Returns the CRC result for the module  

CRC_Deinitialize()

void CRC_Deinitialize (void )

Deinitializes CRC to POR values.

Parameters:
none
Returns:

none

CRC_EventCallback()

void CRC_EventCallback (void )

This is the default callback with weak attribute. The user can override and implement the default callback without weak attribute or can register a custom callback function using  

CRC_EventCallbackRegister.

Parameters:
none
Returns:

none

CRC_EventCallbackRegister()

void CRC_EventCallbackRegister (void(*)(void) handler)

This function can be used to override default callback and to define custom callback for CRC Event event.

Parameters:
in handler

- Address of the callback function

Returns:

none  

CRC_Initialize()

void CRC_Initialize (void )

Initializes the CRC module. This function sets the polynomial and data width; data and seed shift; updates the polynomial and shifts the seed value. After the function is called, the CRC module is ready to calculate the CRC of a data buffer.

Parameters:
none
Returns:

none

CRC_SeedSet()

void CRC_SeedSet (uint32_t seed, enum CRC_SEED_METHOD seedMethod, enum CRC_SEED_DIRECTION seedDirection)

Sets the CRC seed with method and direction.

Precondition:

The CRC module needs to be initialized with the desired settings. Please refer to the CRC initialization functions

Parameters:
in seed

- Set the seed value of the CRC calculation

in seedmethod

- Set the seed method, direct or indirect

in seeddirection

- Set the seed MSB or LSB direction, ignored if the seed method is indirect

Returns:

none  

CRC_Tasks()

void CRC_Tasks (void )

This function cycles through the CRC calculations.  

This function will load the CRC module FIFO with the buffer data.

Precondition:

The CRC module needs to be initialized with the desired settings.  

Please refer to the CRC initialization functions. The caller needs to call the function to start the calculation.

Parameters:
none
Returns:

none

3.5.1.1.3 Enumeration Type Documentation

CRC_SEED_DIRECTION

enum CRC_SEED_DIRECTION

Defines the CRC calculation seed direction in direct method CRC_SeedSet.

CRC_SEED_DIRECTION_Msb

CRC seed in Big Endian

CRC_SEED_DIRECTION_Lsb

CRC seed in Little Endian

CRC_SEED_METHOD

enum CRC_SEED_METHOD

Defines the CRC calculation seed method CRC_SeedSet. The direct method refers to the seed being placed before the shifters with the result being shifted through the polynomial. The indirect method refers to the seed being placed after the shifters with the result not being shifted through the polynomial.

CRC_SEED_METHOD_DIRECT

CRC seed in direct method

CRC_SEED_METHOD_INDIRECT

CRC seed in indirect method

CRC_STATE

enum CRC_STATE

Defines the CRC calculation states.

CRC_STATE_CALCULATE

CRC calculation start

CRC_STATE_FLUSH

CRC calculation data flush

CRC_STATE_CLEANUP

CRC calculation reset

CRC_STATE_DONE

CRC calculation complete

3.5.1.1.4 Variable Documentation

CRC

const struct CRC_INTERFACE CRC

Structure object of type CRC_INTERFACE with the custom name given by the user in the Melody Driver User interface. The default name e.g. CRC can be changed by the user in the CRC user interface. This allows defining a structure with application specific name using the 'Custom Name' field. Application specific name allows the API Portability.

3.5.2 Data Structure Documentation

3.5.2.1 CRC_INTERFACE Struct Reference

Structure containing the function pointers of CRC driver.

3.5.2.1.1 Detailed Description

Structure containing the function pointers of CRC driver.

#include <crc_interface.h>

Data Fields

3.5.2.1.2 Field Documentation

The documentation for this struct was generated from the following file:

source/

crc_interface.h

CalculateBufferStart

void(* CalculateBufferStart) (void *buffer, uint32_t sizeBytes)

Pointer to CRC_CalculateBufferStart.

CalculateProgramStart

void(* CalculateProgramStart) (uint32_t startAddr, uint32_t sizeBytes)

Pointer to CRC_CalculateProgramStart.

CalculationResultGet

uint32_t(* CalculationResultGet) (bool reverse, uint32_t xorValue)

Pointer to CRC_CalculationResultGet.

SeedSet

void(* SeedSet) (uint32_t seed, enum CRC_SEED_METHOD seedMethod, enum CRC_SEED_DIRECTION seedDirection)

Pointer to CRC_SeedSet.

Tasks

void(* Tasks) (void)

Pointer to CRC_Tasks (Supported only in polling mode)

3.5.3 File Documentation

3.5.3.1 source/crc.h File Reference

This is the generated driver header file for the CRC driver.

#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
#include "crc_types.h"
#include "crc_interface.h"

3.5.3.1.1 Functions

  • void CRC_Initialize (void)

    Initializes the CRC module. This function sets the polynomial and data width; data and seed shift; updates the polynomial and shifts the seed value. After the function is called, the CRC module is ready to calculate the CRC of a data buffer.

  • void CRC_Deinitialize (void)

    Deinitializes CRC to POR values.

  • void CRC_SeedSet (uint32_t seed, enum CRC_SEED_METHOD seedMethod, enum CRC_SEED_DIRECTION seedDirection)

    Sets the CRC seed with method and direction.

  • void CRC_CalculateBufferStart (void *buffer, uint32_t sizeBytes)

    CRC module calculation on a buffer in data space.

  • void CRC_CalculateProgramStart (uint32_t startAddr, uint32_t sizeBytes)

    Starts the CRC calculation on a buffer in program space.

  • void CRC_EventCallbackRegister (void(*handler)(void))

    This function can be used to override default callback and to define custom callback for CRC Event event.

  • void CRC_EventCallback (void)

    This is the default callback with weak attribute. The user can override and implement the default callback without weak attribute or can register a custom callback function using  

    CRC_EventCallbackRegister.

  • void CRC_Tasks (void)

    This function cycles through the CRC calculations.  

    This function will load the CRC module FIFO with the buffer data.

  • bool CRC_CalculationIsDone (void)

    Returns the CRC calculation complete status  

  • uint32_t CRC_CalculationResultGet (bool reverse, uint32_t xorValue)

    Gets the CRC result if the calculation is done.

  • uint32_t CRC_CalculationResultRawGet (void)

    Gets the CRC raw result if the calculation is done.

  • uint32_t CRC_CalculationResultReverseGet (void)

    Gets the CRC reversed value of result if the calculation is done.

  • uint32_t CRC_CalculationResultXORGet (uint32_t xorValue)

    Gets the CRC XOR'd value of the result if the calculation is done.

3.5.3.1.2 Variables

  • const struct CRC_INTERFACE CRC

    Structure object of type CRC_INTERFACE with the custom name given by the user in the Melody Driver User interface. The default name e.g. CRC can be changed by the user in the CRC user interface. This allows defining a structure with application specific name using the 'Custom Name' field. Application specific name allows the API Portability.

3.5.3.1.3 Detailed Description

This is the generated driver header file for the CRC driver.

CRC Generated Driver Header File

3.5.3.2 source/crc_interface.h File Reference

#include <stdbool.h>
#include "crc_types.h"

3.5.3.2.1 Data structures

  • struct CRC_INTERFACE

    Structure containing the function pointers of CRC driver.

3.5.3.2.2 Detailed Description

CRC Generated Driver Interface Header File

3.5.3.3 source/crc_types.h File Reference

This is the generated driver types header file for the CRC driver.

3.5.3.3.1 Enumerations

3.5.3.3.2 Detailed Description

This is the generated driver types header file for the CRC driver.

CRC Generated Driver Types Header File