How to use setjmp and longjmp to simuate watchdog timer for FX2 chip?

Hi,

Since FX2 does not have a watchdog timer, I am trying to simulate watchdog behavior using Timer 2 on chip.

The timer setup seems to be functional, but when I try to execute longjmp(), FX2 dies. Any future access to the chip will hang. In the debugger, when I try to execute longjmp(), I will loose the debug connection. Thee only way to get it back is to reset USB.

Is this because of longjmp() or some other thing that I don't know. If it is not appropriate to use longjmp, how can I simulate the watchdog behavior so that lockup in 8051 can be prevented.

Any comments are welcome,

Thanks,

zhongsheng

here is the pseudo code I am using:

void main()
{ // ReEnumeration setjmp(jmp_buf); // Hardware setup // Initialization while (1) { // interrupt handling }
}

void ISR_Timer2 interrupt 5
{ TR2 = 0; TF2 = 0; longjmp(jmp_buf, 3);
}

Parents
  • "how can I simulate the watchdog behavior so that lockup in 8051 can be prevented."

    If you don't trust the rest of your software not to lock-up, how can you trust your software watchdog simulation...?!

    There are plenty of existing discussions on how to do a "software reset", but none of them gives a true, full reset of the complete chip as a hardware reset would.

    If you really want protection, then use a proper external supervisor chip - don't try to mess about with software simulation!

Reply
  • "how can I simulate the watchdog behavior so that lockup in 8051 can be prevented."

    If you don't trust the rest of your software not to lock-up, how can you trust your software watchdog simulation...?!

    There are plenty of existing discussions on how to do a "software reset", but none of them gives a true, full reset of the complete chip as a hardware reset would.

    If you really want protection, then use a proper external supervisor chip - don't try to mess about with software simulation!

Children
More questions in this forum