Skip to content

Commit d349cf8

Browse files
MarekPorwiszrlubos
authored andcommitted
samples: nrf_rpc: ps: Support for disabling RPC communication
Added functions to stop and restore RPC communication. Stopping the communication automatically times out all pending tasks and prevents new communication. Init messages, errors and acks are still allowed. This is intended to allow smooth recovery after failures. Additionally all calbacks that use common API may be cleared. Signed-off-by: Marek Porwisz <[email protected]>
1 parent a5e5ac8 commit d349cf8

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

samples/nrf_rpc/protocols_serialization/client/src/rpc_utils_shell.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <nrf_rpc/rpc_utils/dev_info.h>
1010
#include <nrf_rpc/rpc_utils/remote_shell.h>
1111
#include <nrf_rpc/rpc_utils/system_health.h>
12+
#include <nrf_rpc.h>
1213

1314
#if defined(CONFIG_NRF_RPC_UTILS_DEV_INFO)
1415
static int remote_version_cmd(const struct shell *sh, size_t argc, char *argv[])
@@ -118,6 +119,30 @@ static int cmd_system_health(const struct shell *sh, size_t argc, char *argv[])
118119
}
119120
#endif /* CONFIG_NRF_RPC_UTILS_SYSTEM_HEALTH */
120121

122+
static int cmd_rpc(const struct shell *sh, size_t argc, char *argv[])
123+
{
124+
static bool enabled = true;
125+
int err = 0;
126+
127+
if (argc > 1) {
128+
bool enable = shell_strtobool(argv[1], 10, &err);
129+
130+
if (err == 0) {
131+
if (enable) {
132+
nrf_rpc_resume();
133+
} else {
134+
nrf_rpc_stop(true);
135+
}
136+
137+
enabled = enable;
138+
}
139+
}
140+
141+
shell_print(sh, "RPC is: %s", enabled ? "Enabled" : "Disabled");
142+
143+
return err;
144+
}
145+
121146
SHELL_STATIC_SUBCMD_SET_CREATE(
122147
util_cmds,
123148
#if defined(CONFIG_NRF_RPC_UTILS_DEV_INFO)
@@ -134,6 +159,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
134159
#if defined(CONFIG_NRF_RPC_UTILS_SYSTEM_HEALTH)
135160
SHELL_CMD_ARG(system_health, NULL, "Get system health", cmd_system_health, 0, 0),
136161
#endif
162+
SHELL_CMD_ARG(control, NULL, "Control RPC subsystem ", cmd_rpc, 2, 0),
137163
SHELL_SUBCMD_SET_END);
138164

139165
SHELL_CMD_ARG_REGISTER(rpc, &util_cmds, "nRF RPC utility commands", NULL, 1, 0);

subsys/nrf_rpc/nrf_rpc_cbkproxy.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <stdint.h>
99

1010
#include <zephyr/kernel.h>
11-
11+
#include <nrf_rpc.h>
1212
#include <nrf_rpc/nrf_rpc_cbkproxy.h>
1313

1414
static K_MUTEX_DEFINE(mutex);
@@ -141,16 +141,27 @@ static struct
141141

142142
static uint32_t next_free_in_slot;
143143

144+
static void nrf_rpc_cbproxy_clear(void *context)
145+
{
146+
k_mutex_lock(&mutex, K_FOREVER);
147+
memset(in_slots, 0, sizeof(in_slots));
148+
next_free_in_slot = 0;
149+
k_mutex_unlock(&mutex);
150+
}
151+
144152
int nrf_rpc_cbkproxy_in_set(void *callback)
145153
{
146154
int index = 0;
147155
uint16_t *attach_to = NULL;
148156
uintptr_t callback_int = (uintptr_t)callback;
157+
static struct nrf_rpc_cleanup_handler cleanup_handler;
149158

150159
k_mutex_lock(&mutex, K_FOREVER);
151160

152161
if (next_free_in_slot == 0) {
153162
attach_to = &in_slots[0].lt;
163+
cleanup_handler.handler = nrf_rpc_cbproxy_clear;
164+
nrf_rpc_register_cleanup_handler(&cleanup_handler);
154165
} else {
155166
do {
156167
if (callback_int == in_slots[index].callback) {

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ manifest:
144144
- name: nrfxlib
145145
repo-path: sdk-nrfxlib
146146
path: nrfxlib
147-
revision: 1d88c4484f24820c7cad542916080f409db9257d
147+
revision: 545ef5d19d2e1d1d7a9d4e0cf238c5164dfaac14
148148
- name: trusted-firmware-m
149149
repo-path: sdk-trusted-firmware-m
150150
path: modules/tee/tf-m/trusted-firmware-m

0 commit comments

Comments
 (0)