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/16F161x | PIC16F171xx | PIC16F181xx |
PIC16F188xx | PIC18F-K42 | PIC18F-K83 |
PIC18F-Q10 | PIC18F-Q20 | PIC18F-Q24 |
PIC18F-Q40 | PIC18F-Q41 | PIC18F-Q43 |
PIC18F-Q71 | PIC18F-Q83 | PIC18F-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.
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.
|
CRC calculated result. |
CRC_Initialize()
void CRC_Initialize (void )
Initializes the CRC module. This is called only once before calling other CRC APIs.
|
None. |
CRC_IsBufferEmpty()
bool CRC_IsBufferEmpty (void )
Returns the status of the software buffer.
|
|
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.
|
|
CRC_IsScannerBusy()
bool CRC_IsScannerBusy (void )[inline]
Checks if the scanner cycle is in progress or not.
|
|
CRC_SetCrcInterruptHandler()
void CRC_SetCrcInterruptHandler (void(*)(void) InterruptHandler)
Sets the callback function for the CRC interrupt events.
|
None. |
CRC_SetScannerAddressLimit()
void CRC_SetScannerAddressLimit (uint24_t startAddr, uint24_t endAddr)
Sets the memory address limit for the scanner.
|
None. |
CRC_SetScannerInterruptHandler()
void CRC_SetScannerInterruptHandler (void(*)(void) InterruptHandler)
Sets the callback function for the interrupt event.
|
None. |
CRC_StartCrc()
void CRC_StartCrc (void )[inline]
Starts the CRC serial shifter.
|
None. |
CRC_StartScanner()
void CRC_StartScanner (void )[inline]
Starts the scanning process.
|
None. |
CRC_StopScanner()
void CRC_StopScanner (void )[inline]
Stops the scanning process.
|
None. |
CRC_WriteBuffer()
bool CRC_WriteBuffer (uint32_t data)
Writes data into the software buffer when the CRC interrupt is enabled.
|
|
CRC_WriteData()
bool CRC_WriteData (uint32_t data)
Writes the data into the CRC Data registers.
|
|
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
static void CRC_DefaultCrcInterruptHandler (void)
static void CRC_DefaultScannerInterruptHandler (void)
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.
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.
static uint32_t CRC_ReverseValue (uint32_t crc)
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.
void __interrupt (irq(CRC), base(8))
void CRC_SetCrcInterruptHandler (void(*InterruptHandler)(void))
Sets the callback function for the CRC interrupt events.
void __interrupt (irq(SCAN), base(8))
void CRC_SetScannerInterruptHandler (void(*InterruptHandler)(void))
Sets the callback function for the interrupt event.
3.8.5.1.2 Macros
#define CRC_BUFFER_SIZE 8
3.8.5.1.3 Variables
static volatile uint8_t crcBufferHead = 0
static volatile uint8_t crcBufferTail = 0
static volatile uint32_t crcBuffer [CRC_BUFFER_SIZE]
volatile uint8_t crcBufferRemaining
static void(* CRC_CrcInterruptHandler )(void)
static void(* CRC_ScannerInterruptHandler )(void)
3.8.5.1.4 Detailed Description
This file contains the API implementation for the CRC driver.
CRC Generated Driver File.
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]
crcBuffer
volatile uint32_t crcBuffer[CRC_BUFFER_SIZE][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.