2.6 CRC Driver
Overview
The 16-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 16 Bits.
- Programmable Shift Direction (little or big-endian).
- Supports seeding with Direct and Indirect methods.
- Supports CRC Simulator in UI.
2.6.1 Module Documentation
2.6.1.1 CRC Driver
16-bit Programmable Cyclic Redundancy Check generator using dsPIC MCUs
2.6.1.1.1 Module description
16-bit Programmable Cyclic Redundancy Check generator using dsPIC MCUs
Data structures
struct CRC_INTERFACE
Structure containing the function pointers of CRC driver.
Enumerations
enum CRC_STATE { CRC_STATE_CALCULATE, CRC_STATE_FLUSH, CRC_STATE_CLEANUP, CRC_STATE_DONE }
Defines the CRC calculation states.
enum CRC_SEED_METHOD { CRC_SEED_METHOD_DIRECT, CRC_SEED_METHOD_INDIRECT }
Defines the CRC calculation seed method CRC_SeedSet.
enum CRC_SEED_DIRECTION { CRC_SEED_DIRECTION_Msb, CRC_SEED_DIRECTION_Lsb }
Defines the CRC calculation seed direction in direct method CRC_SeedSet.
Functions
void CRC_Initialize (void)
Initializes the CRC module.
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.
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.
2.6.1.1.2 Function Documentation
CRC_CalculateBufferStart()
void CRC_CalculateBufferStart (void * buffer, uint32_t sizeBytes)
CRC module calculation on a buffer in data space.
The CRC module needs to be initialized with the desired settings |
in | buffer |
- Address of the desired data in data space |
in | sizeBytes |
- Size of the buffer |
none |
CRC_CalculateProgramStart()
void CRC_CalculateProgramStart (uint32_t startAddr, uint32_t sizeBytes)
Starts the CRC calculation on a buffer in program space.
The CRC module needs to be initialized with the desired settings. |
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 |
none |
CRC_CalculationIsDone()
bool CRC_CalculationIsDone (void )
Returns the CRC calculation complete status
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. |
none |
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.
The CRC module needs to be initialized with the desired settings. CRC_CalculationIsDone must be called for the associated function to work. |
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 the CRC result for the module |
CRC_CalculationResultRawGet()
uint32_t CRC_CalculationResultRawGet (void )
Gets the CRC raw result if the calculation is done.
The CRC module needs to be initialized with the desired settings. CRC_CalculationIsDone must be called for the associated function to work. |
none |
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.
The CRC module needs to be initialized with the desired settings. CRC_CalculationIsDone must be called for the associated function to work. |
none |
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.
The CRC module needs to be initialized with the desired settings. CRC_CalculationIsDone must be called for the associated function to work. |
in | xorValue |
- A value that will be XOR'd with the CRC result after reversed if desired |
Returns the CRC result for the module |
CRC_Deinitialize()
void CRC_Deinitialize (void )
Deinitializes CRC to POR values.
none |
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.none |
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.
in | handler |
- Address of the callback function |
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.
none |
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.
The CRC module needs to be initialized with the desired settings. Please refer to the CRC initialization functions |
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 |
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.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. |
none |
none |
2.6.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 |
2.6.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.
2.6.2 Class Documentation
2.6.2.1 CRC_INTERFACE Struct Reference
Structure containing the function pointers of CRC driver.
2.6.2.1.1 Detailed Description
Structure containing the function pointers of CRC driver.
#include <crc_interface.h>
Public Attributes
void(* Initialize )(void)
Pointer to CRC_Initialize.
void(* Deinitialize )(void)
Pointer to CRC_Deinitialize.
void(* SeedSet )(uint32_t seed, enum CRC_SEED_METHOD seedMethod, enum CRC_SEED_DIRECTION seedDirection)
Pointer to CRC_SeedSet.
void(* CalculateBufferStart )(void *buffer, uint32_t sizeBytes)
Pointer to CRC_CalculateBufferStart.
void(* CalculateProgramStart )(uint32_t startAddr, uint32_t sizeBytes)
Pointer to CRC_CalculateProgramStart.
bool(* CalculationIsDone )(void)
Pointer to CRC_CalculationIsDone.
uint32_t(* CalculationResultGet )(bool reverse, uint32_t xorValue)
Pointer to CRC_CalculationResultGet.
uint32_t(* CalculationResultRawGet )(void)
Pointer to CRC_CalculationResultRawGet.
uint32_t(* CalculationResultReverseGet )(void)
Pointer to CRC_CalculationResultReverseGet
uint32_t(* CalculationResultXORGet )(uint32_t xorValue)
Pointer to CRC_CalculationResultXORGet.
void(* EventCallbackRegister )(void(*CallbackHandler)(void))
Pointer to CRC_EventCallbackRegister.
void(* Tasks )(void)
Pointer to CRC_Tasks (Supported only in polling mode)
2.6.2.1.2 Member Data Documentation
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.
CalculationIsDone
bool(* CalculationIsDone) (void)
Pointer to CRC_CalculationIsDone.
CalculationResultGet
uint32_t(* CalculationResultGet) (bool reverse, uint32_t xorValue)
Pointer to CRC_CalculationResultGet.
CalculationResultRawGet
uint32_t(* CalculationResultRawGet) (void)
Pointer to CRC_CalculationResultRawGet.
CalculationResultReverseGet
uint32_t(* CalculationResultReverseGet) (void)
Pointer to CRC_CalculationResultReverseGet
CalculationResultXORGet
uint32_t(* CalculationResultXORGet) (uint32_t xorValue)
Pointer to CRC_CalculationResultXORGet.
Deinitialize
void(* Deinitialize) (void)
Pointer to CRC_Deinitialize.
EventCallbackRegister
void(* EventCallbackRegister) (void(*CallbackHandler)(void))
Pointer to CRC_EventCallbackRegister.
Initialize
void(* Initialize) (void)
Pointer to CRC_Initialize.
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)
2.6.3 File Documentation
2.6.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"
2.6.3.1.1 Functions
void CRC_Initialize (void)
Initializes the CRC module.
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.
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.
2.6.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.
2.6.3.1.3 Detailed Description
This is the generated driver header file for the CRC driver.
CRC Generated Driver Header File
2.6.3.2 source/crc_interface.h File Reference
#include <stdbool.h> #include "crc_types.h"
2.6.3.2.1 Data structures
struct CRC_INTERFACE
Structure containing the function pointers of CRC driver.
2.6.3.2.2 Detailed Description
CRC Generated Driver Interface Header File
2.6.3.3 source/crc_types.h File Reference
This is the generated driver types header file for the CRC driver.
2.6.3.3.1 Enumerations
enum CRC_STATE { CRC_STATE_CALCULATE, CRC_STATE_FLUSH, CRC_STATE_CLEANUP, CRC_STATE_DONE }
Defines the CRC calculation states.
enum CRC_SEED_METHOD { CRC_SEED_METHOD_DIRECT, CRC_SEED_METHOD_INDIRECT }
Defines the CRC calculation seed method CRC_SeedSet.
enum CRC_SEED_DIRECTION { CRC_SEED_DIRECTION_Msb, CRC_SEED_DIRECTION_Lsb }
Defines the CRC calculation seed direction in direct method CRC_SeedSet.
2.6.3.3.2 Detailed Description
This is the generated driver types header file for the CRC driver.
CRC Generated Driver Types Header File