Test the mini2440 bare metal -- the watchdog interrupt and reset operation

Source: Internet
Author: User
Working principle of the watchdog:

Set the full execution cycle of the system program to TP. The timer period of the watchdog is Ti, Ti> TP. When the program is executed normally, the timer will not overflow, if the system cannot change the timer value at the time of TP due to interference or other reasons, the timer will overflow at the time of Ti, causing system reset, so that the system can be executed again, thus playing a monitoring role.

The watchdog has two functions:

1. As a regular clock, interruption can occur;

2. When the watchdog timer is used and the counter wtcnt is 0, a reset is generated;

Functional Block Diagram of the watchdog:

In my program, the pclk is 50 MHz, the pre-division value is 77, and the clock divisor is set to 128,

Clock cycle t_watchdog = 1/[pclk/(pre-division value + 1)/clock divisor]

= 1/[50*1000000/(77 + 1)/128] = 0.0002

T_watchdog indicates the time used by the watchdog counting timer wtcnt to reduce 1. wtcnt is equivalent to a cycle. When wtcnt is 0, assume that the reset function is enabled for the watchdog control register wtcon [0], and the reset function is disabled for the watchdog control register wtcon [0]. If the reset function is enabled, the operation and data (wtdat) are interrupted) the register is assigned to the count (wtcnt) register again, and the cyclic interrupt operation (here the interrupt is similar to the RTC alarm interrupt ).

The so-called dog Feed means that the wtcnt value is assigned again before the value is 0 without interruption or reset.

Here is a quote from instructor ZHAO:

The S3C2440 watchdog timer can not only cause system reset, but also cause general interruption. Therefore, the S3C2440 watchdog timer can be used as a general timer.

Result of the watchdog interruption:

Once an interrupt occurs every four seconds, the LED is lit and the serial port prompts


Watchdog reset result: when the value of rwtcnt is zero in the debugging of the axd, the system enters the reset State. If the CPU stops working, no interruption will occur.



After resetting and disabling the axd, the U-boot serial port initialization prompt (failed to timely trigger the first buzzer and press the button to stop autoboot ):

 

After resetting and disabling the axd, the U-boot serial port initialization prompt (promptly press the key to stop autoboot when the first buzzer rings ):


Here is the reset to use uboot to initialize the development board, but it is not clear why it is necessary to press the button on the first buzzer to enter uboot

Appendix:

Hardware environment: J-link V8, mini2440, J-link adapter board, serial port USB cable

Software environment: Windows 7 (32-bit), Development Board uboot (nandflash), J-Link driver (J-link arm v4.10i), securecrt, and ads1.2

 

Code block

// ================================================ ==============================================/// Implement functions: // watchdog interrupt and reset operations // when wtcon [0] is enabled, the reset function is enabled; When wtcon [0] is disabled, wtcon [2] is enabled; implement interruption //: liang huiyong // ========================================== ================================= # include "2440addr. H "# include" def. H "# include" 2440lib. H "static u8 led_flag = 0; /*************************************** ************** **** **************************************** * ***/Void watchdog_init () {rwtcon = (77 <8) | (1 <5) | (3 <3) | (1 <2 )); // The pre-division value is 77; the watchdog timer is enabled; the clock divisor is 128; and the watchdog is interrupted; // clock cycle t_watchdog = 1/[pclk/(pre-division value + 1)/clock divisor] = 1/[50*1000000/(77 + 1) /128] = 0.0002 // t_watchdog indicates the time used by the watchdog count timer wtcnt to reduce 1 rwtdat = 20000; // wtdat the watchdog data register, rwtcnt = 20000; // wtcnt watchdog count register, current counting value of the watchdog timer }/********************************* ********************* ***************************** * *******************************/Void _ IRQ watchdog_isr () {rsubsrcpnd | = 1 <13; // clear the pending state rsrcpnd of a secondary interrupt | = 0x1 <9; // clear the suspension state of the interrupt rintpnd | = 0x1 <9; // The interrupt LED lights up led_flag ++; uart_printf ("\ n ----- the watchdog is interrupted, led % d \ n ", led_flag); rgpbcon = 0x015400; Switch (led_flag) {Case 1: rgpbdat = 0xe <5; break; Case 2: rgpbdat = 0xd <5; break; Case 3: rgpbdat = 0xb <5; break; Case 4: rgpbdat = 0x7 <5; break;} If (led_flag = 4) led_flag = 0; rsubsrcpnd & = (~ 0x1 <13); rsrcpnd & = (~ 0x1 <9); // enable or disable rintpnd & = (~ 0x1 <9 );} /*************************************** ************** **************************************** * *******/void watchdog () {watchdog_init (); // initialize the watchdog register // select whether to enable the reset // rwtcon |=( 1 <0 ); // enable rwtcon | = (0 <0); // disable rintsubmsk & = ~ (1 <13); // enable the watchdog to interrupt rintmsk ~ (1 <9); // enable the watchdog to interrupt pisr_wdt_ac97 = (unsigned) watchdog_isr; while (1 ){}}




Test the mini2440 bare metal -- the watchdog interrupt and reset operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.