Microchip® Advanced Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRC module driver

See Quick start guide for CRC driver.

Low-level driver implementation for the AVR XMEGA AU/B/C Cyclic Redundancy Check (CRC) module.

A cyclic redundancy check (CRC) is an error detection technique test algorithm used to find accidental errors in data, and it is commonly used to determine the correctness of a data transmission, and data present in the data and program memories. The CRC module takes a data stream or a block of data as input and generates a 16- or 32-bit output that can be appended to the data and used as a checksum. When the same data are later received or read, the device or application can either repeat the calculation for the data with the appended checksum, which should result in the checksum zero flag being set. The other option is to calculate the checksum and compare it to the one calculated earlier. If the new CRC result does not match the one calculated earlier or zero, the block contains a data error. The application is then able to the detect this and may take a corrective action, such as requesting the data to be sent again or simply not using the incorrect data. The CRC module in XMEGA devices supports two commonly used CRC polynomials; CRC-16 (CRC-CCITT) and CRC-32 (IEEE 802.3).

Modules

 
 Quick Start Guide(s)
 In this section you can find a list of all Quick Start guides related to the CRC module driver.
 

Macros

#define CRC_APP   NVM_CMD_APP_CRC_gc
 Perform a CRC calculation on the boot loader section. More...
 
#define CRC_BOOT   NVM_CMD_BOOT_CRC_gc
 Perform a CRC calculation on the application section. More...
 
#define CRC_FLASH_RANGE   NVM_CMD_FLASH_RANGE_CRC_gc
 Perform a CRC calculation on an address range in flash. More...
 
#define DMA_SUPPORTED
 Flag to indicate whether DMA is supported. More...
 

Enumerations

enum  crc_16_32_t {
  CRC_16BIT,
  CRC_32BIT,
  CRC_16BIT,
  CRC_32BIT
}
 Enum to indicate whether to use CRC-16 or CRC-32. More...
 

Functions

void crc16_append_value (uint16_t value, void *ptr)
 Appends a CRC value to the given pointer. More...
 
void crc32_append_value (uint32_t value, void *ptr)
 Get and append data to generate checksum zero with CRC32. More...
 
void crc_dma_checksum_start (uint8_t dma_channel, enum crc_16_32_t crc_16_32)
 Start CRC calculations on data passing through a DMA channel. More...
 
uint32_t crc_dma_checksum_stop (void)
 Disable CRC module and return checksum after DMA transfer. More...
 
uint32_t crc_flash_checksum (NVM_CMD_t crc_type, flash_addr_t flash_addr, uint32_t len)
 Perform a CRC-32 calculation on part of or entire flash. More...
 
uint32_t crc_io_checksum (void *data, uint16_t len, enum crc_16_32_t crc_16_32)
 Calculate the CRC checksum for data in a buffer. More...
 
void crc_io_checksum_byte_add (uint8_t data)
 Add one byte of data to CRC performed on I/O interface. More...
 
void crc_io_checksum_byte_start (enum crc_16_32_t crc_16_32)
 Reset CRC module and set source to I/O interface. More...
 
uint32_t crc_io_checksum_byte_stop (void)
 Disable CRC module and return checksum. More...
 
void crc_set_initial_value (uint32_t value)
 Set initial CRC value for next CRC calculation. More...
 

#define CRC_APP   NVM_CMD_APP_CRC_gc

Perform a CRC calculation on the boot loader section.

#define CRC_BOOT   NVM_CMD_BOOT_CRC_gc

Perform a CRC calculation on the application section.

#define CRC_FLASH_RANGE   NVM_CMD_FLASH_RANGE_CRC_gc

Perform a CRC calculation on an address range in flash.

#define DMA_SUPPORTED

Flag to indicate whether DMA is supported.

Enum to indicate whether to use CRC-16 or CRC-32.

Enumerator
CRC_16BIT 
CRC_32BIT 
CRC_16BIT 
CRC_32BIT 

void crc16_append_value ( uint16_t  value,
void *  ptr 
)

Appends a CRC value to the given pointer.

Taking the checksum of the value and the appended data will result in zero.

Note
At least two bytes must be reserved at the given pointer location.
Parameters
valueCRC value to append
ptrPointer to 2 byte memory location to store value at.

