简体   繁体   English

C-看门狗定时器未启动或未调用回调函数

[英]C - Watchdog Timer not starting or calling the call-back function

I am creating a VxWorks program using the Wind River Workbench 3.3. 我正在使用Wind River Workbench 3.3创建VxWorks程序。

The program requires me to make use of Watchdog Timers, however I am having problems in getting the timers to start. 该程序要求我使用看门狗定时器,但是在启动定时器时遇到了问题。

Below is a snippet of some of my code. 下面是我的一些代码片段。 As you can see in the main function I create my Watchdog Timer (wdCreate()) and the timer is started in the smallObject function (wdStart()). 如您在主函数中看到的,我创建了我的看门狗计时器(wdCreate()),并且计时器在smallObject函数(wdStart())中启动。 I have verified that my code does indeed reach the smallObject function as intended. 我已验证我的代码确实确实达到了预期的smallObject函数。

I have set the call-back function of the timer to the function called closeOpenGates(), however the timer never calls back to this function after any amount of time. 我已经将计时器的回调函数设置为名为closeOpenGates()的函数,但是计时器在任何时间量之后都不会回调该函数。

I have included the necessary header file '#include "wdLib.h". 我已经包含了必要的头文件'#include“ wdLib.h”。

#include "vxWorks.h"
#include "sysLib.h"
#include "taskLib.h"
#include "stdio.h"
#include "stdlib.h"
#include "cinterface.h"
#include "semLib.h"
#include "wdLib.h"
#include “msgQLib.h”

SEM_ID smallObjectSem;
SEM_ID largeObjectSem;

WDOG_ID gateTimer; /* Gate timer */ 
int gateTimerI

void main (void)
{
    char sizeSensorState;
    int res;

    startMotor(); /* Begins the motor to turn the conveyors */

    /* Create the task for handling detected small objects */
    int smallObjectTask;
    smallObjectTask = taskSpawn("Small Object Task", 100, 0, 20000, (FUNCPTR)smallObject, 0,0,0,0,0,0,0,0,0,0);


    gateTimer = wdCreate(); /* Create a timer for when to close the gate */
    if (gateTimer == NULL) 
    {
        printf("\n\nCannot create the gate timer! Terminating task...\n");
        exit(0);
    }

void smallObject(void)
{
    while (1)
    {

        smallObjectDetect0++; /* Increase the detected small object count by 1 */



        /* Start a timer for 3.5s - how long it takes the object to reach the gates */ 
        gateTimerInt = wdStart(gateTimer, 3.5 * sysClkRateGet(), (FUNCPTR)closeOpenGate, 0);
        if (gateTimerInt == ERROR)
        {
            printf("Cannot start the gate timer! Terminating task...");
            exit(0);
        }
        else printf("\nTimer started successfully");    
    }
}

void closeOpenGate (void)
{
    printf("\n Small Timer Successful");

    setGates(1); /* Close the gate on Conveyor 0 */
    taskDelay(1.5 * sysClkRateGet()); /* Wait for 1.5s to allow the small object to fall off */
    setGates(0); /* Reopen the gate */  
}

Any ideas about what might be causing my Watchdog Timer to not start or call-back to the function will be greatly appreciated. 对于可能导致我的看门狗定时器无法启动或回调该函数的任何想法,将不胜感激。

Many thanks. 非常感谢。

The main problem here is you are constantly restarting the timer, inside your task. 这里的主要问题是您在任务内部不断重启计时器。 smallObject executes an infinite loop, and on each occasion calls wdStart. smallObject执行无限循环,并在每种情况下调用wdStart。 The only time it will not do so, is if the call to wdStart fails, in which case the task will exit. 唯一不会这样做的情况是对wdStart的调用失败,在这种情况下任务将退出。

Calling wdStart on a timer that is already running, has the effect of restarting the timer. 在已经运行的计时器上调用wdStart具有重新启动计时器的效果。 Thus, it is constantly restarted, and thus never timesout. 因此,它不断重启,因此永不超时。

您将wdStart()放入while循环中,这导致它始终调用它,并且WatchDog计时器没有机会超时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM