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; } } }
static void uart_pipe_isr(struct device *unused) { ARG_UNUSED(unused); while (uart_irq_update(uart_pipe_dev) && uart_irq_is_pending(uart_pipe_dev)) { int rx; if (!uart_irq_rx_ready(uart_pipe_dev)) { continue; } rx = uart_fifo_read(uart_pipe_dev, recv_buf + recv_off, recv_buf_len - recv_off); if (!rx) { continue; } /* * Call application callback with received data. Application * may provide new buffer or alter data offset. */ recv_off += rx; recv_buf = app_cb(recv_buf, &recv_off); } }
/** * ISR that is called when UART bytes are received. */ static void uart_mcumgr_isr(struct device *unused) { struct uart_mcumgr_rx_buf *rx_buf; u8_t buf[32]; int chunk_len; int i; ARG_UNUSED(unused); while (uart_irq_update(uart_mcumgr_dev) && uart_irq_is_pending(uart_mcumgr_dev)) { chunk_len = uart_mcumgr_read_chunk(buf, sizeof(buf)); if (chunk_len == 0) { continue; } for (i = 0; i < chunk_len; i++) { rx_buf = uart_mcumgr_rx_byte(buf[i]); if (rx_buf != NULL) { uart_mgumgr_recv_cb(rx_buf); } } } }
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 uart_simple_isr(void *unused) { ARG_UNUSED(unused); while (uart_irq_update(UART) && uart_irq_is_pending(UART)) { int rx; if (!uart_irq_rx_ready(UART)) { continue; } rx = uart_fifo_read(UART, recv_buf + recv_off, recv_buf_len - recv_off); if (!rx) { continue; } /* Call application callback with received data. Application * may provide new buffer or alter data offset. */ recv_off += rx; recv_buf = app_cb(recv_buf, &recv_off); } }
void uart_console_isr(struct device *unused) { ARG_UNUSED(unused); while (uart_irq_update(uart_console_dev) && uart_irq_is_pending(uart_console_dev)) { static struct uart_console_input *cmd; uint8_t byte; int rx; if (!uart_irq_rx_ready(uart_console_dev)) { continue; } /* Character(s) have been received */ rx = read_uart(uart_console_dev, &byte, 1); if (rx < 0) { return; } if (uart_irq_input_hook(uart_console_dev, byte) != 0) { /* * The input hook indicates that no further processing * should be done by this handler. */ return; } if (!cmd) { cmd = nano_isr_fifo_get(avail_queue, TICKS_NONE); if (!cmd) return; } /* Handle ANSI escape mode */ if (atomic_test_bit(&esc_state, ESC_ANSI)) { handle_ansi(byte); continue; } /* Handle escape mode */ if (atomic_test_and_clear_bit(&esc_state, ESC_ESC)) { switch (byte) { case ANSI_ESC: atomic_set_bit(&esc_state, ESC_ANSI); atomic_set_bit(&esc_state, ESC_ANSI_FIRST); break; default: break; } continue; } /* Handle special control characters */ if (!isprint(byte)) { switch (byte) { case DEL: if (cur > 0) { del_char(&cmd->line[--cur], end); } break; case ESC: atomic_set_bit(&esc_state, ESC_ESC); break; case '\r': cmd->line[cur + end] = '\0'; uart_poll_out(uart_console_dev, '\r'); uart_poll_out(uart_console_dev, '\n'); cur = 0; end = 0; nano_isr_fifo_put(lines_queue, cmd); cmd = NULL; break; case '\t': if (completion_cb && !end) { cur += completion_cb(cmd->line, cur); } break; default: break; } continue; } /* Ignore characters if there's no more buffer space */ if (cur + end < sizeof(cmd->line) - 1) { insert_char(&cmd->line[cur++], byte, end); } } }
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; }
void uart_console_isr(struct device *unused) { ARG_UNUSED(unused); while (uart_irq_update(uart_console_dev) && uart_irq_is_pending(uart_console_dev)) { static struct console_input *cmd; u8_t byte; int rx; if (!uart_irq_rx_ready(uart_console_dev)) { continue; } /* Character(s) have been received */ rx = read_uart(uart_console_dev, &byte, 1); if (rx < 0) { return; } #ifdef CONFIG_UART_CONSOLE_DEBUG_SERVER_HOOKS if (debug_hook_in != NULL && debug_hook_in(byte) != 0) { /* * The input hook indicates that no further processing * should be done by this handler. */ return; } #endif if (!cmd) { cmd = k_fifo_get(avail_queue, K_NO_WAIT); if (!cmd) { return; } } #ifdef CONFIG_UART_CONSOLE_MCUMGR /* Divert this byte from normal console handling if it is part * of an mcumgr frame. */ if (handle_mcumgr(cmd, byte)) { continue; } #endif /* CONFIG_UART_CONSOLE_MCUMGR */ /* Handle ANSI escape mode */ if (atomic_test_bit(&esc_state, ESC_ANSI)) { handle_ansi(byte, cmd->line); continue; } /* Handle escape mode */ if (atomic_test_and_clear_bit(&esc_state, ESC_ESC)) { if (byte == ANSI_ESC) { atomic_set_bit(&esc_state, ESC_ANSI); atomic_set_bit(&esc_state, ESC_ANSI_FIRST); } continue; } /* Handle special control characters */ if (!isprint(byte)) { switch (byte) { case DEL: if (cur > 0) { del_char(&cmd->line[--cur], end); } break; case ESC: atomic_set_bit(&esc_state, ESC_ESC); break; case '\r': cmd->line[cur + end] = '\0'; uart_poll_out(uart_console_dev, '\r'); uart_poll_out(uart_console_dev, '\n'); cur = 0; end = 0; k_fifo_put(lines_queue, cmd); cmd = NULL; break; case '\t': if (completion_cb && !end) { cur += completion_cb(cmd->line, cur); } break; default: break; } continue; } /* Ignore characters if there's no more buffer space */ if (cur + end < sizeof(cmd->line) - 1) { insert_char(&cmd->line[cur++], byte, end); } } }
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; } } }