예제 #1
0
파일: unit_tests.c 프로젝트: InSoonPark/asf
/**
 * \brief 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.
 *
 * \param test    Current test case
 */
static void run_32bit_io_test(const struct test_case *test)
{
	uint8_t tmp_buffer[LENGTH(data_8bit) + sizeof(uint32_t)];
	int i;
	uint32_t checksum;

	crc_io_checksum_byte_start(CRC_32BIT);

	for(i = 0; i < LENGTH(data_8bit); ++i)
		crc_io_checksum_byte_add(data_8bit[i]);

	checksum = crc_io_checksum_byte_stop();

	test_assert_true(test, checksum == CRC_CHECKSUM_32BIT,
			"Checksum mismatch on IO CRC-32 test");

	memcpy(tmp_buffer, data_8bit, LENGTH(data_8bit));
	crc32_append_value(checksum,
			&tmp_buffer[LENGTH(tmp_buffer) - sizeof(uint32_t)]);

	checksum = crc_io_checksum(tmp_buffer,LENGTH(tmp_buffer), CRC_32BIT);

	test_assert_true(test, checksum == 0,
			"Checksum fail check failed on IO CRC-32 test");
}
예제 #2
0
/**
 * \brief Example 1 main application routine
 */
int main(void)
{
	board_init();
	sysclk_init();

	// Initialize the platform LED's.
	LED_Off(LED0_GPIO);
	LED_Off(LED1_GPIO);

	uint32_t checksum;
	uint8_t data[15];

	// Randomly selected data
	data[0] = 0xAA;
	data[1] = 0xBB;
	data[2] = 0xCC;
	data[3] = 0xDD;
	data[4] = 0xEE;
	data[5] = 0xFF;

	// Calculate checksum for the data
	checksum = crc_io_checksum((void*)data, 6, CRC_32BIT);
	// Append complemented CHECKSUM registers value to the data, little endian
	crc32_append_value(checksum, data+6);
	// Calculate the new checksum
	checksum = crc_io_checksum((void*)data, 10, CRC_32BIT);

	// Check that the data has not been corrupted, and checksum is zero
	if (checksum == 0) {
		// Turn on LED0
		LED_On(LED0_GPIO);
	}

	// Calculate CRC 16 checksum for the data
	checksum = crc_io_checksum((void*)data, 6, CRC_16BIT);
	// Append the checksum to the data, big endian
	crc16_append_value(checksum, data+6);
	// Calculate the new checksum
	checksum = crc_io_checksum((void*)data, 8, CRC_16BIT);

	// Check that the data has not been corrupted, and checksum is zero
	if (checksum == 0) {
		// Turn on LED1
		LED_On(LED1_GPIO);
	}

	// End of application, loop forever
	while (true) {
		// Intentionally left empty
	}

}
예제 #3
0
파일: unit_tests.c 프로젝트: InSoonPark/asf
/**
 * \brief 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.
 *
 * \param test    Current test case
 */
static void run_32bit_dma_test(const struct test_case *test)
{
	uint32_t checksum;
	bool success;
	uint8_t data_buf_8bit[LENGTH(data_8bit) + sizeof(uint32_t)];
	uint8_t data_8bit_cpy[LENGTH(data_8bit) + sizeof(uint32_t)];

	setup_dma_channel(LENGTH(data_8bit),
			(uint8_t *)data_8bit, data_buf_8bit);
	crc_dma_checksum_start(CONF_TEST_DMACH, CRC_32BIT);
	dma_channel_trigger_block_transfer(CONF_TEST_DMACH);

	success = wait_for_dma_transfer(test);

	dma_channel_disable(CONF_TEST_DMACH);
	dma_disable();

	checksum = crc_dma_checksum_stop();

	if (!success) {
		return;
	}

	test_assert_true(test, checksum == CRC_CHECKSUM_32BIT,
			"Checksum mismatch on DMA CRC-32 test");

	memcpy(data_8bit_cpy, data_8bit, LENGTH(data_8bit));
	crc32_append_value(checksum,
			&data_8bit_cpy[LENGTH(data_8bit_cpy) - sizeof(uint32_t)]);

	setup_dma_channel(LENGTH(data_8bit_cpy),
			(uint8_t *)data_8bit_cpy, data_buf_8bit);

	crc_dma_checksum_start(CONF_TEST_DMACH, CRC_32BIT);
	dma_channel_trigger_block_transfer(CONF_TEST_DMACH);

	success = wait_for_dma_transfer(test);

	dma_channel_disable(CONF_TEST_DMACH);
	dma_disable();

	checksum = crc_dma_checksum_stop();

	if (!success) {
		return;
	}

	test_assert_true(test, checksum == 0,
			"Checksum fail check failed on DMA CRC-16 test");
}
예제 #4
0
/**
 * \brief Example 2 main application routine
 */
int main(void)
{
	uint8_t flashbuf[8];
	uint32_t checksum1;
	uint32_t checksum2;

	board_init();
	sysclk_init();
	gfx_mono_init();

	// Calculate checksum for an address range in flash.
	checksum1 = crc_flash_checksum(CRC_FLASH_RANGE, FLASHADDR, 4);

	// Read out the buffer from flash
	nvm_flash_read_buffer(FLASHADDR, flashbuf, 4);

	// Calculate checksum for the buffer from flash
	checksum2 = crc_io_checksum(flashbuf, 4, CRC_32BIT);

	// Make sure the calculated checksums are equal and write to screen
	if (checksum1 == checksum2) {
		gfx_mono_draw_string("Address range CRC OK",
				0, 0, &sysfont);
	}

	// Append the flash checksum and recalculate
	crc32_append_value(checksum1, flashbuf+4);
	checksum1 = crc_io_checksum(flashbuf, 8, CRC_32BIT);

	// Make sure the checksum is zero and write to screen
	if (checksum1 == 0) {
		gfx_mono_draw_string("IO CRC zero       OK", 0,
				SYSFONT_HEIGHT + 1, &sysfont);
	}

	// Calculate checksum for the boot section
	checksum1 = crc_flash_checksum(CRC_BOOT, 0, 0);

	// Recalculate checksum for the boot section using flash range CRC
	checksum2 = crc_flash_checksum(CRC_FLASH_RANGE, BOOT_SECTION_START,
			BOOT_SECTION_END-BOOT_SECTION_START+1);

	// Make sure the checksums are equal and write to screen
	if (checksum1 == checksum2) {
		gfx_mono_draw_string("Boot section CRC  OK",
				0, (SYSFONT_HEIGHT + 1)*2, &sysfont);
	}

	// Calculate checksum for the application section
	checksum1 = crc_flash_checksum(CRC_APP, 0, 0);

	// Recalculate checksum for the application section using flash range CRC
	checksum2 = crc_flash_checksum(CRC_FLASH_RANGE, APP_SECTION_START,
			APP_SECTION_END-APP_SECTION_START+1);
	// Make sure the checksums are equal and write to screen
	if (checksum1 == checksum2) {
		gfx_mono_draw_string("App section CRC   OK",
				0, (SYSFONT_HEIGHT + 1)*3, &sysfont);
	}

	// End of application, loop forever
	while (true) {
		// Intentionally left empty
	}

}