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).
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... | |
Enumerations | |
enum | crc_16_32_t { CRC_16BIT, CRC_32BIT } |
Flag to indicate whether DMA is supported. 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... | |
uint32_t | crc_flash_checksum (NVM_CMD_t crc_type, flash_addr_t flash_addr, uint32_t len) |
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. 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.
Referenced by crc_flash_checksum().
#define CRC_BOOT NVM_CMD_BOOT_CRC_gc |
Perform a CRC calculation on the application section.
Referenced by crc_flash_checksum().
#define CRC_FLASH_RANGE NVM_CMD_FLASH_RANGE_CRC_gc |
Perform a CRC calculation on an address range in flash.
Referenced by crc_flash_checksum(), and run_flash_test().
enum crc_16_32_t |
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.
value | CRC value to append |
ptr | pointer to 2 byte memory location to store value. |
Referenced by 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.
value | the value to convert to append value |
ptr | pointer to 4 byte memory location to store the value. |
References crc_bit_revert().
Referenced by run_32bit_dma_test(), and run_32bit_io_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 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 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.
crc_type | what kind of CRC to do perform on the NVM module: CRC_FLASH_RANGE, CRC_BOOT or CRC_APP |
flash_addr | address of first byte in flash to perform CRC on |
length | number of bytes to perform CRC on |
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 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.
data | data buffer to perform CRC on |
len | the number of bytes to perform CRC on |
crc_16_32 | enum to indicate whether CRC-32 or CRC-16 shall be used |
References crc_io_checksum_byte_add(), crc_io_checksum_byte_start(), and crc_io_checksum_byte_stop().
Referenced by 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.
data | data to perform CRC on |
Referenced by 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.
crc_16_32 | enum 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 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.
checksum | checksum |
References crc_checksum_complete().
Referenced by 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.
value | Initial CRC value |
References crc_initial_value.