3.8 CRC - Cyclic Redundancy Check

3.8.1 Introduction

The MPLAB® Code Configurator (MCC) Melody Cyclic Redundancy Check Peripheral Library (PLIBs) drivers generates APIs to support CRC-specific peripheral functionality on target MCUs.

The Cyclic Redundancy Check (CRC) module is coupled with a memory scanner that provides a means of performing CRC calculations in hardware, without CPU intervention. The memory scanner can automatically provide data from program Flash memory to the CRC module. The CRC module can also be operated by directly writing data to SFRs, without using a scanner.

3.8.2 Supported Device Families

PIC12/16F161xPIC16F171xxPIC16F181xx
PIC16F188xxPIC18F-K42PIC18F-K83
PIC18F-Q10PIC18F-Q20PIC18F-Q24
PIC18F-Q40PIC18F-Q41PIC18F-Q43
PIC18F-Q71PIC18F-Q83PIC18F-Q84

3.8.3 Required Header Files:


#include "mcc_generated_files/crc/crc.h"

3.8.4 Module Documentation

3.8.4.1 CRC

This file contains the API prototypes for the CRC driver.

3.8.4.1.1 Module description

This file contains the API prototypes for the CRC driver.

Version: CRC Driver Version 1.0.1
Functions
  • void CRC_Initialize (void)

    Initializes the CRC module. This is called only once before calling other CRC APIs.

  • void CRC_StartCrc (void)

    Starts the CRC serial shifter.

  • bool CRC_WriteData (uint32_t data)

    Writes the data into the CRC Data registers.

  • uint32_t CRC_GetCalculatedResult (bool reverse, uint32_t xorValue)

    Returns the calculated CRC output value.

  • bool CRC_IsCrcBusy (void)

    Returns the status of the CRCBUSY bit value to check if the shifting is in progress or not.

  • void CRC_StartScanner (void)

    Starts the scanning process.

  • void CRC_StopScanner (void)

    Stops the scanning process.

  • void CRC_SetScannerAddressLimit (uint24_t startAddr, uint24_t endAddr)

    Sets the memory address limit for the scanner.

  • bool CRC_IsScannerBusy (void)

    Checks if the scanner cycle is in progress or not.

  • bool CRC_IsBufferEmpty (void)

    Returns the status of the software buffer.

  • bool CRC_WriteBuffer (uint32_t data)

    Writes data into the software buffer when the CRC interrupt is enabled.

  • void CRC_SetCrcInterruptHandler (void(*InterruptHandler)(void))

    Sets the callback function for the CRC interrupt events.

  • void CRC_SetScannerInterruptHandler (void(*InterruptHandler)(void))

    Sets the callback function for the interrupt event.

3.8.4.1.2 Function Documentation

CRC_GetCalculatedResult()

uint32_t CRC_GetCalculatedResult (bool reverse, uint32_t xorValue)

Returns the calculated CRC output value.

Parameters:
reverse

- Determines if the normal (0) or reverse (1) value of the CRC output will be calculated.

xorValue

- Value which is XOR-ed with CRC result.

Returns:

CRC calculated result.

CRC_Initialize()

void CRC_Initialize (void )

Initializes the CRC module. This is called only once before calling other CRC APIs.

Parameters:
None.
Returns:

None.

CRC_IsBufferEmpty()

bool CRC_IsBufferEmpty (void )

Returns the status of the software buffer.

Parameters:
None.
Return values:
True

- Software buffer is empty.

False

- Software buffer is not empty.

CRC_IsCrcBusy()

bool CRC_IsCrcBusy (void )[inline]

Returns the status of the CRCBUSY bit value to check if the shifting is in progress or not.

Parameters:
None.
Return values:
True

- CRC bit shifting is in progress or pending.

False

- CRC bit shifting is complete or not pending.

CRC_IsScannerBusy()

bool CRC_IsScannerBusy (void )[inline]

Checks if the scanner cycle is in progress or not.

Parameters:
None.
Return values:
True

- Scanner cycle is in progress.

False

- Scanner cycle is complete (or not yet started).

CRC_SetCrcInterruptHandler()

void CRC_SetCrcInterruptHandler (void(*)(void) InterruptHandler)

Sets the callback function for the CRC interrupt events.

Parameters:
*InterruptHandler

- Callback function for the interrupt event.

Returns:

None.

CRC_SetScannerAddressLimit()

void CRC_SetScannerAddressLimit (uint24_t startAddr, uint24_t endAddr)

Sets the memory address limit for the scanner.

