Skip to content

Commit 7c50719

Browse files
Damian-Nordicrlubos
authored andcommitted
nrf_rpc: unify nRF RPC initialization
Currently, almost each component implementing RPC function encoders and decoders, provides an option to automatically start nRF RPC during the system startup. Reduce the code duplication by introducing CONFIG_NRF_RPC_INIT that handles starting nRF RPC regardless of the enabled RPC serialization libraries. Signed-off-by: Damian Krolik <[email protected]>
1 parent afd5026 commit 7c50719

File tree

10 files changed

+61
-95
lines changed

10 files changed

+61
-95
lines changed

samples/nrf_rpc/protocols_serialization/client/snippets/ble/ble.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2144
99
# Enable and configure Bluetooth LE
1010
CONFIG_BT=y
1111
CONFIG_BT_RPC_STACK=y
12-
CONFIG_BT_RPC_INITIALIZE_NRF_RPC=n
12+
CONFIG_NRF_RPC_INIT=n
1313
CONFIG_BT_RPC_GATT_SRV_MAX=4
1414
CONFIG_BT_PERIPHERAL=y
1515
CONFIG_BT_MAX_CONN=1

samples/nrf_rpc/protocols_serialization/server/snippets/ble/ble.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
CONFIG_BT=y
99
CONFIG_BT_RPC=y
1010
CONFIG_BT_RPC_HOST=y
11-
CONFIG_BT_RPC_INITIALIZE_NRF_RPC=n
11+
CONFIG_NRF_RPC_INIT=n
1212

1313
CONFIG_BT_PERIPHERAL=y
1414
CONFIG_BT_MAX_CONN=1

subsys/bluetooth/rpc/Kconfig

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ config BT_RPC
99
default y if BT_RPC_STACK
1010
select NRF_RPC
1111
select NRF_RPC_CBOR
12+
imply NRF_RPC_INIT
1213
select EXPERIMENTAL
1314
depends on BT
1415
depends on !BT_ISO_UNICAST
@@ -48,13 +49,6 @@ config BT_RPC_HOST
4849

4950
endchoice
5051

51-
config BT_RPC_INITIALIZE_NRF_RPC
52-
bool "Automatically initialize nRF RPC library"
53-
default y
54-
help
55-
Initialize nRF RPC library during the system startup. Disabling this
56-
option allow user to initialize it in a different way.
57-
5852
config BT_RPC_GATT_SRV_MAX
5953
int "Maximum number of GATT services"
6054
default 4

