ipc: Add deregister API support for icmsg backend
Add support for deregister_endpoint IPC service API in icmsg backend. Signed-off-by: Emil Obalski <Emil.Obalski@nordicsemi.no>
This commit is contained in:
parent
93e6f73d62
commit
45f0fb1970
2 changed files with 57 additions and 11 deletions
|
@ -13,4 +13,9 @@ config IPC_SERVICE_BACKEND_ICMSG_CB_BUF_SIZE
|
|||
data bigger than some size, you can safely change this option to
|
||||
reduce RAM consumption in your application.
|
||||
|
||||
# The Icmsg backend in its simplicity requires the system workqueue to execute
|
||||
# at a cooperative priority.
|
||||
config SYSTEM_WORKQUEUE_PRIORITY
|
||||
range -256 -1
|
||||
|
||||
endif # IPC_SERVICE_BACKEND_ICMSG
|
||||
|
|
|
@ -117,6 +117,27 @@ static int mbox_init(const struct device *instance)
|
|||
return mbox_set_enabled(&conf->mbox_rx, 1);
|
||||
}
|
||||
|
||||
static int mbox_deinit(const struct device *instance)
|
||||
{
|
||||
const struct backend_config_t *conf = instance->config;
|
||||
struct backend_data_t *dev_data = instance->data;
|
||||
int err;
|
||||
|
||||
err = mbox_set_enabled(&conf->mbox_rx, 0);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = mbox_register_callback(&conf->mbox_rx, NULL, NULL);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
(void)k_work_cancel(&dev_data->mbox_work);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int register_ept(const struct device *instance, void **token,
|
||||
const struct ipc_ept_cfg *cfg)
|
||||
{
|
||||
|
@ -138,8 +159,18 @@ static int register_ept(const struct device *instance, void **token,
|
|||
return ret;
|
||||
}
|
||||
|
||||
dev_data->tx_ib = spsc_pbuf_init((void *)conf->tx_shm_addr,
|
||||
conf->tx_shm_size,
|
||||
SPSC_PBUF_CACHE);
|
||||
dev_data->rx_ib = (void *)conf->rx_shm_addr;
|
||||
|
||||
ret = spsc_pbuf_write(dev_data->tx_ib, magic, sizeof(magic));
|
||||
if (ret < sizeof(magic)) {
|
||||
if (ret < 0) {
|
||||
__ASSERT_NO_MSG(false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ret < (int)sizeof(magic)) {
|
||||
__ASSERT_NO_MSG(ret == sizeof(magic));
|
||||
return ret;
|
||||
}
|
||||
|
@ -157,6 +188,23 @@ static int register_ept(const struct device *instance, void **token,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int deregister_ept(const struct device *instance, void *token)
|
||||
{
|
||||
struct backend_data_t *dev_data = instance->data;
|
||||
int ret;
|
||||
|
||||
ret = mbox_deinit(instance);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
dev_data->cfg = NULL;
|
||||
|
||||
atomic_set(&dev_data->state, ICMSG_STATE_OFF);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int send(const struct device *instance, void *token,
|
||||
const void *msg, size_t len)
|
||||
{
|
||||
|
@ -187,21 +235,12 @@ static int send(const struct device *instance, void *token,
|
|||
|
||||
const static struct ipc_service_backend backend_ops = {
|
||||
.register_endpoint = register_ept,
|
||||
.deregister_endpoint = deregister_ept,
|
||||
.send = send,
|
||||
};
|
||||
|
||||
static int backend_init(const struct device *instance)
|
||||
{
|
||||
const struct backend_config_t *conf = instance->config;
|
||||
struct backend_data_t *dev_data = instance->data;
|
||||
|
||||
__ASSERT_NO_MSG(conf->tx_shm_size > sizeof(struct spsc_pbuf));
|
||||
|
||||
dev_data->tx_ib = spsc_pbuf_init((void *)conf->tx_shm_addr,
|
||||
conf->tx_shm_size,
|
||||
SPSC_PBUF_CACHE);
|
||||
dev_data->rx_ib = (void *)conf->rx_shm_addr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -215,6 +254,8 @@ static int backend_init(const struct device *instance)
|
|||
.mbox_rx = MBOX_DT_CHANNEL_GET(DT_DRV_INST(i), rx), \
|
||||
}; \
|
||||
\
|
||||
BUILD_ASSERT(DT_REG_SIZE(DT_INST_PHANDLE(i, tx_region)) > \
|
||||
sizeof(struct spsc_pbuf)); \
|
||||
static struct backend_data_t backend_data_##i; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(i, \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue