static void interrupt_handler(struct device *unused) { while (uart_irq_update(uart_dev) && uart_irq_is_pending(uart_dev)) { if (uart_irq_tx_ready(uart_dev)) data_transmitted = true; if (uart_irq_rx_ready(uart_dev)) { int len = uart_fifo_read(uart_dev, rx_buffer, sizeof(rx_buffer)); if (len == 0) { printf("RX data ZERO\n"); continue; } else { uart_buf_t *rx_buf = &buf_pool[pool_index]; memcpy(rx_buf->data, rx_buffer, len); rx_buf->len = len; printf("FIFO put (%d): %d bytes\n", pool_index, len); k_fifo_put(&rx_fifo, rx_buf); pool_index++; if (pool_index == BUF_COUNT) pool_index = 0; } } else { printf("ISR: spurious\n"); //break; } } }
void UARTClass::IrqHandler( void ) { uint8_t uc_data; int ret; ret = uart_poll_in(CONFIG_UART_CONSOLE_INDEX, &uc_data); while ( ret != -1 ) { _rx_buffer->store_char(uc_data); ret = uart_poll_in(CONFIG_UART_CONSOLE_INDEX, &uc_data); } // Do we need to keep sending data? if (!uart_irq_tx_ready(CONFIG_UART_CONSOLE_INDEX)) { if (_tx_buffer->_iTail != _tx_buffer->_iHead) { uart_poll_out(CONFIG_UART_CONSOLE_INDEX, _tx_buffer->_aucBuffer[_tx_buffer->_iTail]); _tx_buffer->_iTail = (unsigned int)(_tx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE; } else { // Mask off transmit interrupt so we don't get it anymore uart_irq_tx_disable(CONFIG_UART_CONSOLE_INDEX); } } }
static void interrupt_handler(struct device *dev) { uart_irq_update(dev); if (uart_irq_tx_ready(dev)) { data_transmitted = true; } if (uart_irq_rx_ready(dev)) { uart_fifo_read(dev, &new_data, 1); data_arrived = true; } }
static void bt_uart_isr(struct device *unused) { ARG_UNUSED(unused); while (uart_irq_update(h4_dev) && uart_irq_is_pending(h4_dev)) { if (uart_irq_tx_ready(h4_dev)) { process_tx(); } if (uart_irq_rx_ready(h4_dev)) { process_rx(); } } }
static void interrupt_handler(struct device *dev) { while (uart_irq_update(dev) && uart_irq_is_pending(dev)) { #ifdef VERBOSE_DEBUG SYS_LOG_DBG(""); #endif if (uart_irq_tx_ready(dev)) { #ifdef VERBOSE_DEBUG SYS_LOG_DBG("TX ready interrupt"); #endif k_sem_give(&tx_sem); } if (uart_irq_rx_ready(dev)) { unsigned char byte; #ifdef VERBOSE_DEBUG SYS_LOG_DBG("RX ready interrupt"); #endif while (uart_fifo_read(dev, &byte, sizeof(byte))) { if (slip_process_byte(byte)) { /** * slip_process_byte() returns 1 on * SLIP_END, even after receiving full * packet */ if (!pkt_curr) { SYS_LOG_DBG("Skip SLIP_END"); continue; } SYS_LOG_DBG("Full packet %p", pkt_curr); k_fifo_put(&rx_queue, pkt_curr); pkt_curr = NULL; } } } } }
void bt_uart_isr(void *unused) { static struct bt_buf *buf; static int remaining; ARG_UNUSED(unused); while (uart_irq_update(UART) && uart_irq_is_pending(UART)) { int read; if (!uart_irq_rx_ready(UART)) { if (uart_irq_tx_ready(UART)) { BT_DBG("transmit ready\n"); } else { BT_DBG("spurious interrupt\n"); } continue; } /* Beginning of a new packet */ if (!remaining) { uint8_t type; /* Get packet type */ read = bt_uart_read(UART, &type, sizeof(type), 0); if (read != sizeof(type)) { BT_WARN("Unable to read H4 packet type\n"); continue; } switch (type) { case H4_EVT: buf = bt_uart_evt_recv(&remaining); break; case H4_ACL: buf = bt_uart_acl_recv(&remaining); break; default: BT_ERR("Unknown H4 type %u\n", type); return; } if (buf && remaining > bt_buf_tailroom(buf)) { BT_ERR("Not enough space in buffer\n"); goto failed; } BT_DBG("need to get %u bytes\n", remaining); } if (!buf) { read = bt_uart_discard(UART, remaining); BT_WARN("Discarded %d bytes\n", read); remaining -= read; continue; } read = bt_uart_read(UART, bt_buf_tail(buf), remaining, 0); buf->len += read; remaining -= read; BT_DBG("received %d bytes\n", read); if (!remaining) { BT_DBG("full packet received\n"); /* Pass buffer to the stack */ bt_recv(buf); buf = NULL; } } return; failed: bt_buf_put(buf); remaining = 0; buf = NULL; }
static void bt_uart_isr(struct device *unused) { static int remaining; uint8_t byte; int ret; static uint8_t hdr[4]; ARG_UNUSED(unused); while (uart_irq_update(h5_dev) && uart_irq_is_pending(h5_dev)) { if (!uart_irq_rx_ready(h5_dev)) { if (uart_irq_tx_ready(h5_dev)) { BT_DBG("transmit ready"); } else { BT_DBG("spurious interrupt"); } continue; } ret = uart_fifo_read(h5_dev, &byte, sizeof(byte)); if (!ret) { continue; } switch (h5.rx_state) { case START: if (byte == SLIP_DELIMITER) { h5.rx_state = HEADER; remaining = sizeof(hdr); } break; case HEADER: /* In a case we confuse ending slip delimeter * with starting one. */ if (byte == SLIP_DELIMITER) { remaining = sizeof(hdr); continue; } if (h5_unslip_byte(&byte) < 0) { h5_reset_rx(); continue; } memcpy(&hdr[sizeof(hdr) - remaining], &byte, 1); remaining--; if (remaining) { break; } remaining = H5_HDR_LEN(hdr); switch (H5_HDR_PKT_TYPE(hdr)) { case HCI_EVENT_PKT: h5.rx_buf = bt_buf_get_evt(); if (!h5.rx_buf) { BT_WARN("No available event buffers"); h5_reset_rx(); continue; } h5.rx_state = PAYLOAD; break; case HCI_ACLDATA_PKT: h5.rx_buf = bt_buf_get_acl(); if (!h5.rx_buf) { BT_WARN("No available data buffers"); h5_reset_rx(); continue; } h5.rx_state = PAYLOAD; break; case HCI_3WIRE_LINK_PKT: case HCI_3WIRE_ACK_PKT: h5.rx_buf = net_buf_get(&h5_sig, 0); if (!h5.rx_buf) { BT_WARN("No available signal buffers"); h5_reset_rx(); continue; } h5.rx_state = PAYLOAD; break; default: BT_ERR("Wrong packet type %u", H5_HDR_PKT_TYPE(hdr)); h5.rx_state = END; break; } break; case PAYLOAD: if (h5_unslip_byte(&byte) < 0) { h5_reset_rx(); continue; } memcpy(net_buf_add(h5.rx_buf, sizeof(byte)), &byte, sizeof(byte)); remaining--; if (!remaining) { h5.rx_state = END; } break; case END: if (byte != SLIP_DELIMITER) { BT_ERR("Missing ending SLIP_DELIMITER"); h5_reset_rx(); break; } BT_DBG("Received full packet: type %u", H5_HDR_PKT_TYPE(hdr)); /* Check when full packet is received, it can be done * when parsing packet header but we need to receive * full packet anyway to clear UART. */ if (H5_HDR_RELIABLE(hdr) && H5_HDR_SEQ(hdr) != h5.tx_ack) { BT_ERR("Seq expected %u got %u. Drop packet", h5.tx_ack, H5_HDR_SEQ(hdr)); h5_reset_rx(); break; } h5_process_complete_packet(hdr); h5.rx_state = START; break; } } }
static void bt_uart_isr(struct device *unused) { static struct net_buf *buf; static int remaining; ARG_UNUSED(unused); while (uart_irq_update(h4_dev) && uart_irq_is_pending(h4_dev)) { int read; if (!uart_irq_rx_ready(h4_dev)) { if (uart_irq_tx_ready(h4_dev)) { BT_DBG("transmit ready"); } else { BT_DBG("spurious interrupt"); } continue; } /* Beginning of a new packet */ if (!remaining) { uint8_t type; /* Get packet type */ read = h4_read(h4_dev, &type, sizeof(type), 0); if (read != sizeof(type)) { BT_WARN("Unable to read H4 packet type"); continue; } switch (type) { case H4_EVT: buf = h4_evt_recv(&remaining); break; case H4_ACL: buf = h4_acl_recv(&remaining); break; default: BT_ERR("Unknown H4 type %u", type); return; } BT_DBG("need to get %u bytes", remaining); if (buf && remaining > net_buf_tailroom(buf)) { BT_ERR("Not enough space in buffer"); net_buf_unref(buf); buf = NULL; } } if (!buf) { read = h4_discard(h4_dev, remaining); BT_WARN("Discarded %d bytes", read); remaining -= read; continue; } read = h4_read(h4_dev, net_buf_tail(buf), remaining, 0); buf->len += read; remaining -= read; BT_DBG("received %d bytes", read); if (!remaining) { BT_DBG("full packet received"); /* Pass buffer to the stack */ bt_recv(buf); buf = NULL; } } }
void UARTClass::flush( void ) { while (_tx_buffer->_iHead != _tx_buffer->_iTail); //wait for transmit data to be sent // Wait for transmission to complete while (uart_irq_tx_ready(CONFIG_UART_CONSOLE_INDEX)); }