【问题标题】:C - Watchdog Timer not starting or calling the call-back functionC - 看门狗定时器未启动或调用回调函数
【发布时间】:2018-03-23 08:14:54
【问题描述】:

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

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

下面是我的一些代码的 sn-p。正如您在主函数中看到的那样,我创建了我的看门狗定时器 (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 */  
}

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

非常感谢。

【问题讨论】:

  • 'while (1)'......

标签: c timer vxworks watchdog


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-18
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      相关资源
      最近更新 更多