static inline void process_tx(void) { int bytes; if (!tx.buf) { tx.buf = net_buf_get(&tx.fifo, K_NO_WAIT); if (!tx.buf) { BT_ERR("TX interrupt but no pending buffer!"); uart_irq_tx_disable(h4_dev); return; } } if (!tx.type) { switch (bt_buf_get_type(tx.buf)) { case BT_BUF_ACL_OUT: tx.type = H4_ACL; break; case BT_BUF_CMD: tx.type = H4_CMD; break; default: BT_ERR("Unknown buffer type"); goto done; } bytes = uart_fifo_fill(h4_dev, &tx.type, 1); if (bytes != 1) { BT_WARN("Unable to send H:4 type"); tx.type = H4_NONE; return; } } bytes = uart_fifo_fill(h4_dev, tx.buf->data, tx.buf->len); net_buf_pull(tx.buf, bytes); if (tx.buf->len) { return; } done: tx.type = H4_NONE; net_buf_unref(tx.buf); tx.buf = net_buf_get(&tx.fifo, K_NO_WAIT); if (!tx.buf) { uart_irq_tx_disable(h4_dev); } }
static int bt_uart_send(struct bt_buf *buf) { uint8_t *type; if (bt_buf_headroom(buf) < H4_HEADER_SIZE) { BT_ERR("Not enough headroom in buffer\n"); return -EINVAL; } type = bt_buf_push(buf, 1); switch (buf->type) { case BT_CMD: *type = H4_CMD; break; case BT_ACL_OUT: *type = H4_ACL; break; case BT_EVT: *type = H4_EVT; break; default: BT_ERR("Unknown buf type %u\n", buf->type); return -EINVAL; } return uart_fifo_fill(UART, buf->data, buf->len); }
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; }
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); }
/** * TX - transmit to SLIP interface */ static void tx_thread(void) { SYS_LOG_DBG("TX thread started"); /* Allow to send one TX */ k_sem_give(&tx_sem); while (1) { struct net_pkt *pkt; struct net_buf *buf; size_t len; k_sem_take(&tx_sem, K_FOREVER); pkt = k_fifo_get(&tx_queue, K_FOREVER); buf = net_buf_frag_last(pkt->frags); len = net_pkt_get_len(pkt); SYS_LOG_DBG("Send pkt %p buf %p len %d", pkt, buf, len); hexdump("SLIP <", buf->data, buf->len); /* Remove LQI */ /* TODO: Reuse get_lqi() */ buf->len -= 1; /* remove FCS 2 bytes */ buf->len -= 2; /* SLIP encode and send */ len = slip_buffer(slip_buf, buf); uart_fifo_fill(uart_dev, slip_buf, len); net_pkt_unref(pkt); #if 0 k_yield(); #endif } }
int uart_simple_send(const uint8_t *data, int len) { return uart_fifo_fill(UART, data, len); }