Watchdog of S3c2410.

Source: Internet
Author: User
Tags ranges
1. What is watchdog?
Watchdog, the Chinese name is "Watchdog" and its full name is watchdog timer. We can literally know that it is actually a timer. However, it is different from the Timer we normally use. A common timer generally serves as a timer, and a timer timeout (timer out) causes an interruption, for example, triggering a system clock interruption. If you are familiar with Windows development, you should have used Windows timer. Windows timer has the same function as the timer discussed previously, but Windows timer is a software timer, when Windows timer time-out occurs, the app sends a message to the system to trigger an event. We can see from the above description that no matter the software timer or hardware timer, their role is in
An event occurs at a time point. For a hardware timer, this event may be expressed in the form of an interruption. For a software timer, this event can be expressed in the form of a system message. As mentioned at the beginning of this article, watchdog is essentially a timer, so it should have the characteristics of a common timer. Yes, when it is recorded, it will also cause events, however, in addition to system interruption, this event can also be a reset signal. In this case, we call watchdog a timer that can send a system restart signal.

2. watchdog job description
When a hardware system enables the watchdog function, the software running on the hardware system must send a signal to the watchdog at a specified interval. this behavior is referred to as "feed dog" to prevent the system from restarting when watchdog times out.

3. What does watchdog mean?
You may ask what the meaning of watchdog is? After watchdog is enabled, the software must send messages to it at regular intervals. Isn't it troublesome and resource-consuming? In fact, this behavior is very important. This behavior is a method in which the software reports its running status to the hardware. If a software runs well, it should be able to send messages to watchdog at the specified time interval. This is the same as that when the software tells the hardware: "Hey, buddy, I am running well. Don't worry. ", If the software enters an endless loop (also known as a dead machine) due to an improper operation, it cannot send messages to watchdog, and watchdog will time out, causing hardware to restart. Without the existence of watchdog, the program is dead, but our users are still
Confused, thinking that the system is performing large-scale computation and waiting patiently... This is just an old man... -_-!!

4. Operation of S3C2410 Watchdog
For watchdog of S3C2410, pclk is its only clock signal source. (If you do not know about pclk, you can search for it online or read my next article)
S3C2410 uses three registers to operate watchdog. The three registers are wtcon, wtdat, and wtcnt respectively.
Wtcon: watchdog control register
Wtdat: watchdog data register
Wtcnt: watchdog count register

For more information about the above registers, see the watchdog section in the S3C2410 Data Manual.
5. S3C2410 watchdog job description:
Before enabling watchdog, We must store a value in the register wtdat. After watchdog is enabled, this value will be automatically loaded into the register wtcnt. The role of wtcnt will be explained below, now you only need to know That wtdat must have a value, which will be automatically loaded into wtcnt (Note 1)

Watchdog according to pclk, prescaler value, clock select generates a watchdog's own work cycle. We record this work cycle as t_watchdog (note 2 ), at the end of a t_watchdog cycle, watchdog generates a decreasing signal of count. When this signal is generated, the value in wtcnt is reduced by 1. If the value in wtcnt is decreased to 0 (timer out) when the software layer has not re-written the value to wtcnt (this behavior is my dog Feed mentioned above), then watchdog triggers the reset signal and the system restarts.
Based on the above description, we can more vividly describe the working principle of watchdog and the relationship between the three registers:

Wtcnt obtains a value through wtdat. watchdog sends a decreasing signal to wtcnt in each t_watchdog cycle. When the value of wtcnt decreases to 0, time out occurs and the system is restarted.

Next I will post a program for setting watchdog and enabling watchdog.

1: void enable_watchdog ()
2 :{
3: rwtcon = 0x7f81;
4: rwtdat = 0x8000;
5: rwtcon | = 1 <5;
6 :}

Rwtcon and rwtdat Are register wtcon, and the address of wtdat is unreferenced. I will define them as follows:

# Define rwtcon (* (volatile unsigned int *) 0x53000000)
# Define rwtdat (* (volatile unsigned int *) 0x53000004)

From the above settings, we can see that the value of the Register wtcon is 0x7f81, Which is decomposed as follows:

