Esempio n. 1
0
static int h4_open(void)
{
	BT_DBG("");

	uart_irq_rx_disable(h4_dev);
	uart_irq_tx_disable(h4_dev);

#if defined(CONFIG_BT_NRF51_PM)
	if (nrf51_init(h4_dev) < 0) {
		return -EIO;
	}
#else
	h4_discard(h4_dev, 32);
#endif

	uart_irq_callback_set(h4_dev, bt_uart_isr);

	k_thread_create(&rx_thread_data, rx_thread_stack,
			K_THREAD_STACK_SIZEOF(rx_thread_stack),
			rx_thread, NULL, NULL, NULL,
			K_PRIO_COOP(CONFIG_BT_RX_PRIO),
			0, K_NO_WAIT);

	return 0;
}
Esempio n. 2
0
static void read_char_irq(struct device *dev, char *data)
{
	uart_irq_rx_enable(dev);

	data_arrived = false;
	while (data_arrived == false)
		;
	*data = new_data;

	uart_irq_rx_disable(dev);
}
Esempio n. 3
0
static int read_uart(struct device *uart, uint8_t *buf, unsigned int size)
{
	int rx;

	rx = uart_fifo_read(uart, buf, size);
	if (rx < 0) {
		/* Overrun issue. Stop the UART */
		uart_irq_rx_disable(uart);

		return -EIO;
	}

	return rx;
}
Esempio n. 4
0
File: h4.c Progetto: 01org/zephyr
static void rx_thread(void *p1, void *p2, void *p3)
{
	struct net_buf *buf;

	ARG_UNUSED(p1);
	ARG_UNUSED(p2);
	ARG_UNUSED(p3);

	BT_DBG("started");

	while (1) {
		BT_DBG("rx.buf %p", rx.buf);

		/* We can only do the allocation if we know the initial
		 * header, since Command Complete/Status events must use the
		 * original command buffer (if available).
		 */
		if (rx.have_hdr && !rx.buf) {
			rx.buf = get_rx(K_FOREVER);
			BT_DBG("Got rx.buf %p", rx.buf);
			if (rx.remaining > net_buf_tailroom(rx.buf)) {
				BT_ERR("Not enough space in buffer");
				rx.discard = rx.remaining;
				reset_rx();
			} else {
				copy_hdr(rx.buf);
			}
		}

		/* Let the ISR continue receiving new packets */
		uart_irq_rx_enable(h4_dev);

		buf = net_buf_get(&rx.fifo, K_FOREVER);
		do {
			uart_irq_rx_enable(h4_dev);

			BT_DBG("Calling bt_recv(%p)", buf);
			bt_recv(buf);

			/* Give other threads a chance to run if the ISR
			 * is receiving data so fast that rx.fifo never
			 * or very rarely goes empty.
			 */
			k_yield();

			uart_irq_rx_disable(h4_dev);
			buf = net_buf_get(&rx.fifo, K_NO_WAIT);
		} while (buf);
	}
}
Esempio n. 5
0
void UARTClass::end( void )
{
  int ret=0;
  uint8_t uc_data;
  // Wait for any outstanding data to be sent
  flush();
  uart_irq_rx_disable(CONFIG_UART_CONSOLE_INDEX);
  uart_irq_tx_disable(CONFIG_UART_CONSOLE_INDEX);
  while ( ret != -1 ) {
    ret = uart_poll_in(CONFIG_UART_CONSOLE_INDEX, &uc_data);
  }
  opened = false;
  // Clear any received data
  _rx_buffer->_iHead = _rx_buffer->_iTail;
}
Esempio n. 6
0
static void console_input_init(void)
{
	uint8_t c;

	uart_irq_rx_disable(uart_console_dev);
	uart_irq_tx_disable(uart_console_dev);

	uart_irq_callback_set(uart_console_dev, uart_console_isr);

	/* Drain the fifo */
	while (uart_irq_rx_ready(uart_console_dev)) {
		uart_fifo_read(uart_console_dev, &c, 1);
	}

	uart_irq_rx_enable(uart_console_dev);
}
Esempio n. 7
0
static void uart_pipe_setup(struct device *uart)
{
	uint8_t c;

	uart_irq_rx_disable(uart);
	uart_irq_tx_disable(uart);

	/* Drain the fifo */
	while (uart_fifo_read(uart, &c, 1)) {
		continue;
	}

	uart_irq_callback_set(uart, uart_pipe_isr);

	uart_irq_rx_enable(uart);
}
Esempio n. 8
0
static int h5_open(void)
{
	BT_DBG("");

	uart_irq_rx_disable(h5_dev);
	uart_irq_tx_disable(h5_dev);

	bt_uart_drain(h5_dev);

	uart_irq_callback_set(h5_dev, bt_uart_isr);

	h5_init();

	uart_irq_rx_enable(h5_dev);

	return 0;
}
Esempio n. 9
0
static void uart_simple_setup(int uart, struct uart_init_info *info)
{
	uart_init(uart, info);

	uart_irq_rx_disable(uart);
	uart_irq_tx_disable(uart);
	IRQ_CONFIG(uart_simple, uart_irq_get(uart));
	irq_enable(uart_irq_get(uart));

	/* Drain the fifo */
	while (uart_irq_rx_ready(uart)) {
		unsigned char c;
		uart_fifo_read(uart, &c, 1);
	}

	uart_irq_rx_enable(uart);
}
Esempio n. 10
0
void UARTClass::end( void )
{
  int ret=0;
  uint8_t uc_data;
  // Wait for any outstanding data to be sent
  flush();
  uart_irq_rx_disable(CONFIG_UART_CONSOLE_INDEX);
  uart_irq_tx_disable(CONFIG_UART_CONSOLE_INDEX);
  while ( ret != -1 ) {
    ret = uart_poll_in(CONFIG_UART_CONSOLE_INDEX, &uc_data);
  }
  opened = false;
  // Clear any received data
  _rx_buffer->_iHead = _rx_buffer->_iTail;

  SET_PIN_MODE(17, GPIO_MUX_MODE); // Rdx SOC PIN (Arduino header pin 0)
  SET_PIN_MODE(16, GPIO_MUX_MODE); // Txd SOC PIN (Arduino header pin 1)
}
Esempio n. 11
0
static int bt_monitor_init(struct device *d)
{
	ARG_UNUSED(d);

	monitor_dev = device_get_binding(CONFIG_BLUETOOTH_MONITOR_ON_DEV_NAME);

#if defined(CONFIG_UART_INTERRUPT_DRIVEN)
	uart_irq_rx_disable(monitor_dev);
	uart_irq_tx_disable(monitor_dev);
#endif

#if !defined(CONFIG_UART_CONSOLE)
	__printk_hook_install(monitor_console_out);
	__stdout_hook_install(monitor_console_out);
#endif

	return 0;
}
Esempio n. 12
0
static void bt_uart_setup(int uart, struct uart_init_info *info)
{
	BT_DBG("\n");

	uart_init(uart, info);

	uart_irq_rx_disable(uart);
	uart_irq_tx_disable(uart);
	IRQ_CONFIG(bluetooth, uart_irq_get(uart));
	irq_enable(uart_irq_get(uart));

	/* Drain the fifo */
	while (uart_irq_rx_ready(uart)) {
		unsigned char c;
		uart_fifo_read(uart, &c, 1);
	}

	uart_irq_rx_enable(uart);
}
Esempio n. 13
0
File: h4.c Progetto: CurieBSP/zephyr
static int h4_open(void)
{
	BT_DBG("");

	uart_irq_rx_disable(h4_dev);
	uart_irq_tx_disable(h4_dev);

	/* Drain the fifo */
	while (uart_irq_rx_ready(h4_dev)) {
		unsigned char c;

		uart_fifo_read(h4_dev, &c, 1);
	}

	uart_irq_callback_set(h4_dev, bt_uart_isr);

	uart_irq_rx_enable(h4_dev);

	return 0;
}
Esempio n. 14
0
static int h4_open(void)
{
	BT_DBG("");

	uart_irq_rx_disable(h4_dev);
	uart_irq_tx_disable(h4_dev);

#if defined(CONFIG_BLUETOOTH_NRF51_PM)
	if (nrf51_init(h4_dev) < 0) {
		return -EIO;
	}
#else
	bt_uart_drain(h4_dev);
#endif

	uart_irq_callback_set(h4_dev, bt_uart_isr);

	uart_irq_rx_enable(h4_dev);

	return 0;
}
Esempio n. 15
0
static int h4_open(void)
{
	BT_DBG("");

	uart_irq_rx_disable(h4_dev);
	uart_irq_tx_disable(h4_dev);
	IRQ_CONNECT(CONFIG_BLUETOOTH_UART_IRQ, CONFIG_BLUETOOTH_UART_IRQ_PRI,
		    bt_uart_isr, 0, UART_IRQ_FLAGS);
	irq_enable(CONFIG_BLUETOOTH_UART_IRQ);

	/* Drain the fifo */
	while (uart_irq_rx_ready(h4_dev)) {
		unsigned char c;

		uart_fifo_read(h4_dev, &c, 1);
	}

	uart_irq_rx_enable(h4_dev);

	return 0;
}
Esempio n. 16
0
void UARTClass::init(const uint32_t dwBaudRate, const uint8_t modeReg)
{
  uint8_t c;
  // Make sure both ring buffers are initialized back to empty.
  _rx_buffer->_iHead = _rx_buffer->_iTail = 0;
  _tx_buffer->_iHead = _tx_buffer->_iTail = 0;

  SET_PIN_MODE(17, UART_MUX_MODE); // Rdx SOC PIN (Arduino header pin 0)
  SET_PIN_MODE(16, UART_MUX_MODE); // Txd SOC PIN (Arduino header pin 1)

  info->options = 0;
  info->sys_clk_freq = SYSCLK_DEFAULT_IOSC_HZ;
  info->baud_rate = dwBaudRate;
  info->regs = CONFIG_UART_CONSOLE_REGS;
  info->irq = CONFIG_UART_CONSOLE_IRQ;
  info->int_pri = CONFIG_UART_CONSOLE_INT_PRI;
  info->async_format = modeReg;

  uart_init(CONFIG_UART_CONSOLE_INDEX, info);

  uart_irq_rx_disable(CONFIG_UART_CONSOLE_INDEX);
  uart_irq_tx_disable(CONFIG_UART_CONSOLE_INDEX);

  uart_int_connect(CONFIG_UART_CONSOLE_INDEX,           /* UART to which to connect */
                   UART_Handler, /* interrupt handler */
                   NULL,           /* argument to pass to handler */
                   NULL           /* ptr to interrupt stub code */
                   );

  while (uart_irq_rx_ready(CONFIG_UART_CONSOLE_INDEX))
      uart_fifo_read(CONFIG_UART_CONSOLE_INDEX, &c, 1);


  uart_irq_rx_enable(CONFIG_UART_CONSOLE_INDEX);

}
Esempio n. 17
0
File: main.c Progetto: 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;
}
Esempio n. 18
0
File: h4.c Progetto: 01org/zephyr
static inline void read_payload(void)
{
	struct net_buf *buf;
	bool prio;
	int read;

	if (!rx.buf) {
		rx.buf = get_rx(K_NO_WAIT);
		if (!rx.buf) {
			if (rx.discardable) {
				BT_WARN("Discarding event 0x%02x", rx.evt.evt);
				rx.discard = rx.remaining;
				reset_rx();
				return;
			}

			BT_WARN("Failed to allocate, deferring to rx_thread");
			uart_irq_rx_disable(h4_dev);
			return;
		}

		BT_DBG("Allocated rx.buf %p", rx.buf);

		if (rx.remaining > net_buf_tailroom(rx.buf)) {
			BT_ERR("Not enough space in buffer");
			rx.discard = rx.remaining;
			reset_rx();
			return;
		}

		copy_hdr(rx.buf);
	}

	read = uart_fifo_read(h4_dev, net_buf_tail(rx.buf), rx.remaining);
	net_buf_add(rx.buf, read);
	rx.remaining -= read;

	BT_DBG("got %d bytes, remaining %u", read, rx.remaining);
	BT_DBG("Payload (len %u): %s", rx.buf->len,
	       bt_hex(rx.buf->data, rx.buf->len));

	if (rx.remaining) {
		return;
	}

	prio = (rx.type == H4_EVT && bt_hci_evt_is_prio(rx.evt.evt));

	buf = rx.buf;
	rx.buf = NULL;

	if (rx.type == H4_EVT) {
		bt_buf_set_type(buf, BT_BUF_EVT);
	} else {
		bt_buf_set_type(buf, BT_BUF_ACL_IN);
	}

	reset_rx();

	if (prio) {
		BT_DBG("Calling bt_recv_prio(%p)", buf);
		bt_recv_prio(buf);
	} else {
		BT_DBG("Putting buf %p to rx fifo", buf);
		net_buf_put(&rx.fifo, buf);
	}
}