Low-level driver implementation for the AVR XMEGA AU CRC module.
The CRC computation is done by the hardware CRC module. Even if this hardware module computes the checksum, the CPU can still be required to read the data. In the case of 32-bit CRC computation for flash memory, the whole process can be run without support from the CPU. However, for the 16-bit computation the CPU would have to read from Flash memory and transfer data to the CRC module. For CRC computations of data in SRAM, EEPROM or peripherals, the CPU will have to transfer data to the CRC module unless a DMA transaction is setup. The CRC-CCITT polynomial is 0x1021 and the IEEE 802.3 polynomial is 0x04C11DB7. More details on the CRC implementation can be found in the XMEGA AU manual.
Enumerations | |
enum | crc_16_32_t { CRC_16BIT, CRC_32BIT, CRC_16BIT, CRC_32BIT } |
Enum for indicating whether to use 16- or 32-bits CRC. More... | |
uint32_t | crc_initial_value = 0 |
Initial CRC value to use on next CRC calculation. More... | |
static bool | crc_is_busy (void) |
Check if the CRC module is busy. More... | |
static void | crc_reset (void) |
Reset CRC module and set CHECKSUM to initial value. More... | |
static uint16_t | crc16_checksum_read (void) |
Read CRC-16 checksum. More... | |
static uint32_t | crc32_checksum_read (void) |
Read CRC-32 checksum. More... | |
static uint32_t | crc_checksum_read (void) |
Read checksum. More... | |
static void | crc_set_source (CRC_SOURCE_t source) |
Set data source for the CRC module after reset. More... | |
static void | crc_disable (void) |
Disable the CRC module. More... | |
static uint32_t | crc_checksum_complete (void) |
Complete CRC calculation by reading checksum and disabling module. More... | |
static void | crc_32_enable (void) |
Enable CRC-32. More... | |
NVM Commands | |
NVM commands for 32-bit CRC of flash memory. These are only used by CLASSB_CRC32_Flash_HW. | |
#define | CRC_FLASH_RANGE NVM_CMD_FLASH_RANGE_CRC_gc |
Compute a CRC checksum on an address range. More... | |
#define | CRC_BOOT NVM_CMD_BOOT_CRC_gc |
Compute a CRC checksum on the application section. More... | |
#define | CRC_APP NVM_CMD_APP_CRC_gc |
Compute a CRC checksum on the boot section. More... | |
CRC tests | |
Invariant memory tests based on CRC that are compliant with IEC60730 Class B. | |
uint16_t | CLASSB_CRC16_EEPROM_HW (eepromptr_t dataptr, const crcbytenum_t numBytes, eeprom_uint16ptr_t pchecksum) |
Compute 16-bit CRC for EEPROM address range using hardware CRC module. More... | |
uint16_t | CLASSB_CRC16_Flash_HW (flashptr_t dataptr, const crcbytenum_t numBytes, eeprom_uint16ptr_t pchecksum) |
Compute 16-bit CRC for Flash address range using hardware CRC module. More... | |
uint32_t | CLASSB_CRC32_EEPROM_HW (eepromptr_t dataptr, const crcbytenum_t numBytes, eeprom_uint32ptr_t pchecksum) |
Compute 32-bit CRC for EEPROM address range using hardware CRC module. More... | |
uint32_t | CLASSB_CRC32_Flash_HW (NVM_CMD_t crc_type, flashptr_t dataptr, const crcbytenum_t numBytes, eeprom_uint32ptr_t pchecksum) |
Compute 32-bit CRC for Flash address range using hardware CRC module. More... | |
Internal functions | |
void | crc_set_initial_value (uint32_t value) |
Set initial CRC value for next CRC calculation. More... | |
void | crc32_append_value (uint32_t value, void *ptr) |
Get and append data to generate checksum zero with CRC32. More... | |
void | crc16_append_value (uint16_t value, void *ptr) |
Appends a CRC value to the given pointer. 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_start (enum crc_16_32_t crc_16_32) |
Reset CRC module and set source to I/O interface. More... | |
void | crc_io_checksum_byte_add (uint8_t data) |
Add one byte of data to CRC performed on I/O interface. More... | |
uint32_t | crc_io_checksum_byte_stop (void) |
Disable CRC module and return checksum. More... | |
void | nvm_issue_flash_range_crc (flash_addr_t start_addr, flash_addr_t end_addr) |
Issue flash range CRC command. More... | |
#define CRC_APP NVM_CMD_APP_CRC_gc |
Compute a CRC checksum on the boot section.
Referenced by crc_flash_checksum(), and main().
#define CRC_BOOT NVM_CMD_BOOT_CRC_gc |
Compute a CRC checksum on the application section.
Referenced by crc_flash_checksum(), and main().
#define CRC_FLASH_RANGE NVM_CMD_FLASH_RANGE_CRC_gc |
Compute a CRC checksum on an address range.
Referenced by crc_flash_checksum(), main(), and run_flash_test().
enum crc_16_32_t |
uint16_t CLASSB_CRC16_EEPROM_HW | ( | eepromptr_t | origDataptr, |
crcbytenum_t | numBytes, | ||
eeprom_uint16ptr_t | pchecksum | ||
) |
Compute 16-bit CRC for EEPROM address range using hardware CRC module.
This function returns the 16-bit CRC of the specified EEPROM address range.
origDataptr | Address of EEPROM location to start CRC computation at. |
numBytes | Number of bytes of the data. |
pchecksum | Pointer to the checksum stored in EEPROM. |
References CLASSB_EEMAP_BEGIN, CLASSB_EEMAP_END, CLASSB_ERROR_HANDLER_CRC, CRC16_INITIAL_REMAINDER, CRC_16BIT, crc_io_checksum(), and crc_set_initial_value().
uint16_t CLASSB_CRC16_Flash_HW | ( | flashptr_t | origDataptr, |
crcbytenum_t | numBytes, | ||
eeprom_uint16ptr_t | pchecksum | ||
) |
Compute 16-bit CRC for Flash address range using hardware CRC module.
This function returns the 16-bit CRC of the specified Flash address range.
origDataptr | Address of Flash location to start CRC computation at. |
numBytes | Number of bytes of the data. |
pchecksum | Pointer to the checksum stored in EEPROM. |
References CLASSB_EEMAP_BEGIN, CLASSB_EEMAP_END, CLASSB_ERROR_HANDLER_CRC, CRC16_INITIAL_REMAINDER, CRC_16BIT, crc_io_checksum_byte_add(), crc_io_checksum_byte_start(), crc_io_checksum_byte_stop(), crc_set_initial_value(), and PROGMEM_READ_BYTE.
uint32_t CLASSB_CRC32_EEPROM_HW | ( | eepromptr_t | origDataptr, |
crcbytenum_t | numBytes, | ||
eeprom_uint32ptr_t | pchecksum | ||
) |
Compute 32-bit CRC for EEPROM address range using hardware CRC module.
This function returns the 32-bit CRC of the specified EEPROM address range.
origDataptr | Address of EEPROM location to start CRC computation at. |
numBytes | Number of bytes of the data. |
pchecksum | Pointer to the checksum stored in EEPROM. |
References CLASSB_EEMAP_BEGIN, CLASSB_EEMAP_END, CLASSB_ERROR_HANDLER_CRC, CRC32_INITIAL_REMAINDER, CRC_32BIT, crc_io_checksum(), and crc_set_initial_value().
uint32_t CLASSB_CRC32_Flash_HW | ( | NVM_CMD_t | crc_type, |
flashptr_t | origDataptr, | ||
crcbytenum_t | numBytes, | ||
eeprom_uint32ptr_t | pchecksum | ||
) |
Compute 32-bit CRC for Flash address range using hardware CRC module.
This function returns the 32-bit CRC of the specified Flash address range.
crc_type | Type of CRC computation: CRC_FLASH_RANGE, CRC_BOOT or CRC_APP. |
origDataptr | Address of Flash location to start CRC computation at. |
numBytes | Number of bytes of the data. |
pchecksum | Pointer to the checksum stored in EEPROM. |
References CLASSB_EEMAP_BEGIN, CLASSB_EEMAP_END, CLASSB_ERROR_HANDLER_CRC, CRC32_INITIAL_REMAINDER, crc_flash_checksum(), and crc_set_initial_value().
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 at. |
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. |
|
inlinestatic |
Read CRC-16 checksum.
This function returns the computed CRC-16 checksum.
Referenced by crc_checksum_read().
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. |
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. |
|
inlinestatic |
Read CRC-32 checksum.
This function extracts the CRC-32 checksum from the registers.
Referenced by crc_checksum_read().
|
inlinestatic |
Enable CRC-32.
This function will set the CRC-32 polynomial to be used to generate the checksum.
Referenced by crc_flash_checksum(), and crc_io_checksum_byte_start().
|
inlinestatic |
Complete CRC calculation by reading checksum and disabling module.
References crc_checksum_read(), and crc_disable().
Referenced by crc_flash_checksum(), and crc_io_checksum_byte_stop().
|
inlinestatic |
Read checksum.
This function waits until the CRC conversion is complete and returns either the 32-bit or 16-bit checksum as a 32-bit value.
References crc16_checksum_read(), crc32_checksum_read(), and crc_is_busy().
Referenced by crc_checksum_complete().
|
inlinestatic |
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.
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 |
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.
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 |
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 | Indicator for whether CRC-32 or CRC-16 shall be used |
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 |
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 | Byte 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.
data | data to perform CRC on |
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 | Indicator 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.
crc_16_32 | enum to indicate whether CRC-32 or CRC-16 shall be used |
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 | Calculated checksum |
This function stops the CRC calculation for bytes added with the crc_io_checksum_byte_add and returns the calculated checksum.
checksum | checksum |
|
inlinestatic |
Check if the CRC module is busy.
This function can be used to see if a CRC checksum generation is completed.
true | if module is busy |
false | if module is not busy |
Referenced by crc_checksum_read().
|
inlinestatic |
Reset CRC module and set CHECKSUM to initial value.
The CRC registers will be reset one peripheral clock cycle after the RESET[1] bit is set. The initial value is reset to 0 after loading it into the CHECKSUM registers.
References crc_initial_value.
Referenced by crc_flash_checksum(), and crc_io_checksum_byte_start().
void crc_set_initial_value | ( | uint32_t | value | ) |
Set initial CRC value for next CRC calculation.
value | Initial CRC value |
|
inlinestatic |
Set data source for the CRC module after reset.
The selected source is locked until either the CRC generation is completed or the CRC module is reset. CRC generation complete is generated and signalled from the selected source when used with the DMA controller or flash memory. To disable the CRC module, use CRC_SOURCE_DISABLE_gc as source.
source | The data source for the CRC module |
References source.
Referenced by crc_disable(), crc_flash_checksum(), and crc_io_checksum_byte_start().
void nvm_issue_flash_range_crc | ( | flash_addr_t | start_addr, |
flash_addr_t | end_addr | ||
) |
Issue flash range CRC command.
This function sets the FLASH range CRC command in the NVM.CMD register. It then loads the start and end byte address of the part of FLASH to generate a CRC-32 for into the ADDR and DATA registers and finally performs the execute command.
start_addr | end byte address |
end_addr | start byte address |
References ccp_write_io().
Referenced by crc_flash_checksum().
uint32_t crc_initial_value = 0 |
Initial CRC value to use on next CRC calculation.
Referenced by crc_reset(), and crc_set_initial_value().