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
|
|
|
*
|
2024-09-11 13:45:11 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
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>
|
2023-02-01 14:41:12 +01:00
|
|
|
#include <sys/param.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>
|
2023-03-29 12:17:45 +02:00
|
|
|
#include <debug.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
|
|
|
|
2021-04-29 13:41:27 +02:00
|
|
|
#ifndef CONFIG_SCHED_CRITMONITOR_MAXTIME_WDOG
|
|
|
|
# define CONFIG_SCHED_CRITMONITOR_MAXTIME_WDOG 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_WDOG > 0
|
|
|
|
# define CALL_FUNC(func, arg) \
|
|
|
|
do \
|
|
|
|
{ \
|
2023-09-28 10:37:27 +02:00
|
|
|
clock_t start; \
|
|
|
|
clock_t elapsed; \
|
|
|
|
start = perf_gettime(); \
|
2021-04-29 13:41:27 +02:00
|
|
|
func(arg); \
|
2023-09-28 10:37:27 +02:00
|
|
|
elapsed = perf_gettime() - start; \
|
2021-04-29 13:41:27 +02:00
|
|
|
if (elapsed > CONFIG_SCHED_CRITMONITOR_MAXTIME_WDOG) \
|
|
|
|
{ \
|
2023-09-28 10:37:27 +02:00
|
|
|
CRITMONITOR_PANIC("WDOG %p, %s IRQ, execute too long %ju\n", \
|
2023-04-07 12:52:57 +02:00
|
|
|
func, up_interrupt_context() ? \
|
2023-09-28 10:37:27 +02:00
|
|
|
"IN" : "NOT", (uintmax_t)elapsed); \
|
2021-04-29 13:41:27 +02:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
#else
|
|
|
|
# define CALL_FUNC(func, arg) func(arg)
|
|
|
|
#endif
|
|
|
|
|
2024-07-15 05:08:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_TICKLESS
|
|
|
|
static unsigned int g_wdtimernested;
|
|
|
|
#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
|
2020-08-06 19:41:45 +02:00
|
|
|
* run. If so, remove the watchdog from the list and execute it.
|
2014-08-07 19:39:16 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2024-06-18 13:57:57 +02:00
|
|
|
* ticks - current time in ticks
|
2014-08-07 19:39:16 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2014-08-07 19:39:16 +02:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
static inline_function void wd_expiration(clock_t ticks)
|
2014-08-07 19:39:16 +02:00
|
|
|
{
|
2014-08-22 16:46:34 +02:00
|
|
|
FAR struct wdog_s *wdog;
|
2024-07-10 16:13:26 +02:00
|
|
|
irqstate_t flags;
|
2021-06-21 12:23:09 +02:00
|
|
|
wdentry_t func;
|
2014-08-07 19:39:16 +02:00
|
|
|
|
2024-07-10 16:13:26 +02:00
|
|
|
flags = enter_critical_section();
|
|
|
|
|
2024-07-15 05:08:55 +02:00
|
|
|
#ifdef CONFIG_SCHED_TICKLESS
|
|
|
|
/* Increment the nested watchdog timer count to handle cases where wd_start
|
|
|
|
* is called in the watchdog callback functions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
g_wdtimernested++;
|
|
|
|
#endif
|
|
|
|
|
2021-09-03 09:37:43 +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
|
|
|
|
*/
|
2014-08-07 19:39:16 +02:00
|
|
|
|
2024-07-05 13:24:34 +02:00
|
|
|
while (!list_is_empty(&g_wdactivelist))
|
2014-08-07 19:39:16 +02:00
|
|
|
{
|
2024-07-05 13:24:34 +02:00
|
|
|
wdog = list_first_entry(&g_wdactivelist, struct wdog_s, node);
|
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
/* Check if expected time is expired */
|
|
|
|
|
|
|
|
if (!clock_compare(wdog->expired, ticks))
|
2024-06-11 17:23:44 +02:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-09-03 09:37:43 +02:00
|
|
|
/* Remove the watchdog from the head of the list */
|
2014-08-07 19:39:16 +02:00
|
|
|
|
2024-06-11 17:23:44 +02:00
|
|
|
list_delete(&wdog->node);
|
2014-08-07 19:39:16 +02:00
|
|
|
|
2021-09-03 09:37:43 +02:00
|
|
|
/* Indicate that the watchdog is no longer active. */
|
2014-08-07 19:39:16 +02:00
|
|
|
|
2021-09-03 09:37:43 +02:00
|
|
|
func = wdog->func;
|
|
|
|
wdog->func = NULL;
|
2014-08-07 19:39:16 +02:00
|
|
|
|
2021-09-03 09:37:43 +02:00
|
|
|
/* Execute the watchdog function */
|
2014-08-07 19:39:16 +02:00
|
|
|
|
2021-09-03 09:37:43 +02:00
|
|
|
up_setpicbase(wdog->picbase);
|
|
|
|
CALL_FUNC(func, wdog->arg);
|
2014-08-07 19:39:16 +02:00
|
|
|
}
|
2024-07-15 05:08:55 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_TICKLESS
|
|
|
|
/* Decrement the nested watchdog timer count */
|
|
|
|
|
|
|
|
g_wdtimernested--;
|
|
|
|
#endif
|
2024-07-10 16:13:26 +02:00
|
|
|
|
|
|
|
leave_critical_section(flags);
|
2014-08-07 19:39:16 +02:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: wd_insert
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Insert the timer into the global list to ensure that
|
|
|
|
* the list is sorted in increasing order of expiration absolute time.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* wdog - Watchdog ID
|
|
|
|
* expired - expired absolute time in clock ticks
|
|
|
|
* wdentry - Function to call on timeout
|
|
|
|
* arg - Parameter to pass to wdentry
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* wdog and wdentry is not NULL.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline_function
|
|
|
|
void wd_insert(FAR struct wdog_s *wdog, clock_t expired,
|
|
|
|
wdentry_t wdentry, wdparm_t arg)
|
|
|
|
{
|
|
|
|
FAR struct wdog_s *curr;
|
|
|
|
|
|
|
|
/* Traverse the watchdog list */
|
|
|
|
|
|
|
|
list_for_every_entry(&g_wdactivelist, curr, struct wdog_s, node)
|
|
|
|
{
|
|
|
|
/* Until curr->expired has not timed out relative to expired */
|
|
|
|
|
|
|
|
if (!clock_compare(curr->expired, expired))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There are two cases:
|
|
|
|
* - Traverse to the end, where curr == &g_wdactivelist.
|
|
|
|
* - Find a curr such that curr->expected has not timed out
|
|
|
|
* relative to expired.
|
|
|
|
* In either case 1 or 2, we just insert the wdog before curr.
|
|
|
|
*/
|
|
|
|
|
|
|
|
list_add_before(&curr->node, &wdog->node);
|
|
|
|
|
|
|
|
wdog->func = wdentry;
|
|
|
|
up_getpicbase(&wdog->picbase);
|
|
|
|
wdog->arg = arg;
|
|
|
|
wdog->expired = expired;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/****************************************************************************
|
2024-08-08 06:16:15 +02:00
|
|
|
* Name: wd_start_abstick
|
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
|
2024-06-18 13:57:57 +02:00
|
|
|
* interrupt level after the specified number of ticks has reached.
|
2017-02-24 17:58:37 +01:00
|
|
|
* 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
|
2024-06-18 13:57:57 +02:00
|
|
|
* ticks - Absoulute time in clock ticks
|
2020-04-07 18:07:13 +02:00
|
|
|
* wdentry - Function to call on timeout
|
2024-06-18 13:57:57 +02:00
|
|
|
* arg - Parameter to pass to wdentry.
|
2020-04-07 18:07:13 +02:00
|
|
|
*
|
2020-08-09 20:29:35 +02:00
|
|
|
* NOTE: The parameter 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
|
|
|
|
2024-08-08 06:16:15 +02:00
|
|
|
int wd_start_abstick(FAR struct wdog_s *wdog, clock_t ticks,
|
|
|
|
wdentry_t wdentry, wdparm_t arg)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2016-02-14 15:17:46 +01:00
|
|
|
irqstate_t flags;
|
2024-06-18 13:57:57 +02:00
|
|
|
bool reassess = false;
|
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
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
if (wdog == NULL || wdentry == NULL)
|
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
|
|
|
}
|
|
|
|
|
2024-09-10 06:35:01 +02:00
|
|
|
/* Calculate ticks+1, forcing the delay into a range that we can handle.
|
|
|
|
*
|
|
|
|
* NOTE that one is added to the delay. This is correct and must not be
|
|
|
|
* changed: The contract for the use wdog_start is that the wdog will
|
|
|
|
* delay FOR AT LEAST as long as requested, but may delay longer due to
|
|
|
|
* variety of factors. The wdog logic has no knowledge of the the phase
|
|
|
|
* of the system timer when it is started: The next timer interrupt may
|
|
|
|
* occur immediately or may be delayed for almost a full cycle. In order
|
|
|
|
* to meet the contract requirement, the requested time is also always
|
|
|
|
* incremented by one so that the delay is always at least as long as
|
|
|
|
* requested.
|
|
|
|
*
|
|
|
|
* There is extensive documentation about this time issue elsewhere.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ticks++;
|
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
/* NOTE: There is a race condition here... the caller may receive
|
2024-08-08 06:16:15 +02:00
|
|
|
* the watchdog between the time that wd_start_abstick is called and
|
2007-02-18 00:21:28 +01:00
|
|
|
* the critical section is established.
|
|
|
|
*/
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2024-06-18 13:57:57 +02:00
|
|
|
#ifdef CONFIG_SCHED_TICKLESS
|
|
|
|
/* We need to reassess timer if the watchdog list head has changed. */
|
|
|
|
|
2014-08-21 16:44:29 +02:00
|
|
|
if (WDOG_ISACTIVE(wdog))
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2024-06-18 13:57:57 +02:00
|
|
|
reassess |= list_is_head(&g_wdactivelist, &wdog->node);
|
|
|
|
list_delete(&wdog->node);
|
|
|
|
wdog->func = NULL;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
wd_insert(wdog, ticks, wdentry, arg);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-09-06 15:01:43 +02:00
|
|
|
if (!g_wdtimernested &&
|
|
|
|
(reassess || list_is_head(&g_wdactivelist, &wdog->node)))
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2024-06-18 13:57:57 +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-11 16:25:25 +02:00
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
nxsched_reassess_timer();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
UNUSED(reassess);
|
2014-08-11 16:25:25 +02:00
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
/* Check if the watchdog has been started. If so, delete it. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
if (WDOG_ISACTIVE(wdog))
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2024-06-18 13:57:57 +02:00
|
|
|
list_delete(&wdog->node);
|
|
|
|
wdog->func = NULL;
|
|
|
|
}
|
2018-11-09 16:26:34 +01:00
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
wd_insert(wdog, ticks, wdentry, arg);
|
2018-11-09 16:26:34 +01:00
|
|
|
#endif
|
2024-06-18 13:57:57 +02:00
|
|
|
leave_critical_section(flags);
|
|
|
|
return OK;
|
|
|
|
}
|
2018-11-09 16:26:34 +01:00
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: wd_start
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function adds a watchdog timer to the active timer queue. The
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Watchdog timers execute in the address environment that was in effect
|
|
|
|
* when wd_start() is called.
|
|
|
|
*
|
|
|
|
* Watchdog timers execute only once.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* wdog - Watchdog ID
|
|
|
|
* delay - Delay count in clock 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
int wd_start(FAR struct wdog_s *wdog, sclock_t delay,
|
|
|
|
wdentry_t wdentry, wdparm_t arg)
|
|
|
|
{
|
|
|
|
/* Verify the wdog and setup parameters */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
if (delay < 0)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2024-06-18 13:57:57 +02:00
|
|
|
return -EINVAL;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2024-08-08 06:16:15 +02:00
|
|
|
return wd_start_abstick(wdog, clock_systime_ticks() + delay,
|
|
|
|
wdentry, arg);
|
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_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.
|
2021-08-25 07:52:20 +02:00
|
|
|
* noswitches - True: Can't do context switches now.
|
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
|
2024-06-18 13:57:57 +02:00
|
|
|
clock_t wd_timer(clock_t ticks, bool noswitches)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2014-08-22 16:46:34 +02:00
|
|
|
FAR struct wdog_s *wdog;
|
2024-07-10 16:13:26 +02:00
|
|
|
irqstate_t flags;
|
2024-06-18 13:57:57 +02:00
|
|
|
sclock_t ret;
|
2023-08-25 14:56:24 +02:00
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
/* Check if the watchdog at the head of the list is ready to run */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
if (!noswitches)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2024-06-18 13:57:57 +02:00
|
|
|
wd_expiration(ticks);
|
2021-08-25 07:52:20 +02:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-07-10 16:13:26 +02:00
|
|
|
flags = enter_critical_section();
|
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
/* Return the delay for the next watchdog to expire */
|
2021-08-25 07:52:20 +02:00
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
if (list_is_empty(&g_wdactivelist))
|
2021-08-25 07:52:20 +02:00
|
|
|
{
|
2024-07-10 16:13:26 +02:00
|
|
|
leave_critical_section(flags);
|
2024-07-15 17:24:39 +02:00
|
|
|
return 0;
|
2014-08-07 19:39:16 +02:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
/* Notice that if noswitches, expired - g_wdtickbase
|
|
|
|
* may get negative value.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
wdog = list_first_entry(&g_wdactivelist, struct wdog_s, node);
|
|
|
|
ret = wdog->expired - ticks;
|
2016-11-18 20:57:30 +01:00
|
|
|
|
2024-07-10 16:13:26 +02:00
|
|
|
leave_critical_section(flags);
|
|
|
|
|
2016-11-18 20:57:30 +01:00
|
|
|
/* Return the delay for the next watchdog to expire */
|
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
return MAX(ret, 1);
|
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
|
2024-06-18 13:57:57 +02:00
|
|
|
void wd_timer(clock_t ticks)
|
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
|
|
|
|
2024-06-18 13:57:57 +02:00
|
|
|
wd_expiration(ticks);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2014-08-07 19:39:16 +02:00
|
|
|
#endif /* CONFIG_SCHED_TICKLESS */
|