Prescaler value = 255
Division_factor = 16 (clock select = 16)
Interrupt Generation = 0 (no interruption)
Reset = 1 (enable reset signal)

Set the value of the Register wtdat to 0 x 4th in Row 3.
Enable watchdog in Row 3

After the above function is called, your system has enabled watchdog, so you must re-write a non-0 value (feed dog) to the register before the value in wtcnt is reduced to 0 ), otherwise, the system will be restarted. The following is the feed_dog function.

Void feed_dog ()
{
Rwtcnt = 0x8000;
}

The following is an example of using void enable_watchdog () and feed_dog () together.

Void main ()
{
Init_system ();
.
...
.....
Enable_watchdog ();
.
...
.....
While (1)
{
Feed_dog ();
}
}
In this example, I assume that the main function is the main function of the system. After a series of system initialization, The enable_watchdog () function is called and the watchdog is started, the while loop below is continuous feed_dog so that the system does not repeat. Of course, this architecture cannot be used in practical applications to operate watchdog. Generally, the call of the feed_dog function is installed in the interrupt service routine of the timer. Of course, the time out of the timer (note that the time out of the timer is not the time out of watchdog) must be appropriate. Otherwise, watchdog has time before the timer can interrupt the call of the feed_dog function.
Out will cause the system to restart.

NOTE 1: In fact, after the system is powered on, the wtdat and wtcnt registers are automatically filled with two initial values 0x8000 by the hardware. After watchdog is enabled, instead of loading the value in wtdat immediately, wtcnt uses the initial value 0x8000. After the first time out occurs, the values in the wtdat register will be truly loaded into the wtcnt register.

NOTE 2: t_watchdog can be calculated based on the formula:
T_watchdog = 1/(pclk/(prescaler value + 1)/division_factor)
The prescaler value is in the 8-15 bits of the register wtcon. Its value ranges from 0 to 15 ~ 255
Division_factor consists of 3 ~ The value of the four-digit (clock select) can be 64,128, 01, 10, and 11, respectively, representing the division_factor values as 16, 32, and.

For more information about each register, see the operating manual of S3c2410.

 

Appendix: s3c2410watchdog register

1. What is watchdog?
Watchdog, the Chinese name is "Watchdog" and its full name is watchdog timer. We can literally know that it is actually a timer. However, it is different from the Timer we normally use. A common timer generally serves as a timer, and a timer timeout (timer out) causes an interruption, for example, triggering a system clock interruption. If you are familiar with Windows development, you should have used Windows timer. Windows timer has the same function as the timer discussed previously, but Windows timer is a software timer, when Windows timer time-out occurs, the app sends a message to the system to trigger an event. We can see from the above description that no matter the software timer or hardware timer, their role is in
An event occurs at a time point. For a hardware timer, this event may be expressed in the form of an interruption. For a software timer, this event can be expressed in the form of a system message. As mentioned at the beginning of this article, watchdog is essentially a timer, so it should have the characteristics of a common timer. Yes, when it is recorded, it will also cause events, however, in addition to system interruption, this event can also be a reset signal. In this case, we call watchdog a timer that can send a system restart signal.

2. watchdog job description
When a hardware system enables the watchdog function, the software running on the hardware system must send a signal to the watchdog at a specified interval. this behavior is referred to as "feed dog" to prevent the system from restarting when watchdog times out.

3. What does watchdog mean?
You may ask what the meaning of watchdog is? After watchdog is enabled, the software must send messages to it at regular intervals. Isn't it troublesome and resource-consuming? In fact, this behavior is very important. This behavior is a method in which the software reports its running status to the hardware. If a software runs well, it should be able to send messages to watchdog at the specified time interval. This is the same as that when the software tells the hardware: "Hey, buddy, I am running well. Don't worry. ", If the software enters an endless loop (also known as a dead machine) due to an improper operation, it cannot send messages to watchdog, and watchdog will time out, causing hardware to restart. Without the existence of watchdog, the program is dead, but our users are still
Confused, thinking that the system is performing large-scale computation and waiting patiently... This is just an old man... -_-!!