subsys/bluetooth/rpc/common/bt_rpc_common.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,6 @@ NRF_RPC_IPC_TRANSPORT(bt_rpc_tr, DEVICE_DT_GET(DT_NODELABEL(ipc0)), "bt_rpc_ept"
2828
#endif
2929
NRF_RPC_GROUP_DEFINE(bt_rpc_grp, "bt_rpc", &bt_rpc_tr, NULL, NULL, NULL);
3030

31-
#if CONFIG_BT_RPC_INITIALIZE_NRF_RPC
32-
static void err_handler(const struct nrf_rpc_err_report *report)
33-
{
34-
LOG_ERR("nRF RPC error %d ocurred. See nRF RPC logs for more details.",
35-
report->code);
36-
k_oops();
37-
}
38-
39-
static int serialization_init(void)
40-
{
41-
42-
int err;
43-
44-
LOG_DBG("Init begin");
45-
46-
err = nrf_rpc_init(err_handler);
47-
if (err) {
48-
return -EINVAL;
49-
}
50-
51-
LOG_DBG("Init done\n");
52-
53-
return 0;
54-
}
55-
56-
SYS_INIT(serialization_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
57-
#endif /* CONFIG_BT_RPC_INITIALIZE_NRF_RPC */
58-
5931
enum {
6032
CHECK_ENTRY_FLAGS,
6133
CHECK_ENTRY_UINT,

subsys/net/openthread/rpc/Kconfig

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,4 @@ config OPENTHREAD_RPC_ERASE_SETTINGS
9696

9797
endmenu # "OpenThread over RPC server configuration"
9898

99-
config OPENTHREAD_RPC_INITIALIZE_NRF_RPC
100-
bool "Automatically initialize nRF RPC library"
101-
default n
102-
help
103-
Initialize nRF RPC library during the system startup. Disabling this
104-
option allow user to initialize it in a different way.
105-
10699
endif # OPENTHREAD_RPC

subsys/net/openthread/rpc/common/ot_rpc_group.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,3 @@ NRF_RPC_IPC_TRANSPORT(ot_rpc_tr, DEVICE_DT_GET(DT_NODELABEL(ipc0)), "ot_rpc_ept"
2424
#endif
2525
NRF_RPC_GROUP_DEFINE(ot_group, "ot", &ot_rpc_tr, NULL, NULL, NULL);
2626
LOG_MODULE_REGISTER(ot_rpc, LOG_LEVEL_DBG);
27-
28-
#ifdef CONFIG_OPENTHREAD_RPC_INITIALIZE_NRF_RPC
29-
static void err_handler(const struct nrf_rpc_err_report *report)
30-
{
31-
LOG_ERR("nRF RPC error %d ocurred. See nRF RPC logs for more details", report->code);
32-
k_oops();
33-
}
34-
35-
static int serialization_init(void)
36-
{
37-
int err;
38-
39-
err = nrf_rpc_init(err_handler);
40-
if (err) {
41-
return -EINVAL;
42-
}
43-
44-
return 0;
45-
}
46-
47-
SYS_INIT(serialization_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY);
48-
#endif /* CONFIG_OPENTHREAD_RPC_INITIALIZE_NRF_RPC */

subsys/nfc/rpc/common/nfc_rpc_group.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,3 @@ NRF_RPC_IPC_TRANSPORT(nfc_rpc_tr, DEVICE_DT_GET(DT_NODELABEL(ipc0)), "nfc_rpc_ep
2525
#endif
2626
NRF_RPC_GROUP_DEFINE(nfc_group, "nfc", &nfc_rpc_tr, NULL, NULL, NULL);
2727
LOG_MODULE_REGISTER(nfc_rpc, LOG_LEVEL_DBG);
28-
29-
#ifdef CONFIG_NFC_RPC_INITIALIZE_NRF_RPC
30-
static void err_handler(const struct nrf_rpc_err_report *report)
31-
{
32-
LOG_ERR("nRF RPC error %d ocurred. See nRF RPC logs for more details", report->code);
33-
k_oops();
34-
}
35-
36-
static int serialization_init(void)
37-
{
38-
int err;
39-
40-
err = nrf_rpc_init(err_handler);
41-
if (err) {
42-
return -EINVAL;
43-
}
44-
45-
return 0;
46-
}
47-
48-
SYS_INIT(serialization_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY);
49-
#endif /* CONFIG_NFC_RPC_INITIALIZE_NRF_RPC */

subsys/nrf_rpc/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ zephyr_library_sources_ifdef(CONFIG_NRF_RPC_CALLBACK_PROXY nrf_rpc_cbkproxy.c)
1818

1919
zephyr_library_sources_ifdef(CONFIG_NRF_RPC_UART_TRANSPORT nrf_rpc_uart.c)
2020

21+
zephyr_library_sources_ifdef(CONFIG_NRF_RPC_INIT nrf_rpc_init.c)
22+
2123
add_subdirectory_ifdef(CONFIG_NRF_RPC_UTILS rpc_utils)

subsys/nrf_rpc/Kconfig

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ config _NRF_RPC_DUMMY_SELECT
1515
default y
1616
select THREAD_CUSTOM_DATA
1717

18+
config NRF_RPC_CBOR
19+
select ZCBOR
20+
select ZCBOR_STOP_ON_ERROR
21+
22+
# End of Zephyr port dependencies selection
23+
1824
choice NRF_RPC_TRANSPORT
1925
prompt "NRF RPC transport"
2026
default NRF_RPC_IPC_SERVICE
@@ -109,13 +115,6 @@ endif # NRF_RPC_UART_RELIABLE
109115

110116
endmenu # "nRF RPC over UART configuration"
111117

112-
config NRF_RPC_CBOR
113-
bool
114-
select ZCBOR
115-
select ZCBOR_STOP_ON_ERROR
116-
117-
# End of Zephyr port dependencies selection
118-
119118
config NRF_RPC_THREAD_STACK_SIZE
120119
int "Stack size of thread from thread pool"
121120
default 1024
@@ -174,6 +173,11 @@ config NRF_RPC_CBKPROXY_IN_SLOTS
174173

175174
endif # NRF_RPC_CALLBACK_PROXY
176175

176+
config NRF_RPC_INIT
177+
bool "Automatically initialize nRF RPC library"
178+
help
179+
Initialize nRF RPC library during the system startup.
180+
177181
module = NRF_RPC
178182
module-str = NRF_RPC
179183
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
@@ -194,6 +198,14 @@ source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
194198

195199
endif # NRF_RPC_CBOR
196200

201+
if NRF_RPC_INIT
202+
203+
module = NRF_RPC_INIT
204+
module-str = NRF_RPC_INIT
205+
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
206+
207+
endif # NRF_RPC_INIT
208+
197209
rsource "rpc_utils/Kconfig"
198210

199211
endif # NRF_RPC

subsys/nrf_rpc/nrf_rpc_init.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#define NRF_RPC_LOG_MODULE NRF_RPC_INIT
8+
#include <nrf_rpc_log.h>
9+
10+
#include <zephyr/init.h>
11+
12+
#include <nrf_rpc.h>
13+
14+
static void err_handler(const struct nrf_rpc_err_report *report)
15+
{
16+
LOG_ERR("nRF RPC error %d ocurred. See nRF RPC logs for more details",
17+
report->code);
18+
k_oops();
19+
}
20+
21+
static int nrf_rpc_sys_init(void)
22+
{
23+
int err;
24+
25+
LOG_DBG("RPC init begin");
26+
27+
err = nrf_rpc_init(err_handler);
28+
if (err) {
29+
return -EINVAL;
30+
}
31+
32+
LOG_DBG("RPC init done");
33+
34+
return 0;
35+
}
36+
37+
SYS_INIT(nrf_rpc_sys_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);

0 commit comments

Comments
 (0)