1 /*
2 * Copyright (c) 2021 BrainCo Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <zephyr/device.h>
9 #include <zephyr/drivers/ipm.h>
10 #include <zephyr/drivers/gpio.h>
11 #include <zephyr/sys/printk.h>
12
13 #define SLEEP_TIME_MS 1000
14
15 struct ipm_data {
16 const struct gpio_dt_spec *led;
17 bool led_is_on;
18 };
19
20 static struct ipm_data data;
21
22 static const struct gpio_dt_spec led0 =
23 GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
24
new_message_callback(const struct device * dev,void * user_data,uint32_t id,volatile void * data)25 void new_message_callback(const struct device *dev, void *user_data,
26 uint32_t id, volatile void *data)
27 {
28 struct ipm_data *ipm_data = (struct ipm_data *)user_data;
29
30 gpio_pin_set(ipm_data->led->port, ipm_data->led->pin, (int)ipm_data->led_is_on);
31
32 ipm_data->led_is_on = !ipm_data->led_is_on;
33 }
34
main(void)35 int main(void)
36 {
37 const struct device *const ipm = DEVICE_DT_GET(DT_NODELABEL(mailbox));
38
39 printk("STM32 h7_dual_core application\n");
40
41 if (!device_is_ready(ipm)) {
42 printk("ipm device not ready\n");
43 return 0;
44 }
45
46 if (!gpio_is_ready_dt(&led0)) {
47 printk("led0 device not ready\n");
48 return 0;
49 }
50
51 gpio_pin_configure_dt(&led0, GPIO_OUTPUT_INACTIVE);
52
53 data.led = &led0;
54 data.led_is_on = false;
55
56 ipm_register_callback(ipm, new_message_callback, &data);
57
58 ipm_set_enabled(ipm, 1);
59
60 while (1) {
61 ipm_send(ipm, 0, 0, NULL, 0);
62 k_msleep(SLEEP_TIME_MS);
63 }
64 return 0;
65 }
66