Taking the checksum of the value and the appended data will result in zero.

Note
At least two bytes must be reserved at the given pointer location.
Parameters
valueCRC value to append
ptrpointer to 2 byte memory location to store value.

Referenced by main(), run_16bit_dma_test(), and run_16bit_io_test().

void crc32_append_value ( uint32_t  value,
void *  ptr 
)

Get and append data to generate checksum zero with CRC32.

This function calculates checksum value to append to the data after generating its checksum. The value is written to given pointer as little endian. Taking the checksum of the data appended will result in checksum zero.

Note
At least four bytes must be reserved at the given pointer location.
Parameters
valueThe value to convert to append value
ptrPointer to 4 byte memory location to store the value.

This function calculates checksum value to append to the data after generating its checksum. The value is written to given pointer as little endian. Taking the checksum of the data appended will result in checksum zero.

Note
At least four bytes must be reserved at the given pointer location.
Parameters
valuethe value to convert to append value
ptrpointer to 4 byte memory location to store the value.

References crc_bit_revert().

Referenced by main(), run_32bit_dma_test(), and run_32bit_io_test().

void crc_dma_checksum_start ( uint8_t  dma_channel,
enum crc_16_32_t  crc_16_32 
)

Start CRC calculations on data passing through a DMA channel.

This function resets and sets up the CRC module to do CRC calculations on data passing through chosen DMA channel. Once a DMA channel is selected as the source, the CRC module will continuously generate the CRC on the data passing through the DMA channel. The checksum is available for readout once the DMA transaction is completed or aborted. A CRC can be performed not only on communication data, but also on data in SRAM or I/O memory by passing these data through a DMA channel. If the latter is done, the destination register for the DMA data can be the data input (DATAIN) register in the CRC module.

The checksum can be read and the CRC module disabled with crc_dma_checksum_stop.

Note
The DMA channel must be set up separately
Parameters
dma_channelDMA channel to use (0 to N-1)
crc_16_32enum to indicate whether CRC-32 or CRC-16 shall be used

References crc_32_enable(), CRC_32BIT, crc_reset(), and crc_set_source().

Referenced by main(), run_16bit_dma_test(), and run_32bit_dma_test().

uint32_t crc_dma_checksum_stop ( void  )

Disable CRC module and return checksum after DMA transfer.

Note
This function must be called after DMA transfer is initiated.
Returns
checksum checksum value

References crc_checksum_complete().

Referenced by example_crc_dma_transfer_done(), run_16bit_dma_test(), and run_32bit_dma_test().

uint32_t crc_flash_checksum ( NVM_CMD_t  crc_type,
flash_addr_t  flash_addr,
uint32_t  length 
)

Perform a CRC-32 calculation on part of or entire flash.

This function can perform a CRC-32 calculation on the entire flash memory, on only the application section, on only the boot section, or on a selectable range of the flash memory.

This function sets up the type of CRC to perform and configures the memory range to perform the CRC on, and starts the CRC via the NVM module. When the calculation is done, the function disables the CRC module and returns the checksum. For CRC on the boot or application section, start address and length are not needed.

Note
In the flash range mode, an even number of bytes is read. If the user selects a range with an odd number of bytes, an extra byte will be read, and the checksum will not correspond to the selected range.
Parameters
crc_typeWhat kind of CRC to do perform on the nvm module: CRC_FLASH_RANGE, CRC_BOOT or CRC_APP
flash_addrAddress of first byte in flash to perform CRC on
lengthNumber of bytes to perform CRC on
Returns
checksum CRC-32 checksum

Perform a CRC-32 calculation on part of or entire flash.

This function setups the type of CRC to perform and configures the memory range to perform the CRC on, and starts the CRC via the NVM module. When the calculation is done, the function disables the CRC module and returns the checksum. For CRC on the boot or application section, start address and length are not needed.

Note
In the flash range mode, an even number of bytes is read. If the user selects a range with an odd number of bytes, an extra byte will be read, and the checksum will not correspond to the selected range.
Parameters
crc_typewhat kind of CRC to do perform on the NVM module: CRC_FLASH_RANGE, CRC_BOOT or CRC_APP
flash_addraddress of first byte in flash to perform CRC on
lengthnumber of bytes to perform CRC on
Returns
checksum CRC-32 checksum

