Atmel Software Framework

xmega/drivers/crc/unit_tests/unit_tests.c File Reference

Unit tests for Cyclic Redundancy Check (CRC) driver.

Copyright (c) 2011-2015 Atmel Corporation. All rights reserved.

#include <stdio.h>
#include <stdbool.h>
#include <asf.h>
#include <sysclk.h>
#include <board.h>
#include <dma.h>
#include <unit_test/suite.h>
#include <crc.h>
#include <sleepmgr.h>
#include "conf_test.h"

Macros

#define LENGTH(x)   (sizeof(x) / sizeof(*x))
 Get array length. More...
 

Functions

int main (void)
 Run CRC driver unit tests. More...
 
Helper functions
static void setup_dma_channel (uint8_t buf_length, uint8_t *src_buffer, uint8_t *dst_buffer)
 Setup a DMA channel for CRC calculation. More...
 
static bool wait_for_dma_transfer (const struct test_case *test)
 Wait for DMA transfer to complete and check status. More...
 
Unit test functions
static void run_32bit_io_test (const struct test_case *test)
 32-bit checksum of data block test More...
 
static void run_16bit_io_test (const struct test_case *test)
 16-bit checksum of data block test More...
 
static void run_32bit_dma_test (const struct test_case *test)
 32-bit checksum of DMA transfer data More...
 
static void run_16bit_dma_test (const struct test_case *test)
 16-bit checksum of DMA transfer data More...
 
static void run_flash_test (const struct test_case *test)
 32-bit CRC of flash memory test More...
 

Data declarations

#define CRC_CHECKSUM_32BIT   0x26CB2533
 Pre-calculated checksums of data_8bit and data_8bit_flash (without the trailing zeros) More...
 
#define CRC_CHECKSUM_16BIT   0x51D1
 
const uint8_t data_8bit []
 
 PROGMEM_DECLARE (uint8_t, data_8bit_flash[])
 

#define CRC_CHECKSUM_16BIT   0x51D1
#define CRC_CHECKSUM_32BIT   0x26CB2533

Pre-calculated checksums of data_8bit and data_8bit_flash (without the trailing zeros)

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

#define LENGTH (   x)    (sizeof(x) / sizeof(*x))

PROGMEM_DECLARE ( uint8_t  ,
data_8bit_flash  [] 
)
static void run_16bit_dma_test ( const struct test_case test)
static

16-bit checksum of DMA transfer data

This test sets up DMA to do a data block transfer, and sets up the CRC module to do a 16 bit checksum on the data. The checksum will then be added to another buffer, the same procedure is setup with this new buffer which should result in a checksum = 0.

Parameters
testCurrent test case

References crc16_append_value(), CRC_16BIT, CRC_CHECKSUM_16BIT, crc_dma_checksum_start(), crc_dma_checksum_stop(), data_8bit, dma_channel_disable(), dma_channel_trigger_block_transfer(), dma_disable(), LENGTH, setup_dma_channel(), success, test_assert_true, and wait_for_dma_transfer().

Referenced by main().

static void run_16bit_io_test ( const struct test_case test)
static

16-bit checksum of data block test

This test does a checksum of a data block with a known checksum, and verifies that they are equal. It then appends the 16-bit CRC to the end of the data, and does another checksum operation, which should result in the zero flag being set.

Parameters
testCurrent test case

References crc16_append_value(), CRC_16BIT, CRC_CHECKSUM_16BIT, crc_io_checksum(), crc_io_checksum_byte_add(), crc_io_checksum_byte_start(), crc_io_checksum_byte_stop(), data_8bit, LENGTH, and test_assert_true.

Referenced by main().

static void run_32bit_dma_test ( const struct test_case test)
static

32-bit checksum of DMA transfer data

This test sets up DMA to do a data block transfer, and sets up the CRC module to do a 32 bit checksum on the data. The checksum will then be added to another buffer, the same procedure is setup with this new buffer which should result in a checksum = 0.

Parameters
testCurrent test case

References crc32_append_value(), CRC_32BIT, CRC_CHECKSUM_32BIT, crc_dma_checksum_start(), crc_dma_checksum_stop(), data_8bit, dma_channel_disable(), dma_channel_trigger_block_transfer(), dma_disable(), LENGTH, setup_dma_channel(), success, test_assert_true, and wait_for_dma_transfer().

Referenced by main().

static void run_32bit_io_test ( const struct test_case test)
static

32-bit checksum of data block test

This test does a checksum of a data block with a known checksum, and verifies that they are equal. It then appends the 32-bit CRC to the end of the data, and does another checksum operation, which should result in the zero flag being set.

Parameters
testCurrent test case

References crc32_append_value(), CRC_32BIT, CRC_CHECKSUM_32BIT, crc_io_checksum(), crc_io_checksum_byte_add(), crc_io_checksum_byte_start(), crc_io_checksum_byte_stop(), data_8bit, LENGTH, and test_assert_true.

Referenced by main().

static void run_flash_test ( const struct test_case test)
static

32-bit CRC of flash memory test

This test does a 32-bit checksum on the flash memory and verifies the checksum against a pre-calculated 32-bit CRC checksum.

Parameters
testCurrent test case

References CRC_CHECKSUM_32BIT, crc_flash_checksum(), CRC_FLASH_RANGE, LENGTH, and test_assert_true.

Referenced by main().

static void setup_dma_channel ( uint8_t  buf_length,
uint8_t *  src_buffer,
uint8_t *  dst_buffer 
)
static

Setup a DMA channel for CRC calculation.

Parameters
buf_lengthLength of buffer to transfer
src_bufferPointer to transfer buffer
dst_bufferPointer to receive buffer

References dma_channel_enable(), dma_channel_read_config(), dma_channel_set_dest_dir_mode(), dma_channel_set_src_dir_mode(), dma_channel_write_burst_length(), dma_channel_write_config(), dma_channel_write_destination(), dma_channel_write_repeats(), dma_channel_write_source(), dma_channel_write_transfer_count(), and dma_enable().

Referenced by run_16bit_dma_test(), and run_32bit_dma_test().

static bool wait_for_dma_transfer ( const struct test_case test)
static

Wait for DMA transfer to complete and check status.

Parameters
testCurrent test case
Return values
trueif DMA transfer completed without error
falseif DMA transfer failed

References DMA_CH_FREE, DMA_CH_TRANSFER_COMPLETED, DMA_CH_TRANSFER_ERROR, dma_get_channel_status(), status, and test_assert_true.

Referenced by run_16bit_dma_test(), and run_32bit_dma_test().

const uint8_t data_8bit[]
Initial value:
= {
0xF0, 0x0F, 0xAB, 0x12, 0x21, 0x01, 0x10, 0x20,
0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90
}

Referenced by run_16bit_dma_test(), run_16bit_io_test(), run_32bit_dma_test(), and run_32bit_io_test().