Skip to content

Commit

Permalink
Fix init BLE and OT on the same build.
Browse files Browse the repository at this point in the history
Signed-off-by: Przemyslaw Bida <[email protected]>
  • Loading branch information
canisLupus1313 authored and Damian-Nordic committed Apr 5, 2024
1 parent 3a52f60 commit fbe00da
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
3 changes: 3 additions & 0 deletions include/nrf_rpc/nrf_rpc_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions subsys/bluetooth/rpc/common/bt_rpc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions subsys/net/openthread/rpc/common/ot_rpc_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion subsys/nrf_rpc/nrf_rpc_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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;
}
Expand Down

0 comments on commit fbe00da

Please sign in to comment.