1 /*
2  * Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/sys/printk.h>
9 #include <zephyr/drivers/ipm.h>
10 #include <zephyr/device.h>
11 #include <string.h>
12 
13 static const char fake_request[] = {"PRO_CPU: Fake request to APP_CPU"};
14 
15 static const struct device *ipm_dev;
16 static char received_string[64];
17 static struct k_sem sync;
18 
ipm_receive_callback(const struct device * ipmdev,void * user_data,uint32_t id,volatile void * data)19 static void ipm_receive_callback(const struct device *ipmdev, void *user_data,
20 			       uint32_t id, volatile void *data)
21 {
22 	ARG_UNUSED(ipmdev);
23 	ARG_UNUSED(user_data);
24 
25 	strcpy(received_string, (const char *)data);
26 	k_sem_give(&sync);
27 }
28 
main(void)29 int main(void)
30 {
31 	k_sem_init(&sync, 0, 1);
32 
33 	ipm_dev = DEVICE_DT_GET(DT_NODELABEL(ipm0));
34 	if (!ipm_dev) {
35 		printk("Failed to get IPM device.\n\r");
36 		return 0;
37 	}
38 
39 	ipm_register_callback(ipm_dev, ipm_receive_callback, NULL);
40 
41 	while (1) {
42 		printk("PRO_CPU is sending a fake request, waiting remote response...\n\r");
43 
44 		ipm_send(ipm_dev, -1, sizeof(fake_request), &fake_request, sizeof(fake_request));
45 		k_sem_take(&sync, K_FOREVER);
46 
47 		printk("PRO_CPU received a message from APP_CPU : %s\n\r", received_string);
48 
49 		k_sleep(K_MSEC(200));
50 	}
51 	return 0;
52 }
53