Beispiel #1
0
int main(void)
{
	board_init();
	sysclk_init();

	/* Turn off LEDs to start with */
	LED_Off(LED0_GPIO);
	LED_Off(LED1_GPIO);
	LED_Off(LED2_GPIO);

	/* Enable all three interrupt levels of the PMIC.
	 * Alternatively, use pmic_init() to achieve the same.
	 */
	pmic_enable_level(PMIC_LVL_LOW | PMIC_LVL_MEDIUM | PMIC_LVL_HIGH);

	/* Enable the timer/counter's clock. */
	sysclk_enable_module(SYSCLK_PORT_C, SYSCLK_TC4);

	/* Initialize count, period and compare registers of the timer/counter. */
	TCC4.CNT = 0x0000;
	TCC4.PER = 0xffff;
	TCC4.CCA = 0x5555;
	TCC4.CCB = 0xaaaa;

	/* Set up timer/counter in normal mode with two compare channels. */
	TCC4.CTRLB |= TC45_WGMODE_NORMAL_gc;
	TCC4.CTRLE = TC45_CCAMODE_COMP_gc | TC45_CCBMODE_COMP_gc;

	/* Set levels for overflow and compare channel interrupts. */
	TCC4.INTCTRLA = TC45_OVFINTLVL_HI_gc;
	TCC4.INTCTRLB = TC45_CCAINTLVL_LO_gc | TC45_CCBINTLVL_MED_gc;

	/* Start the timer/counter and enable interrupts. */
	TCC4.CTRLA = TC45_CLKSEL_DIV64_gc;
	cpu_irq_enable();

	while (1) {
		/* Do nothing - LED toggling is managed by interrupts. */
		/* NOP to allow for debug pauses. */
		asm("nop");
	}
}
Beispiel #2
0
/* ! \brief Set up and run the test suite */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate     = CONF_TEST_BAUDRATE,
		.charlength   = CONF_TEST_CHARLENGTH,
		.paritytype   = CONF_TEST_PARITY,
		.stopbits     = CONF_TEST_STOPBITS,
	};

	sysclk_init();
	board_init();
	pmic_init();
	sleepmgr_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	/* Enable low level interrupts */
	pmic_enable_level(PMIC_LVL_LOW);

	/* Enable interrupt requests */
	cpu_irq_enable();

	DEFINE_TEST_CASE(memory_copy_burst_length_test,
			NULL, run_edma_memory_copy_burst_length_test, NULL,
			"Memory copy and burst lengths");

	DEFINE_TEST_CASE(standard_config_interface_test,
			NULL, run_edma_standard_config_interface_test, NULL,
			"Write and read conf param for stdCH");

	DEFINE_TEST_CASE(peripheral_config_interface_test,
			NULL, run_edma_peripheral_config_interface_test, NULL,
			"Write and read conf param for perCH");

	DEFINE_TEST_CASE(trigger_callback_test,
			NULL, run_edma_triggered_with_callback, NULL,
			"External trigger and EDMA callback");

	DEFINE_TEST_CASE(error_handling_test,
			NULL, run_edma_error_handling_test, NULL,
			"Error handling by the module");

	DEFINE_TEST_CASE(search_and_double_buffer_test,
			NULL, run_edma_search_dbuf_test, NULL,
			"SEARCH and DOUBLE BUFFER modes");

	DEFINE_TEST_ARRAY(edma_tests) = {
		&memory_copy_burst_length_test,
		&standard_config_interface_test,
		&peripheral_config_interface_test,
		&trigger_callback_test,
		&error_handling_test,
		&search_and_double_buffer_test
	};

	DEFINE_TEST_SUITE(edma_suite,
			edma_tests,
			"XMEGA EDMA driver test suite");

	test_suite_run(&edma_suite);

	while (1) {
		/* Intentionally left empty */
	}
}
Beispiel #3
0
/**
 * \brief This function runs a SHA204 Read test on all four devices.
 *
 * This test wakes up the devices, reads their TWI addresses from
 * their Config zone, and sends them back to sleep. The test fails if
 * there are communication failures or the TWI addresses do not match.
 *
 * \param test current test case
 */
