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.

Adding a callback to CC2650 watchdog hangs

Other Parts Discussed in Thread: CC2650, CC2640, CC1350, SYSBIOS

When I add a callback to the watchdog in my CC2650 empty project (running tirtos 2.20) the chip hangs. 

These are the changes made to an empty project for the CC2650DK_7ID:

// Added headers
#include <inc/hw_ints.h>
#include <inc/hw_memmap.h>
#include <ti/drivers/watchdog/WatchdogCC26XX.h>
#include <ti/drivers/power/PowerCC26XX.h>

// Added to empty.c
Watchdog_Handle watchdogHandle;

extern uint32_t WatchdogCC26XX_convertMsToTicks(uint32_t milliseconds);

#define WATCHDOG_COUNT 1
#define WATCHDOG_TIMEOUT_MS     6000

WatchdogCC26XX_Object watchdog_objects[WATCHDOG_COUNT];

const WatchdogCC26XX_HWAttrs watchdog_hwAttributes[WATCHDOG_COUNT] = {
    {
        .baseAddr = WDT_BASE,
        .intNum = INT_WDT_IRQ,
        .reloadValue = 10000
   }
};

const Watchdog_Config Watchdog_config[WATCHDOG_COUNT] = {
    {
        .fxnTablePtr = &WatchdogCC26XX_fxnTable,
        .object = &watchdog_objects,
        .hwAttrs = &watchdog_hwAttributes
   }
};


void watchdog_callback(UArg a0) {
  PIN_setOutputValue(ledPinHandle, Board_LED1, 0);
  while(1); // stall here to check if callback is being called
}

void watchdog_init()
{
    Watchdog_init();
    Watchdog_Params params;
    Watchdog_Params_init(&params);
    params.callbackFxn = watchdog_callback;
    params.resetMode = Watchdog_RESET_OFF;
    params.debugStallMode = Watchdog_DEBUG_STALL_ON;
    watchdogHandle = Watchdog_open(0, &params);
    Watchdog_setReload(watchdogHandle, WatchdogCC26XX_convertMsToTicks(WATCHDOG_TIMEOUT_MS));

    /* Avoid standby to keep the watchdog running */
    Power_setConstraint(PowerCC26XX_SB_DISALLOW);
}

int main(void)
{
    Task_Params taskParams;

    /* Call board init functions */
    Board_initGeneral();
    // Board_initI2C();
    // Board_initSPI();
    // Board_initUART();
    // Board_initWatchdog();
    watchdog_init();
    ...
}

I was able to confirm that the watchdog was working by switching the reset mode to on and observing resets.

If i halt it after a while I can see that its in this state:

