1 /*
2 * Copyright (c) 2018, NXP
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <zephyr/sys/printk.h>
9 #include <zephyr/device.h>
10 #include <zephyr/drivers/ipm.h>
11
12 int gcounter;
13
ping_ipm_callback(const struct device * dev,void * context,uint32_t id,volatile void * data)14 void ping_ipm_callback(const struct device *dev, void *context,
15 uint32_t id, volatile void *data)
16 {
17 gcounter = *(int *)data;
18 /* Show current ping-pong counter value */
19 printk("Received: %d\n", gcounter);
20 /* Increment on our side */
21 gcounter++;
22 if (gcounter < 100) {
23 /* Send back to the other core */
24 ipm_send(dev, 1, 0, &gcounter, 4);
25 }
26 }
27
main(void)28 int main(void)
29 {
30 int first_message = 1; /* do not start from 0,
31 * zero value can't be sent via mailbox register
32 */
33 const struct device *ipm;
34
35 printk("Hello World from MASTER! %s\n", CONFIG_ARCH);
36
37 /* Get IPM device handle */
38 ipm = DEVICE_DT_GET_ANY(nxp_lpc_mailbox);
39 if (!(ipm && device_is_ready(ipm))) {
40 printk("Could not get IPM device handle!\n");
41 while (1) {
42 }
43 }
44
45 /* Register application callback with no context */
46 ipm_register_callback(ipm, ping_ipm_callback, NULL);
47 /* Enable the IPM device */
48 ipm_set_enabled(ipm, 1);
49
50 /* Send initial message with 4 bytes length*/
51 ipm_send(ipm, 1, 0, &first_message, 4);
52 while (1) {
53 }
54 return 0;
55 }
56