Skip to content

Commit c4961ec

Browse files
committed
sched/wdog: merge wdog_periods_s into wdog_s
Make wdog support period semantics by default, avoid exposing two structures to enhance consistency Signed-off-by: chao an <[email protected]>
1 parent fa5590d commit c4961ec

File tree

5 files changed

+16
-50
lines changed

5 files changed

+16
-50
lines changed

include/nuttx/wdog.h

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,8 @@ struct wdog_s
8888
FAR void *picbase; /* PIC base address */
8989
#endif
9090
clock_t expired; /* Timer associated with the absoulute time */
91-
};
92-
93-
struct wdog_period_s
94-
{
95-
struct wdog_s wdog; /* Watchdog */
9691
clock_t period; /* Period time in ticks */
97-
wdentry_t func; /* Wrapped function to execute when delay expires */
92+
wdentry_t pfunc; /* Period Function to execute when delay expires */
9893
};
9994

10095
/****************************************************************************
@@ -311,7 +306,7 @@ static inline int wd_start_realtime(FAR struct wdog_s *wdog,
311306
*
312307
****************************************************************************/
313308

314-
int wd_start_period(FAR struct wdog_period_s *wdog, sclock_t delay,
309+
int wd_start_period(FAR struct wdog_s *wdog, sclock_t delay,
315310
clock_t period, wdentry_t wdentry, wdparm_t arg);
316311

317312
/****************************************************************************
@@ -332,32 +327,6 @@ int wd_start_period(FAR struct wdog_period_s *wdog, sclock_t delay,
332327

333328
int wd_cancel(FAR struct wdog_s *wdog);
334329

335-
/****************************************************************************
336-
* Name: wd_cancel_period
337-
*
338-
* Description:
339-
* This function cancels a currently running periodic watchdog timer.
340-
*
341-
* Input Parameters:
342-
* wdog_period - Pointer of the periodic watchdog.
343-
*
344-
* Returned Value:
345-
* Zero (OK) is returned on success; A negated errno value is returned to
346-
* indicate the nature of any failure.
347-
*
348-
****************************************************************************/
349-
350-
static inline int wd_cancel_period(FAR struct wdog_period_s *wdog_period)
351-
{
352-
if (!wdog_period)
353-
{
354-
return -EINVAL;
355-
}
356-
357-
wdog_period->period = 0;
358-
return wd_cancel(&wdog_period->wdog);
359-
}
360-
361330
/****************************************************************************
362331
* Name: wd_gettime
363332
*

include/nuttx/wqueue.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ struct work_s
257257
clock_t qtime; /* Time work queued */
258258
} s;
259259
struct wdog_s timer; /* Delay expiry timer */
260-
struct wdog_period_s ptimer; /* Period expiry timer */
261260
} u;
262261
worker_t worker; /* Work callback */
263262
FAR void *arg; /* Callback argument */

sched/wdog/wd_cancel.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ int wd_cancel(FAR struct wdog_s *wdog)
6565

6666
flags = spin_lock_irqsave(&g_wdspinlock);
6767

68+
wdog->period = 0;
69+
6870
/* Make sure that the watchdog is valid and still active. */
6971

7072
if (wdog == NULL || !WDOG_ISACTIVE(wdog))

sched/wdog/wd_start.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static unsigned int g_wdtimernested;
9898
****************************************************************************/
9999

100100
/****************************************************************************
101-
* Name: wdentry_period
101+
* Name: wd_period_callback
102102
*
103103
* Description:
104104
* Periodic watchdog timer callback function.
@@ -111,23 +111,20 @@ static unsigned int g_wdtimernested;
111111
*
112112
****************************************************************************/
113113

114-
static void wdentry_period(wdparm_t arg)
114+
static void wd_period_callback(wdparm_t arg)
115115
{
116-
FAR struct wdog_period_s *wdperiod;
116+
FAR struct wdog_s *wdog = ((FAR struct wdog_s *)(uintptr_t)arg);
117117

118-
wdperiod = wdparm_to_ptr(FAR struct wdog_period_s *, arg);
119-
120-
wdperiod->func(wdperiod->wdog.arg);
118+
wdog->pfunc(wdog->arg);
121119

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

126-
if (wdperiod->period != 0)
124+
if (wdog->period != 0)
127125
{
128-
wd_start_abstick(&wdperiod->wdog,
129-
wdperiod->wdog.expired + wdperiod->period - 1,
130-
wdentry_period, wdperiod->wdog.arg);
126+
wd_start_abstick(wdog, wdog->expired + wdog->period - 1,
127+
wd_period_callback, wdog->arg);
131128
}
132129
}
133130

@@ -187,8 +184,7 @@ static inline_function void wd_expiration(clock_t ticks)
187184
func = wdog->func;
188185
wdog->func = NULL;
189186

190-
arg = func != wdentry_period ? wdog->arg : ptr_to_wdparm(
191-
list_container_of(wdog, struct wdog_period_s, wdog));
187+
arg = wdog->arg;
192188

193189
/* Execute the watchdog function */
194190

@@ -460,18 +456,18 @@ int wd_start(FAR struct wdog_s *wdog, sclock_t delay,
460456
*
461457
****************************************************************************/
462458

463-
int wd_start_period(FAR struct wdog_period_s *wdog, sclock_t delay,
459+
int wd_start_period(FAR struct wdog_s *wdog, sclock_t delay,
464460
clock_t period, wdentry_t wdentry, wdparm_t arg)
465461
{
466462
if (!wdog || !period || !wdentry)
467463
{
468464
return -EINVAL;
469465
}
470466

471-
wdog->func = wdentry;
467+
wdog->pfunc = wdentry;
472468
wdog->period = period;
473469

474-
return wd_start(&wdog->wdog, delay, wdentry_period, arg);
470+
return wd_start(wdog, delay, wd_period_callback, arg);
475471
}
476472

477473
/****************************************************************************

sched/wqueue/kwork_queue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ int work_queue_period_wq(FAR struct kwork_wqueue_s *wqueue,
195195
}
196196
else
197197
{
198-
ret = wd_start_period(&work->u.ptimer, delay, period,
198+
ret = wd_start_period(&work->u.timer, delay, period,
199199
work_timer_expiry, (wdparm_t)work);
200200
}
201201

0 commit comments

Comments
 (0)