static void test_all_devices(const struct test_case *test)
{
	test_assert_true(test, success, "Previous test failed.");
	success = false;
	
	uint8_t sha204_status;
	uint8_t i;
	uint8_t twi_address;
	uint8_t twi_address_retrieved = 0;
	uint8_t command[READ_COUNT];
	uint8_t response[READ_4_RSP_SIZE];
	
	sha204_status = sha204p_wakeup();
	test_assert_true(test, sha204_status == SHA204_SUCCESS, "Sending Wakeup token failed.");

	// Address 16 holds the TWI address.
	struct sha204_read_parameters args = 
			{.tx_buffer = command, .rx_buffer = response, .zone = SHA204_ZONE_CONFIG, .address = 16};
	
	// Read TWI address from all four devices that are mounted on the Security Xplained extension board.
	for (i = 0; i < SHA204_DEVICE_COUNT; i++) {
		twi_address = sha204_i2c_address(i);
		sha204p_set_device_id(twi_address);

		memset(response, 0, sizeof(response));
		success = false;
		sha204_status = sha204m_read(&args);
		if (sha204_status != SHA204_SUCCESS)
			break;
		twi_address_retrieved = args.rx_buffer[SHA204_BUFFER_POS_DATA] & 0xFE;
		if (twi_address_retrieved != twi_address)
			break;

		sha204_status = sha204p_sleep();
		if (sha204_status != SHA204_SUCCESS)
			break;

		success = true;
	}
	// Sleep remaining devices in case one of them failed.
	for (; i < SHA204_DEVICE_COUNT; i++) {
		twi_address = sha204_i2c_address(i);
		sha204p_set_device_id(twi_address);
		sha204p_sleep();
	}	
	test_assert_true(test, sha204_status == SHA204_SUCCESS, "Communication error.");
	test_assert_true(test, twi_address_retrieved == twi_address, "TWI address does not match.");

	success = true;
}


//! \name Unit test configuration
//@{
/**
 * \def CONF_TEST_USART
 * \brief USART to redirect STDIO to
 */
/**
 * \def CONF_TEST_BAUDRATE
 * \brief Baudrate of USART
 */
/**
 * \def CONF_TEST_CHARLENGTH
 * \brief Character length (bits) of USART
 */
/**
 * \def CONF_TEST_PARITY
 * \brief Parity mode of USART
 */
/**
 * \def CONF_TEST_STOPBITS
 * \brief Stop bit configuration of USART
 */
//@}

/**
 * \brief This function runs ATSHA204 component unit tests.
 */
int main (void)
{
	const usart_serial_options_t usart_serial_options =
	{
		.baudrate     = CONF_TEST_BAUDRATE,
		.charlength   = CONF_TEST_CHARLENGTH,
		.paritytype   = CONF_TEST_PARITY,
		.stopbits     = CONF_TEST_STOPBITS,
	};

	sysclk_init();
	board_init();
	pmic_init();
	sleepmgr_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	// Enable low level interrupts
	pmic_enable_level(PMIC_LVL_LOW);

	// Enable interrupt requests
	cpu_irq_enable();

	// Define all the test cases
	DEFINE_TEST_CASE(sha204_test1, NULL, test_sha204_wakeup, NULL,
			"Testing Wakeup / Sleep");

	DEFINE_TEST_CASE(sha204_test2, NULL, test_all_devices, NULL,
			"Testing all devices");

	// Put test case addresses in an array
	DEFINE_TEST_ARRAY(sha204_tests) = {
		&sha204_test1,
		&sha204_test2
	};

	// Define the test suite
	DEFINE_TEST_SUITE(sha204_suite, sha204_tests,
			"XMEGA ATSHA204 component test suite");

	// Run all tests in the test suite
	test_suite_run(&sha204_suite);

	while (1) {
		// Loop for infinity
	}
}
Beispiel #4
0
/* ! \brief Set up and run the test suite */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate     = CONF_TEST_BAUDRATE,
		.charlength   = CONF_TEST_CHARLENGTH,
		.paritytype   = CONF_TEST_PARITY,
		.stopbits     = CONF_TEST_STOPBITS,
	};

	sysclk_init();
	board_init();
	pmic_init();
	sleepmgr_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	/* Enable low level interrupts */
	pmic_enable_level(PMIC_LVL_LOW);

	/* Enable interrupt requests */
	cpu_irq_enable();

	DEFINE_TEST_CASE(memory_copy_burst_length_test, NULL,
			run_dma_memory_copy_burst_length_test,
			NULL, "Memory copy and burst lengths");

	DEFINE_TEST_CASE(direction_test, NULL, run_dma_direction_test,
			NULL, "Copy directions");

	DEFINE_TEST_CASE(config_interface_test, NULL,
			run_dma_config_interface_test, NULL,
			"Write and read configuration parameters");

	DEFINE_TEST_CASE(trigger_callback_test, NULL,
			run_dma_triggered_with_callback, NULL,
			"External trigger and DMA callback");

	DEFINE_TEST_CASE(error_handling_test, NULL,
			run_dma_error_handling_test, NULL,
			"Error handling by the module");

	DEFINE_TEST_CASE(double_buffering_test, NULL,
			run_dma_double_buffering_test,
			NULL, "Double buffering");

	DEFINE_TEST_ARRAY(dma_tests) = {
		&memory_copy_burst_length_test,
		&direction_test,
		&config_interface_test,
		&trigger_callback_test,
		&error_handling_test,
		&double_buffering_test
	};

	DEFINE_TEST_SUITE(dma_suite, dma_tests, "XMEGA DMA driver test suite");

	test_suite_run(&dma_suite);

	while (1) {
		/* Intentionally left empty */
	}
}