1 /*
2 * Copyright 2023 Linaro.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <zephyr/shell/shell.h>
10 #include <zephyr/drivers/ipm.h>
11 #include <zephyr/kernel.h>
12
ipm_receive_callback(const struct device * ipmdev,void * user_data,uint32_t id,volatile void * data)13 static void ipm_receive_callback(const struct device *ipmdev, void *user_data,
14 uint32_t id, volatile void *data)
15 {
16 ARG_UNUSED(ipmdev);
17 ARG_UNUSED(user_data);
18
19 printf("Received IPM notification over IVSHMEM\n");
20 }
21
main(void)22 int main(void)
23 {
24 const struct device *ipm_dev = DEVICE_DT_GET(DT_NODELABEL(ipm_ivshmem0));
25
26 ipm_register_callback(ipm_dev, ipm_receive_callback, NULL);
27 return 0;
28 }
29
cmd_ipm_send(const struct shell * sh,size_t argc,char ** argv)30 static int cmd_ipm_send(const struct shell *sh,
31 size_t argc, char **argv)
32 {
33
34 const struct device *ipm_dev = DEVICE_DT_GET(DT_NODELABEL(ipm_ivshmem0));
35
36 int peer_id = strtol(argv[1], NULL, 10);
37
38 return ipm_send(ipm_dev, 0, peer_id, NULL, 0);
39 }
40
41 SHELL_STATIC_SUBCMD_SET_CREATE(sub_ivshmem_ipm,
42 SHELL_CMD_ARG(ivshmem_ipm_send, NULL,
43 "Send notification to other side using IPM",
44 cmd_ipm_send, 2, 0),
45 SHELL_SUBCMD_SET_END);
46
47 SHELL_CMD_ARG_REGISTER(ivshmem_ipm_send,
48 &sub_ivshmem_ipm,
49 "Send notification to other side using IPM",
50 cmd_ipm_send, 2, 0);
51