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.

Watchdog for TIVA C

Hi,

I am struggling to use watchdog for my TIVA C controller, Actually I want to reset my processor under certain condition. Kindly could you please provide me some code setting up the watchdog.

Regards,

Mohsin

  • Hello Mohsin

    To use the watchdog

    SysCtlPeripheralEnable(SYSCTL_PERIPH_WFOG0);

    WatchdogReloadSet(WATCHDOG0_BASE,SysCtlClockGet()); // 1 sec watchdog timer

    WatchdogIntEnable(WATCHDOG0_BASE);

    IntEnable(INT_WATCHDOG);

    WatchdogResetEnable(WATCHDOG0_BASE);

    WatchdogEnable(WATCHDOG0_BASE);

    Please do map the watchdog interrupt handler. On failing to do so 1 sec after interrupt the reset will occur

    Regards

    Amit

  • Hello Amit,

    Thanks for your reply.

    See my code. What I am looking for is that when a certain condition gets true, it should completely reset the processor. Kindly guide me on this.

    Regards,

    Mohsin

    int
    main(void)
    {

    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
    SYSCTL_XTAL_16MHZ);

    InitConsole();

    UARTprintf("Hello \n");

    //

    // Enable the peripherals used.

    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0);

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Enable the watchdog interrupt.
    //
    IntEnable(INT_WATCHDOG);

    //
    // Set the period of the watchdog timer.
    //
    WatchdogReloadSet(WATCHDOG0_BASE, SysCtlClockGet());

    //
    // Enable reset generation from the watchdog timer.
    //
    WatchdogResetEnable(WATCHDOG0_BASE);

    //
    // Enable the watchdog timer.
    //
    WatchdogEnable(WATCHDOG0_BASE);
    for (;;)
    {
    // let say

    if(condition==true)

    {

    //reset the processor

    }

    }

  • Hello Mohsin,

    If the intent is to reset the device under certain condition then I would suggest using SysCtlReset() function instead of using a watchdog.

    Regards

    Amit

  • Amit's MCU Reset method surely works - yet another possibility may exist.

    if you add an "else" clause to your, "if(condition==true)" and if the watchdog is not reloaded too often, elsewhere w/in your code - then the "else's" containing:

    WatchdogReloadSet(WATCHDOG0_BASE, WATCHDOG_RELOAD_VALUE);

    will prevent the watchdog from asserting.

    Limiting the watchdog's deployment - as I've suggested above - is not, "best practice" - but may be all that's required for simple/limited programs. 

    Using "just" the forced MCU SW Reset - as suggested earlier - may leave you vulnerable to other program or system irregularities.   For example - certain program "irregularities" have likely caused your "condition" to be detected - but that same irregularity may be severe enough to "spoil" the condition setting to, "true!"   (note: we've seen this!) 

    The watchdog is intended to "escape" your program from such occurrences - it may prove best to combine both the watchdog and a strategic SW Reset - to gain the most robust program operation...