blob: a0a230268eaa88d5f96e5011166ec2b5766ec405 [file] [log] [blame]
/*
* Copyright (c) 2020 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/zephyr.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/edac.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL);
#define STACKSIZE 1024
#define PRIORITY 7
static atomic_t handled;
/**
* Callback called from ISR. Runs in supervisor mode
*/
static void notification_callback(const struct device *dev, void *data)
{
/* Special care need to be taken for NMI callback:
* delayed_work, mutex and semaphores are not working stable
* here, using integer increment for now
*/
atomic_set(&handled, true);
}
void main(void)
{
const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(ibecc));
if (!device_is_ready(dev)) {
printk("%s: device not ready.\n", dev->name);
return;
}
if (edac_notify_callback_set(dev, notification_callback)) {
LOG_ERR("Cannot set notification callback");
return;
}
LOG_INF("EDAC shell application initialized");
}
void thread_function(void)
{
LOG_DBG("Thread started");
while (true) {
if (atomic_cas(&handled, true, false)) {
printk("Got notification about IBECC event\n");
k_sleep(K_MSEC(300));
}
}
}
K_THREAD_DEFINE(thread_id, STACKSIZE, thread_function, NULL, NULL, NULL,
PRIORITY, 0, 0);