1 /*
2  * Copyright (c) 2021 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/device.h>
9 #include <hal/nrf_ipc.h>
10 #include <zephyr/sys/printk.h>
11 #include <zephyr/logging/log.h>
12 LOG_MODULE_REGISTER(main);
13 
14 #if (CONFIG_SOC_SERIES_BSIM_NRFXX)
15 #include "nsi_cpu_if.h"
16 
17 /* For simulation, we can define shared memory variables linkable from
18  * other MCUs just by using NATIVE_SIMULATOR_IF
19  */
20 NATIVE_SIMULATOR_IF_DATA uint32_t shared_cell_buffer;
21 static uint32_t shared_cell = (uintptr_t)&shared_cell_buffer;
22 #else
23 static uint32_t shared_cell = 0x20070000;
24 #endif
25 
timeout_handler(struct k_timer * timer)26 static void timeout_handler(struct k_timer *timer)
27 {
28 	nrf_ipc_task_t task = offsetof(NRF_IPC_Type, TASKS_SEND[2]);
29 	uint32_t now = sys_clock_tick_get_32();
30 
31 	*(volatile uint32_t *)shared_cell = now;
32 	nrf_ipc_task_trigger(NRF_IPC, task);
33 
34 	LOG_INF("IPC send at %d ticks", now);
35 
36 	/* Do it only for the first second. */
37 	if (now > sys_clock_hw_cycles_per_sec()) {
38 		k_timer_stop(timer);
39 	}
40 }
41 
42 K_TIMER_DEFINE(timer, timeout_handler, NULL);
43 
main(void)44 int main(void)
45 {
46 	LOG_INF("Synchronization using %s driver", IS_ENABLED(CONFIG_MBOX) ? "mbox" : "ipm");
47 	k_timer_start(&timer, K_MSEC(50), K_MSEC(50));
48 	return 0;
49 }
50