watchdog: Support auto monitor keep alive from oneshot lowerhalf
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
1eefec4db3
commit
03f45a124a
@ -371,6 +371,10 @@ choice
|
|||||||
config WATCHDOG_AUTOMONITOR_BY_CAPTURE
|
config WATCHDOG_AUTOMONITOR_BY_CAPTURE
|
||||||
bool "Capture callback"
|
bool "Capture callback"
|
||||||
|
|
||||||
|
config WATCHDOG_AUTOMONITOR_BY_ONESHOT
|
||||||
|
bool "Oneshot callback"
|
||||||
|
depends on ONESHOT
|
||||||
|
|
||||||
config WATCHDOG_AUTOMONITOR_BY_TIMER
|
config WATCHDOG_AUTOMONITOR_BY_TIMER
|
||||||
bool "Timer callback"
|
bool "Timer callback"
|
||||||
depends on TIMER
|
depends on TIMER
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include <nuttx/semaphore.h>
|
#include <nuttx/semaphore.h>
|
||||||
#include <nuttx/wdog.h>
|
#include <nuttx/wdog.h>
|
||||||
#include <nuttx/wqueue.h>
|
#include <nuttx/wqueue.h>
|
||||||
|
#include <nuttx/timers/oneshot.h>
|
||||||
#include <nuttx/timers/timer.h>
|
#include <nuttx/timers/timer.h>
|
||||||
#include <nuttx/timers/watchdog.h>
|
#include <nuttx/timers/watchdog.h>
|
||||||
|
|
||||||
@ -76,16 +77,18 @@
|
|||||||
struct watchdog_upperhalf_s
|
struct watchdog_upperhalf_s
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_WATCHDOG_AUTOMONITOR
|
#ifdef CONFIG_WATCHDOG_AUTOMONITOR
|
||||||
# if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
# if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_ONESHOT)
|
||||||
FAR struct timer_lowerhalf_s *timer;
|
FAR struct oneshot_lowerhalf_s *oneshot;
|
||||||
|
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
||||||
|
FAR struct timer_lowerhalf_s *timer;
|
||||||
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_WDOG)
|
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_WDOG)
|
||||||
struct wdog_s wdog;
|
struct wdog_s wdog;
|
||||||
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_WORKER)
|
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_WORKER)
|
||||||
struct work_s work;
|
struct work_s work;
|
||||||
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_IDLE)
|
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_IDLE)
|
||||||
struct pm_callback_s idle;
|
struct pm_callback_s idle;
|
||||||
# endif
|
# endif
|
||||||
bool monitor;
|
bool monitor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t crefs; /* The number of times the device has been opened */
|
uint8_t crefs; /* The number of times the device has been opened */
|
||||||
@ -146,6 +149,25 @@ static int watchdog_automonitor_capture(int irq, FAR void *context,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_ONESHOT)
|
||||||
|
static void
|
||||||
|
watchdog_automonitor_oneshot(FAR struct oneshot_lowerhalf_s *oneshot,
|
||||||
|
FAR void *arg)
|
||||||
|
{
|
||||||
|
FAR struct watchdog_upperhalf_s *upper = arg;
|
||||||
|
FAR struct watchdog_lowerhalf_s *lower = upper->lower;
|
||||||
|
|
||||||
|
if (upper->monitor)
|
||||||
|
{
|
||||||
|
struct timespec ts =
|
||||||
|
{
|
||||||
|
WATCHDOG_AUTOMONITOR_PING_INTERVAL, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
lower->ops->keepalive(lower);
|
||||||
|
ONESHOT_START(oneshot, watchdog_automonitor_oneshot, upper, &ts);
|
||||||
|
}
|
||||||
|
}
|
||||||
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
||||||
static bool watchdog_automonitor_timer(FAR uint32_t *next_interval_us,
|
static bool watchdog_automonitor_timer(FAR uint32_t *next_interval_us,
|
||||||
FAR void *arg)
|
FAR void *arg)
|
||||||
@ -202,7 +224,11 @@ static void watchdog_automonitor_idle(FAR struct pm_callback_s *cb,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_WATCHDOG_AUTOMONITOR
|
#ifdef CONFIG_WATCHDOG_AUTOMONITOR
|
||||||
# if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
# if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_ONESHOT)
|
||||||
|
static void
|
||||||
|
watchdog_automonitor_start(FAR struct watchdog_upperhalf_s *upper,
|
||||||
|
FAR struct oneshot_lowerhalf_s *oneshot)
|
||||||
|
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
||||||
static void
|
static void
|
||||||
watchdog_automonitor_start(FAR struct watchdog_upperhalf_s *upper,
|
watchdog_automonitor_start(FAR struct watchdog_upperhalf_s *upper,
|
||||||
FAR struct timer_lowerhalf_s *timer)
|
FAR struct timer_lowerhalf_s *timer)
|
||||||
@ -215,10 +241,17 @@ watchdog_automonitor_start(FAR struct watchdog_upperhalf_s *upper)
|
|||||||
|
|
||||||
if (!upper->monitor)
|
if (!upper->monitor)
|
||||||
{
|
{
|
||||||
upper->monitor = true;
|
|
||||||
# if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_CAPTURE)
|
# if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_CAPTURE)
|
||||||
lower->ops->capture(lower, watchdog_automonitor_capture);
|
lower->ops->capture(lower, watchdog_automonitor_capture);
|
||||||
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_ONESHOT)
|
||||||
|
struct timespec ts =
|
||||||
|
{
|
||||||
|
WATCHDOG_AUTOMONITOR_PING_INTERVAL, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
upper->oneshot = oneshot;
|
||||||
|
ONESHOT_START(oneshot, watchdog_automonitor_oneshot, upper, &ts);
|
||||||
|
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
||||||
upper->timer = timer;
|
upper->timer = timer;
|
||||||
timer->ops->setcallback(timer, watchdog_automonitor_timer, upper);
|
timer->ops->setcallback(timer, watchdog_automonitor_timer, upper);
|
||||||
timer->ops->settimeout(timer, WATCHDOG_AUTOMONITOR_PING_INTERVAL_MSEC);
|
timer->ops->settimeout(timer, WATCHDOG_AUTOMONITOR_PING_INTERVAL_MSEC);
|
||||||
@ -233,6 +266,7 @@ watchdog_automonitor_start(FAR struct watchdog_upperhalf_s *upper)
|
|||||||
upper->idle.notify = watchdog_automonitor_idle;
|
upper->idle.notify = watchdog_automonitor_idle;
|
||||||
pm_register(&upper->idle);
|
pm_register(&upper->idle);
|
||||||
# endif
|
# endif
|
||||||
|
upper->monitor = true;
|
||||||
if (lower->ops->settimeout)
|
if (lower->ops->settimeout)
|
||||||
{
|
{
|
||||||
lower->ops->settimeout(lower, WATCHDOG_AUTOMONITOR_TIMEOUT_MSEC);
|
lower->ops->settimeout(lower, WATCHDOG_AUTOMONITOR_TIMEOUT_MSEC);
|
||||||
@ -252,6 +286,8 @@ static void watchdog_automonitor_stop(FAR struct watchdog_upperhalf_s *upper)
|
|||||||
lower->ops->stop(lower);
|
lower->ops->stop(lower);
|
||||||
# if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_CAPTURE)
|
# if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_CAPTURE)
|
||||||
lower->ops->capture(lower, NULL);
|
lower->ops->capture(lower, NULL);
|
||||||
|
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_ONESHOT)
|
||||||
|
ONESHOT_CANCEL(upper->oneshot, NULL);
|
||||||
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
||||||
upper->timer->ops->stop(upper->timer);
|
upper->timer->ops->stop(upper->timer);
|
||||||
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_WDOG)
|
# elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_WDOG)
|
||||||
@ -622,7 +658,11 @@ static int wdog_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
#if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_ONESHOT)
|
||||||
|
FAR void *watchdog_register(FAR const char *path,
|
||||||
|
FAR struct watchdog_lowerhalf_s *lower,
|
||||||
|
FAR struct oneshot_lowerhalf_s *oneshot)
|
||||||
|
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
||||||
FAR void *watchdog_register(FAR const char *path,
|
FAR void *watchdog_register(FAR const char *path,
|
||||||
FAR struct watchdog_lowerhalf_s *lower,
|
FAR struct watchdog_lowerhalf_s *lower,
|
||||||
FAR struct timer_lowerhalf_s *timer)
|
FAR struct timer_lowerhalf_s *timer)
|
||||||
@ -672,7 +712,9 @@ FAR void *watchdog_register(FAR const char *path,
|
|||||||
goto errout_with_path;
|
goto errout_with_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
#if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_ONESHOT)
|
||||||
|
watchdog_automonitor_start(upper, oneshot);
|
||||||
|
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
||||||
watchdog_automonitor_start(upper, timer);
|
watchdog_automonitor_start(upper, timer);
|
||||||
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR)
|
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR)
|
||||||
watchdog_automonitor_start(upper);
|
watchdog_automonitor_start(upper);
|
||||||
|
@ -224,7 +224,12 @@ extern "C"
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
#if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_ONESHOT)
|
||||||
|
struct oneshot_lowerhalf_s;
|
||||||
|
FAR void *watchdog_register(FAR const char *path,
|
||||||
|
FAR struct watchdog_lowerhalf_s *lower,
|
||||||
|
FAR struct oneshot_lowerhalf_s *oneshot);
|
||||||
|
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
||||||
struct timer_lowerhalf_s;
|
struct timer_lowerhalf_s;
|
||||||
FAR void *watchdog_register(FAR const char *path,
|
FAR void *watchdog_register(FAR const char *path,
|
||||||
FAR struct watchdog_lowerhalf_s *lower,
|
FAR struct watchdog_lowerhalf_s *lower,
|
||||||
|
Loading…
Reference in New Issue
Block a user