69 lines
1.5 KiB
C
69 lines
1.5 KiB
C
/*
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2022-02-22 airm2m first version
|
|
*/
|
|
|
|
#include "board.h"
|
|
#include <drivers/watchdog.h>
|
|
|
|
#ifdef RT_USING_WDT
|
|
|
|
#define LOG_TAG "drv.wdt"
|
|
#include <drv_log.h>
|
|
|
|
|
|
static rt_watchdog_t watchdog;
|
|
static struct rt_watchdog_ops ops;
|
|
|
|
static rt_err_t wdt_init(rt_watchdog_t *wdt)
|
|
{
|
|
return RT_EOK;
|
|
}
|
|
|
|
static rt_err_t wdt_control(rt_watchdog_t *wdt, int cmd, void *arg)
|
|
{
|
|
switch (cmd)
|
|
{
|
|
/* feed the watchdog */
|
|
case RT_DEVICE_CTRL_WDT_KEEPALIVE:
|
|
WDT_Feed();
|
|
break;
|
|
/* set watchdog timeout */
|
|
case RT_DEVICE_CTRL_WDT_SET_TIMEOUT:
|
|
WDT_SetTimeout((*((rt_uint32_t*)arg))*1000);
|
|
break;
|
|
case RT_DEVICE_CTRL_WDT_GET_TIMEOUT:
|
|
break;
|
|
case RT_DEVICE_CTRL_WDT_START:
|
|
|
|
break;
|
|
default:
|
|
LOG_W("This command is not supported.");
|
|
return -RT_ERROR;
|
|
}
|
|
return RT_EOK;
|
|
}
|
|
|
|
int rt_wdt_init(void)
|
|
{
|
|
ops.init = &wdt_init;
|
|
ops.control = &wdt_control;
|
|
watchdog.ops = &ops;
|
|
/* register watchdog device */
|
|
if (rt_hw_watchdog_register(&watchdog, "wdt", RT_DEVICE_FLAG_DEACTIVATE, RT_NULL) != RT_EOK)
|
|
{
|
|
LOG_E("wdt device register failed.");
|
|
return -RT_ERROR;
|
|
}
|
|
LOG_D("wdt device register success.");
|
|
return RT_EOK;
|
|
}
|
|
INIT_BOARD_EXPORT(rt_wdt_init);
|
|
|
|
#endif /* RT_USING_WDT */
|