Lines Matching refs:h5
145 static void h5_reset_rx(struct h5_data *h5) in h5_reset_rx() argument
147 if (h5->rx_buf) { in h5_reset_rx()
148 net_buf_unref(h5->rx_buf); in h5_reset_rx()
149 h5->rx_buf = NULL; in h5_reset_rx()
152 h5->rx_state = START; in h5_reset_rx()
182 static void process_unack(struct h5_data *h5) in process_unack() argument
184 uint8_t next_seq = h5->tx_seq; in process_unack()
185 uint8_t number_removed = h5->unack_queue_len; in process_unack()
187 if (!h5->unack_queue_len) { in process_unack()
191 LOG_DBG("rx_ack %u tx_ack %u tx_seq %u unack_queue_len %u", h5->rx_ack, h5->tx_ack, in process_unack()
192 h5->tx_seq, h5->unack_queue_len); in process_unack()
194 while (h5->unack_queue_len > 0) { in process_unack()
195 if (next_seq == h5->rx_ack) { in process_unack()
207 if (next_seq != h5->rx_ack) { in process_unack()
208 LOG_ERR("Wrong sequence: rx_ack %u tx_seq %u next_seq %u", h5->rx_ack, in process_unack()
209 h5->tx_seq, next_seq); in process_unack()
215 struct net_buf *buf = k_fifo_get(&h5->unack_queue, K_NO_WAIT); in process_unack()
226 h5->unack_queue_len--; in process_unack()
297 struct h5_data *h5 = dev->data; in h5_send() local
306 H5_SET_ACK(hdr, h5->tx_ack); in h5_send()
308 (void)k_work_cancel_delayable(&h5->ack_work); in h5_send()
312 H5_SET_SEQ(hdr, h5->tx_seq); in h5_send()
313 h5->tx_seq = (h5->tx_seq + 1) % 8; in h5_send()
341 struct h5_data *h5 = CONTAINER_OF(delayable, struct h5_data, retx_work); in retx_timeout() local
343 LOG_DBG("unack_queue_len %u", h5->unack_queue_len); in retx_timeout()
345 if (h5->unack_queue_len) { in retx_timeout()
352 while ((buf = k_fifo_get(&h5->tx_queue, K_NO_WAIT))) { in retx_timeout()
357 while ((buf = k_fifo_get(&h5->unack_queue, K_NO_WAIT))) { in retx_timeout()
360 k_fifo_put(&h5->tx_queue, buf); in retx_timeout()
361 h5->tx_seq = (h5->tx_seq - 1) & 0x07; in retx_timeout()
362 h5->unack_queue_len--; in retx_timeout()
367 k_fifo_put(&h5->tx_queue, buf); in retx_timeout()
375 struct h5_data *h5 = CONTAINER_OF(delayable, struct h5_data, ack_work); in ack_timeout() local
379 h5_send(h5->dev, NULL, HCI_3WIRE_ACK_PKT, 0); in ack_timeout()
384 struct h5_data *h5 = dev->data; in h5_process_complete_packet() local
390 h5->rx_ack = H5_HDR_ACK(hdr); in h5_process_complete_packet()
394 h5->tx_ack = (h5->tx_ack + 1) % 8; in h5_process_complete_packet()
396 k_work_reschedule(&h5->ack_work, H5_RX_ACK_TIMEOUT); in h5_process_complete_packet()
401 process_unack(h5); in h5_process_complete_packet()
403 buf = h5->rx_buf; in h5_process_complete_packet()
404 h5->rx_buf = NULL; in h5_process_complete_packet()
411 k_fifo_put(&h5->rx_queue, buf); in h5_process_complete_packet()
417 h5->recv(dev, buf); in h5_process_complete_packet()
430 struct h5_data *h5 = dev->data; in bt_uart_isr() local
455 switch (h5->rx_state) { in bt_uart_isr()
458 h5->rx_state = HEADER; in bt_uart_isr()
472 h5_reset_rx(h5); in bt_uart_isr()
490 h5->rx_state = PAYLOAD; in bt_uart_isr()
493 h5->rx_buf = bt_buf_get_rx(BT_BUF_ACL_IN, in bt_uart_isr()
495 if (!h5->rx_buf) { in bt_uart_isr()
497 h5_reset_rx(h5); in bt_uart_isr()
501 h5->rx_state = PAYLOAD; in bt_uart_isr()
504 h5->rx_buf = bt_buf_get_rx(BT_BUF_ISO_IN, K_NO_WAIT); in bt_uart_isr()
505 if (!h5->rx_buf) { in bt_uart_isr()
507 h5_reset_rx(h5); in bt_uart_isr()
511 h5->rx_state = PAYLOAD; in bt_uart_isr()
515 h5->rx_buf = net_buf_alloc(&h5_pool, K_NO_WAIT); in bt_uart_isr()
516 if (!h5->rx_buf) { in bt_uart_isr()
518 h5_reset_rx(h5); in bt_uart_isr()
522 h5->rx_state = PAYLOAD; in bt_uart_isr()
526 h5->rx_state = END; in bt_uart_isr()
530 h5->rx_state = END; in bt_uart_isr()
535 h5_reset_rx(h5); in bt_uart_isr()
542 if (!h5->rx_buf) { in bt_uart_isr()
543 h5->rx_buf = get_evt_buf(byte); in bt_uart_isr()
544 if (!h5->rx_buf) { in bt_uart_isr()
546 h5_reset_rx(h5); in bt_uart_isr()
551 buf_tailroom = net_buf_tailroom(h5->rx_buf); in bt_uart_isr()
555 h5_reset_rx(h5); in bt_uart_isr()
559 net_buf_add_mem(h5->rx_buf, &byte, sizeof(byte)); in bt_uart_isr()
562 h5->rx_state = END; in bt_uart_isr()
568 h5_reset_rx(h5); in bt_uart_isr()
579 H5_HDR_SEQ(hdr) != h5->tx_ack) { in bt_uart_isr()
580 LOG_ERR("Seq expected %u got %u. Drop packet", h5->tx_ack, in bt_uart_isr()
582 h5_reset_rx(h5); in bt_uart_isr()
587 h5->rx_state = START; in bt_uart_isr()
600 struct h5_data *h5 = dev->data; in h5_queue() local
622 k_fifo_put(&h5->tx_queue, buf); in h5_queue()
630 struct h5_data *h5 = dev->data; in tx_thread() local
644 LOG_DBG("link_state %u", h5->link_state); in tx_thread()
646 switch (h5->link_state) { in tx_thread()
656 buf = k_fifo_get(&h5->tx_queue, K_FOREVER); in tx_thread()
664 k_fifo_put(&h5->unack_queue, buf); in tx_thread()
665 h5->unack_queue_len++; in tx_thread()
667 k_work_reschedule(&h5->retx_work, H5_TX_ACK_TIMEOUT); in tx_thread()
674 static void h5_set_txwin(struct h5_data *h5, uint8_t *conf) in h5_set_txwin() argument
676 conf[2] = h5->tx_win & 0x07; in h5_set_txwin()
682 struct h5_data *h5 = dev->data; in rx_thread() local
692 buf = k_fifo_get(&h5->rx_queue, K_FOREVER); in rx_thread()
697 if (h5->link_state == ACTIVE) { in rx_thread()
703 if (h5->link_state == ACTIVE) { in rx_thread()
707 h5->link_state = INIT; in rx_thread()
708 h5_set_txwin(h5, conf_req); in rx_thread()
718 h5_set_txwin(h5, conf_req); in rx_thread()
721 h5->link_state = ACTIVE; in rx_thread()
724 h5->tx_win = (buf->data[2] & 0x07); in rx_thread()
727 LOG_DBG("Finished H5 configuration, tx_win %u", h5->tx_win); in rx_thread()
744 struct h5_data *h5 = dev->data; in h5_init() local
749 h5->link_state = UNINIT; in h5_init()
750 h5->rx_state = START; in h5_init()
751 h5->tx_win = 4U; in h5_init()
754 k_fifo_init(&h5->tx_queue); in h5_init()
761 k_fifo_init(&h5->rx_queue); in h5_init()
769 k_fifo_init(&h5->unack_queue); in h5_init()
772 k_work_init_delayable(&h5->ack_work, ack_timeout); in h5_init()
773 k_work_init_delayable(&h5->retx_work, retx_timeout); in h5_init()
779 struct h5_data *h5 = dev->data; in h5_open() local
786 h5->dev = dev; in h5_open()
788 h5->recv = recv; in h5_open()