Watchdog Doesn't Reset (WB 3.5.0)
Answer
2/7/19 3:23 AM

I am having trouble understanding the implementation of the Watchdog timer.  Please see my code below for my implementation.  The below code doesn't seem to trip the watchdog reset after 5 seconds as I would assume.  If i uncomment the else statment to keep the task running, then the watchdog does trigger.  Why does the Watchdog timer only tick when the Task is running? 
Am I setting it up incorrectly?  I would like it to constantly tick regardless of what is going on in my code.  Please note I have tried the code with .RunOnCpuHalt = true;  If if recall the previous code I wrote doens't stall when that task is in the background.  Any insights here would be helpful.

Thanks for your help.

/* own header files */
#include "XdkAppInfo.h"
#undef BCDS_MODULE_ID  /* Module ID define before including Basics package*/
#define BCDS_MODULE_ID XDK_APP_MODULE_ID_APP_CONTROLLER

/* own header files */
#include "AppController.h"

/* system header files */
#include <stdio.h>

/* additional interface header files */
#include "BCDS_CmdProcessor.h"
#include "XDK_Utils.h"
#include "FreeRTOS.h"
#include "task.h"
#include "BCDS_MCU_Watchdog.h"

/* constant definitions ***************************************************** */

/* local variables ********************************************************** */

static CmdProcessor_T * AppCmdProcessor;/**< Handle to store the main Command processor handle to be used by run-time event driven threads */

static xTaskHandle AppControllerHandle = NULL;/**< OS thread handle for Application controller to be used by run-time blocking threads */

static MCU_Watchdog_Init_T WatchdogSetupInfo =
		{
				.WdgCallback = NULL,
				.ResetMode = MCU_WATCHDOG_RESET_ON,
				.RunOnCpuHalt = false,
				.Timeout = 5000
		};  // Watchdog setup parameters

/* global variables ********************************************************* */

/* inline functions ********************************************************* */

/* local functions ********************************************************** */

/**
 * @brief Responsible for controlling application control flow.
 * Any application logic which is blocking in nature or fixed time dependent
 * can be placed here.
 *
 * @param[in] pvParameters
 * FreeRTOS task handle. Could be used if more than one thread is using this function block.
 */
static void AppControllerFire(void* pvParameters)
{
    BCDS_UNUSED(pvParameters);
    int count = 0;

    /* A function that implements a task must not exit or attempt to return to
     its caller function as there is nothing to return to. */
    while (1)
    {
    	if (count < 10) {
    		MCU_Watchdog_Feed();
    	}
//   	else {
//    		while(1);
//    	}
    	count++;
    	printf("count = %d\r\n", count);
    	vTaskDelay(1000);
    }
}

/**
 * @brief To enable the necessary modules for the application
 *
 * @param [in] param1
 * A generic pointer to any context data structure which will be passed to the function when it is invoked by the command processor.
 *
 * @param [in] param2
 * A generic 32 bit value  which will be passed to the function when it is invoked by the command processor..
 */
static void AppControllerEnable(void * param1, uint32_t param2)
{
    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);
    Retcode_T retcode = RETCODE_OK;

    retcode = MCU_Watchdog_Enable();
    if (RETCODE_OK == retcode)
    {
        if (pdPASS != xTaskCreate(AppControllerFire, (const char * const ) "AppController", TASK_STACK_SIZE_APP_CONTROLLER, NULL, TASK_PRIO_APP_CONTROLLER, &AppControllerHandle))
        {
            retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_OUT_OF_RESOURCES);
        }
    }
    if (RETCODE_OK != retcode)
    {
        printf("AppControllerEnable : Failed \r\n");
        Retcode_RaiseError(retcode);
        assert(0); /* To provide LED indication for the user */
    }
    Utils_PrintResetCause();
}

/**
 * @brief To setup the necessary modules for the application
 *
 * @param [in] param1
 * A generic pointer to any context data structure which will be passed to the function when it is invoked by the command processor.
 *
 * @param [in] param2
 * A generic 32 bit value  which will be passed to the function when it is invoked by the command processor..
 */
static void AppControllerSetup(void * param1, uint32_t param2)
{
    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);
    Retcode_T retcode = RETCODE_OK;

    retcode = MCU_Watchdog_Init((WdgHandle_T) &WatchdogSetupInfo);
	if (RETCODE_OK == retcode)
	{
        retcode = CmdProcessor_Enqueue(AppCmdProcessor, AppControllerEnable, NULL, UINT32_C(0));
	}
    if (RETCODE_OK != retcode)
    {
        printf("AppControllerSetup : Failed \r\n");
        Retcode_RaiseError(retcode);
        assert(0); /* To provide LED indication for the user */
    }
}

