コード例 #1
0
ファイル: main.c プロジェクト: poussa/js-iot
int send_data(struct device *dev, const void* pBuffer, uint32_t lengthInBytes) 
{
    printf("sending %d bytes ... \n", lengthInBytes);
    const uint8_t *buffer = (const uint8_t*)(pBuffer);
    uint32_t bytesSent = 0;
    uint32_t remaining = lengthInBytes;
    uint32_t len;

    while (bytesSent < lengthInBytes) {
    
        if (remaining >= UART_FIFO_SIZE)
            len = UART_FIFO_SIZE;
        else
            len = remaining;

        uart_irq_tx_enable(dev);
        data_transmitted = false;
        len = uart_fifo_fill(dev, &buffer[bytesSent], len);
        while (data_transmitted == false)
            ;
        uart_irq_tx_disable(dev);

        remaining -= len;
        bytesSent += len;
    }
 
    printf("done %d bytes\n", bytesSent);

    return 0;
}
コード例 #2
0
size_t UARTClass::write( const uint8_t uc_data )
{
  if (!opened)
    return(0);

  // Is the hardware currently busy?
  if (_tx_buffer->_iTail != _tx_buffer->_iHead)
  {
    // If busy we buffer
    int l = (_tx_buffer->_iHead + 1) % SERIAL_BUFFER_SIZE;
    while (_tx_buffer->_iTail == l)
      ; // Spin locks if we're about to overwrite the buffer. This continues once the data is sent

    _tx_buffer->_aucBuffer[_tx_buffer->_iHead] = uc_data;
    _tx_buffer->_iHead = l;
    // Make sure TX interrupt is enabled
    uart_irq_tx_enable(CONFIG_UART_CONSOLE_INDEX);
  }
  else 
  {
     // Bypass buffering and send character directly
     uart_poll_out(CONFIG_UART_CONSOLE_INDEX, uc_data);
  }
  return 1;
}
コード例 #3
0
ファイル: h4.c プロジェクト: 01org/zephyr
static int h4_send(struct net_buf *buf)
{
	BT_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);

	net_buf_put(&tx.fifo, buf);
	uart_irq_tx_enable(h4_dev);

	return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: 32bitmicro/zephyr
static void write_buf_irq(struct device *dev, const char *buf, int len)
{
	int i;

	uart_irq_tx_enable(dev);

	for (i = 0; i < len; i++) {
		data_transmitted = false;
		uart_fifo_fill(dev, &buf[i], 1);
		while (data_transmitted == false)
			;
	}

	uart_irq_tx_disable(dev);
}
コード例 #5
0
ファイル: main.c プロジェクト: rsalveti/zephyr
void main(void)
{
	struct device *dev;
	u32_t baudrate, dtr = 0;
	int ret;

	dev = device_get_binding(CONFIG_CDC_ACM_PORT_NAME);
	if (!dev) {
		SYS_LOG_ERR("CDC ACM device not found");
		return;
	}

	SYS_LOG_DBG("Wait for DTR");

	while (1) {
		uart_line_ctrl_get(dev, LINE_CTRL_DTR, &dtr);
		if (dtr)
			break;
	}

	uart_dev = dev;

	SYS_LOG_DBG("DTR set, continue");

#if CONFIG_DCD_DSR
	/* They are optional, we use them to test the interrupt endpoint */
	ret = uart_line_ctrl_set(dev, LINE_CTRL_DCD, 1);
	if (ret)
		printk("Failed to set DCD, ret code %d\n", ret);

	ret = uart_line_ctrl_set(dev, LINE_CTRL_DSR, 1);
	if (ret)
		printk("Failed to set DSR, ret code %d\n", ret);

	/* Wait 1 sec for the host to do all settings */
	sys_thread_busy_wait(1000000);
#endif
	ret = uart_line_ctrl_get(dev, LINE_CTRL_BAUD_RATE, &baudrate);
	if (ret)
		printk("Failed to get baudrate, ret code %d\n", ret);
	else
		printk("Baudrate detected: %d\n", baudrate);

	SYS_LOG_INF("USB serial initialized");

	/* Initialize net_pkt */
	net_pkt_init();

	/* Initialize RX queue */
	init_rx_queue();

	/* Initialize TX queue */
	init_tx_queue();

	/* Initialize ieee802154 device */
	if (!init_ieee802154()) {
		SYS_LOG_ERR("Unable to initialize ieee802154");
		return;
	};

	uart_irq_callback_set(dev, interrupt_handler);

	/* Enable rx interrupts */
	uart_irq_rx_enable(dev);

	/* Enable tx interrupts */
	uart_irq_tx_enable(dev);
}