Skip to content

sched/wdog: merge wdog_periods_s into wdog_s #15959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 2 additions & 33 deletions include/nuttx/wdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,8 @@ struct wdog_s
FAR void *picbase; /* PIC base address */
#endif
clock_t expired; /* Timer associated with the absoulute time */
};

struct wdog_period_s
{
struct wdog_s wdog; /* Watchdog */
clock_t period; /* Period time in ticks */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the chagne will increase wdog_s size even the caller doesn't require the period callback.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about add a kconfig setting to make period wdog feature configurable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't resolve the problem, since not all user in the same image use the periodic watchdog.

wdentry_t func; /* Wrapped function to execute when delay expires */
wdentry_t pfunc; /* Period Function to execute when delay expires */
};

/****************************************************************************
Expand Down Expand Up @@ -311,7 +306,7 @@ static inline int wd_start_realtime(FAR struct wdog_s *wdog,
*
****************************************************************************/

int wd_start_period(FAR struct wdog_period_s *wdog, sclock_t delay,
int wd_start_period(FAR struct wdog_s *wdog, sclock_t delay,
clock_t period, wdentry_t wdentry, wdparm_t arg);

/****************************************************************************
Expand All @@ -332,32 +327,6 @@ int wd_start_period(FAR struct wdog_period_s *wdog, sclock_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
*
Expand Down
1 change: 0 additions & 1 deletion include/nuttx/wqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ struct work_s
clock_t qtime; /* Time work queued */
} s;
struct wdog_s timer; /* Delay expiry timer */
struct wdog_period_s ptimer; /* Period expiry timer */
} u;
worker_t worker; /* Work callback */
FAR void *arg; /* Callback argument */
Expand Down
2 changes: 2 additions & 0 deletions sched/wdog/wd_cancel.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ int wd_cancel(FAR struct wdog_s *wdog)

flags = spin_lock_irqsave(&g_wdspinlock);

wdog->period = 0;

/* Make sure that the watchdog is valid and still active. */

if (wdog == NULL || !WDOG_ISACTIVE(wdog))
Expand Down
29 changes: 11 additions & 18 deletions sched/wdog/wd_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@

#endif

#define wdparm_to_ptr(type, arg) ((type)(uintptr_t)arg)
#define ptr_to_wdparm(ptr) wdparm_to_ptr(wdparm_t, ptr)

/****************************************************************************
* Private Data
****************************************************************************/
Expand All @@ -98,7 +95,7 @@ static unsigned int g_wdtimernested;
****************************************************************************/

/****************************************************************************
* Name: wdentry_period
* Name: wd_period_callback
*
* Description:
* Periodic watchdog timer callback function.
Expand All @@ -111,23 +108,20 @@ static unsigned int g_wdtimernested;
*
****************************************************************************/

static void wdentry_period(wdparm_t arg)
static void wd_period_callback(wdparm_t arg)
{
FAR struct wdog_period_s *wdperiod;

wdperiod = wdparm_to_ptr(FAR struct wdog_period_s *, arg);
FAR struct wdog_s *wdog = ((FAR struct wdog_s *)(uintptr_t)arg);

wdperiod->func(wdperiod->wdog.arg);
wdog->pfunc(wdog->arg);

/* Since we set `ticks++` at `wd_start_abstick`,
* we need to use `expired - 1` here to avoid time drift.
*/

if (wdperiod->period != 0)
if (wdog->period != 0)
{
wd_start_abstick(&wdperiod->wdog,
wdperiod->wdog.expired + wdperiod->period - 1,
wdentry_period, wdperiod->wdog.arg);
wd_start_abstick(wdog, wdog->expired + wdog->period - 1,
wd_period_callback, wdog->arg);
}
}

Expand Down Expand Up @@ -187,8 +181,7 @@ static inline_function void wd_expiration(clock_t ticks)
func = wdog->func;
wdog->func = NULL;

arg = func != wdentry_period ? wdog->arg : ptr_to_wdparm(
list_container_of(wdog, struct wdog_period_s, wdog));
arg = wdog->arg;

/* Execute the watchdog function */

Expand Down Expand Up @@ -460,18 +453,18 @@ int wd_start(FAR struct wdog_s *wdog, sclock_t delay,
*
****************************************************************************/

int wd_start_period(FAR struct wdog_period_s *wdog, sclock_t delay,
int wd_start_period(FAR struct wdog_s *wdog, sclock_t delay,
clock_t period, wdentry_t wdentry, wdparm_t arg)
{
if (!wdog || !period || !wdentry)
{
return -EINVAL;
}

wdog->func = wdentry;
wdog->pfunc = wdentry;
wdog->period = period;

return wd_start(&wdog->wdog, delay, wdentry_period, arg);
return wd_start(wdog, delay, wd_period_callback, arg);
}

/****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion sched/wqueue/kwork_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ int work_queue_period_wq(FAR struct kwork_wqueue_s *wqueue,
}
else
{
ret = wd_start_period(&work->u.ptimer, delay, period,
ret = wd_start_period(&work->u.timer, delay, period,
work_timer_expiry, (wdparm_t)work);
}

Expand Down
Loading