xiaoxiang781216 commented on code in PR #20915: URL: https://github.com/apache/nuttx/pull/20915#discussion_r4356671600
########## drivers/timers/Kconfig: ########## @@ -480,6 +480,20 @@ menuconfig WATCHDOG if WATCHDOG +config WATCHDOG_WDOG + bool "Watchdog implemented by wdog timer" + default n + depends on !WATCHDOG_AUTOMONITOR_BY_ONESHOT && !WATCHDOG_AUTOMONITOR_BY_TIMER Review Comment: why has these dependence ########## drivers/timers/watchdog_wdog.c: ########## @@ -0,0 +1,215 @@ +/**************************************************************************** + * drivers/timers/watchdog_wdog.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> +#include <errno.h> +#include <stdint.h> +#include <stdbool.h> + +#include <nuttx/clock.h> +#include <nuttx/kmalloc.h> +#include <nuttx/wdog.h> +#include <nuttx/timers/watchdog.h> +#include <nuttx/timers/watchdog_wdog.h> + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* expire is called from the wdog timer context when the watchdog expires */ + +struct watchdog_wdog_s +{ + struct watchdog_lowerhalf_s lower; /* Must be first */ + struct wdog_s wdog; /* The timer that expires */ + CODE void (*expire)(void); + uint32_t timeout; /* Timeout in milliseconds */ + bool started; /* Is the watchdog running */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int watchdog_wdog_start(FAR struct watchdog_lowerhalf_s *lower); +static int watchdog_wdog_stop(FAR struct watchdog_lowerhalf_s *lower); +static int watchdog_wdog_keepalive(FAR struct watchdog_lowerhalf_s *lower); +static int watchdog_wdog_getstatus(FAR struct watchdog_lowerhalf_s *lower, + FAR struct watchdog_status_s *status); +static int watchdog_wdog_settimeout(FAR struct watchdog_lowerhalf_s *lower, + uint32_t timeout); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct watchdog_ops_s g_watchdog_wdog_ops = +{ + .start = watchdog_wdog_start, + .stop = watchdog_wdog_stop, + .keepalive = watchdog_wdog_keepalive, + .getstatus = watchdog_wdog_getstatus, + .settimeout = watchdog_wdog_settimeout, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: watchdog_wdog_expire + * + * Description: + * The wdog handler: the watchdog was not fed in time. + * + ****************************************************************************/ + +static void watchdog_wdog_expire(wdparm_t arg) +{ + FAR struct watchdog_wdog_s *priv = (FAR struct watchdog_wdog_s *)arg; + + if (priv->expire != NULL) + { + priv->expire(); + } + else + { + PANIC(); + } +} + +/**************************************************************************** + * Name: watchdog_wdog_arm + ****************************************************************************/ + +static int watchdog_wdog_arm(FAR struct watchdog_wdog_s *priv) +{ + return wd_start(&priv->wdog, MSEC2TICK(priv->timeout), + watchdog_wdog_expire, (wdparm_t)priv); +} + +static int watchdog_wdog_start(FAR struct watchdog_lowerhalf_s *lower) +{ + FAR struct watchdog_wdog_s *priv = (FAR struct watchdog_wdog_s *)lower; + int ret; + + ret = watchdog_wdog_arm(priv); + if (ret >= 0) + { + priv->started = true; + } + + return ret; +} + +static int watchdog_wdog_stop(FAR struct watchdog_lowerhalf_s *lower) +{ + FAR struct watchdog_wdog_s *priv = (FAR struct watchdog_wdog_s *)lower; + + priv->started = false; + wd_cancel(&priv->wdog); Review Comment: wd_cancel_sync ########## drivers/timers/watchdog_wdog.c: ########## @@ -0,0 +1,215 @@ +/**************************************************************************** + * drivers/timers/watchdog_wdog.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> +#include <errno.h> +#include <stdint.h> +#include <stdbool.h> + +#include <nuttx/clock.h> +#include <nuttx/kmalloc.h> +#include <nuttx/wdog.h> +#include <nuttx/timers/watchdog.h> +#include <nuttx/timers/watchdog_wdog.h> + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* expire is called from the wdog timer context when the watchdog expires */ + +struct watchdog_wdog_s +{ + struct watchdog_lowerhalf_s lower; /* Must be first */ + struct wdog_s wdog; /* The timer that expires */ + CODE void (*expire)(void); + uint32_t timeout; /* Timeout in milliseconds */ + bool started; /* Is the watchdog running */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int watchdog_wdog_start(FAR struct watchdog_lowerhalf_s *lower); +static int watchdog_wdog_stop(FAR struct watchdog_lowerhalf_s *lower); +static int watchdog_wdog_keepalive(FAR struct watchdog_lowerhalf_s *lower); +static int watchdog_wdog_getstatus(FAR struct watchdog_lowerhalf_s *lower, + FAR struct watchdog_status_s *status); +static int watchdog_wdog_settimeout(FAR struct watchdog_lowerhalf_s *lower, + uint32_t timeout); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct watchdog_ops_s g_watchdog_wdog_ops = +{ + .start = watchdog_wdog_start, + .stop = watchdog_wdog_stop, + .keepalive = watchdog_wdog_keepalive, + .getstatus = watchdog_wdog_getstatus, + .settimeout = watchdog_wdog_settimeout, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: watchdog_wdog_expire + * + * Description: + * The wdog handler: the watchdog was not fed in time. + * + ****************************************************************************/ + +static void watchdog_wdog_expire(wdparm_t arg) +{ + FAR struct watchdog_wdog_s *priv = (FAR struct watchdog_wdog_s *)arg; + + if (priv->expire != NULL) + { + priv->expire(); + } + else + { + PANIC(); Review Comment: should we support board_reboot or board_poweroff? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
