I wrote the following to learn how to use the watchdog. I have two problems:
1. there are 4 for() statments in the code, it seems that without them, the watchdog cannot be turned on or off. I also tired i<10, but it also didn't work. Technical Reference Manual dosen't show that it should wait sometime until the register value changed.
2. when I only stop the watchdog, the code works well, "Turn off watchdog 2..." will be output through uart. But when I turn off the watchdog, set the wldr register, then turn on the watchdog. The code will not work on the board, no output from uart.
Is there anything wrong with my code?
// disable watchdog 2
uart_write("Turn off watchdog 2...");
*reg_wdtimer2_wspr = 0x0000AAAA;
for (i=0; i<100; i++){};
while (*reg_wdtimer2_wspr & ~0x0000AAAA){};
*reg_wdtimer2_wspr = 0x00005555;
for (i=0; i<100; i++){};
while (*reg_wdtimer2_wspr & ~0x00005555){};
*reg_wdtimer2_wldr = 0x0;
// enable watchdog 2
uart_write("Turn on watchdog 2...");
*reg_wdtimer2_wspr = 0x0000BBBB;
for (i=0; i<100; i++){}; // It takes sometime to make the change on register.
while (*reg_wdtimer2_wspr & ~0x0000BBBB){};
*reg_wdtimer2_wspr = 0x00004444;
for (i=0; i<100; i++){};
while (*reg_wdtimer2_wspr & ~0x00004444){};