1 /*
2  * Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <zephyr/kernel.h>
10 #include <zephyr/drivers/mbox.h>
11 
12 #define TX_ID (0)
13 #define RX_ID (1)
14 
callback(const struct device * dev,uint32_t channel,void * user_data,struct mbox_msg * data)15 static void callback(const struct device *dev, uint32_t channel,
16 		     void *user_data, struct mbox_msg *data)
17 {
18 	printk("Pong (on channel %d)\n", channel);
19 }
20 
main(void)21 int main(void)
22 {
23 	struct mbox_channel tx_channel;
24 	struct mbox_channel rx_channel;
25 	const struct device *dev;
26 
27 	printk("Hello from NET\n");
28 
29 	dev = DEVICE_DT_GET(DT_NODELABEL(mbox));
30 
31 	mbox_init_channel(&tx_channel, dev, TX_ID);
32 	mbox_init_channel(&rx_channel, dev, RX_ID);
33 
34 	if (mbox_register_callback(&rx_channel, callback, NULL)) {
35 		printk("mbox_register_callback() error\n");
36 		return 0;
37 	}
38 
39 	if (mbox_set_enabled(&rx_channel, 1)) {
40 		printk("mbox_set_enable() error\n");
41 		return 0;
42 	}
43 
44 	while (1) {
45 
46 		printk("Ping (on channel %d)\n", tx_channel.id);
47 
48 		if (mbox_send(&tx_channel, NULL) < 0) {
49 			printk("mbox_send() error\n");
50 			return 0;
51 		}
52 
53 		k_sleep(K_MSEC(3000));
54 	}
55 	return 0;
56 }
57