コード例 #1
0
ファイル: xcl_example4.c プロジェクト: InSoonPark/asf
/*! \brief Main function.
 */
int main(void)
{
	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();
	sysclk_init();
	sleepmgr_init();
	irq_initialize_vectors();
	cpu_irq_enable();

	/* Configure the XCL module:
	 * - Asynchronous mode usage (locks Power Down sleep mode)
	 * - Configure XCL to use XMEGA port D
	 * - Configure LUT in 1 LUTs with 3 differents inputs
	 * - LUT IN0 input on pin 2 or port D
	 * - LUT IN1 input on XCL LUT OUT1
	 * - LUT OUT0 output on pin 4 or port D
	 * - LUT IN2 input on pin 1 or port D
	 * - LUT IN3 input on pin 3 or port D
	 * - LUT OUT1 output on LUT IN1
	 * - No time Delay for both LUT0 and LUT1
	 * - LUT0 performs XOR operation
	 * - LUT1 performs XOR operation
	 */
	xcl_enable(XCL_ASYNCHRONOUS);
	xcl_port(PD);
	xcl_lut_type(LUT_1LUT3IN);
	xcl_lut_in0(LUT_IN_PINL);
	xcl_lut_in1(LUT_IN_XCL);
	xcl_lut_in2(LUT_IN_PINL);
	xcl_lut_in3(LUT_IN_PINL);
	xcl_lut0_output(LUT0_OUT_PIN4);
	xcl_lut_config_delay(DLY11, LUT_DLY_DISABLE, LUT_DLY_DISABLE);
	xcl_lut0_truth(XOR);
	xcl_lut1_truth(XOR);

	/*
	 * main loop simply enters sleep mode
	 */
	while (true) {
		sleepmgr_enter_sleep();
	}
}
コード例 #2
0
/**
 * \internal
 * \brief Test XCL Glue Logic module with 3 Inputs XOR
 *
 * This tests check the capabilty of the XCL Glue Logic Drivers to hangle
 * a 3 inputs XOR operation.
 *
 * \param test Current test case.
 */
static void run_xcl_glue_logic_3inputs_xor_test(
		const struct test_case *test)
{
	port_pin_t in0, in2, in3, out0;
	bool out;

	in0 = IOPORT_CREATE_PIN(PORTD, 2);
	in2 = IOPORT_CREATE_PIN(PORTD, 1);
	in3 = IOPORT_CREATE_PIN(PORTD, 3);
	out0 = IOPORT_CREATE_PIN(PORTD, 4);

	ioport_configure_pin(in0, IOPORT_DIR_OUTPUT);
	ioport_configure_pin(in2, IOPORT_DIR_OUTPUT);
	ioport_configure_pin(in3, IOPORT_DIR_OUTPUT);

	/* Configure the XCL module:
	 * - Asynchronous mode usage (locks Power Down sleep mode)
	 * - Configure XCL to use ATxmega32E5 port D
	 * - Configure LUT in 1 LUTs with 3 differents inputs
	 * - LUT IN0 input on pin 2 of port D
	 * - LUT IN1 input on XCL LUT OUT1
	 * - LUT OUT0 output on pin 4 of port D
	 * - LUT IN2 input on pin 1 of port D
	 * - LUT IN3 input on pin 3 of port D
	 * - LUT OUT1 output on LUT IN1
	 * - No time Delay for both LUT0 and LUT1
	 * - LUT0 performs XOR operation
	 * - LUT1 performs XOR operation
	 */
	xcl_enable(XCL_ASYNCHRONOUS);
	xcl_port(PD);
	xcl_lut_type(LUT_1LUT3IN);
	xcl_lut_in0(LUT_IN_PINL);
	xcl_lut_in1(LUT_IN_XCL);
	xcl_lut_in2(LUT_IN_PINL);
	xcl_lut_in3(LUT_IN_PINL);
	xcl_lut0_output(LUT0_OUT_PIN4);
	xcl_lut_config_delay(DLY11, LUT_DLY_DISABLE, LUT_DLY_DISABLE);
	xcl_lut0_truth(XOR);
	xcl_lut1_truth(XOR);

	gpio_set_pin_low(in0);
	gpio_set_pin_low(in2);
	gpio_set_pin_low(in3);
	asm("nop");
	asm("nop"); /* give two cycles propagation delay to read the port pin */
	out = ioport_get_pin_level(out0);
	test_assert_true(test, out == false, " XCL XOR failure");

	gpio_set_pin_high(in0);
	gpio_set_pin_low(in2);
	gpio_set_pin_low(in3);
	asm("nop");
	asm("nop"); /* give two cycles propagation delay to read the port pin */
	out = ioport_get_pin_level(out0);
	test_assert_true(test, out == true, " XCL XOR failure");

	gpio_set_pin_low(in0);
	gpio_set_pin_high(in2);
	gpio_set_pin_low(in3);
	asm("nop");
	asm("nop"); /* give two cycles propagation delay to read the port pin */
	out = ioport_get_pin_level(out0);
	test_assert_true(test, out == true, " XCL XOR failure");

	gpio_set_pin_low(in0);
	gpio_set_pin_low(in2);
	gpio_set_pin_high(in3);
	asm("nop");
	asm("nop"); /* give two cycles propagation delay to read the port pin */
	out = ioport_get_pin_level(out0);
	test_assert_true(test, out == true, " XCL XOR failure");

	gpio_set_pin_low(in0);
	gpio_set_pin_high(in2);
	gpio_set_pin_high(in3);
	asm("nop");
	asm("nop"); /* give two cycles propagation delay to read the port pin */
	out = ioport_get_pin_level(out0);
	test_assert_true(test, out == false, " XCL XOR failure");

	gpio_set_pin_high(in0);
	gpio_set_pin_high(in2);
	gpio_set_pin_high(in3);
	asm("nop");
	asm("nop"); /* give two cycles propagation delay to read the port pin */
	out = ioport_get_pin_level(out0);
	test_assert_true(test, out == true, " XCL XOR failure");
}
コード例 #3
0
ファイル: usart_example3.c プロジェクト: InSoonPark/asf
/*! \brief Main function.
 */