/* global functions ********************************************************* */

/** Refer interface header for description */
void AppController_Init(void * cmdProcessorHandle, uint32_t param2)
{
    BCDS_UNUSED(param2);

    Retcode_T retcode = RETCODE_OK;

    if (cmdProcessorHandle == NULL)
    {
        printf("AppController_Init : Command processor handle is NULL \r\n");
        retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_NULL_POINTER);
    }
    else
    {
        AppCmdProcessor = (CmdProcessor_T *) cmdProcessorHandle;
        retcode = CmdProcessor_Enqueue(AppCmdProcessor, AppControllerSetup, NULL, UINT32_C(0));
    }

    if (RETCODE_OK != retcode)
    {
        Retcode_RaiseError(retcode);
        assert(0); /* To provide LED indication for the user */
    }
}

 

0 (0 Votes)
RE: Watchdog Doesn't Reset (WB 3.5.0)
Answer
2/7/19 2:02 PM as a reply to BCDS Tester.
Dear Chris,

I analyzed your issue more in detail and came to the same conclusion you did. In fact, you did nothing wrong with your usage of the module at all. The explanation for this issue is quite interesting.

With the latest update to the XDK-Workbench 3.5.0, the watchdog module is running underlying on every flashed XDK application.

As such, the module is already intialized at the startup of your XDK application, within the function systemStartup() for an expiring period of 4.26 minutes.

To make it able to run the watchdog underlying to the application, the function MCU_Watchdog_Feed() is called within an idle task. This idle task is called every time the main task is waiting for something and delayed via vTaskDelay() .

That means every time you called in your task the function vTaskDelay() , you triggered a call of MCU_Watchdog_Feed() .
However, if you stayed in the task forever due to the infinite while loop in the else condition, the idle task is never called and therefore is the watchdog not triggered.

For more information, I recommend taking a closer look at the implementation in the interface SystemStartup.c .
You can find the interface by navigating to it over the following folderpath:

SDK > xdk110 > Common > source

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Watchdog Doesn't Reset (WB 3.5.0)
Answer
2/7/19 3:53 PM as a reply to Franjo Stjepandic.

Franjo,

Thanks for that response and analysis.  I will look closer at the implementation in the startup routines.  I did not see where this was fed before.

From your explaination it sounds like the User Application cannot really make use of the Watchdog timer without editing the SDK.  The user can change the watchdog setup (timeout and other parameters) but can't change how the watchdog is fed unless this is edited.  I prefer not change the SDK if I can, so that others can plug and play with the code I create, so I will find another way to trigger a reset based on the conditions of my application.

Christopher Koch

0 (0 Votes)
RE: Watchdog Doesn't Reset (WB 3.5.0)
Answer
2/7/19 4:50 PM as a reply to BCDS Tester.
Hello Chris,

I am always happy to help. Unfortunately, in this case, the initialization of the watchdog timer can be excluded with a define, but sadly the actual feeding in the idle task is not affected by this.

As such, it would be necessary to make adaptions to the SDK.

Nevertheless, maybe you could go more into detail about the circumstances of your application. There might be some other approach left about adding a reset into it.

Kind regards,
Franjo
0 (0 Votes)
RE: Watchdog Doesn't Reset (WB 3.5.0)
Answer
2/7/19 8:45 PM as a reply to Franjo Stjepandic.

Franjo,

I feared as much.  I will look for another solution.  Luckily you have already pointed me down the right path in the other thread we have going here.

I am using MQTT and would like to protect against any connection issues with the MQTT broker or the internet connection being lost.  To be honest, the current path you have me looking down was going to be the final path, I just wanted to have a quick fix with a watchdog.

Thanks again for all your help.

Christopher Koch

0 (0 Votes)
RE: Watchdog Doesn't Reset (WB 3.5.0)
Answer
2/8/19 1:35 PM as a reply to BCDS Tester.
Hello Chris,

I am glad that I could point you to the suitable solution.

A quick fix with the watchdog module, is of course, a good idea as final fallback, but if it is triggered too often you have the disadvantage that the battery is drained even faster. So in regards of MQTT implementing routines to reconnecting to the local Wi-Fi and the MQTT broker is definitely more beneficial.

Kind regards,
Franjo
0 (0 Votes)