In this use case, the CRC module is configured for:
- Performing CRC on data passing through a DMA channel
- Using CRC-16
This use case shows how to calculate the checksum for data passing through a DMA channel.
Setup steps
Prerequisites
For the setup code of this use case to work, the following must be added to the project:
- PMIC driver for interrupt handling
- DMA driver for enabling DMA transaction
- The common Clock service.
- A callback function for DMA transfer complete must be provided by the user:
- A static uint8_t array of data with at least DMA_BUFFER_SIZE entries to perform CRC on.
Example code
Some defines and data buffers must be set up:
#define DMA_CHANNEL 0
#define DMA_BUFFER_SIZE 8
Add to application initialization:
Workflow
- Initialize system clock:
Usage steps
Example code
uint32_t checksum;
memset(&config, 0, sizeof(config));
DMA_CH_SRCRELOAD_TRANSACTION_gc);
DMA_CH_DESTRELOAD_TRANSACTION_gc);
(uint16_t)(uintptr_t)destination);
while (true) {
}
Workflow
- Enable the CRC module for DMA
- Enable DMA
- Set callback function for DMA completion
- Make sure config is all zeroed out so we don't get any stray bits
memset(&config, 0, sizeof(config));
- Configure the DMA channel with the following settings:
- Low interrupt priority
- 1 byte burst length
- DMA_BUFFER_SIZE bytes for each transfer
- Reload source and destination address at end of each transfer
- Increment source and destination address during transfer
- Source address is set to source buffer
- Destination address is set to destination buffer
DMA_CH_SRCRELOAD_TRANSACTION_gc);
DMA_CH_DESTRELOAD_TRANSACTION_gc);
(uint16_t)(uintptr_t)destination);
- Use the configuration above by enabling the DMA channel in use.
- Enable interrupts
- Trigger the DMA transfer
- Do nothing while waiting for DMA transfer to complete