コード例 #1
0
ファイル: main.c プロジェクト: jeez/qmsi
int main(void)
{
	uint32_t baudrate, dtr = 0;
	int bytes_read;

	QM_PUTS("Starting: USB CDC ACM Example");

	qm_irq_request(QM_IRQ_USB_0_INT, qm_usb_0_isr);

	/* Enable the USB VBUS on Quark SE DevBoard. */
	enable_usb_vbus();

	/* Init USB CDC ACM. */
	cdc_acm_init();

	QM_PUTS("CDC ACM Initialized. Waiting for DTR.");
	do {
		cdc_acm_line_ctrl_get(LINE_CTRL_DTR, &dtr);
	} while (!dtr);

	QM_PUTS("DTR set, start test.");

	/* Wait 1 sec for the host to do all settings. */
	clk_sys_udelay(ONE_SEC_UDELAY);

	if (cdc_acm_line_ctrl_get(LINE_CTRL_BAUD_RATE, &baudrate)) {
		QM_PUTS("Failed to get baudrate, ret code.");
	} else {
		QM_PRINTF("Baudrate detected: %d\n", baudrate);
	}

	QM_PUTS("USB CDC ACM set. Switch to the USB Serial Console.");
	cdc_acm_irq_callback_set(interrupt_handler);
	write_data(banner1, strlen(banner1));
	write_data(banner2, strlen(banner2));

	/* Enable RX interrupts. */
	cdc_acm_irq_rx_enable();

	/* Echo the received data. */
	while (1) {
		read_and_echo_data(&bytes_read);
	}

	return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: poussa/js-iot
int main(int argc, char const *argv[])
{
    int ret;

    printf("start buffers: %d, size=%d total size=%d\n",
        sizeof(buf_pool)/sizeof(uart_buf_t), sizeof(uart_buf_t), sizeof(buf_pool));

    uart_dev = device_get_binding(CONFIG_CDC_ACM_PORT_NAME);

    if (uart_dev == NULL) {
        printf("%s: error\n", __FUNCTION__);
        return 0;
    }
 
    ret = uart_line_ctrl_set(uart_dev, LINE_CTRL_BAUD_RATE, 115200);
    if (ret)
        printf("Baudrate set failed %d\n", ret);

    k_sleep(1000);

    uart_irq_rx_disable(uart_dev);
    uart_irq_tx_disable(uart_dev);

    /* drain the fifo */
    uint8_t c;
    while(uart_fifo_read(uart_dev, &c, 1)) {
        continue;
    }

    uart_irq_callback_set(uart_dev, interrupt_handler);
    uart_irq_rx_enable(uart_dev);

    read_and_echo_data(uart_dev);

	return 0;
}