2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2014-08-08 22:21:48 +02:00
|
|
|
* sched/wdog/wd_start.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-03-11 20:51:28 +01:00
|
|
|
* 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
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-03-11 20:51:28 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-03-11 20:51:28 +01:00
|
|
|
* 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.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
2009-06-17 00:08:59 +02:00
|
|
|
|
2009-12-14 19:39:29 +01:00
|
|
|
#include <stdint.h>
|
2009-12-14 22:15:18 +01:00
|
|
|
#include <stdbool.h>
|
2007-02-21 22:55:16 +01:00
|
|
|
#include <stdarg.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sched.h>
|
2014-08-07 19:39:16 +02:00
|
|
|
#include <assert.h>
|
2007-02-21 22:55:16 +01:00
|
|
|
#include <errno.h>
|
2009-06-17 00:08:59 +02:00
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
#include <nuttx/irq.h>
|
2009-06-17 00:08:59 +02:00
|
|
|
#include <nuttx/arch.h>
|
2014-08-21 19:16:55 +02:00
|
|
|
#include <nuttx/wdog.h>
|
2009-06-17 00:08:59 +02:00
|
|
|
|
2014-08-09 01:53:55 +02:00
|
|
|
#include "sched/sched.h"
|
2014-08-08 22:21:48 +02:00
|
|
|
#include "wdog/wdog.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2009-12-14 22:15:18 +01:00
|
|
|
* Pre-processor Definitions
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-07 19:39:16 +02:00
|
|
|
#ifndef MIN
|
|
|
|
# define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MAX
|
|
|
|
# define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Private Functions
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2016-02-18 00:17:44 +01:00
|
|
|
|
2014-08-07 19:39:16 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: wd_expiration
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if the timer for the watchdog at the head of list is ready to
|
|
|
|
* run. If so, remove the watchdog from the list and execute it.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2014-08-07 19:39:16 +02:00
|
|
|
* None
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2014-08-07 19:39:16 +02:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void wd_expiration(void)
|
|
|
|
{
|
2014-08-22 16:46:34 +02:00
|
|
|
FAR struct wdog_s *wdog;
|
2014-08-07 19:39:16 +02:00
|
|
|
|
|
|
|
/* Check if the watchdog at the head of the list is ready to run */
|
|
|
|
|
2014-08-22 16:46:34 +02:00
|
|
|
if (((FAR struct wdog_s *)g_wdactivelist.head)->lag <= 0)
|
2014-08-07 19:39:16 +02:00
|
|
|
{
|
|
|
|
/* Process the watchdog at the head of the list as well as any
|
|
|
|
* other watchdogs that became ready to run at this time
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (g_wdactivelist.head &&
|
2014-08-22 16:46:34 +02:00
|
|
|
((FAR struct wdog_s *)g_wdactivelist.head)->lag <= 0)
|
2014-08-07 19:39:16 +02:00
|
|
|
{
|
|
|
|
/* Remove the watchdog from the head of the list */
|
|
|
|
|
2014-08-22 16:46:34 +02:00
|
|
|
wdog = (FAR struct wdog_s *)sq_remfirst(&g_wdactivelist);
|
2014-08-07 19:39:16 +02:00
|
|
|
|
|
|
|
/* If there is another watchdog behind this one, update its
|
|
|
|
* its lag (this shouldn't be necessary).
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (g_wdactivelist.head)
|
|
|
|
{
|
2014-08-22 16:46:34 +02:00
|
|
|
((FAR struct wdog_s *)g_wdactivelist.head)->lag += wdog->lag;
|
2014-08-07 19:39:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Indicate that the watchdog is no longer active. */
|
|
|
|
|
2014-08-21 16:44:29 +02:00
|
|
|
WDOG_CLRACTIVE(wdog);
|
2014-08-07 19:39:16 +02:00
|
|
|
|
|
|
|
/* Execute the watchdog function */
|
|
|
|
|
|
|
|
up_setpicbase(wdog->picbase);
|
2019-10-04 17:10:15 +02:00
|
|
|
|
|
|
|
#if CONFIG_MAX_WDOGPARMS == 0
|
|
|
|
wdog->func(0);
|
|
|
|
#elif CONFIG_MAX_WDOGPARMS == 1
|
|
|
|
wdog->func((int)wdog->argc,
|
|
|
|
wdog->parm[0]);
|
|
|
|
#elif CONFIG_MAX_WDOGPARMS == 2
|
|
|
|
wdog->func((int)wdog->argc,
|
|
|
|
wdog->parm[0], wdog->parm[1]);
|
|
|
|
#elif CONFIG_MAX_WDOGPARMS == 3
|
|
|
|
wdog->func((int)wdog->argc,
|
|
|
|
wdog->parm[0], wdog->parm[1], wdog->parm[2]);
|
|
|
|
#elif CONFIG_MAX_WDOGPARMS == 4
|
|
|
|
wdog->func((int)wdog->argc,
|
|
|
|
wdog->parm[0], wdog->parm[1], wdog->parm[2],
|
|
|
|
wdog->parm[3]);
|
|
|
|
#else
|
|
|
|
# error Missing support
|
2014-08-07 19:39:16 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2012-07-14 21:30:31 +02:00
|
|
|
* Name: wd_start
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2018-08-19 19:19:43 +02:00
|
|
|
* This function adds a watchdog timer to the active timer queue. The
|
2017-02-24 17:58:37 +01:00
|
|
|
* specified watchdog function at 'wdentry' will be called from the
|
|
|
|
* interrupt level after the specified number of ticks has elapsed.
|
|
|
|
* Watchdog timers may be started from the interrupt level.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2014-08-07 19:39:16 +02:00
|
|
|
* Watchdog timers execute in the address environment that was in effect
|
2012-07-14 21:30:31 +02:00
|
|
|
* when wd_start() is called.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Watchdog timers execute only once.
|
|
|
|
*
|
2012-07-14 21:30:31 +02:00
|
|
|
* To replace either the timeout delay or the function to be executed,
|
|
|
|
* call wd_start again with the same wdog; only the most recent wdStart()
|
|
|
|
* on a given watchdog ID has any effect.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2020-04-07 18:07:13 +02:00
|
|
|
* wdog - Watchdog ID
|
2017-02-24 17:58:37 +01:00
|
|
|
* delay - Delay count in clock ticks
|
2020-04-07 18:07:13 +02:00
|
|
|
* wdentry - Function to call on timeout
|
|
|
|
* parm1..4 - Parameters to pass to wdentry
|
|
|
|
*
|
|
|
|
* NOTE: All parameters must be of type wdparm_t.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2018-01-31 17:09:14 +01:00
|
|
|
* Zero (OK) is returned on success; a negated errno value is return to
|
|
|
|
* indicate the nature of any failure.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Assumptions:
|
2012-07-14 21:30:31 +02:00
|
|
|
* The watchdog routine runs in the context of the timer interrupt handler
|
|
|
|
* and is subject to all ISR restrictions.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-01-05 14:58:04 +01:00
|
|
|
int wd_start(WDOG_ID wdog, int32_t delay, wdentry_t wdentry, int argc, ...)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2014-08-22 16:46:34 +02:00
|
|
|
va_list ap;
|
|
|
|
FAR struct wdog_s *curr;
|
|
|
|
FAR struct wdog_s *prev;
|
|
|
|
FAR struct wdog_s *next;
|
|
|
|
int32_t now;
|
2016-02-14 15:17:46 +01:00
|
|
|
irqstate_t flags;
|
2014-08-22 16:46:34 +02:00
|
|
|
int i;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-01-31 17:09:14 +01:00
|
|
|
/* Verify the wdog and setup parameters */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-01-31 17:09:14 +01:00
|
|
|
if (wdog == NULL || argc > CONFIG_MAX_WDOGPARMS || delay < 0)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2018-01-31 17:09:14 +01:00
|
|
|
return -EINVAL;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the watchdog has been started. If so, stop it.
|
|
|
|
* NOTE: There is a race condition here... the caller may receive
|
|
|
|
* the watchdog between the time that wd_start is called and
|
|
|
|
* the critical section is established.
|
|
|
|
*/
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2014-08-21 16:44:29 +02:00
|
|
|
if (WDOG_ISACTIVE(wdog))
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2007-02-21 22:55:16 +01:00
|
|
|
wd_cancel(wdog);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the data in the watchdog structure */
|
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
wdog->func = wdentry; /* Function to execute when delay expires */
|
2009-06-17 23:15:31 +02:00
|
|
|
up_getpicbase(&wdog->picbase);
|
2008-01-31 18:59:22 +01:00
|
|
|
wdog->argc = argc;
|
2007-02-21 22:55:16 +01:00
|
|
|
|
|
|
|
va_start(ap, argc);
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
{
|
2015-05-18 16:53:42 +02:00
|
|
|
wdog->parm[i] = va_arg(ap, wdparm_t);
|
2007-02-21 22:55:16 +01:00
|
|
|
}
|
2019-10-24 18:49:28 +02:00
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2007-02-21 22:55:16 +01:00
|
|
|
for (; i < CONFIG_MAX_WDOGPARMS; i++)
|
|
|
|
{
|
|
|
|
wdog->parm[i] = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2019-10-24 18:49:28 +02:00
|
|
|
|
2007-02-21 22:55:16 +01:00
|
|
|
va_end(ap);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Calculate delay+1, forcing the delay into a range that we can handle */
|
|
|
|
|
|
|
|
if (delay <= 0)
|
|
|
|
{
|
|
|
|
delay = 1;
|
|
|
|
}
|
|
|
|
else if (++delay <= 0)
|
|
|
|
{
|
|
|
|
delay--;
|
|
|
|
}
|
|
|
|
|
2014-08-11 16:25:25 +02:00
|
|
|
#ifdef CONFIG_SCHED_TICKLESS
|
2020-03-11 20:51:28 +01:00
|
|
|
/* Cancel the interval timer that drives the timing events. This will
|
|
|
|
* cause wd_timer to be called which update the delay value for the first
|
|
|
|
* time at the head of the timer list (there is a possibility that it
|
|
|
|
* could even remove it).
|
2014-08-11 16:25:25 +02:00
|
|
|
*/
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
sched_timer_cancel();
|
2014-08-11 16:25:25 +02:00
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Do the easy case first -- when the watchdog timer queue is empty. */
|
|
|
|
|
|
|
|
if (g_wdactivelist.head == NULL)
|
|
|
|
{
|
2018-11-09 16:26:34 +01:00
|
|
|
#ifdef CONFIG_SCHED_TICKLESS
|
|
|
|
/* Update clock tickbase */
|
|
|
|
|
|
|
|
g_wdtickbase = clock_systimer();
|
|
|
|
#endif
|
|
|
|
|
2014-08-10 21:12:18 +02:00
|
|
|
/* Add the watchdog to the head == tail of the queue. */
|
2014-08-07 19:39:16 +02:00
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
sq_addlast((FAR sq_entry_t *)wdog, &g_wdactivelist);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* There are other active watchdogs in the timer queue */
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
now = 0;
|
2014-08-22 16:46:34 +02:00
|
|
|
prev = curr = (FAR struct wdog_s *)g_wdactivelist.head;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Advance to positive time */
|
|
|
|
|
|
|
|
while ((now += curr->lag) < 0 && curr->next)
|
|
|
|
{
|
|
|
|
prev = curr;
|
|
|
|
curr = curr->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Advance past shorter delays */
|
|
|
|
|
|
|
|
while (now <= delay && curr->next)
|
2015-10-08 03:59:14 +02:00
|
|
|
{
|
|
|
|
prev = curr;
|
|
|
|
curr = curr->next;
|
|
|
|
now += curr->lag;
|
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-02-21 22:55:16 +01:00
|
|
|
/* Check if the new wdog must be inserted before the curr. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
if (delay < now)
|
|
|
|
{
|
|
|
|
/* The relative delay time is smaller or equal to the current delay
|
|
|
|
* time, so decrement the current delay time by the new relative
|
|
|
|
* delay time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
delay -= (now - curr->lag);
|
|
|
|
curr->lag -= delay;
|
|
|
|
|
|
|
|
/* Insert the new watchdog in the list */
|
|
|
|
|
2014-08-22 16:46:34 +02:00
|
|
|
if (curr == (FAR struct wdog_s *)g_wdactivelist.head)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2014-08-10 21:12:18 +02:00
|
|
|
/* Insert the watchdog at the head of the list */
|
2014-08-07 19:39:16 +02:00
|
|
|
|
2014-08-22 16:46:34 +02:00
|
|
|
sq_addfirst((FAR sq_entry_t *)wdog, &g_wdactivelist);
|
2014-08-10 21:12:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Insert the watchdog in mid- or end-of-queue */
|
|
|
|
|
2014-08-22 16:46:34 +02:00
|
|
|
sq_addafter((FAR sq_entry_t *)prev, (FAR sq_entry_t *)wdog,
|
2014-08-10 21:12:18 +02:00
|
|
|
&g_wdactivelist);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The new watchdog delay time is greater than the curr delay time,
|
2007-02-21 22:55:16 +01:00
|
|
|
* so the new wdog must be inserted after the curr. This only occurs
|
|
|
|
* if the wdog is to be added to the end of the list.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delay -= now;
|
|
|
|
if (!curr->next)
|
|
|
|
{
|
2015-10-08 03:59:14 +02:00
|
|
|
sq_addlast((FAR sq_entry_t *)wdog, &g_wdactivelist);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
next = curr->next;
|
|
|
|
next->lag -= delay;
|
2015-10-08 03:59:14 +02:00
|
|
|
sq_addafter((FAR sq_entry_t *)curr, (FAR sq_entry_t *)wdog,
|
2007-02-18 00:21:28 +01:00
|
|
|
&g_wdactivelist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Put the lag into the watchdog structure and mark it as active. */
|
|
|
|
|
2014-08-21 16:44:29 +02:00
|
|
|
wdog->lag = delay;
|
|
|
|
WDOG_SETACTIVE(wdog);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-07 19:39:16 +02:00
|
|
|
#ifdef CONFIG_SCHED_TICKLESS
|
2014-08-11 16:25:25 +02:00
|
|
|
/* Resume the interval timer that will generate the next interval event.
|
|
|
|
* If the timer at the head of the list changed, then this will pick that
|
|
|
|
* new delay.
|
2014-08-07 19:39:16 +02:00
|
|
|
*/
|
|
|
|
|
2014-08-11 16:25:25 +02:00
|
|
|
sched_timer_resume();
|
2014-08-07 19:39:16 +02:00
|
|
|
#endif
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2007-02-18 00:21:28 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2012-07-14 21:30:31 +02:00
|
|
|
* Name: wd_timer
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2008-01-31 18:59:22 +01:00
|
|
|
* This function is called from the timer interrupt handler to determine
|
|
|
|
* if it is time to execute a watchdog function. If so, the watchdog
|
2014-08-07 19:39:16 +02:00
|
|
|
* function will be executed in the context of the timer interrupt
|
|
|
|
* handler.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2014-08-07 19:39:16 +02:00
|
|
|
* ticks - If CONFIG_SCHED_TICKLESS is defined then the number of ticks
|
2017-05-11 21:35:56 +02:00
|
|
|
* in the interval that just expired is provided. Otherwise,
|
2014-08-07 19:39:16 +02:00
|
|
|
* this function is called on each timer interrupt and a value of one
|
|
|
|
* is implicit.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2014-08-07 19:39:16 +02:00
|
|
|
* If CONFIG_SCHED_TICKLESS is defined then the number of ticks for the
|
|
|
|
* next delay is provided (zero if no delay). Otherwise, this function
|
|
|
|
* has no returned value.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Assumptions:
|
2014-08-07 19:39:16 +02:00
|
|
|
* Called from interrupt handler logic with interrupts disabled.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-07 19:39:16 +02:00
|
|
|
#ifdef CONFIG_SCHED_TICKLESS
|
|
|
|
unsigned int wd_timer(int ticks)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2014-08-22 16:46:34 +02:00
|
|
|
FAR struct wdog_s *wdog;
|
2016-11-18 20:57:30 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
irqstate_t flags;
|
|
|
|
#endif
|
|
|
|
unsigned int ret;
|
2014-08-07 19:39:16 +02:00
|
|
|
int decr;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-11-18 20:57:30 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* We are in an interrupt handler as, as a consequence, interrupts are
|
2018-08-19 19:19:43 +02:00
|
|
|
* disabled. But in the SMP case, interrupts MAY be disabled only on
|
2016-11-18 20:57:30 +01:00
|
|
|
* the local CPU since most architectures do not permit disabling
|
|
|
|
* interrupts on other CPUS.
|
|
|
|
*
|
|
|
|
* Hence, we must follow rules for critical sections even here in the
|
|
|
|
* SMP case.
|
|
|
|
*/
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Check if there are any active watchdogs to process */
|
|
|
|
|
2016-11-18 20:57:30 +01:00
|
|
|
while (g_wdactivelist.head != NULL && ticks > 0)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2014-08-07 19:39:16 +02:00
|
|
|
/* Get the watchdog at the head of the list */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-22 16:46:34 +02:00
|
|
|
wdog = (FAR struct wdog_s *)g_wdactivelist.head;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-15 14:56:42 +02:00
|
|
|
#ifndef CONFIG_SCHED_TICKLESS_ALARM
|
|
|
|
/* There is logic to handle the case where ticks is greater than
|
2014-08-07 19:39:16 +02:00
|
|
|
* the watchdog lag, but if the scheduling is working properly
|
|
|
|
* that should never happen.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-07 19:39:16 +02:00
|
|
|
DEBUGASSERT(ticks <= wdog->lag);
|
2014-08-15 14:56:42 +02:00
|
|
|
#endif
|
|
|
|
/* Decrement the lag for this watchdog. */
|
|
|
|
|
2014-08-07 19:39:16 +02:00
|
|
|
decr = MIN(wdog->lag, ticks);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-07 19:39:16 +02:00
|
|
|
/* There are. Decrement the lag counter */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-11-09 16:26:34 +01:00
|
|
|
wdog->lag -= decr;
|
|
|
|
ticks -= decr;
|
|
|
|
g_wdtickbase += decr;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-07 19:39:16 +02:00
|
|
|
/* Check if the watchdog at the head of the list is ready to run */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-07 19:39:16 +02:00
|
|
|
wd_expiration();
|
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-11-09 16:26:34 +01:00
|
|
|
/* Update clock tickbase */
|
|
|
|
|
|
|
|
g_wdtickbase += ticks;
|
|
|
|
|
2014-08-07 19:39:16 +02:00
|
|
|
/* Return the delay for the next watchdog to expire */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-11-18 20:57:30 +01:00
|
|
|
ret = g_wdactivelist.head ?
|
|
|
|
((FAR struct wdog_s *)g_wdactivelist.head)->lag : 0;
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
leave_critical_section(flags);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Return the delay for the next watchdog to expire */
|
|
|
|
|
|
|
|
return ret;
|
2014-08-07 19:39:16 +02:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-07 19:39:16 +02:00
|
|
|
#else
|
|
|
|
void wd_timer(void)
|
|
|
|
{
|
2016-11-18 20:57:30 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* We are in an interrupt handler as, as a consequence, interrupts are
|
2018-08-19 19:19:43 +02:00
|
|
|
* disabled. But in the SMP case, interrupts MAY be disabled only on
|
2016-11-18 20:57:30 +01:00
|
|
|
* the local CPU since most architectures do not permit disabling
|
|
|
|
* interrupts on other CPUS.
|
|
|
|
*
|
|
|
|
* Hence, we must follow rules for critical sections even here in the
|
|
|
|
* SMP case.
|
|
|
|
*/
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
#endif
|
|
|
|
|
2014-08-07 19:39:16 +02:00
|
|
|
/* Check if there are any active watchdogs to process */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-07 19:39:16 +02:00
|
|
|
if (g_wdactivelist.head)
|
|
|
|
{
|
|
|
|
/* There are. Decrement the lag counter */
|
2007-02-21 22:55:16 +01:00
|
|
|
|
2014-08-22 16:46:34 +02:00
|
|
|
--(((FAR struct wdog_s *)g_wdactivelist.head)->lag);
|
2014-08-07 19:39:16 +02:00
|
|
|
|
|
|
|
/* Check if the watchdog at the head of the list is ready to run */
|
|
|
|
|
|
|
|
wd_expiration();
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2016-11-18 20:57:30 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
leave_critical_section(flags);
|
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2014-08-07 19:39:16 +02:00
|
|
|
#endif /* CONFIG_SCHED_TICKLESS */
|