1 /*
2  * Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <stdio.h>
8 #include <zephyr/kernel.h>
9 #include <zephyr/device.h>
10 #include <zephyr/sys/printk.h>
11 #include <zephyr/drivers/ipm.h>
12 
13 static const struct device *ipm_dev;
14 static char resp[64];
15 struct k_sem sync;
16 
ipm_receive_callback(const struct device * ipmdev,void * user_data,uint32_t id,volatile void * data)17 static void ipm_receive_callback(const struct device *ipmdev, void *user_data, uint32_t id,
18 				 volatile void *data)
19 {
20 	k_sem_give(&sync);
21 }
22 
main(void)23 int main(void)
24 {
25 	k_sem_init(&sync, 0, 1);
26 
27 	ipm_dev = DEVICE_DT_GET(DT_NODELABEL(ipm0));
28 	if (!ipm_dev) {
29 		printk("Failed to get IPM device.\n\r");
30 		return 0;
31 	}
32 
33 	ipm_register_callback(ipm_dev, ipm_receive_callback, NULL);
34 
35 	while (1) {
36 		k_sem_take(&sync, K_FOREVER);
37 		snprintf(resp, sizeof(resp), "APP_CPU uptime ticks %lli\n", k_uptime_ticks());
38 		ipm_send(ipm_dev, -1, sizeof(resp), &resp, sizeof(resp));
39 	}
40 
41 	return 0;
42 }
43