Exemple #1
0
/**
 * \brief Test PARC functions in callback way.
 *
 * \param test Current test case.
 */
static void run_parc_callback_test(const struct test_case *test)
{
	uint32_t input_data = 0x01;
	parc_get_config_defaults(&config);
	parc_init(&module_inst, PARC, &config);
	parc_enable(&module_inst);

	parc_register_callback(&module_inst,
			(parc_callback_t)parc_complete_callback, PARC_CALLBACK_DATA_READY);
	parc_enable_interrupts(&module_inst, PARC_INTERRUPT_DRDY);
	parc_enable_callback(&module_inst, PARC_CALLBACK_DATA_READY);
	parc_start_capture(&module_inst);

	for (uint32_t i = 0; i < 8; i++) {
		callback_data_ready = false;
		parc_port_input_simulation(true, input_data);
		delay_ms(DELAY_TIME);
		test_assert_true(test, callback_data_ready == true,
				"Capture data failure");
		test_assert_true(test, captured_data == (input_data & DATA_MASK),
				"Wrong captured data!");
		input_data = 1 << i;
	}
	parc_disable_interrupts(&module_inst, PARC_INTERRUPT_DRDY);
	parc_disable_callback(&module_inst,PARC_CALLBACK_DATA_READY);
	parc_stop_capture(&module_inst);
	parc_disable(&module_inst);
}
Exemple #2
0
/**
 * \brief Test PARC register write/read.
 *
 * \param test Current test case.
 */
static void run_parc_ctrl_test(const struct test_case *test)
{
	parc_get_config_defaults(&config);
	parc_init(&module_inst, PARC, &config);
	parc_enable(&module_inst);

	test_assert_true(test, parc_get_status(&module_inst) == PARC_STATUS_EN,
			"Test PARC enable: enable failed");

	parc_start_capture(&module_inst);
	test_assert_true(test, parc_get_status(&module_inst) ==
			(PARC_STATUS_CS | PARC_STATUS_EN),
			"Test PARC start: start failed");
	parc_stop_capture(&module_inst);
	parc_disable(&module_inst);
}
Exemple #3
0
/**
 * \brief Test PARC functions in polling way.
 *
 * \param test Current test case.
 */
static void run_parc_polled_test(const struct test_case *test)
{
	uint32_t input_data = 0x01;

	/* PARC config */
	parc_get_config_defaults(&config);
	parc_init(&module_inst, PARC, &config);
	parc_enable(&module_inst);
	parc_start_capture(&module_inst);

	for (uint32_t i = 0; i < 8; i++) {
		parc_port_input_simulation(true, input_data);
		delay_ms(DELAY_TIME);
		test_assert_true(test, parc_is_data_ready(&module_inst) == true,
				"Capture on rising edge failure!");
		parc_read(&module_inst, &captured_data);
		test_assert_true(test, captured_data == (input_data & DATA_MASK),
				"Wrong captured data!");
		input_data = 1 << i;
	}
	parc_stop_capture(&module_inst);
	parc_disable(&module_inst);
}
Exemple #4
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) {
	}
}