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 timer jump to code in main using C

Hi,

Facing a problem that i really need some help with. What i need is that whenever the watchdog timer gives an interrupt i want to start execution again in my main program starting from a certain line but i am really confused as to how to do this? Will i have to use inline assembly or is there any other option?

Any help would be appreciated

Thanks,

Tarun

  • Short answer: No.

    What you can do is:

    1) Have your WDT ISR set a flag that is checked by main as needed.

    2) Use the WDT in Watchdog (not Timer) mode, and have main check WDTIFG when it (re-)starts.

  • What about using inline assembly where i write a jmp instruction. i will find out the address using debug mode from where i want to start the execution after getting a watchdog interrupt.

  • Tarun Karuturi said:
    What about using inline assembly where i write a jmp instruction.

    Generally, it is a bad idea to interrupt program execution at one point and continue elsewhere. This may result in unpredictable program behavior. The compiler doesn't know about this kind of manipulation and may rearrange your code due to optimization. You may jump behind coude you need to re-executo or before code that you won't execute again.

    It's indeed best to le tth eWDT trigger a reset and then (if it is important anyway) check whether the restart was from a watchdog reset or a brownout reset.

    Many things are possible with inline assembly. This doesn't mean they should be done.

    IMHO, the only situation where oyu interrupt code and continue elsewhere is when implementing a task switcher. Everyhting else is playing Russian roulette.

**Attention** This is a public forum