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 */
}
}