References Assert, crc_32_enable(), CRC_APP, CRC_BOOT, crc_checksum_complete(), CRC_FLASH_RANGE, crc_reset(), crc_set_source(), nvm_issue_command(), and nvm_issue_flash_range_crc().

Referenced by CLASSB_CRC32_Flash_HW(), main(), and run_flash_test().

uint32_t crc_io_checksum ( void *  data,
uint16_t  len,
enum crc_16_32_t  crc_16_32 
)

Calculate the CRC checksum for data in a buffer.

This function initializes the CRC module, calculates the checksum for the selected number of bytes in a data buffer, disables the module and returns the calculated checksum.

Parameters
dataData buffer to perform CRC on
lenThe number of bytes to perform CRC on
crc_16_32Indicator for whether CRC-32 or CRC-16 shall be used
Returns
checksum checksum

This function initializes the CRC module, calculates the checksum for the selected number of bytes in a data buffer, disables the module and returns the calculated checksum.

Parameters
datadata buffer to perform CRC on
lenthe number of bytes to perform CRC on
crc_16_32enum to indicate whether CRC-32 or CRC-16 shall be used
Returns
checksum checksum

References crc_io_checksum_byte_add(), crc_io_checksum_byte_start(), and crc_io_checksum_byte_stop().

Referenced by CLASSB_CRC16_EEPROM_HW(), CLASSB_CRC32_EEPROM_HW(), main(), run_16bit_io_test(), and run_32bit_io_test().

void crc_io_checksum_byte_add ( uint8_t  data)

Add one byte of data to CRC performed on I/O interface.

This function writes a byte to the DATAIN register. Each time this function is called, the checksum is calculated for the new data appended to all previous data written since the crc_io_checksum_byte_start was called. A new checksum is ready one clock cycle after the DATAIN register is written.

Parameters
dataByte to perform CRC on

This function writes a byte to the DATAIN register. Each time this function is called, the checksum is calculated for the new data appended to all previous data written since the crc_io_checksum_byte_start was called. A new checksum is ready one clock cycle after the DATAIN register is written.

Parameters
datadata to perform CRC on

References data.

Referenced by CLASSB_CRC16_Flash_HW(), crc_io_checksum(), run_16bit_io_test(), and run_32bit_io_test().

void crc_io_checksum_byte_start ( enum crc_16_32_t  crc_16_32)

Reset CRC module and set source to I/O interface.

This function initializes the CRC module, and crc_io_checksum_byte_add can be used to add bytes to calculate checksum for. When any number of bytes have been added, the crc_io_checksum_byte_stop can be called to disable the module and get the calculated checksum.

Parameters
crc_16_32Indicator for whether CRC-32 or CRC-16 shall be used

This function initializes the CRC module, and crc_io_checksum_byte_add can be used to add bytes to calculate checksum for. When any number of bytes have been added, the crc_io_checksum_byte_stop can be called to disable the module and get the calculated checksum.

Parameters
crc_16_32enum to indicate whether CRC-32 or CRC-16 shall be used

References crc_32_enable(), CRC_32BIT, crc_reset(), and crc_set_source().

Referenced by CLASSB_CRC16_Flash_HW(), crc_io_checksum(), run_16bit_io_test(), and run_32bit_io_test().

uint32_t crc_io_checksum_byte_stop ( void  )

Disable CRC module and return checksum.

This function stops the CRC calculation for bytes added with the crc_io_checksum_byte_add and returns the calculated checksum.

Return values
checksumCalculated checksum

This function stops the CRC calculation for bytes added with the crc_io_checksum_byte_add and returns the calculated checksum.

Return values
checksumchecksum

References crc_checksum_complete().

Referenced by CLASSB_CRC16_Flash_HW(), crc_io_checksum(), run_16bit_io_test(), and run_32bit_io_test().

void crc_set_initial_value ( uint32_t  value)

Set initial CRC value for next CRC calculation.

Note
Value is reset to 0 when CRC calculation completes.
Parameters
valueInitial CRC value

References crc_initial_value.

Referenced by CLASSB_CRC16_EEPROM_HW(), CLASSB_CRC16_Flash_HW(), CLASSB_CRC32_EEPROM_HW(), and CLASSB_CRC32_Flash_HW().