diff --git a/include/nrf_rpc/nrf_rpc_uart.h b/include/nrf_rpc/nrf_rpc_uart.h index 5f0a037dacaf..ec265dafd2bd 100644 --- a/include/nrf_rpc/nrf_rpc_uart.h +++ b/include/nrf_rpc/nrf_rpc_uart.h @@ -39,6 +39,9 @@ typedef struct nrf_rpc_uart { hdlc_state_t hdlc_state; uint8_t frame_buffer[NRF_RPC_MAX_FRAME_SIZE]; size_t frame_len; + + /* UART send semaphore */ + struct k_sem uart_tx_sem; } nrf_rpc_uart; extern const struct nrf_rpc_tr_api nrf_rpc_uart_service_api; diff --git a/subsys/bluetooth/rpc/common/bt_rpc_common.c b/subsys/bluetooth/rpc/common/bt_rpc_common.c index 74d29dddd79e..9613af6e03c7 100644 --- a/subsys/bluetooth/rpc/common/bt_rpc_common.c +++ b/subsys/bluetooth/rpc/common/bt_rpc_common.c @@ -25,9 +25,9 @@ BUILD_ASSERT(!IS_ENABLED(CONFIG_BT_BREDR), "BT_RPC does not support BR/EDR"); #if CONFIG_NRF_RPC_IPC_SERVICE NRF_RPC_IPC_TRANSPORT(bt_rpc_tr, DEVICE_DT_GET(DT_NODELABEL(ipc0)), "bt_rpc_ept"); #elif CONFIG_NRF_RPC_UART_TRANSPORT -NRF_RPC_UART_TRANSPORT(bt_rpc_tr, DEVICE_DT_GET(DT_NODELABEL(uart1))); +NRF_RPC_UART_TRANSPORT(rpc_tr, DEVICE_DT_GET(DT_NODELABEL(uart1))); #endif -NRF_RPC_GROUP_DEFINE(bt_rpc_grp, "bt_rpc", &bt_rpc_tr, NULL, NULL, NULL); +NRF_RPC_GROUP_DEFINE(bt_rpc_grp, "bt_rpc", &rpc_tr, NULL, NULL, NULL); enum { CHECK_ENTRY_FLAGS, diff --git a/subsys/net/openthread/rpc/common/ot_rpc_group.c b/subsys/net/openthread/rpc/common/ot_rpc_group.c index 82a56e36f47e..729adc8e062a 100644 --- a/subsys/net/openthread/rpc/common/ot_rpc_group.c +++ b/subsys/net/openthread/rpc/common/ot_rpc_group.c @@ -15,10 +15,12 @@ #if CONFIG_NRF_RPC_IPC_SERVICE NRF_RPC_IPC_TRANSPORT(ot_group_tr, DEVICE_DT_GET(DT_NODELABEL(ipc0)), "ot_rpc_ept"); -#elif CONFIG_NRF_RPC_UART_TRANSPORT -NRF_RPC_UART_TRANSPORT(ot_group_tr, DEVICE_DT_GET(DT_NODELABEL(uart1))); +#elif CONFIG_NRF_RPC_UART_TRANSPORT && !CONFIG_BT_RPC +NRF_RPC_UART_TRANSPORT(rpc_tr, DEVICE_DT_GET(DT_NODELABEL(uart1))); +#elif CONFIG_NRF_RPC_UART_TRANSPORT && CONFIG_BT_RPC +extern const struct nrf_rpc_tr rpc_tr; #endif -NRF_RPC_GROUP_DEFINE(ot_group, "ot", &ot_group_tr, NULL, NULL, NULL); +NRF_RPC_GROUP_DEFINE(ot_group, "ot", &rpc_tr, NULL, NULL, NULL); LOG_MODULE_REGISTER(ot_rpc, LOG_LEVEL_DBG); #ifdef CONFIG_OPENTHREAD_RPC_INITIALIZE_NRF_RPC diff --git a/subsys/nrf_rpc/nrf_rpc_uart.c b/subsys/nrf_rpc/nrf_rpc_uart.c index 82d5369933a5..2b3359e7c7ce 100644 --- a/subsys/nrf_rpc/nrf_rpc_uart.c +++ b/subsys/nrf_rpc/nrf_rpc_uart.c @@ -115,6 +115,11 @@ static int init(const struct nrf_rpc_tr *transport, nrf_rpc_tr_receive_handler_t { struct nrf_rpc_uart *uart_tr = transport->ctx; + if(uart_tr->transport != NULL) { + LOG_DBG("init not needed"); + return 0; + } + uart_tr->transport = transport; LOG_DBG("init called"); @@ -145,6 +150,8 @@ static int init(const struct nrf_rpc_tr *transport, nrf_rpc_tr_receive_handler_t return 0; } + k_sem_init(&uart_tr->uart_tx_sem, 1, 1); + k_work_init(&uart_tr->cb_work, work_handler); ring_buf_init(&uart_tr->rx_ringbuf, sizeof(uart_tr->rx_buffer), uart_tr->rx_buffer); uart_tr->hdlc_state = hdlc_state_unsync; @@ -159,7 +166,7 @@ static int send(const struct nrf_rpc_tr *transport, const uint8_t *data, size_t LOG_HEXDUMP_DBG(data, length, "Sending frame"); struct nrf_rpc_uart *uart_tr = transport->ctx; // uint16_t crc; - + k_sem_take(&uart_tr->uart_tx_sem, K_FOREVER); // crc = crc16_ccitt(0xffff, data, length); uart_poll_out(uart_tr->uart, hdlc_char_delimiter); @@ -179,6 +186,7 @@ static int send(const struct nrf_rpc_tr *transport, const uint8_t *data, size_t uart_poll_out(uart_tr->uart, hdlc_char_delimiter); k_free((void*)data); + k_sem_give(&uart_tr->uart_tx_sem); return 0; }