Any assistance in debugging this issue is greatly appreciated!

  • Hi Brandon,

    The TI-RTOS 2.20 code for Watchdog_init() contains the following:

        /* Call each driver's init function */
        for (Watchdog_count = 0; Watchdog_config[Watchdog_count].fxnTablePtr != NULL;  Watchdog_count++) {
            Watchdog_config[Watchdog_count].fxnTablePtr->watchdogInit((Watchdog_Handle)&(Watchdog_config[Watchdog_count]));
        }

    I think you just need to add a {NULL, NULL, NULL} line to your Watchdog_confg array so the for loop in Watchdog_init() will break out:

    const Watchdog_Config Watchdog_config[] = {
        {
            .fxnTablePtr = &WatchdogCC26XX_fxnTable,
            .object = &watchdogCC26XXObjects[0],
            .hwAttrs = &watchdogCC26XXHWAttrs[0]
        },
        {NULL, NULL, NULL},
    };

    Also make sure to remove Watchdog_COUNT from the array declaration for this to compile.

    Best regards,

        Janet

  • Hi Janet,

    I implemented the change you suggested and I am still seeing the same behavior.

    When i step through the watchdog initialization, everything seems to go ok. Enabling logging I get:
    Watchdog: handle 4ef4 opened
    Watchdog: WDT with handle 0x4ef4 has been set to reload to 0x895440

    which leads me to believe initialization is going right. The callback is properly being saved in the handler as well as far as I can tell...

    Thanks for getting back to me so quickly!
  • Hi Brandon,

    I'm able to reproduce the problem you are seeing.  I disabled the ROM by commenting out the line ROM.romName = ROM.CC2650; in the .cfg file, and I can see that an exception has occurred.  The code is spinning in Hwi_excHandler().  I'm not sure why and am still looking into this.

    Best regards,

    Janet

  • Hi Brandon,

    It turns out this problem is caused by the C26XX Watchdog driver.  It is setting the interrupt as an NMI.  I tried changing it to a regular interrupt and your program worked fine.  I'm attaching my modified WatchdogC26XX.c file with this change.  You can copy it to:

    tirtos_cc13xx_cc26xx_2_20_00_06/products/tidrivers_cc13xx_cc26xx_2_20_00_08/packages/ti/drivers/watchdog

    You will need to rebuild the drivers.

    2538.WatchdogCC26XX.c

    Best regards,

        Janet

  • Hi Janet,

    I was able to get it to work on my end. Thanks so much for the assistance! I took a look at the older versions of the drivers and noticed that they had it set to a regular interrupt. The new driver version switched it over to nmi.

    Thanks,
    Brandon
  • Glad to hear it's working. This should be fixed in the next TI-RTOS release.
    Best regards,
    Janet
  • hi,

    I am using the same example given above to use the watchdog feature and it is working, but my problem is like if i have set the watchdog period to be around 30 second. After first cycle it is starting up and then making itself discover able but on the next cycle when it is getting watchdog it is not getting discovered  (Green Led is also not blinking at that time).Again after the third cycle it is getting reboot and making itself discover able , on fourth cycle it is showing same behavior as in the second.I dont know how to tackle the issue.I am using the ble_sdk_2_02_01_18 and compiler is Ti V 5.2.9. and small snapshot of my code i am attaching::  

    #define WATCHDOG_COUNT 1
    #define WATCHDOG_TIMEOUT_MS 12000//1800000 // 1800000/1000= 1800/60=30 minutes  

    I am using right now the 30 minute watchdog timer. So it is getting reset after 30 minutes but not showing until next 30 minutes.Please help me what i am doing wrong here.

    /******************************************************************************

    @file main.c

    @brief Main entry of the BLE SensorTag sample application.

    Group: WCS, BTS
    Target Device: CC2650, CC2640, CC1350

    ******************************************************************************

    Copyright (c) 2014-2016, Texas Instruments Incorporated
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.

    * Neither the name of Texas Instruments Incorporated nor the names of
    its contributors may be used to endorse or promote products derived
    from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    ******************************************************************************
    Release Name: ble_sdk_2_02_01_18
    Release Date: 2016-10-26 15:20:04
    *****************************************************************************/

    // TI RTOS
    #include <ti/sysbios/BIOS.h>
    #include <xdc/runtime/Error.h>
    #include <ti/drivers/Power.h>
    #include <ti/drivers/power/PowerCC26XX.h>
    #include <ti/drivers/Watchdog.h>
    // BLE
    #include "bcomdef.h"

    // Application
    #include "sensortag.h"
    #include "sensortag_tmp.h"
    #include "sensortag_hum.h"
    #include "sensortag_bar.h"

    #ifndef USE_DEFAULT_USER_CFG

    #include "ble_user_config.h"

    // BLE user defined configuration
    bleUserCfg_t user0Cfg = BLE_USER_CFG;

    #endif // USE_DEFAULT_USER_CFG

    /*******************************************************************************
    * MACROS
    */
    #define WATCHDOG_COUNT 1
    #define WATCHDOG_TIMEOUT_MS 12000//1800000 // 1800000/1000= 1800/60=30 minutes
    /*******************************************************************************
    * CONSTANTS
    */

    /*******************************************************************************
    * TYPEDEFS
    */

    /*******************************************************************************
    * LOCAL VARIABLES
    */

    /*******************************************************************************
    * GLOBAL VARIABLES
    */

    #ifdef CC1350_LAUNCHXL
    #ifdef POWER_SAVING
    // Power Notify Object for wake-up callbacks
    Power_NotifyObj rFSwitchPowerNotifyObj;
    static uint8_t rFSwitchNotifyCb(uint8_t eventType, uint32_t *eventArg,
    uint32_t *clientArg);
    #endif //POWER_SAVING

    PIN_State radCtrlState;
    PIN_Config radCtrlCfg[] =
    {
    Board_DIO1_RFSW | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* RF SW Switch defaults to 2.4GHz path*/
    Board_DIO30_SWPWR | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Power to the RF Switch */
    PIN_TERMINATE
    };
    PIN_Handle radCtrlHandle;
    #endif //CC1350_LAUNCHXL

    /*******************************************************************************
    * EXTERNS
    */

    extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
    extern uint32_t WatchdogCC26XX_convertMsToTicks(uint32_t milliseconds);
    void watchdog_initlize(void);
    /*******************************************************************************
    * Locals
    */
    /*******************************************************************************
    * @fn Main
    *
    * @brief Application Main
    *
    * input parameters
    *
    * @param None.
    *
    * output parameters
    *
    * @param None.
    *
    * @return None.
    */
    int main()
    {
    /* Register Application callback to trap asserts raised in the Stack */
    RegisterAssertCback(AssertHandler);

    PIN_init(BoardGpioInitTable);

    #ifdef CC1350_LAUNCHXL
    // Enable 2.4GHz Radio
    radCtrlHandle = PIN_open(&radCtrlState, radCtrlCfg);

    #ifdef POWER_SAVING
    Power_registerNotify(&rFSwitchPowerNotifyObj,
    PowerCC26XX_ENTERING_STANDBY | PowerCC26XX_AWAKE_STANDBY,
    (Power_NotifyFxn) rFSwitchNotifyCb, NULL);
    #endif //POWER_SAVING
    #endif //CC1350_LAUNCHXL

    #ifndef POWER_SAVING
    /* Set constraints for Standby and Idle mode */
    Power_setConstraint(PowerCC26XX_SB_DISALLOW);
    Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
    #endif // POWER_SAVING

    /* Initialize ICall module */
    ICall_init();

    /* Start tasks of external images - Priority 5 */
    ICall_createRemoteTasks();

    /* Kick off profile - Priority 3 */
    GAPRole_createTask();

    /* Kick off application - Priority 1 */
    SensorTag_createTask();
    SensorTagTmp_createTask();
    SensorTagHum_createTask();
    SensorTagBar_createTask();
    /* Kick off application WatchDog */
    watchdog_initlize();

    BIOS_start(); /* enable interrupts and start SYS/BIOS */

    return 0;
    }


    /*******************************************************************************
    * @fn AssertHandler
    *
    * @brief This is the Application's callback handler for asserts raised
    * in the stack. When EXT_HAL_ASSERT is defined in the Stack
    * project this function will be called when an assert is raised,
    * and can be used to observe or trap a violation from expected
    * behavior.
    *
    * As an example, for Heap allocation failures the Stack will raise
    * HAL_ASSERT_CAUSE_OUT_OF_MEMORY as the assertCause and
    * HAL_ASSERT_SUBCAUSE_NONE as the assertSubcause. An application
    * developer could trap any malloc failure on the stack by calling
    * HAL_ASSERT_SPINLOCK under the matching case.
    *
    * An application developer is encouraged to extend this function
    * for use by their own application. To do this, add hal_assert.c
    * to your project workspace, the path to hal_assert.h (this can
    * be found on the stack side). Asserts are raised by including
    * hal_assert.h and using macro HAL_ASSERT(cause) to raise an
    * assert with argument assertCause. the assertSubcause may be
    * optionally set by macro HAL_ASSERT_SET_SUBCAUSE(subCause) prior
    * to asserting the cause it describes. More information is
    * available in hal_assert.h.
    *
    * input parameters
    *
    * @param assertCause - Assert cause as defined in hal_assert.h.
    * @param assertSubcause - Optional assert subcause (see hal_assert.h).
    *
    * output parameters
    *
    * @param None.
    *
    * @return None.
    */
    void AssertHandler(uint8 assertCause, uint8 assertSubcause)
    {
    // check the assert cause
    switch (assertCause)
    {
    default:
    HAL_ASSERT_SPINLOCK;
    }

    return;
    }


    /*******************************************************************************
    * @fn smallErrorHook
    *
    * @brief Error handler to be hooked into TI-RTOS.
    *
    * input parameters
    *
    * @param eb - Pointer to Error Block.
    *
    * output parameters
    *
    * @param None.
    *
    * @return None.
    */
    void smallErrorHook(Error_Block *eb)
    {
    for (;;);
    }

    #if defined (CC1350_LAUNCHXL) && defined (POWER_SAVING)
    /*******************************************************************************
    * @fn rFSwitchNotifyCb
    *
    * @brief Power driver callback to toggle RF switch on Power state
    * transitions.
    *
    * input parameters
    *
    * @param eventType - The state change.
    * @param eventArg - Not used.
    * @param clientArg - Not used.
    *
    * @return Power_NOTIFYDONE to indicate success.
    */
    static uint8_t rFSwitchNotifyCb(uint8_t eventType, uint32_t *eventArg,
    uint32_t *clientArg)
    {
    if (eventType == PowerCC26XX_ENTERING_STANDBY)
    {
    // Power down RF Switch
    PIN_setOutputValue(radCtrlHandle, Board_DIO30_SWPWR, 0);
    }
    else if (eventType == PowerCC26XX_AWAKE_STANDBY)
    {
    // Power up RF Switch
    PIN_setOutputValue(radCtrlHandle, Board_DIO30_SWPWR, 1);
    }

    // Notification handled successfully
    return Power_NOTIFYDONE;
    }
    #endif //CC1350_LAUNCHXL || POWER_SAVING


    /*******************************************************************************
    * @fn watchdog_init()
    *
    * @brief Implement watchdog feature.
    *
    *
    * input parameters
    *
    * @param None.
    *
    * @return void.
    */

    void watchdog_callback(UArg a0) {

    while(1); // stall here to check if callback is being called
    }
    /*******************************************************************************
    * @fn watchdog_init()
    *
    * @brief Implement watchdog feature.
    *
    *
    * input parameters
    *
    * @param None.
    *
    * @return void.
    */

    void watchdog_initlize(void)
    {
    Watchdog_Handle watchdogHandle;
    Watchdog_init();
    Watchdog_Params params;
    Watchdog_Params_init(&params);
    params.callbackFxn = watchdog_callback;
    params.resetMode = Watchdog_RESET_ON;
    params.debugStallMode = Watchdog_DEBUG_STALL_ON;
    watchdogHandle = Watchdog_open(0, &params);
    Watchdog_setReload(watchdogHandle, WatchdogCC26XX_convertMsToTicks(WATCHDOG_TIMEOUT_MS));

    /* Avoid standby to keep the watchdog running */
    Power_setConstraint(PowerCC26XX_SB_DISALLOW);
    }
    /*******************************************************************************
    */

  • Hi Deepak,

    This thread has been marked as answered quite a while ago.  Could you please file a new post?

    Best regards,

    Janet

  • I totally agree with you, Janet - Deepak's add-on is not even tangential, it's a totally separate issue. But even if it were tangential - on a focused/concise/closed/answered thread like this, it's the equivalent of photo-bombing someone's best vacation picture ... can we just call it Forum Bombing?

    Anyway, you spend a lot of time helping us on these forums to have achieved MasterMind, so thank you for your time and effort and help!

    On a funny side-note - Deepak's forum bombing here moved the thread back to the top of recent post and actually helped me to find this thread which answers my thread in the low power rf that had been neglected for almost a month now:
    e2e.ti.com/.../2168667

    And of course, your patch to WatchdogCC26XX.c was the fix...