Test the mini2440 bare metal-the watchdog interrupt and reset operations, and the mini2440 bare metal

Source: Internet
Author: User

Test the mini2440 bare metal-the watchdog interrupt and reset operations, and the mini2440 bare metal
Working principle of the watchdog:

Set the time for the entire system program to run for one cycle to Tp. The timer period of the watchdog is Ti, Ti> Tp. When the program runs normally, the timer will not overflow, if the system cannot modify 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, enabling the system to run again, thus playing a monitoring role.

The watchdog has two functions:

1. As a regular clock, interruption may 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, if the reset function is enabled for the watchdog control register WTCON [0], the reset is enabled. If the reset function is disabled for the watchdog control register WTCON [0], the operation is interrupted and data (WTDAT) is enabled) registers are assigned to the count (WTCNT) registers for cyclic interrupt operations (here the interrupt is similar to the RTC alarm clock interrupt ).

The so-called dog Feed means that the WTCNT value is assigned again before the value is 0, so that it will not be interrupted 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 In the watchdog counter of the AXD debugging runs to zero, the system enters the reset State. If the CPU stops working, no interruption is triggered.



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 do not understand why you have 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 for every 1 reduction 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 ){}}





How to enable the reset of the Watchdog

Failed to feed it in time, resulting in non-stop reset.
 
How to Use the watchdog reset command

In a micro-computer system composed of single-chip microcomputer, the work of single-chip microcomputer is often affected by external electromagnetic fields, resulting in program running and falling into an endless loop, the normal operation of the program is interrupted, and the system controlled by the single-chip microcomputer cannot continue to work. This will cause the entire system to stagnate and lead to unpredictable consequences, therefore, for the sake of real-time monitoring of the running status of the single chip microcomputer, a chip dedicated to monitoring the running status of the single chip computer is generated, commonly known as "watchdog)
The application of the Watchdog Circuit enables the single-chip microcomputer to work continuously in the unmanned State. Its working principle is: the watchdog chip is connected to an I/O pin of the single-chip microcomputer, the I/O pin uses a program to control it regularly to send high-level (or low-level) to the dog's pin. This program statement is distributed in the middle of other MCU control statements, once a single-chip computer enters an endless loop after the program runs and falls into a program segment due to interference, the program that writes the watchdog pin cannot be executed. At this time, the Watchdog Circuit sends a reset signal to the Pin connected to the reset pin of the microcontroller because it does not receive the signal sent by the microcontroller, that is, the program starts from the starting position of the program memory, so that the automatic reset of the single chip microcomputer is realized.
Watchdog timer, also known as watchdog timer, is a timer circuit. Generally, there is an input, kicking the dog or service the dog, and an output to the RST end of the MCU, when the MCU works normally, a signal is output at every end of time to the dog feeding end, And the WDT is cleared. If the dog is not fed after the specified time (generally when the program is running ), if the WDT time exceeds, a reset signal is returned to the MCU, which is a MCU reset. prevents the MCU from crashing. the role of the watchdog is to prevent an endless loop of programs, or to run programs.
Working principle: After the system runs, the watchdog counter is started, and the watchdog starts to automatically count. If it does not clear the watchdog at a certain time, then the watchdog counter will overflow and cause the watchdog to interrupt, resulting in system reset. Therefore, when using a chip with a watchdog, you must clear the watchdog.
The Hardware Watchdog uses a timer to monitor the running of the main program. That is to say, during the running of the main program, we need to reset the timer before the scheduled time. If an endless loop occurs, or the PC pointer cannot return. After the scheduled time is reached, the microcontroller will be reset. Common WDT chips, such as MAX813, 5045, and IMP 813, are priced at 4 ~ 10 yuan.
The principle of the Software Watchdog Technology is similar to this, but it is implemented using software methods. We still use the 51 series. We know that there are two timers in the 51 microcontroller, we can use these two timers to monitor the running of the main program. We can set a scheduled time for T0, assign a value to a variable when scheduled interruption occurs, and this variable has an initial value at the beginning of the main program running, here, we want to set the scheduled value to be less than the running time of the main program. In this way, we can judge the variable value at the end of the main program. If the value changes as expected, it indicates that T0 interruption is normal. If there is no change, reset the program. When T1 is used to monitor the operation of the main program, we set a certain scheduled time for T1 and reset it in the main program. If it cannot be reset within a certain period of time, the timing interruption of T1 will reset the microcontroller. Here, the scheduled time of T1 is greater than the running time of the main program, leaving some margin for the main program. The T1 interruption is normal or not, and we will monitor it by T0 scheduled interrupt subprogram. In this way, it becomes a loop. T0 monitors T1 and T1, and the main program monitors T0 again to ensure the stable operation of the system.
The 51 series has a dedicated watchdog timer to calculate the system frequency. When the timer overflows, it will cause reset. The watchdog can set the overflow rate and can also be used as a timer separately.
Ling Yang 61's watchdog is relatively single, one is a single time, and the other is the function in actual use, just add the clear dog command in the loop is OK.
The C8051Fxxx single-chip microcomputer also has a 21-bit internal use system ...... the remaining full text>

Related Article

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.