2014-03-04 14:32:56 +08:00
|
|
|
/*
|
2023-04-18 10:26:23 +08:00
|
|
|
* COPYRIGHT (C) 2011-2023, Real-Thread Information Technology Ltd
|
2021-03-08 18:19:04 +08:00
|
|
|
*
|
2018-10-14 19:37:18 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2014-03-04 14:32:56 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2012-09-12 heyuanjie87 first version.
|
|
|
|
* 2014-03-04 Bernard code cleanup
|
|
|
|
*/
|
|
|
|
|
2024-09-14 05:40:40 +08:00
|
|
|
#include "drivers/dev_watchdog.h"
|
2014-03-04 14:32:56 +08:00
|
|
|
|
|
|
|
/* RT-Thread Device Interface */
|
|
|
|
|
|
|
|
/*
|
2020-05-19 17:30:19 +08:00
|
|
|
* This function initializes watchdog
|
2014-03-04 14:32:56 +08:00
|
|
|
*/
|
|
|
|
static rt_err_t rt_watchdog_init(struct rt_device *dev)
|
|
|
|
{
|
|
|
|
rt_watchdog_t *wtd;
|
|
|
|
|
|
|
|
RT_ASSERT(dev != RT_NULL);
|
|
|
|
wtd = (rt_watchdog_t *)dev;
|
|
|
|
if (wtd->ops->init)
|
|
|
|
{
|
|
|
|
return (wtd->ops->init(wtd));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (-RT_ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static rt_err_t rt_watchdog_open(struct rt_device *dev, rt_uint16_t oflag)
|
|
|
|
{
|
|
|
|
return (RT_EOK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static rt_err_t rt_watchdog_close(struct rt_device *dev)
|
|
|
|
{
|
|
|
|
rt_watchdog_t *wtd;
|
|
|
|
|
|
|
|
RT_ASSERT(dev != RT_NULL);
|
|
|
|
wtd = (rt_watchdog_t *)dev;
|
|
|
|
|
|
|
|
if (wtd->ops->control(wtd, RT_DEVICE_CTRL_WDT_STOP, RT_NULL) != RT_EOK)
|
|
|
|
{
|
|
|
|
rt_kprintf(" This watchdog can not be stoped\n");
|
|
|
|
|
|
|
|
return (-RT_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (RT_EOK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static rt_err_t rt_watchdog_control(struct rt_device *dev,
|
2017-10-15 22:56:46 +08:00
|
|
|
int cmd,
|
2014-03-04 14:32:56 +08:00
|
|
|
void *args)
|
|
|
|
{
|
|
|
|
rt_watchdog_t *wtd;
|
|
|
|
|
|
|
|
RT_ASSERT(dev != RT_NULL);
|
|
|
|
wtd = (rt_watchdog_t *)dev;
|
|
|
|
|
|
|
|
return (wtd->ops->control(wtd, cmd, args));
|
|
|
|
}
|
|
|
|
|
2018-06-10 17:59:17 +08:00
|
|
|
#ifdef RT_USING_DEVICE_OPS
|
2021-03-08 18:19:04 +08:00
|
|
|
const static struct rt_device_ops wdt_ops =
|
2018-06-10 17:59:17 +08:00
|
|
|
{
|
|
|
|
rt_watchdog_init,
|
|
|
|
rt_watchdog_open,
|
|
|
|
rt_watchdog_close,
|
|
|
|
RT_NULL,
|
|
|
|
RT_NULL,
|
|
|
|
rt_watchdog_control,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2014-03-04 14:32:56 +08:00
|
|
|
/**
|
|
|
|
* This function register a watchdog device
|
|
|
|
*/
|
|
|
|
rt_err_t rt_hw_watchdog_register(struct rt_watchdog_device *wtd,
|
|
|
|
const char *name,
|
|
|
|
rt_uint32_t flag,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct rt_device *device;
|
|
|
|
RT_ASSERT(wtd != RT_NULL);
|
|
|
|
|
|
|
|
device = &(wtd->parent);
|
|
|
|
|
2022-04-06 21:12:39 +08:00
|
|
|
device->type = RT_Device_Class_WDT;
|
2014-03-04 14:32:56 +08:00
|
|
|
device->rx_indicate = RT_NULL;
|
|
|
|
device->tx_complete = RT_NULL;
|
|
|
|
|
2018-06-10 17:59:17 +08:00
|
|
|
#ifdef RT_USING_DEVICE_OPS
|
|
|
|
device->ops = &wdt_ops;
|
|
|
|
#else
|
2014-03-04 14:32:56 +08:00
|
|
|
device->init = rt_watchdog_init;
|
|
|
|
device->open = rt_watchdog_open;
|
|
|
|
device->close = rt_watchdog_close;
|
|
|
|
device->read = RT_NULL;
|
|
|
|
device->write = RT_NULL;
|
|
|
|
device->control = rt_watchdog_control;
|
2018-06-10 17:59:17 +08:00
|
|
|
#endif
|
2014-03-04 14:32:56 +08:00
|
|
|
device->user_data = data;
|
|
|
|
|
|
|
|
/* register a character device */
|
|
|
|
return rt_device_register(device, name, flag);
|
|
|
|
}
|