__STATIC_INLINE bool check_pending_tx() { bool tx_continue = false; if (m_header_pending.p_buffer != NULL) { m_header = m_header_pending; m_payload = m_payload_pending; m_crc = m_crc_pending; m_header_pending.p_buffer = NULL; m_header_pending.num_of_bytes = 0; m_payload_pending.p_buffer = NULL; m_payload_pending.num_of_bytes = 0; m_crc_pending.p_buffer = NULL; m_crc_pending.num_of_bytes = 0; m_tx_index = 0; // may be also done in ser_phy_hci_tx_byte??? tx_continue = true; /* Start sending pending packet */ (void)ser_phy_hci_tx_byte(); } return tx_continue; }
uint32_t ser_phy_hci_slip_tx_pkt_send(const ser_phy_hci_pkt_params_t * p_header, const ser_phy_hci_pkt_params_t * p_payload, const ser_phy_hci_pkt_params_t * p_crc) { /* Block TXRDY interrupts at this point*/ // NRF_UART0->INTENCLR = (UART_INTENCLR_TXDRDY_Clear << UART_INTENCLR_TXDRDY_Pos); CRITICAL_REGION_ENTER(); if (p_header == NULL) { return NRF_ERROR_NULL; } /* Check if no tx is ongoing */ if (!m_tx_busy) { m_header = *p_header; if (p_payload != NULL) { m_payload = *p_payload; } if (p_crc != NULL) { m_crc = *p_crc; } } /* Tx is ongoing, schedule transmission as pending */ else { if (p_crc != NULL) { m_crc_pending = *p_crc; } if (p_payload != NULL) { m_payload_pending = *p_payload; } m_header_pending = *p_header; } /* Start packet transmission only if no other tx is ongoing */ if (!m_tx_busy) { m_tx_busy = true; (void)ser_phy_hci_tx_byte(); } /* Enable TXRDY interrupts at this point*/ // NRF_UART0->INTENSET = (UART_INTENSET_TXDRDY_Set << UART_INTENSET_TXDRDY_Pos); CRITICAL_REGION_EXIT(); return NRF_SUCCESS; }
static void ser_phy_uart_evt_callback(app_uart_evt_t * uart_evt) { if (uart_evt == NULL) { return; } switch (uart_evt->evt_type) { case APP_UART_COMMUNICATION_ERROR: // Process error only if this is parity or overrun error. // Break and framing error is always present when app side is not active if (uart_evt->data.error_communication & (UART_ERRORSRC_PARITY_Msk | UART_ERRORSRC_OVERRUN_Msk)) { callback_hw_error(uart_evt->data.error_communication); } break; case APP_UART_TX_EMPTY: (void)ser_phy_hci_tx_byte(); break; case APP_UART_DATA: // After first reception disable pulldown - it was only needed before start // of the other side if (!m_other_side_active) { nrf_gpio_cfg_input(comm_params.rx_pin_no, NRF_GPIO_PIN_NOPULL); m_other_side_active = true; } m_rx_byte = uart_evt->data.value; ser_phi_hci_rx_byte(m_rx_byte); break; default: APP_ERROR_CHECK(NRF_ERROR_INTERNAL); break; } }