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

标签 c timer vxworks watchdog

我正在使用 Wind River Workbench 3.3 创建 VxWorks 程序。

该程序要求我使用看门狗定时器,但是我在启动定时器时遇到问题。

下面是我的一些代码的片段。正如您在主函数中看到的,我创建了看门狗定时器 (wdCreate()),并且定时器在smallObject 函数(wdStart()) 中启动。我已经验证我的代码确实达到了预期的smallObject 函数。

我已将计时器的回调函数设置为名为 closeOpenGates() 的函数,但是计时器在任何时间后都不会回调该函数。

我已经包含了必要的头文件'#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 */  
}

任何关于可能导致我的看门狗定时器无法启动或回调函数的想法都将不胜感激。

非常感谢。

最佳答案

这里的主要问题是您在任务中不断重新启动计时器。 SmallObject 执行无限循环,并且每次都会调用 wdStart。 唯一不会这样做的情况是对 wdStart 的调用失败,在这种情况下任务将退出。

在已运行的计时器上调用 wdStart 具有重新启动计时器的效果。因此,它会不断重新启动,因此永远不会超时。

关于C - 看门狗定时器未启动或调用回调函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49445097/

相关文章:

c++ - Socket getaddrinfo() - VxWorks 的等效函数?

c - 在这个例子中应该创建什么任务?

c - 重建所有项目或部分项目需要什么?

c - 二维莫顿解码功能 64bits

c - 为什么我插入队列的数据没有从另一端出来?

循环中的javascript超时

java - 使用 Timer/ScheduledThreadPool 来减少频繁更改元素的 CPU 负载

c - 每个级别的内存层次结构的延迟测量

控制台仅对所有 double 显示 0

java - Swing Timer 滴答声不稳定,不规则