2016-08-07 16:25:30 +02:00
|
|
|
/****************************************************************************
|
2014-08-08 22:21:48 +02:00
|
|
|
* sched/wdog/wd_gettime.c
|
2007-03-21 18:21:26 +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-03-21 18:21:26 +01:00
|
|
|
*
|
2020-03-11 20:51:28 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-03-21 18:21:26 +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-03-21 18:21:26 +01:00
|
|
|
*
|
2016-08-07 16:25:30 +02:00
|
|
|
****************************************************************************/
|
2007-03-21 18:21:26 +01:00
|
|
|
|
2016-08-07 16:25:30 +02:00
|
|
|
/****************************************************************************
|
2007-03-21 18:21:26 +01:00
|
|
|
* Included Files
|
2016-08-07 16:25:30 +02:00
|
|
|
****************************************************************************/
|
2007-03-21 18:21:26 +01:00
|
|
|
|
2009-12-14 19:39:29 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2014-08-21 19:16:55 +02:00
|
|
|
#include <nuttx/wdog.h>
|
2016-02-14 15:17:46 +01:00
|
|
|
#include <nuttx/irq.h>
|
2009-12-14 19:39:29 +01:00
|
|
|
|
2014-08-08 22:21:48 +02:00
|
|
|
#include "wdog/wdog.h"
|
2007-03-21 18:21:26 +01:00
|
|
|
|
2016-08-07 16:25:30 +02:00
|
|
|
/****************************************************************************
|
2007-03-21 18:21:26 +01:00
|
|
|
* Public Functions
|
2016-08-07 16:25:30 +02:00
|
|
|
****************************************************************************/
|
2007-03-21 18:21:26 +01:00
|
|
|
|
2016-08-07 16:25:30 +02:00
|
|
|
/****************************************************************************
|
2012-07-14 21:30:31 +02:00
|
|
|
* Name: wd_gettime
|
2007-03-21 18:21:26 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2009-06-25 19:44:35 +02:00
|
|
|
* This function returns the time remaining before the specified watchdog
|
2017-02-24 17:58:37 +01:00
|
|
|
* timer expires.
|
2007-03-21 18:21:26 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-02-24 17:58:37 +01:00
|
|
|
* wdog - watchdog ID
|
2007-03-21 18:21:26 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2016-08-07 16:25:30 +02:00
|
|
|
* The time in system ticks remaining until the watchdog time expires.
|
|
|
|
* Zero means either that wdog is not valid or that the wdog has already
|
|
|
|
* expired.
|
2007-03-21 18:21:26 +01:00
|
|
|
*
|
2016-08-07 16:25:30 +02:00
|
|
|
****************************************************************************/
|
2007-03-21 18:21:26 +01:00
|
|
|
|
2020-08-04 12:31:31 +02:00
|
|
|
int wd_gettime(FAR struct wdog_s *wdog)
|
2007-03-21 18:21:26 +01:00
|
|
|
{
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* Verify the wdog */
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2017-02-24 17:58:37 +01:00
|
|
|
if (wdog != NULL && WDOG_ISACTIVE(wdog))
|
2007-03-21 18:21:26 +01:00
|
|
|
{
|
2016-08-07 16:25:30 +02:00
|
|
|
/* Traverse the watchdog list accumulating lag times until we find the
|
|
|
|
* wdog that we are looking for
|
2007-03-21 18:21:26 +01:00
|
|
|
*/
|
|
|
|
|
2014-08-22 16:46:34 +02:00
|
|
|
FAR struct wdog_s *curr;
|
2007-03-21 18:21:26 +01:00
|
|
|
int delay = 0;
|
|
|
|
|
2016-08-07 16:25:30 +02:00
|
|
|
for (curr = (FAR struct wdog_s *)g_wdactivelist.head;
|
|
|
|
curr != NULL;
|
|
|
|
curr = curr->next)
|
2007-03-21 18:21:26 +01:00
|
|
|
{
|
|
|
|
delay += curr->lag;
|
|
|
|
if (curr == wdog)
|
|
|
|
{
|
2018-11-09 16:26:34 +01:00
|
|
|
delay -= wd_elapse();
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2007-03-21 18:21:26 +01:00
|
|
|
return delay;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2007-03-21 18:21:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|