Exemple #1
0
/**
 * \brief Test checking different registers of the USART module
 *
 * This function calls the different check functions and make sure they set the
 * correct values.
 *
 * \param test Current test case.
 */
static void run_check_registers_test(const struct test_case *test)
{
	bool success;
	uint8_t data = 'b';

	
	const usart_rs232_options_t options = {
		.baudrate   = CONF_UNIT_BAUDRATE,
		.charlength = CONF_UNIT_CHARLENGTH,
		.paritytype = CONF_UNIT_PARITY,
		.stopbits   = CONF_UNIT_STOPBITS
	};

	usart_init_rs232(&CONF_UNIT_USART, &options);
      
	/* Test empty data register */
	success = usart_data_register_is_empty(&CONF_UNIT_USART);
	test_assert_true(test, success,
			"Checking if the data register is empty failed");
	
	/* Test finished data transfers */
	usart_put(&CONF_UNIT_USART, data);
	for(volatile uint16_t delay=0;delay<20000;delay++);
    
	success = usart_rx_is_complete(&CONF_UNIT_USART);
	usart_get(&CONF_UNIT_USART);
	test_assert_true(test, success,
   	                "Checking if the receive is finished failed");		       
					
	success = usart_tx_is_complete(&CONF_UNIT_USART);
	test_assert_true(test, success,
	                "Checking if the transmit is finished failed");

}
Exemple #2
0
/** Initializes the sensor platform - as this calls the board and sysclock
 *  init functions internally, it will also wait for any pending serial
 *  transfer(s) to complete before calling sensor_platform_init() and will
 *  re-initialize the USART afterwards to ensure no corrupt or lost data.
 */
static void configure_sensor_platform(void)
{
#if XMEGA
	usart_clear_tx_complete(CONF_TEST_USART);
	while (!usart_tx_is_complete(CONF_TEST_USART));
#elif UC3
	while (!(usart_tx_empty(CONF_TEST_USART)));
#endif

	sensor_platform_init();

	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);	
}
Exemple #3
0
/*! \brief Main function.
 */
int main(void)
{
	uint8_t tx_buf[] = "\n\rHello AVR world ! : ";
	uint8_t i;

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

	/* 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 = false,
		.pec_length = USART_SERIAL_VARIABLE_CHAR_LENGTH,
		.pec_action = USART_PECACT_PERC01_gc,
		.encoding_type = USART_DECTYPE_DATA_gc,
		.encoding_stream = USART_LUTACT_OFF_gc,
	};

	/* Initialize usart driver in RS232 mode */
	usart_xmegae_init_rs232(USART_SERIAL_EXAMPLE, &USART_SERIAL_OPTIONS);
	usart_set_rx_interrupt_level(USART_SERIAL_EXAMPLE, USART_INT_LVL_LO);

	/* Send "message header" */
	for (i = 0; i < sizeof(tx_buf); i++) {
		usart_putchar(USART_SERIAL_EXAMPLE, tx_buf[i]);
		while (!usart_tx_is_complete(USART_SERIAL_EXAMPLE)) {
		}
		usart_clear_tx_complete(USART_SERIAL_EXAMPLE);
	}

	/* Incoming character is process under interrupt
	 * main loop simply enters sleep mode */
	while (true) {
		sleepmgr_enter_sleep();
	}
}
/**
 * \internal
 * \brief Helper function to wait for the last send operation to complete
 */
__always_inline static void ili9341_wait_for_send_done(void)
{
#if defined(CONF_ILI9341_USART_SPI)
#  if XMEGA
	while (!usart_tx_is_complete(CONF_ILI9341_USART_SPI)) {
		/* Do nothing */
	}
	usart_clear_tx_complete(CONF_ILI9341_USART_SPI);
#  else
	/* Wait for TX to complete */
	while (!usart_spi_is_tx_empty(CONF_ILI9341_USART_SPI)) {
		/* Do nothing */
	}
#  endif
#elif defined(CONF_ILI9341_SPI)
	/* Wait for TX to complete */
	while (!spi_is_tx_empty(CONF_ILI9341_SPI)) {
		/* Do nothing */
	}
#endif
}
Exemple #5
0
/*! \brief Main function.
 */
int main(void)
{
	uint8_t encoded_message[] = {
		0xF2, 0xF5, 0xAB, 0x97, 0x96, 0x8C, 0xDF, 0x96, 0x91, 0xDF,
		0x9E, 0x91, 0xDF, 0x9A, 0x91, 0x9C, 0x90, 0x9B, 0x9A, 0x9B,
		0xDF, 0x92, 0x9A, 0x8C, 0x8C, 0x9E, 0x98, 0x9A, 0xDF, 0x8C,
		0x9A, 0x91, 0x8B, 0xDF, 0x99, 0x8D, 0x90, 0x92,
		0xDF, 0xA7, 0xB2, 0xBA, 0xB8, 0xBE, 0xDF, 0xAA,
		0xAC, 0xBE, 0xAD, 0xAB, 0xDE
	};
	uint8_t i;

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

	/* 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 = false,
		.pec_length = USART_SERIAL_VARIABLE_CHAR_LENGTH,
		.pec_action = USART_PECACT_PERC01_gc,
		.encoding_type = USART_DECTYPE_DATA_gc,
		.encoding_stream = USART_LUTACT_BOTH_gc,
	};

	/* Initialize usart driver in RS232 mode */
	usart_xmegae_init_rs232(USART_SERIAL_EXAMPLE, &USART_SERIAL_OPTIONS);
	usart_set_rx_interrupt_level(USART_SERIAL_EXAMPLE, USART_INT_LVL_LO);

	xcl_port(USART_SERIAL_XCL_PORT);
	xcl_lut_type(LUT_2LUT2IN);
	xcl_lut_in0(USART_SERIAL_LUT_IN_PIN);
	xcl_lut_in1(LUT_IN_XCL);
	xcl_lut0_output(LUT0_OUT_DISABLE);
	xcl_lut_config_delay(DLY11, LUT_DLY_DISABLE, LUT_DLY_DISABLE);
	xcl_lut0_truth(NOT_IN0);

	xcl_lut_in2(LUT_IN_XCL);
	xcl_lut_in3(LUT_IN_XCL);
	xcl_lut1_truth(NOT_IN3);

	/* Send "message header" */
	for (i = 0; i < sizeof(encoded_message); i++) {
		usart_putchar(USART_SERIAL_EXAMPLE, encoded_message[i]);
		while (!usart_tx_is_complete(USART_SERIAL_EXAMPLE)) {
		}
		usart_clear_tx_complete(USART_SERIAL_EXAMPLE);
	}

	/* Incoming character is process under interrupt
	 * main loop simply enters sleep mode */
	while (true) {
		sleepmgr_enter_sleep();
	}
}