Skip to content

Commit 45f0fb1

Browse files
Emil Obalskicarlescufi
authored andcommitted
ipc: Add deregister API support for icmsg backend
Add support for deregister_endpoint IPC service API in icmsg backend. Signed-off-by: Emil Obalski <[email protected]>
1 parent 93e6f73 commit 45f0fb1

File tree

2 files changed

+57
-11
lines changed

2 files changed

+57
-11
lines changed

subsys/ipc/ipc_service/backends/Kconfig.icmsg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ config IPC_SERVICE_BACKEND_ICMSG_CB_BUF_SIZE
1313
data bigger than some size, you can safely change this option to
1414
reduce RAM consumption in your application.
1515

16+
# The Icmsg backend in its simplicity requires the system workqueue to execute
17+
# at a cooperative priority.
18+
config SYSTEM_WORKQUEUE_PRIORITY
19+
range -256 -1
20+
1621
endif # IPC_SERVICE_BACKEND_ICMSG

subsys/ipc/ipc_service/backends/ipc_icmsg.c

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,27 @@ static int mbox_init(const struct device *instance)
117117
return mbox_set_enabled(&conf->mbox_rx, 1);
118118
}
119119

120+
static int mbox_deinit(const struct device *instance)
121+
{
122+
const struct backend_config_t *conf = instance->config;
123+
struct backend_data_t *dev_data = instance->data;
124+
int err;
125+
126+
err = mbox_set_enabled(&conf->mbox_rx, 0);
127+
if (err != 0) {
128+
return err;
129+
}
130+
131+
err = mbox_register_callback(&conf->mbox_rx, NULL, NULL);
132+
if (err != 0) {
133+
return err;
134+
}
135+
136+
(void)k_work_cancel(&dev_data->mbox_work);
137+
138+
return 0;
139+
}
140+
120141
static int register_ept(const struct device *instance, void **token,
121142
const struct ipc_ept_cfg *cfg)
122143
{
@@ -138,8 +159,18 @@ static int register_ept(const struct device *instance, void **token,
138159
return ret;
139160
}
140161

162+
dev_data->tx_ib = spsc_pbuf_init((void *)conf->tx_shm_addr,
163+
conf->tx_shm_size,
164+
SPSC_PBUF_CACHE);
165+
dev_data->rx_ib = (void *)conf->rx_shm_addr;
166+
141167
ret = spsc_pbuf_write(dev_data->tx_ib, magic, sizeof(magic));
142-
if (ret < sizeof(magic)) {
168+
if (ret < 0) {
169+
__ASSERT_NO_MSG(false);
170+
return ret;
171+
}
172+
173+
if (ret < (int)sizeof(magic)) {
143174
__ASSERT_NO_MSG(ret == sizeof(magic));
144175
return ret;
145176
}
@@ -157,6 +188,23 @@ static int register_ept(const struct device *instance, void **token,
157188
return 0;
158189
}
159190

191+
static int deregister_ept(const struct device *instance, void *token)
192+
{
193+
struct backend_data_t *dev_data = instance->data;
194+
int ret;
195+
196+
ret = mbox_deinit(instance);
197+
if (ret) {
198+
return ret;
199+
}
200+
201+
dev_data->cfg = NULL;
202+
203+
atomic_set(&dev_data->state, ICMSG_STATE_OFF);
204+
205+
return 0;
206+
}
207+
160208
static int send(const struct device *instance, void *token,
161209
const void *msg, size_t len)
162210
{
@@ -187,21 +235,12 @@ static int send(const struct device *instance, void *token,
187235

188236
const static struct ipc_service_backend backend_ops = {
189237
.register_endpoint = register_ept,
238+
.deregister_endpoint = deregister_ept,
190239
.send = send,
191240
};
192241

193242
static int backend_init(const struct device *instance)
194243
{
195-
const struct backend_config_t *conf = instance->config;
196-
struct backend_data_t *dev_data = instance->data;
197-
198-
__ASSERT_NO_MSG(conf->tx_shm_size > sizeof(struct spsc_pbuf));
199-
200-
dev_data->tx_ib = spsc_pbuf_init((void *)conf->tx_shm_addr,
201-
conf->tx_shm_size,
202-
SPSC_PBUF_CACHE);
203-
dev_data->rx_ib = (void *)conf->rx_shm_addr;
204-
205244
return 0;
206245
}
207246

@@ -215,6 +254,8 @@ static int backend_init(const struct device *instance)
215254
.mbox_rx = MBOX_DT_CHANNEL_GET(DT_DRV_INST(i), rx), \
216255
}; \
217256
\
257+
BUILD_ASSERT(DT_REG_SIZE(DT_INST_PHANDLE(i, tx_region)) > \
258+
sizeof(struct spsc_pbuf)); \
218259
static struct backend_data_t backend_data_##i; \
219260
\
220261
DEVICE_DT_INST_DEFINE(i, \

0 commit comments

Comments
 (0)