1 /*
2 * Copyright (c) 2020 Intel Corporation
3 * Copyright 2025 NXP
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 #include <zephyr/kernel.h>
9 #include <zephyr/device.h>
10 #include <zephyr/devicetree.h>
11
12 #include <zephyr/drivers/edac.h>
13
14 #include <zephyr/logging/log.h>
15 LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL);
16
17 #define STACKSIZE 1024
18 #define PRIORITY 15
19
20 static atomic_t handled;
21
22 /**
23 * Callback called from ISR. Runs in supervisor mode
24 */
notification_callback(const struct device * dev,void * data)25 static void notification_callback(const struct device *dev, void *data)
26 {
27 /* Special care need to be taken for NMI callback:
28 * delayed_work, mutex and semaphores are not working stable
29 * here, using integer increment for now
30 */
31 atomic_set(&handled, true);
32 }
33
main(void)34 int main(void)
35 {
36 const struct device *const dev = DEVICE_DT_GET_OR_NULL(DT_CHOSEN(zephyr_edac));
37
38 if (!device_is_ready(dev)) {
39 printk("%s: device not ready.\n", dev->name);
40 return 0;
41 }
42
43 if (edac_notify_callback_set(dev, notification_callback)) {
44 LOG_ERR("Cannot set notification callback");
45 return 0;
46 }
47
48 LOG_INF("EDAC shell application initialized");
49 return 0;
50 }
51
thread_function(void)52 void thread_function(void)
53 {
54 LOG_DBG("Thread started");
55
56 while (true) {
57 if (atomic_cas(&handled, true, false)) {
58 printk("Got notification about ECC event\n");
59 k_sleep(K_MSEC(300));
60 }
61 }
62 }
63
64 K_THREAD_DEFINE(thread_edac, STACKSIZE, thread_function, NULL, NULL, NULL, PRIORITY, 0, 0);
65