Пример #1
0
/**
 * \brief Test LIN transmit.
 *
 * This test initializes the LIN and start a transmit.
 *
 * \param test Current test case.
 */
static void run_lin_test(const struct test_case *test)
{
	st_lin_message lin_desc;

	/* Enable the peripheral clock in the PMC. */
	pmc_enable_periph_clk(ID_USART0);

	/* Enable LIN transceiver */
	gpio_set_pin_high(PIN_USART0_CTS_IDX);
	gpio_set_pin_high(PIN_USART0_RTS_IDX);

	/* Node 0:  LIN_MASTER_MODE */
	lin_init(USART0, true, LIN_MASTER_NODE_NUM, 9600, sysclk_get_cpu_hz());

	/* Configure lin_descriptor */
	/* Init LIN data Node 0 */
	/* Object 0 */
	lin_desc.uc_id = LIN_FRAME_ID_12;
	lin_desc.uc_dlc = sizeof(lin_data_node);
	lin_desc.lin_cmd = PUBLISH;
	lin_desc.uc_status = 0;
	lin_desc.uc_pt_data = lin_data_node;
	lin_register_descriptor(LIN_MASTER_NODE_NUM, 0, &lin_desc);

	configure_tc();
	/* In case of Master Mode, the timing transmission starts... */
	tc_start(TC0, 0);

	/* Configure and enable interrupt of USART */
	NVIC_EnableIRQ(USART0_IRQn);
	usart_enable_interrupt(USART0, US_IER_LINTC);

	delay_ms(200);
	test_assert_true(test, ul_LIN_int_flag, "LIN transmit failed!");
}
Пример #2
0
/**
 *  \brief Init Usart COM2 master.
 */
static void _init_com_master (void)
{
	uint32_t id = get_usart_id_from_addr(lin_desc2.addr);

	/* Configure Pios usart*/
	pio_configure(&pins_com2[0], ARRAY_SIZE(pins_com2));

	/* Init LIN MASTER data Node 0 */
	lin_init(&lin_desc2, LIN_MASTER_NODE_NUM);

	/* Configure interrupts */
	usart_enable_it(lin_desc2.addr, US_IER_LINTC);
	aic_set_source_vector(id, _com2_master_handler);
}
Пример #3
0
/**
 *  \brief Init Usart COM3 slave.
 */
static void _init_com_slave (void)
{
	uint32_t id = get_usart_id_from_addr(lin_desc3.addr);

	/* Configure Pios usart*/
	pio_configure(&pins_com3[0], ARRAY_SIZE(pins_com3));

	/* Init LIN SLAVE data Node 0 */
	lin_init(&lin_desc3, LIN_SLAVE_NODE_NUM);

	/* Configure interrupts */
	usart_enable_it(lin_desc3.addr, US_IER_LINID);
	aic_set_source_vector(id, _com3_slave_handler);
	aic_enable(id);
}
Пример #4
0
/**
 * \brief This is an example demonstrating the LIN mode of USART IP
 * functionalities using a dedicated USART LIN driver.
 */
int main(void)
{
	st_lin_message lin_desc;
	uint8_t uc_key;

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

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

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

	/* Enable the peripheral clock in the PMC. */
	pmc_enable_periph_clk(ID_USART0);

	/* Enable LIN transceiver */
	gpio_set_pin_high(PIN_USART0_CTS_IDX);
	gpio_set_pin_high(PIN_USART0_RTS_IDX);

	display_menu();

	while (true) {
		while (uart_read(CONSOLE_UART, &uc_key)) {
		}

		switch (uc_key) {
		case 'm':
		case 'M':
			puts("-- Set LIN to Master mode\n\r");

			/* Node 0:  LIN_MASTER_MODE */
			lin_init(USART0, true, LIN_MASTER_NODE_NUM, 9600,
					sysclk_get_cpu_hz());

			/* Configure lin_descriptor */
			/* Init LIN data Node 0 */
			/* Object 0 */
			lin_desc.uc_id = LIN_FRAME_ID_12;
			lin_desc.uc_dlc = sizeof(lin_data_node);
			lin_desc.lin_cmd = PUBLISH;
			lin_desc.uc_status = 0;
			lin_desc.uc_pt_data = lin_data_node;
			lin_register_descriptor(LIN_MASTER_NODE_NUM, 0, &lin_desc);

			configure_tc();
			/* In case of Master Mode, the timing transmission starts. */
			tc_start(TC0, 0);
			break;

		case 's':
		case 'S':
			puts("-- Set LIN to Slave mode\n\r");
			/* Node 0:  LIN_SLAVE_MODE */
			lin_init(USART0, false, LIN_SLAVE_NODE_NUM, 9600,
					sysclk_get_cpu_hz());

			/* Configure lin_descriptor */
			/* Init LIN data Node 0 */
			/* Object 0 */
			lin_desc.uc_id = LIN_FRAME_ID_12;
			lin_desc.uc_dlc = sizeof(lin_data_node);
			lin_desc.lin_cmd = SUBSCRIBE;
			lin_desc.uc_status = 0;
			lin_desc.uc_pt_data = lin_data_node;
			lin_desc.pt_function = lin_slave_task_ID12;
			lin_register_descriptor(LIN_SLAVE_NODE_NUM, 0, &lin_desc);

			/* Configure and enable interrupt of USART. */
			NVIC_EnableIRQ(USART0_IRQn);
			usart_enable_interrupt(USART0, US_IER_LINID);
			/* In case of Slave Mode, only wait for ID reception. */
			break;

		case 'h':
		case 'H':
			display_menu();
			break;
		}
		puts("Press \'h\' or \'H\' to display the main menu again!!\r");
	}
}