int main(void)
{
	uint8_t ping_msg[] = "\n\rPing? ->";
	uint8_t pong_msg[] = "\n\r        Pong! ->";

	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();
	sysclk_init();
	irq_initialize_vectors();
	cpu_irq_enable();

	/* USART options. */
	static usart_xmegae_rs232_options_t USART_SERIAL_OPTIONS = {
		.baudrate = USART_SERIAL_EXAMPLE_BAUDRATE,
		.charlength = USART_SERIAL_CHAR_LENGTH,
		.paritytype = USART_SERIAL_PARITY,
		.stopbits = USART_SERIAL_STOP_BIT,
		.start_frame_detection = false,
		.one_wire = true,
		.pec_length = 0,
		.encoding_type = USART_DECTYPE_DATA_gc,
		.encoding_stream = USART_LUTACT_OFF_gc,
	};

	/* Initialize usart driver in RS232 mode */
	usart_xmegae_init_rs232(USART1_SERIAL_EXAMPLE, &USART_SERIAL_OPTIONS);
	usart_xmegae_init_rs232(USART2_SERIAL_EXAMPLE, &USART_SERIAL_OPTIONS);

	usart_set_rx_interrupt_level(USART1_SERIAL_EXAMPLE, USART_INT_LVL_LO);
	usart_set_rx_interrupt_level(USART2_SERIAL_EXAMPLE, USART_INT_LVL_LO);

	/* To initiate the first transfer "Ping" */
	message2_received = true;

	/* Configure XCL so it copies the PC2 pin to PC4 (it allows to wire PC4
	 * to RS232 TXD pin on STK600 to spy the one wire communication */
	xcl_enable(XCL_ASYNCHRONOUS);
	xcl_port(PC);
	xcl_lut_type(LUT_2LUT2IN);
	xcl_lut_in0(LUT_IN_PINL);
	xcl_lut_in1(LUT_IN_XCL);
	xcl_lut0_output(LUT0_OUT_PIN4);
	xcl_lut_config_delay(DLY11, LUT_DLY_DISABLE, LUT_DLY_DISABLE);
	xcl_lut0_truth(IN0);

	/* Incoming character is process under interrupt
	 * main loop simply enters sleep mode */
	while (true) {
		if (message2_received) {
			/* When "pong" is received, send "ping" */
			gpio_toggle_pin(LED0_GPIO);
			message2_received = false;
			send_onewire_message(USART1_SERIAL_EXAMPLE, ping_msg,
					sizeof(ping_msg));
		}

		if (message1_received) {
			/* When "ping" is received, send "pong" */
			gpio_toggle_pin(LED0_GPIO);
			message1_received = false;
			send_onewire_message(USART2_SERIAL_EXAMPLE, pong_msg,
					sizeof(pong_msg));
		}
	}
}