示例#1
0
文件: crc.c 项目: 0xBADCA7/lk
/**
 * @brief	Application main function
 * @return	Does not return
 * @note	This function will not return.
 */
int main(void)
{
	uint32_t result[6], gencrc;

	/* Board Initialization */
	SystemCoreClockUpdate();
	Board_Init();

	/* Chip Initialization */
	Chip_CRC_Init();

	/* Enable SysTick Timer */
	SysTick_Config(SystemCoreClock / TICKRATE_HZ);

	/* Loop tests with occasional forced error */
	while (1) {
		result[0] = Chip_CRC_CRC8(&bytes[0], 1);
		result[1] = Chip_CRC_CRC8(bytes, (sizeof(bytes) / sizeof(bytes[0])));
		result[2] = Chip_CRC_CRC16(&words[0], 1);
		if (ticks % 2 == 0) {
			/* introduce bit errors on every other tick */
			result[2] -= 1;
		}
		result[3] = Chip_CRC_CRC16(words, (sizeof(words) / sizeof(words[0])));
		result[4] = Chip_CRC_CRC32(&dwords[0], 1);
		result[5] = Chip_CRC_CRC32(dwords, (sizeof(dwords) / sizeof(dwords[0])));

		gencrc = Chip_CRC_CRC32((uint32_t *) result, 5);
		result[0] = Chip_CRC_CRC32((uint32_t *) expect, 5);
		if (result[0] != gencrc) {
			Board_LED_Set(0, true);
		}
		else {
			Board_LED_Set(0, false);
		}

		/* Wait for tick */
		__WFE();
	}
	return 0;
}
示例#2
0
/**
 * @brief	Main program body
 * @return	This function doesn't return
 */
int main(void) {
	uint32_t result;
	uint32_t BlockData[BLOCK_SIZE / 4];
	volatile int noExit = 1;/* For build warning only */

	/* Board Initialization */
	SystemCoreClockUpdate();
	Board_Init();

	/* Chip Initialization */
	Chip_CRC_Init();

	Board_LED_Set(0, false);
	initBlockData((uint8_t *) BlockData);
	DEBUGSTR("CRC engine test\r\n");

	/* 8-bit CCIT */
	result = Chip_CRC_CRC8((const uint8_t *) BlockData, BLOCK_SIZE);
	DEBUGOUT("CCIT test results, expected 0x%x, got 0x%x\r\n",
			 EXPECTED_CCIT_SUM, result);
	if (result != EXPECTED_CCIT_SUM) {
		Board_LED_Set(0, true);
	}

	/* 16-bit CRC16 */
	result = Chip_CRC_CRC16((const uint16_t *) BlockData, BLOCK_SIZE / 2);
	DEBUGOUT("CRC16 test results, expected 0x%x, got 0x%x\r\n",
			 EXPECTED_CRC16_SUM, result);
	if (result != EXPECTED_CRC16_SUM) {
		Board_LED_Set(0, true);
	}

	/* 32-bit CRC16 */
	result = Chip_CRC_CRC32((const uint32_t *) BlockData, BLOCK_SIZE / 4);
	DEBUGOUT("CRC32 test results, expected 0x%x, got 0x%x\r\n",
			 EXPECTED_CRC32_SUM, result);
	if (result != EXPECTED_CRC32_SUM) {
		Board_LED_Set(0, true);
	}

	while (noExit) {}

	return 0;
}