Parameters:
startAddr

- Start address of the memory block.

endAddr

- End address of the memory block.

Returns:

None.

CRC_SetScannerInterruptHandler()

void CRC_SetScannerInterruptHandler (void(*)(void) InterruptHandler)

Sets the callback function for the interrupt event.

Parameters:
*InterruptHandler

- Callback function for the scanner interrupt events.

Returns:

None.

CRC_StartCrc()

void CRC_StartCrc (void )[inline]

Starts the CRC serial shifter.

Parameters:
None.
Returns:

None.

CRC_StartScanner()

void CRC_StartScanner (void )[inline]

Starts the scanning process.

Parameters:
None.
Returns:

None.

CRC_StopScanner()

void CRC_StopScanner (void )[inline]

Stops the scanning process.

Parameters:
None.
Returns:

None.

CRC_WriteBuffer()

bool CRC_WriteBuffer (uint32_t data)

Writes data into the software buffer when the CRC interrupt is enabled.

Parameters:
data

- CRC input data.

Return values:
True

- Write operation is successful.

False

- Write operation is unsuccessful.

CRC_WriteData()

bool CRC_WriteData (uint32_t data)

Writes the data into the CRC Data registers.

Parameters:
data

- CRC input data.

Return values:
True

- Data write was successful.

False

- Data write was not successful.

3.8.5 File Documentation

3.8.5.1 source/crc.c File Reference

This file contains the API implementation for the CRC driver.

#include <xc.h>
#include "../crc.h"

3.8.5.1.1 Functions

3.8.5.1.4 Detailed Description

This file contains the API implementation for the CRC driver.

CRC Generated Driver File.

Version: CRC Driver Version 1.0.1

3.8.5.1.5 Function Documentation

__interrupt()[1/2]

void __interrupt (irq(CRC) , base(8) )

__interrupt()[2/2]

void __interrupt (irq(SCAN) , base(8) )

CRC_DefaultCrcInterruptHandler()

static void CRC_DefaultCrcInterruptHandler (void )[static]

CRC_DefaultScannerInterruptHandler()

static void CRC_DefaultScannerInterruptHandler (void )[static]

CRC_ReverseValue()

static uint32_t CRC_ReverseValue (uint32_t crc)[static]

3.8.5.1.6 Macro Definition Documentation

CRC_BUFFER_SIZE

#define CRC_BUFFER_SIZE 8

Section: Included Files

3.8.5.1.7 Variable Documentation

CRC_CrcInterruptHandler

void(* CRC_CrcInterruptHandler) (void)[static]

CRC_ScannerInterruptHandler

void(* CRC_ScannerInterruptHandler) (void)[static]

crcBufferHead

volatile uint8_t crcBufferHead = 0[static]

crcBufferRemaining

volatile uint8_t crcBufferRemaining

crcBufferTail

volatile uint8_t crcBufferTail = 0[static]

3.8.5.2 source/crc.h File Reference

#include <stdint.h>
#include <stdbool.h>

3.8.5.2.1 Functions

  • void CRC_Initialize (void)

    Initializes the CRC module. This is called only once before calling other CRC APIs.

  • void CRC_StartCrc (void)

    Starts the CRC serial shifter.

  • bool CRC_WriteData (uint32_t data)

    Writes the data into the CRC Data registers.

  • uint32_t CRC_GetCalculatedResult (bool reverse, uint32_t xorValue)

    Returns the calculated CRC output value.

  • bool CRC_IsCrcBusy (void)

    Returns the status of the CRCBUSY bit value to check if the shifting is in progress or not.

  • void CRC_StartScanner (void)

    Starts the scanning process.

  • void CRC_StopScanner (void)

    Stops the scanning process.

  • void CRC_SetScannerAddressLimit (uint24_t startAddr, uint24_t endAddr)

    Sets the memory address limit for the scanner.

  • bool CRC_IsScannerBusy (void)

    Checks if the scanner cycle is in progress or not.

  • bool CRC_IsBufferEmpty (void)

    Returns the status of the software buffer.

  • bool CRC_WriteBuffer (uint32_t data)

    Writes data into the software buffer when the CRC interrupt is enabled.

  • void CRC_SetCrcInterruptHandler (void(*InterruptHandler)(void))

    Sets the callback function for the CRC interrupt events.

  • void CRC_SetScannerInterruptHandler (void(*InterruptHandler)(void))

    Sets the callback function for the interrupt event.

3.8.5.2.2 Detailed Description

CRC Generated Driver File.