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); }
Jumping to the reset vector - or the start of your main() does not work.
If you jump to the reset vector, the processor will not be in the same state as after a real reset. Some of the startup code may fail since interrupt sources are enabled before they should. A hardware lockup after a voltage spike will also not be corrected.
If you jump to start of main(), your hareware may differ even more compared to after a normal cold-start sequence.
If an external reset chip is too expensive/large, check if you could at least use a processor pin to activate the external reset. As long as the processor hasn't locked up, you should then be able to get a full reset. The solution isn't as good as an external (or built-in) watchdog, but it is at least a lot better than a jump to the reset vector or to the start of main().