Пример #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 Button event.
 */
static void _process_button_evt(void)
{
	uint32_t id = get_usart_id_from_addr(lin_desc2.addr);

	switch (key) {
	case 'P':
	case 'p':
		/* No interrupt on Master */
		aic_disable(id);
		/* Configure lin_descriptor MASTER */
		lin_msg_master.id = LIN_FRAME_ID_12;
		lin_msg_master.dlc = sizeof(lin_data_master);
		lin_msg_master.lin_cmd = PUBLISH;
		lin_register_descriptor(LIN_MASTER_NODE_NUM, 0, &lin_msg_master);
		/* Configure lin_descriptor SLAVE */
		lin_msg_slave.id = LIN_FRAME_ID_12;
		lin_msg_slave.dlc = sizeof(lin_data_slave);
		lin_msg_slave.lin_cmd = SUBSCRIBE;
		lin_msg_slave.pfnct = lin_slave_task_ID12,
		lin_register_descriptor(LIN_SLAVE_NODE_NUM, 0, &lin_msg_slave);
		memcpy(&lin_data_master, "12345678", sizeof(lin_data_master));
		break;

	case 'S':
	case 's':
		/* Configure lin_descriptor MASTER */
		lin_msg_master.id = LIN_FRAME_ID_15;
		lin_msg_master.dlc = sizeof(lin_data_master);
		lin_msg_master.lin_cmd = SUBSCRIBE;
		lin_register_descriptor(LIN_MASTER_NODE_NUM, 1, &lin_msg_master);
		/* Configure lin_descriptor SLAVE */
		lin_msg_slave.id = LIN_FRAME_ID_15;
		lin_msg_slave.dlc = sizeof(lin_data_slave);
		lin_msg_slave.lin_cmd = PUBLISH;
		lin_register_descriptor(LIN_SLAVE_NODE_NUM, 1, &lin_msg_slave);
		/* Interrupt Master, wait transfert complete */
		aic_enable(id);
		memcpy(&lin_data_slave, "87654321", sizeof(lin_data_slave));
		break;

	default:
		aic_disable(id);
		lin_msg_master.lin_cmd = IGNORE;
		lin_msg_slave.lin_cmd = IGNORE;
		break;
	}
}
Пример #3
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");
	}
}