Example #1
0
/**
 * \brief Run PARC driver unit tests.
 */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate   = CONF_UART_BAUDRATE,
		.charlength = CONF_UART_CHAR_LENGTH,
		.paritytype = CONF_UART_PARITY,
		.stopbits   = CONF_UART_STOP_BITS
	};
	/* Initialize the SAM system. */
	sysclk_init();
	board_init();
	/* Configure console USART. */
	stdio_serial_init(CONF_UART, &usart_serial_options);

	parc_port_source_simulation_config();

	/* Define all the test cases. */
	DEFINE_TEST_CASE(parc_ctrl_test, NULL, run_parc_ctrl_test, NULL,
			"SAM PARC enable/disable test");
	DEFINE_TEST_CASE(parc_polled_test, NULL, run_parc_polled_test, NULL,
			"SAM PARC polled test.");
	DEFINE_TEST_CASE(parc_callback_test, NULL, run_parc_callback_test, NULL,
			"SAM PARC callback test.");

	/* Put test case addresses in an array. */
	DEFINE_TEST_ARRAY(parc_tests) = {
		&parc_ctrl_test,
		&parc_polled_test,
		&parc_callback_test
	};

	/* Define the test suite. */
	DEFINE_TEST_SUITE(parc_suite, parc_tests, "SAM PARC driver test suite");

	/* Run all tests in the test suite. */
	test_suite_run(&parc_suite);

	while(1){
		/* Busy-wait forever. */
	}
}
Example #2
0
/**
 * \brief Application entry point for PARC example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint32_t uc_key;

	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Configure UART for debug message output. */
	configure_console();
	parc_port_source_simulation_config();

	//! [parc_variables]	
	struct parc_module module_inst;
	struct parc_config config;
	//! [parc_variables]	

	/* Output example information. */
	puts(STRING_HEADER);

	/* Configure TC. */
	configure_tc();
	/* Start timer. */
	tc_start(TC0, 0);

	//! [parc_get_defaults]	
	// Get default configuration
	parc_get_config_defaults(&config);
	//! [parc_get_defaults]	
	printf("Press y to sample the data when both data enable pins are enabled.\r\n");
	printf("Press n to sample the data, don't care the status of the data enable pins.\r\n");
	uc_key = 0;
	while ((uc_key != 'y') && (uc_key != 'n')) {
		usart_read(CONF_UART, &uc_key);
	}
	if (uc_key == 'y') {
		/* Sample the data when both data enable pins are enabled. */
		config.smode = PARC_SMODE_PCEN1_AND_PCEN2_H;
		ioport_set_pin_level(PIN_PCEN1_INPUT, IOPORT_PIN_LEVEL_HIGH);
		ioport_set_pin_level(PIN_PCEN2_INPUT, IOPORT_PIN_LEVEL_HIGH);
		printf("Receive data when both data enable pins are enabled.\r\n");
	} else {
		/* Sample the data, don't care the status of the data enable pins. */
		config.smode = PARC_SMODE_ALWAYS;
		printf("Receive data, don't care the status of the data enable pins.\r\n");
	}

	printf("Press y to sample all the data.\r\n");
	printf("Press n to sample the data only one out of two.\r\n");
	uc_key = 0;
	while ((uc_key != 'y') && (uc_key != 'n')) {
		usart_read(CONF_UART, &uc_key);
	}
	if (uc_key == 'y') {
			/* Sample all the data. */
		config.capture_mode = PARC_BOTH_CAPTURE;
		printf("All data are sampled.\r\n");
	} else {
		/* Sample the data only one out of two. */
		config.capture_mode = PARC_EVEN_CAPTURE;
		printf("Only one out of two data is sampled, with an even index.\r\n");
	}

	//! [parc_init_enable_and_start]
	//! [parc_init_enable_and_start_1]
	// Initialize PARC.
	parc_init(&module_inst, PARC, &config);
	//! [parc_init_enable_and_start_1]
	
	//! [parc_init_enable_and_start_2]
	// Enable the PARC
	parc_enable(&module_inst);
	
	// Start capture.
	parc_start_capture(&module_inst);
	//! [parc_init_enable_and_start_2]
	//! [parc_init_enable_and_start]

	/* Enable PDCA module clock */
	pdca_enable(PDCA);
	/* Init PDCA channel with the pdca_options.*/
	pdca_channel_set_config(PDCA_PARC_CHANNEL, &PDCA_PARC_OPTIONS);

	/* Set callback for PDCA interrupt. */
	pdca_channel_set_callback(PDCA_PARC_CHANNEL,
			pdca_parc_callback,PDCA_0_IRQn,1,PDCA_IER_RCZ);

	/* Enable PDCA channel, start receiving data. */
	pdca_channel_enable(PDCA_PARC_CHANNEL);
	/* Start read PARC data capture via PDCA. */
	pdca_channel_write_load(PDCA_PARC_CHANNEL,
			(void *)gs_puc_buffer, BUFFER_SIZE);
	/* Main loop. */
	while(1) {
	}
}