sched/wdog: Remove the wd_start_period.

For better simplicity, this commit replaced the periodical wdog APIs with the more expressive wd_start_next. The wd_start_next restarts watchdog timer based on the last expiration time.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit is contained in:
ouyangxiangzhen
2025-06-04 11:35:31 +08:00
committed by Alan C. Assis
parent 5e94d4482b
commit 9d1b958524
2 changed files with 22 additions and 114 deletions

View File

@@ -99,13 +99,6 @@ struct wdog_s
clock_t expired; /* Timer associated with the absolute time */
};
struct wdog_period_s
{
struct wdog_s wdog; /* Watchdog */
clock_t period; /* Period time in ticks */
wdentry_t func; /* Wrapped function to execute when delay expires */
};
/****************************************************************************
* Pubic Function Prototypes
****************************************************************************/
@@ -271,10 +264,11 @@ int wd_start_abstick(FAR struct wdog_s *wdog, clock_t ticks,
*
****************************************************************************/
static inline int wd_start_realtime(FAR struct wdog_s *wdog,
FAR const struct timespec *realtime,
wdentry_t wdentry,
wdparm_t arg)
static inline_function
int wd_start_realtime(FAR struct wdog_s *wdog,
FAR const struct timespec *realtime,
wdentry_t wdentry,
wdparm_t arg)
{
#ifdef CONFIG_CLOCK_TIMEKEEPING
irqstate_t flags;
@@ -296,15 +290,15 @@ static inline int wd_start_realtime(FAR struct wdog_s *wdog,
}
/****************************************************************************
* Name: wd_start_period
* Name: wd_start_next
*
* Description:
* This function periodically adds a watchdog timer to the active timer.
* This function restart watchdog timer based on the last expiration time.
* It can be used to implement a periodic watchdog timer.
*
* Input Parameters:
* wdog - Pointer of the periodic watchdog.
* delay - Delayed time in system ticks.
* period - Period in system ticks.
* wdentry - Function to call on timeout.
* arg - Parameter to pass to wdentry.
*
@@ -320,8 +314,19 @@ static inline int wd_start_realtime(FAR struct wdog_s *wdog,
*
****************************************************************************/
int wd_start_period(FAR struct wdog_period_s *wdog, clock_t delay,
clock_t period, wdentry_t wdentry, wdparm_t arg);
static inline_function
int wd_start_next(FAR struct wdog_s *wdog, clock_t delay,
wdentry_t wdentry, wdparm_t arg)
{
/* Ensure delay is within the range the wdog can handle. */
if (delay > WDOG_MAX_DELAY)
{
return -EINVAL;
}
return wd_start_abstick(wdog, wdog->expired + delay, wdentry, arg);
}
/****************************************************************************
* Name: wd_cancel
@@ -341,32 +346,6 @@ int wd_start_period(FAR struct wdog_period_s *wdog, clock_t delay,
int wd_cancel(FAR struct wdog_s *wdog);
/****************************************************************************
* Name: wd_cancel_period
*
* Description:
* This function cancels a currently running periodic watchdog timer.
*
* Input Parameters:
* wdog_period - Pointer of the periodic watchdog.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned to
* indicate the nature of any failure.
*
****************************************************************************/
static inline int wd_cancel_period(FAR struct wdog_period_s *wdog_period)
{
if (!wdog_period)
{
return -EINVAL;
}
wdog_period->period = 0;
return wd_cancel(&wdog_period->wdog);
}
/****************************************************************************
* Name: wd_gettime
*

View File

@@ -97,36 +97,6 @@ static unsigned int g_wdtimernested;
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: wdentry_period
*
* Description:
* Periodic watchdog timer callback function.
*
* Input Parameters:
* arg - The argument of the wdog callback.
*
* Returned Value:
* None
*
****************************************************************************/
static void wdentry_period(wdparm_t arg)
{
FAR struct wdog_period_s *wdperiod;
wdperiod = wdparm_to_ptr(FAR struct wdog_period_s *, arg);
wdperiod->func(wdperiod->wdog.arg);
if (wdperiod->period != 0)
{
wd_start_abstick(&wdperiod->wdog,
wdperiod->wdog.expired + wdperiod->period,
wdentry_period, wdperiod->wdog.arg);
}
}
/****************************************************************************
* Name: wd_expiration
*
@@ -181,11 +151,9 @@ static inline_function void wd_expiration(clock_t ticks)
/* Indicate that the watchdog is no longer active. */
func = wdog->func;
arg = wdog->arg;
wdog->func = NULL;
arg = func != wdentry_period ? wdog->arg : ptr_to_wdparm(
list_container_of(wdog, struct wdog_period_s, wdog));
/* Execute the watchdog function */
up_setpicbase(wdog->picbase);
@@ -419,45 +387,6 @@ int wd_start(FAR struct wdog_s *wdog, clock_t delay,
return wd_start_abstick(wdog, clock_delay2abstick(delay), wdentry, arg);
}
/****************************************************************************
* Name: wd_start_period
*
* Description:
* This function periodically adds a watchdog timer to the active timer.
*
* Input Parameters:
* wdog - Pointer of the periodic watchdog.
* delay - Delayed time in system ticks.
* period - Period in system ticks.
* wdentry - Function to call on timeout.
* arg - Parameter to pass to wdentry.
*
* NOTE: The parameter must be of type wdparm_t.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is return to
* indicate the nature of any failure.
*
* Assumptions:
* The watchdog routine runs in the context of the timer interrupt handler
* and is subject to all ISR restrictions.
*
****************************************************************************/
int wd_start_period(FAR struct wdog_period_s *wdog, clock_t delay,
clock_t period, wdentry_t wdentry, wdparm_t arg)
{
if (!wdog || !period || !wdentry)
{
return -EINVAL;
}
wdog->func = wdentry;
wdog->period = period;
return wd_start(&wdog->wdog, delay, wdentry_period, arg);
}
/****************************************************************************
* Name: wd_timer
*