4. Operation of S3C2410 Watchdog
For watchdog of S3C2410, pclk is its only clock signal source. (If you do not know about pclk, you can search for it online or read my next article)
S3C2410 uses three registers to operate watchdog. The three registers are wtcon, wtdat, and wtcnt respectively.
Wtcon: watchdog control register
Wtdat: watchdog data register
Wtcnt: watchdog count register

For more information about the above registers, see the watchdog section in the S3C2410 Data Manual.
5. S3C2410 watchdog job description:
Before enabling watchdog, We must store a value in the register wtdat. After watchdog is enabled, this value will be automatically loaded into the register wtcnt. The role of wtcnt will be explained below, now you only need to know That wtdat must have a value, which will be automatically loaded into wtcnt (Note 1)

Watchdog according to pclk, prescaler value, clock select generates a watchdog's own work cycle. We record this work cycle as t_watchdog (note 2 ), at the end of a t_watchdog cycle, watchdog generates a decreasing signal of count. When this signal is generated, the value in wtcnt is reduced by 1. If the value in wtcnt is decreased to 0 (timer out) when the software layer has not re-written the value to wtcnt (this behavior is my dog Feed mentioned above), then watchdog triggers the reset signal and the system restarts.
Based on the above description, we can more vividly describe the working principle of watchdog and the relationship between the three registers:

Wtcnt obtains a value through wtdat. watchdog sends a decreasing signal to wtcnt in each t_watchdog cycle. When the value of wtcnt decreases to 0, time out occurs and the system is restarted.

Next I will post a program for setting watchdog and enabling watchdog.

1: void enable_watchdog ()
2 :{
3: rwtcon = 0x7f81;
4: rwtdat = 0x8000;
5: rwtcon | = 1 <5;
6 :}

Rwtcon and rwtdat Are register wtcon, and the address of wtdat is unreferenced. I will define them as follows:

# Define rwtcon (* (volatile unsigned int *) 0x53000000)
# Define rwtdat (* (volatile unsigned int *) 0x53000004)

From the above settings, we can see that the value of the Register wtcon is 0x7f81, Which is decomposed as follows:

Prescaler value = 255
Division_factor = 16 (clock select = 16)
Interrupt Generation = 0 (no interruption)
Reset = 1 (enable reset signal)

Set the value of the Register wtdat to 0 x 4th in Row 3.
Enable watchdog in Row 3

After the above function is called, your system has enabled watchdog, so you must re-write a non-0 value (feed dog) to the register before the value in wtcnt is reduced to 0 ), otherwise, the system will be restarted. The following is the feed_dog function.

Void feed_dog ()
{
Rwtcnt = 0x8000;
}

The following is an example of using void enable_watchdog () and feed_dog () together.

Void main ()
{
Init_system ();
.
...
.....
Enable_watchdog ();
.
...
.....
While (1)
{
Feed_dog ();
}
}
In this example, I assume that the main function is the main function of the system. After a series of system initialization, The enable_watchdog () function is called and the watchdog is started, the while loop below is continuous feed_dog so that the system does not repeat. Of course, this architecture cannot be used in practical applications to operate watchdog. Generally, the call of the feed_dog function is installed in the interrupt service routine of the timer. Of course, the time out of the timer (note that the time out of the timer is not the time out of watchdog) must be appropriate. Otherwise, watchdog has time before the timer can interrupt the call of the feed_dog function.
Out will cause the system to restart.

NOTE 1: In fact, after the system is powered on, the wtdat and wtcnt registers are automatically filled with two initial values 0x8000 by the hardware. After watchdog is enabled, instead of loading the value in wtdat immediately, wtcnt uses the initial value 0x8000. After the first time out occurs, the values in the wtdat register will be truly loaded into the wtcnt register.

NOTE 2: t_watchdog can be calculated based on the formula:
T_watchdog = 1/(pclk/(prescaler value + 1)/division_factor)
The prescaler value is in the 8-15 bits of the register wtcon. Its value ranges from 0 to 15 ~ 255
Division_factor consists of 3 ~ The value of the four-digit (clock select) can be 64,128, 01, 10, and 11, respectively, representing the division_factor values as 16, 32, and.

For more information about each register, see the operating manual of S3c2410.

 

Appendix: s3c2410watchdog register

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.