This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/CC2640R2F: Watchdog callback and expired time problem

Part Number: CC2640R2F
Other Parts Discussed in Thread: SIMPLELINK-CC2640R2-SDK, BLE-STACK

Tool/software: TI-RTOS

Hi, TI enginner,

I am working on watchdog timer with BLE-STACK V3.0.1 (Support for CC2640R2F)(SIMPLELINK-CC2640R2-SDK_1.40.00.45)(20 Jul 2017)

Please see my question in yellow background.

Here are my key codes:

#define Board_WATCHDOG              CC2640R2_LAUNCHXL_WATCHDOG0

Watchdog_Handle watchdog;

static void wdtCallback(UArg handle)
{
     Watchdog_clear((Watchdog_Handle)handle);//********never run, why? *********
}

static void wdtInitFxn(void)
{
  Watchdog_init();

  Watchdog_Params wp;
  Watchdog_Params_init(&wp);
  wp.callbackFxn = wdtCallback;
  wp.debugStallMode = Watchdog_DEBUG_STALL_ON;
  wp.resetMode = Watchdog_RESET_ON;

  watchdog = Watchdog_open(Board_WATCHDOG, &wp);

  uint32_t ticks = Watchdog_convertMsToTicks( watchdog, EXP_TIME);////****** if I want to expire after 1s, I have to set EXP_TIME  to 1000/50, why? ***********
  Watchdog_setReload(watchdog, ticks);
}

So I have to run the dog feed function in task funciton:

static void simpleBLE_taskFxn(UArg a0, UArg a1)
{

simpleBLE_init();

for (;;)
{

events = Event_pend(syncEvent, Event_Id_NONE, MR_ALL_EVENTS,
ICALL_TIMEOUT_FOREVER);

if (events)
{

.......

}

Watchdog_clear(watchdog);//********it can run*********

}

Thanks!

Charles Bai.

  • Hi Charles,

         If Watchdog_RESET_ON the callback is not needed. By default the Watchdog_RESET_ON is already set so you don't need wp.resetMode = Watchdog_RESET_ON;. You can check this at watchdog.h.

         If Watchdog_RESET_OFF then callback is needed. At callback don't clear the watchdog. At callback you can do diagnostics, call system reset.

    Here is a basic Watchdog Initialization.

    void Wathdog__Init(void)
    {
        Watchdog_Params params;
        
        Watchdog_init();
        
        /* Create and enable a Watchdog with resets disabled */
        /* Default Watchdog_RESET_ON*/
        Watchdog_Params_init(&params);
        params.callbackFxn = (Watchdog_Callback)Watchdog__Callback;
        WatchdogHandle = Watchdog_open(Board_WATCHDOG0, &params);
        
        if (WatchdogHandle == NULL) {
            /* Error opening Watchdog */
            while (1);
        }
    }  

    You set the timeout at the board file. If Watchdog_RESET_ON and timeout expires, it will countdown again the second time and on the second timeout it will reset the device.

    You clear the watchdog before if(events). Because, if the device goes to Standby Mode, it will not be able to reach the watchdog clear code after if(events) condition.

    -kel

  • Hi, kel
    Thanks!
    I see.

    But, when I set timeout 5s as follow without running Watchdog_clear(watchdog), the system will reset after about 60s.

    uint32_t ticks = Watchdog_convertMsToTicks( watchdog, 5*1000);
    Watchdog_setReload(watchdog, ticks);

    where can I config the ms to tick ratio?

    -Charles
  • Charles Bai said:
    But, when I set timeout 5s as follow without running Watchdog_clear(watchdog), the system will reset after about 60s.

    I have used that Watchdog_convertMsToTicks() before and works as is. Maybe your code implementation causes to reset after 60s. Do not call watchdog clear anywhere to test if it works.

    Charles Bai said:
    where can I config the ms to tick ratio?

    at the .c board file.

    /*
     *  =============================== Watchdog ===============================
     */
    #include <ti/drivers/Watchdog.h>
    #include <ti/drivers/watchdog/WatchdogCC26XX.h>
    
    WatchdogCC26XX_Object watchdogCC26XXObjects[CC2640R2_LAUNCHXL_WATCHDOGCOUNT];
    
    const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC2640R2_LAUNCHXL_WATCHDOGCOUNT] = {
        {
            .baseAddr    = WDT_BASE,
            .reloadValue = 1000 /* Reload value in milliseconds */
        },
    };
    
    const Watchdog_Config Watchdog_config[CC2640R2_LAUNCHXL_WATCHDOGCOUNT] = {
        {
            .fxnTablePtr = &WatchdogCC26XX_fxnTable,
            .object      = &watchdogCC26XXObjects[CC2640R2_LAUNCHXL_WATCHDOG0],
            .hwAttrs     = &watchdogCC26XXHWAttrs[CC2640R2_LAUNCHXL_WATCHDOG0]
        },
    };
    
    const uint_least8_t Watchdog_count = CC2640R2_LAUNCHXL_WATCHDOGCOUNT;

    So just set your watchdog reload value here. 

    -kel

  • You clear the watchdog before if(events). Because, if the device goes to Standby Mode, it will not be able to reach the watchdog clear code after if(events) condition.

    hi,I want to know if I only clear WDT count at the callback function, Does it have some possibility cause system reset because if the device goes to Standby Mode, it will not be able to reach the watchdog clear code after if(events) condition ?

  • user4721640 said:
    You clear the watchdog before if(events). Because, if the device goes to Standby Mode, it will not be able to reach the watchdog clear code after if(events) condition.

    Yes, when the device goes to Standby Mode, it will not be able to reach the watchdog clear code  after if(events). The watchdog count down also stops at Standby Mode. So, when it wakes up due to a event, it will go to watchdog clear code. This method works when the device goes to standby mode and then goes to active mode and vice versa.

    user4721640 said:
    hi,I want to know if I only clear WDT count at the callback function,

    That is what is done at the example program, so you can run it again and again. But, for actual implementation don't do that.

    See, my watchdog code implementation in this post below.

    -kel

  • void Watchdog_Callback(uintptr_t unused)
    {
    HAL_SYSTEM_RESET();
    }

    Thank u,I have already unstand your idea, and i have two question:
    1.why add HAL_SYSTEM_RESET() to callback function, if system runs wrong, MCU maybe can't run there,so it doesn't work? I don't know,I just guess. If set this: params.resetMode = Watchdog_RESET_ON , I think if WDT time out twice ,MCU should reset although i don't add HAL_SYSTEM_RESET() to callback function ,right?
    2. You change Reload value in board.c ,i want to know dose this function Watchdog_setReload work?
    Watchdog_setReload(watchdogHandle, 1500000); // 1sec (WDT runs always at 48MHz/32)
  • user4721640 said:
    why add HAL_SYSTEM_RESET() to callback function, if system runs wrong, MCU maybe can't run there,so it doesn't work? I don't know,I just guess. If set this: params.resetMode = Watchdog_RESET_ON , I think if WDT time out twice ,MCU should reset although i don't add HAL_SYSTEM_RESET() to callback function ,right?

    The Watchdog Causes Warm Reset. There is a mention that Warm Reset is not recommended and you need to convert the Warm Reset to System Reset. There is a code to convert Warm Reset to System Reset. I did not implement that. But rather I call HAL_SYSTEM_RESET() at Watchdog Callback.

    I did set params.resetMode = Watchdog_RESET_ON at initialization. So if there is something wrong at second watchdog timeout, it will do a device Warm Reset.

    user4721640 said:
    You change Reload value in board.c ,i want to know dose this function Watchdog_setReload work?
    Watchdog_setReload(watchdogHandle, 1500000); // 1sec (WDT runs always at 48MHz/32)

    Base from the example program the Watchdog_setReload() works as is. I have already use it also. But, I choose to set the reload value at the board files. Because, calling Watchdog_setReload() will add to RAM usage.

    -kel

  • ok, Thank for you again.
  • Another thing, Does HAL_SYSTEM_RESET() equal to Hard reset? if i use HAL_SYSTEM_RESET() frequently ,for example ,call every half hour ,Is that result in some negative effects?
    well ,i just want to add Timing Reset to my project ,so i must ensure no accidents when i do that , i need do a test.
  • Yes, HAL_SYSTEM_RESET() is a hard reset.