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.

CC2640R2F: cc2640r2f

Part Number: CC2640R2F
Other Parts Discussed in Thread: SYSBIOS

what is the code to hang a system if watchdog is expired and the message that system hang should be displayed in tera term app

  • Hi,

    We have watchdog example you can take a look at. You can register a callback function when the watchdog expires, and in the callback function you can do uart print.

    The example can be found in the SDK/examples/rtos/device(CC2640R2_xxxx)/drivers/watchdog.
  • Hi,

    Put a while(1); loop somewhere in your code and then do what TI Christin suggested above.

    -kel
  • /* For usleep() */
    #include <unistd.h>
    #include <stdbool.h>
    #include <stdint.h>

    #include <stddef.h>

    #include<xdc/runtime/System.h>

    /* Driver Header files */

    #include <ti/drivers/PIN.h>
    #include <ti/drivers/Watchdog.h>
    #include <ti/drivers/watchdog/WatchdogCC26XX.h>
    #include <ti/sysbios/family/arm/m3/Hwi.h>
    #include <ti/display/Display.h>

    /* Board Header file */
    #include "Board.h"

    /* Global memory storage for a PIN_Config table */

    static PIN_State ledPinState;
    static PIN_State buttonPinState;

    /* Pin driver handles */
    static PIN_Handle ledPinHandle;
    static PIN_Handle buttonPinHandle;


    /*
    * Application LED pin configuration table:
    * - Board_PIN_LED0 is initially off.
    */
    PIN_Config ledPinTable[] = {
    Board_PIN_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    PIN_TERMINATE
    };

    /*
    * Application button pin configuration table:
    */
    PIN_Config buttonPinTable[] = {
    Board_PIN_BUTTON0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_POSEDGE,
    PIN_TERMINATE
    };


    bool watchdogExpired = true;
    Watchdog_Handle handle;

    /*
    * ======== watchdogCallback ========
    * Watchdog interrupt callback function.
    */


    void watchdogCallback(uintptr_t unused)
    {
    /* Clear watchdog interrupt flag */
    Watchdog_clear(handle);

    watchdogExpired = true;
    System_printf("hello");


    }



    /*
    * ======== main ========
    */
    void *mainThread(void *arg0)
    {

    Watchdog_Params params;

    /* Call board init functions */
    Watchdog_init();
    /* Open Display Driver */

    Display_Handle displayHandle;

    Display_Params displayParams;

    Display_Params_init(&displayParams);

    displayHandle = Display_open(Display_Type_UART, &displayParams );


    /* Open LED pin */
    ledPinHandle = PIN_open(&ledPinState, ledPinTable);
    if(!ledPinHandle) {
    /* Error initializing board LED pin */
    while (1);
    }

    /* Turn OFF user LED */
    PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, 0);

    /* Setup callback for button pin */
    buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);
    if(!buttonPinHandle) {
    /* Error initializing button pins */
    while (1);
    }

    PIN_setInterrupt(buttonPinHandle, Board_PIN_BUTTON0|PIN_IRQ_POSEDGE);

    /* Create and enable a Watchdog with resets disabled */
    Watchdog_Params_init(&params);
    params.callbackFxn = (Watchdog_Callback)watchdogCallback;
    params.resetMode = Watchdog_RESET_ON;


    handle = Watchdog_open(Board_WATCHDOG0, &params);

    if (handle == NULL) {
    /* Error opening Watchdog */
    // while (1);
    }

    /* Enter continous loop */
    // while (1) {



    /* If watchdog expired since last started, turn ON LED */
    if (watchdogExpired) {
    watchdogExpired = true;

    PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, 1);
    Display_printf(displayHandle, 0, 0, "SYSTEM HANG");

    while(1);



    watchdogExpired = false;

    PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, 0);


    }
    // }

    }


    This is my following code but i am unable to spot the difference with RESET_MODE_ON and RESET_MODE_OFF as both are giving the same output due to while(); but i want to hang the system automatically when watchdog timer is expired with reset mode on.is it possible??
  • Hi,

    To have Watchdog Callback you need to set params.resetMode = Watchdog_RESET_OFF;

    Then at watchdogCallback() do not call Watchdog_clear(handle);

    -kel
  • Can u clarify me what is the difference in reset mode on and reset mode off in watchdog timer
  • Hi,

    See, Watchdog doxygen documentation at the docs folder.

    The default Watchdog reset mode is Watchdog_RESET_ON. You can see that at watchdog.h. If the Watchdog Counter expires it will count down again and at the second expiration, it will reset the device. The only problem with this is that the Watchdog will perform a warm reset, which is not recommended. You need to add code to convert warm reset to system reset.

    If the Watchdog reset mode is Watchdog_RESET_OFF and the Watchdog Counter expires, the Watchdog Callback will be called. In the Watchdog Callback you can do some diagnostics, print something to UART then do a HAL_SYSTEM_REST().

    -kel
  • Hi
    In order to have system reset i have entered this code after event_pend
    events = Event_pend(syncEvent, Event_Id_NONE, SBP_ALL_EVENTS,
    ICALL_TIMEOUT_FOREVER);
    if(ticks>20){
    for(volatile uint32_t x = 0; x <= 0xffffffff; x++);

    }

    ticks=ticks+1;
    Is it okie ?
    One more thing even if i am using rest mode on or reset mode off ,in both cases i m able to access callback function which has a display statement popped up in both the cases, why?
  • Is that how you kick off watchdog? There are various way to do it, as long as it works for you, there is no absolute correct way.

    The callback will always be executed when the watchdog expires, and then the device will reset or not base on your setting. Since callback function will always be executed, then you will always be able to see the display.
  • Hi
    Can i know the appropriate code to hang the system when the watchdog will expire keeping the reset mode on.
  • What's the purpose of using a while 1 but still want to reset the device after watchdog expires?

    When the device hit while 1, the program will just stop and can't get out of the loop. (I assume that's what you meant by hang the system)
  • Christin Lee said:
    When the device hit while 1, the program will just stop and can't get out of the loop. (I assume that's what you meant by hang the system)

    Yes, to simulate a hang.

    -kel

  • I am not sure if I understand M SPIM's request.

    Do you want to have a while 1 to simulate system hanging and then when that happens, you will to start watchdog and reset the device?

    If so, you can just kick off your watchdog when you enter your while 1 the first time and then wait for the device to reset after timeout.
  • Christin Lee said:
    Do you want to have a while 1 to simulate system hanging and then when that happens, you will to start watchdog and reset the device?

    1. The watchdog should be started at initialization.
    2. Watchdog Clear should be placed after Event Pend code line at main RTOS task.
    3. To simulate a hang put a while(1); somewhere in your code. Maybe in the RTOS task or when there is BLE Connection.
    4. At watchdog callback print something.

    -kel

  • I have implemented the following code in simple_peripheral.c:

    Clock_Struct watchdogKickTimer;
    Watchdog_Handle hWDT;

    void watchdogKickHandler(UArg arg)
    {


    Watchdog_clear(hWDT);
    }



    void someTask()
    {

    Watchdog_Params wp;
    Watchdog_Params_init(&wp);
    wp.callbackFxn = NULL;

    wp.debugStallMode = Watchdog_DEBUG_STALL_ON;
    wp.resetMode = Watchdog_RESET_ON;
    hWDT = Watchdog_open(Board_WATCHDOG0, &wp);
    Watchdog_setReload(hWDT, 10*1500000); // 10sec (WDT runs always at 48MHz/32)
    Power_setConstraint(PowerCC26XX_SB_DISALLOW);
    Util_constructClock(&watchdogKickTimer, watchdogKickHandler,5*1000, 5*1000, true, NULL); //kick watchdog, every 5 second
    }

    But the last statement Util_constructClock(&watchdogKickTimer, watchdogKickHandler,5*1000, 5*1000, true, NULL); //kick watchdog, every 5 second is giving an error : "Util_constructClock" redeclared with incompatible type
    So what can be the alternative to stop this error.
  • Move the clock construct to SimpleBLEPeripheral_init and see if the same error msg still pops up.
  • Hi M SPIM,

        I will share my Watchdog code implementation later. But, for now I can tell you that I also implemented to kick the watchdog using a util clock and it was not a good idea. Because it will periodically wake up your device from standby mode and consume current.

    -kel

  • Hi Markel
    Yeah u r correct.
    Actually i am a beginner in bluetooth so if possible please share your watchdog implementation of your code as i have been experimenting on it from many days but i want to see the correct approach.
  • Hi,

        First you need to make sure that Watchdog is set at the board files including the Watchdog reload value.

    watchdog_app.c

    #include <ti/drivers/Watchdog.h>
    #include "watchdog_app.h"   
    
    
    
    Watchdog_Handle WatchdogHandle;
    
    
    void Watchdog_Callback(uintptr_t unused)
    {
        HAL_SYSTEM_RESET();
    }
    
    
    void Watchdog_Clear(void)
    {
        Watchdog_clear(WatchdogHandle);
    }  
    
    
    void Watchdog_Init(void)
    {
        Watchdog_Params params;    
            
        Watchdog_init();
        
        Watchdog_Params_init(&params);
        params.callbackFxn = (Watchdog_Callback)Watchdog_Callback;
        params.resetMode = Watchdog_RESET_ON;
        WatchdogHandle = Watchdog_open(Board_WATCHDOG0, &params);
            
        if (WatchdogHandle == NULL) {
            /* Error opening Watchdog */
            while (1);
        }
    }

    watchdog_app.h

    #ifndef WATCHDOGAPP_H
    #define WATCHDOGAPP_H
    
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    
    
    extern void Watchdog_Init(void);
    extern void Watchdog_Clear(void);
    
    /*********************************************************************
    *********************************************************************/
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif /* WATCHDOGAPP_H */

    simple_peripheral.c

    static void SimpleBLEPeripheral_init(void)
    {
       Watchdog_Init();
    
    }
    
    static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
    {
      // Initialize application
      SimpleBLEPeripheral_init();
    
      // Application main loop
      for (;;)
      {
        uint32_t events;
    
        // Waits for an event to be posted associated with the calling thread.
        // Note that an event associated with a thread is posted when a
        // message is queued to the message receive queue of the thread
        events = Event_pend(syncEvent, Event_Id_NONE, SBP_ALL_EVENTS,
                            ICALL_TIMEOUT_FOREVER);
    
        Watchdog_Clear();
    
        if (events)
        {
        }
      }
    }

    -kel

  • Hi
    Thanks a lot but while compilation i am getting this error even after inclusion of all header files. Can you suggest me how to recover the problem?

    unresolved symbol Watchdog_Clear, first referenced in <whole-program> simple_peripheral_cc2640r2lp_app C/C++ Problem
    unresolved symbol Watchdog_Init, first referenced in <whole-program> simple_peripheral_cc2640r2lp_app C/C++ Problem
    unresolved symbol WatchdogCallback, first referenced in <whole-program> simple_peripheral_cc2640r2lp_app C/C++ Problem
  • Hi,

    watchdog_app.c and watchdog_app.h need to be added to your project. Then at simple_peripheral.c include the watchdog_app.h header.

    -kel
  • actually i am trying to implement watchdog timer in simple_peripheral.c and no extra project is there so in this case i have added watchdog header file to simple_ peripheral.c i.e.
    #include <ti/drivers/Watchdog.h>
    #include <ti/drivers/watchdog/WatchdogCC26XX.h>
    But still that unresolved issue is appearing . How to resolve this?
  • Hi M SPIM,

        You need to add Watchdog Callback, Watchdog Clear, Watchodog Init C Functions at simple peripheral.c

    -kel

  • Hi
    Thankyou for the information ,it hepled me a lot to understand the concept.