Disclosure of Invention
In view of the above, the present application provides a watchdog timer, a control method thereof and an electronic device, which can overcome or improve the problems of the prior art, and the specific contents thereof are as follows:
one aspect of the present application provides a method for controlling a watchdog timer, including:
providing a plurality of power domains that can be respectively turned on or off, the plurality of power domains respectively having a plurality of clocks;
opening a current power domain, wherein a clock of the watchdog timer is a clock of the current power domain;
acquiring an initial count value switched to a target power domain, and writing the initial count value into a watchdog timer;
opening a target power domain, and switching the clock of the watchdog timer to the clock of the opened power domain;
the current power domain is turned off.
Optionally, the plurality of power domains comprises a first power domain having a first clock and a second power domain having a second clock; when the first power domain is a current power domain and the second power domain is a target power domain:
opening the current power domain, wherein the clock of the watchdog timer is the clock of the current power domain, and the clock comprises: opening a first power domain, and controlling the clock of the watchdog timer to be switched into a first clock;
acquiring a starting count value for switching to a target power domain, and writing the starting count value into a watchdog timer comprises the following steps: when the first power domain is opened, acquiring a first current count value of the watchdog timer, calculating a second initial count value switched to a second power domain according to the first current count value, and writing the second initial count value into the watchdog timer;
the switching of the clock of the watchdog timer to the clock of the turned-on power domain by turning on the target power domain comprises: opening a second power domain, and controlling the clock of the watchdog timer to be switched into a second clock;
turning off the current power domain includes: the first power domain is turned off.
Optionally, when the first power domain is an initial power domain, switching to the first clock by turning on the first power domain and controlling the clock of the watchdog timer further includes: and opening the watchdog timer, and setting the count value of the watchdog timer as an initial count value.
Optionally, obtaining a reset count value of the current domain according to the initial count value:
the reset count value of the current domain is (initial count value/(initial domain clock) × current domain clock;
wherein the current domain may be any power domain in the power domain that is turned on.
Optionally, the step of opening the first power domain, controlling the clock of the watchdog timer to switch to the first clock, obtaining a first current count value of the watchdog timer, calculating a second initial count value switched to the second power domain according to the first current count value, and writing the second initial count value into the space between the watchdog timers further includes: the watchdog timer uses the first clock to count; judging whether resetting is needed; if yes, resetting the count value and counting by using a first clock; otherwise, judging whether the switching to the second power domain is needed, if so, acquiring a first current count value of the watchdog timer, calculating a second initial count value switched to the second power domain according to the first current count value, and writing the second initial count value into the watchdog timer; otherwise the watchdog timer uses the first clock to count.
Optionally, the method for controlling the watchdog timer further includes:
when the second power domain is opened, acquiring a second current count value of the watchdog timer;
calculating a first initial count value switched to the first power domain according to the second current count value, and writing the first initial count value into a watchdog timer;
opening a first power domain, and controlling the clock of the watchdog timer to be switched into a first clock;
the second power domain is turned off.
Optionally, the plurality of power domains further includes a third power domain having a third clock, and when the second power domain is turned on, obtaining a second current count value of the watchdog timer;
calculating a third initial count value switched to a third power domain according to the second current count value, and writing the third initial count value into a watchdog timer;
opening a third power domain, and controlling the clock of the watchdog timer to be switched into a third clock;
the second power domain is turned off.
One aspect of the present application provides a method for controlling a watchdog timer, including:
providing a plurality of power domains which can be respectively switched on or off, wherein the power domains respectively have a plurality of clocks, the power domains comprise an nth power domain and an mth power domain, the mth power domain has an mth clock, and the nth power domain has an nth clock, wherein m and n are positive integers, and m is not equal to n;
when the mth power domain is opened, acquiring the mth current count value of the watchdog timer;
calculating an nth initial count value switched to an nth power domain according to the mth current count value, and writing the nth initial count value into a watchdog timer;
opening an nth power domain, and controlling the clock of the watchdog timer to be switched to an nth clock;
the mth power domain is turned off.
Optionally, the nth starting count value is calculated as:
Tn=(Tm–em)/fc*fn–sn;
where Tn denotes an nth start count value, Tm denotes an mth current count value, em denotes an additional operation time including a time required to calculate the nth start count value, and sn denotes an additional operation time after the nth power domain is turned on and before the watchdog timer starts counting.
Optionally, the plurality of power domains further include an initial power domain, the initial power domain is a power domain opened when the watchdog timer is started, and after the watchdog timer is started, a count value of the watchdog timer is set to be an initial count value.
Optionally, obtaining a reset count value of the current domain according to the initial count value:
the reset count value of the current domain is (initial count value/initial domain clock) × the current domain clock;
wherein the current domain may be any power domain turned on in the power domain.
An aspect of the present application provides a watchdog timer, wherein the watchdog timer uses the above control method of the watchdog timer.
One aspect of the present application provides an electronic device, including a watchdog timer, where the watchdog timer uses the control method of the watchdog timer.
Compared with the prior art, the starting count value of the target power domain is obtained through calculation, and the starting count value switched to the target power domain is written into the watchdog timer. When the target power domain is opened, the clock of the watchdog timer is correspondingly switched to the clock corresponding to the target power domain, and counting is carried out from the initial counting value according to the clock, so that the watchdog timer can be suitable for different power domains and different clocks, and independent watchdog timers are not required to be configured for each power domain. The switching requirements of multiple power domains and multiple clocks can be met only by one watchdog timer, the stability of the watchdog timer is improved, and the circuit design is simplified.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. The following embodiments and their technical features may be combined with each other without conflict. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Please refer to fig. 1, which is a flowchart illustrating an embodiment of a method for controlling a watchdog timer according to the present application. The control method of the watchdog timer comprises the following steps:
step S101, providing a plurality of power domains, wherein the power domains can be respectively switched on or off, and the power domains are respectively provided with a plurality of clocks.
The watchdog timer usually works in a common power domain of the chip, the common power domain and the power circuit are in the same power domain, and the common power domain is powered on as long as the chip supplies power. This common power domain may also be referred to as a permanent power domain. In addition, the chip may have multiple power domains that may be turned off or on. These power domains that can be turned off may have different clocks. When different power domains are opened, the clock of the watchdog timer needs to be correspondingly switched to the clock of the opened power domain.
And step S102, opening the current power domain, wherein the clock of the watchdog timer is the clock of the current power domain.
And the current power domain is the power domain which is started by the watchdog timer at the current timing.
Step S103, obtaining an initial count value for switching to the target power domain, and writing the initial count value into the watchdog timer.
And the target power domain is a power domain to be switched on. And the clock of the watchdog timer needs to be switched to the corresponding clock of the target power domain after the target power domain is opened. The initial count value is the count value of the watchdog timer which starts to count after the clock is switched to the clock corresponding to the target power domain.
Step S104, opening the target power domain, and switching the clock of the watchdog timer to the clock of the opened power domain.
Step S105, turning off the current power domain.
Compared with the prior art, the control method of the watchdog timer obtains the initial count value of the target power domain through calculation, and writes the initial count value switched to the target power domain into the watchdog timer. When the target power domain is opened, the clock of the watchdog timer is correspondingly switched to the clock corresponding to the target power domain, and counting is carried out from the initial counting value according to the clock, so that the watchdog timer can be suitable for different power domains and different clocks, and independent watchdog timers are not required to be configured for each power domain. The switching requirements of multiple power domains and multiple clocks can be met only by one watchdog timer, the stability of the watchdog timer is improved, and the circuit design is simplified.
Please refer to fig. 2, which is a flowchart illustrating a further exemplary embodiment of the control method of the watchdog timer shown in fig. 1. The control method of the watchdog timer comprises the following steps:
step S201, providing a plurality of power domains, where the plurality of power domains includes a first power domain and a second power domain, the first power domain has a first clock, and the second power domain has a second clock.
Step S202, a first power domain is opened, and the clock of the watchdog timer is controlled to be switched to a first clock.
Step S203, obtaining a first current count value of the watchdog timer, calculating a second initial count value switched to the second power domain according to the first current count value, and writing the second initial count value into the watchdog timer.
Step S204, a second power domain is opened, and the clock of the watchdog timer is controlled to be switched to a second clock. At this time, the watchdog timer counts using the second clock.
Step S205, turn off the first power domain.
In the foregoing steps S201 to S205, the first power domain is a current power domain, and the second power domain is a target power domain.
Optionally, in some embodiments, the first power domain is an initial power domain, and the switching the clock of the watchdog timer to the first clock in step S202 further includes: and opening the watchdog timer, and setting the count value of the watchdog timer as an initial count value. The initial count value may be a count value preset by the system.
It is to be understood that when the watchdog timer is not started, if the first power domain is turned on and serves as the current power domain, the watchdog timer is started and clocks the chip portion operating in the first power domain, and then the first power domain at this time may be regarded as the initial power domain. That is, the initial power domain may be regarded as a power domain turned on when the watchdog timer is started, and when the first power domain is the initial power domain, the watchdog timer is started and counts according to the first clock.
Optionally, in some embodiments, the method for controlling a watchdog timer further includes:
in step S206, the plurality of power domains further includes a third power domain having a third clock, and when the second power domain is turned on, a second current count value of the watchdog timer is obtained.
Step S207, calculating a third initial count value switched to the third power domain according to the second current count value, and writing the third initial count value into the watchdog timer.
Step S208, turning on the third power domain, and controlling the clock of the watchdog timer to switch to the third clock.
Step S209, turn off the second power domain.
It should be noted that, in steps S206 to S209, the second power domain may be regarded as the current power domain, and the third power domain may be regarded as the target power domain. One skilled in the art will appreciate that each of the plurality of power domains may be a current power domain or a target power domain. For example, but not limiting of, the third power domain and the first power domain may be the same or different.
Please refer to fig. 3, which is a flowchart illustrating a control method of the watchdog timer shown in fig. 2 according to a further embodiment. As shown in fig. 3, between step S202 and step S203, the method may further include:
in step S2001, the watchdog timer counts using the first clock.
In step S2002, it is determined whether or not a reset is necessary. It is determined whether the watchdog timer needs to be reset. If yes, go to step S2003; otherwise, go to step S2004.
In step S2003, the count value is reset. After the count value is reset, the watchdog timer returns to step S2001 and counts using the first clock.
Optionally, in some embodiments, the count value after the watchdog timer is reset is defined as a reset count value, and for the initial power domain, the reset count value is an initial count value that is initially set. For other power domains, the reset count value is: the reset count value of the current domain is (initial count value/initial domain clock) × the current domain clock; wherein the current domain may be any power domain turned on in the power domain.
Step S2004, whether a switch to the second power domain is required. If yes, go to step S203, otherwise, go back to step S2001, the watchdog timer uses the first clock to count.
It should be noted that, although the first power domain and the second power domain are taken as an example in steps 2001 to 2004, it can be understood by those skilled in the art that any suitable current power domain and target power domain may be applied, and only the first power domain needs to be regarded as the current power domain and the second power domain needs to be regarded as the target power domain. The terms first, second, third and the like in the description of the present application do not denote any order or particular importance, but rather are used for convenience of description and should not be construed to limit the scope of the present application. Those skilled in the art will appreciate that when the watchdog countdown timer expires, the chip needs to be re-powered up and restarted by notifying the circuit outside the chip through other digital logic circuits inside the permanent power domain or through pins. This is not described in detail in the present application.
Compared with the prior art, the control method of the watchdog timer obtains the initial count value of the second power domain through calculation, and writes the second initial count value. And when the second power domain is opened, correspondingly switching the clock of the watchdog timer to the second clock, and counting from the second initial count value according to the second clock. Likewise, the watchdog timer may write a third starting count value when switching from the second power domain to the third power domain and switch to have a clock corresponding to the third power domain. Therefore, the watchdog timer can be suitable for different power domains and different clocks, and an independent watchdog timer is not required to be configured for each power domain. The switching requirements of multiple power domains and multiple clocks can be met only by one watchdog timer, the stability of the watchdog timer is improved, and the circuit design is simplified.
Please refer to fig. 4, which is a flowchart illustrating a control method of a watchdog timer according to an embodiment of the present application. The control method of the watchdog timer comprises the following steps:
step S301, providing a plurality of power domains, wherein the power domains can be respectively turned on or off, the power domains respectively have a plurality of clocks, the power domains comprise an nth power domain and an mth power domain, the mth power domain has an mth clock, and the nth power domain has an nth clock. Wherein m and n are positive integers, and m is not equal to n.
Step S302, when the mth power domain is opened, the mth current count value of the watchdog timer is obtained.
Step S303, calculating an nth starting count value for switching to the nth power domain according to the mth current count value, and writing the nth starting count value into the watchdog timer.
Step S304, the nth power domain is opened, and the clock of the watchdog timer is controlled to be switched to the nth clock.
Step S305, turn off the mth power domain.
Optionally, in some embodiments, the nth starting count value is calculated by:
Tn=(Tm–em)/fc*fn–sn;
where Tn denotes an nth start count value, Tm denotes an mth current count value, em denotes an additional operation time including a time required to calculate the nth start count value, and sn denotes an additional operation time after the nth power domain is turned on and before the watchdog timer starts counting.
Optionally, in some embodiments, the plurality of power domains further include an initial power domain, where the initial power domain is a power domain that is turned on when the watchdog timer is started, and after the watchdog timer is started, a count value of the watchdog timer is set to be an initial count value.
Optionally, in some embodiments, the method for controlling a watchdog timer further includes: and acquiring a reset count value of the current domain according to the initial count value. The reset count value is used when the count value of the watchdog timer needs to be reset. For the initial power domain, the count value is reset to the initial count value of the initial setting. For other power domains, the reset count value is: the reset count value of the current domain is (initial count value/initial domain clock) × the current domain clock; wherein the current domain may be any power domain turned on in the power domain.
Compared with the prior art, the control method of the watchdog timer obtains the initial count value of the nth power domain through calculation, and writes the nth initial count value of the nth power domain. When the nth power domain is opened, the clock of the watchdog timer is correspondingly switched to the nth clock, and counting is carried out from the nth initial counting value according to the nth clock, so that the watchdog timer can be suitable for different power domains and different clocks, and independent watchdog timers do not need to be configured for each power domain. The switching requirements of multiple power domains and multiple clocks can be met only by one watchdog timer, the stability of the watchdog timer is improved, and the circuit design is simplified.
The present application also provides a watchdog timer, which may use the control method of the watchdog timer of the above embodiment or the modified embodiment. The present application further provides an electronic device, including a watchdog timer, where the watchdog timer uses the control method of the watchdog timer in the foregoing embodiment or the modified embodiment.
Although the invention has been shown and described with respect to one or more implementations, equivalent alterations and modifications will occur to others skilled in the art based upon a reading and understanding of this specification and the annexed drawings. The present invention includes all such modifications and variations, and is limited only by the scope of the following claims. In particular regard to the various functions performed by the above described components, the terms used to describe such components are intended to correspond, unless otherwise indicated, to any component which performs the specified function of the described component (e.g., that is functionally equivalent), even though not structurally equivalent to the disclosed structure which performs the function in the herein illustrated exemplary implementations of the specification. In addition, while a particular feature of the specification may have been disclosed with respect to only one of several implementations, such feature may be combined with one or more other features of the other implementations as may be desired and advantageous for a given or particular application. Furthermore, to the extent that the terms "includes," has, "" contains, "or variants thereof are used in either the detailed description or the claims, such terms are intended to be inclusive in a manner similar to the term" comprising. Further, it is understood that reference to "a plurality" herein means two or more. For the steps mentioned in the text, the numerical suffixes are only used for clearly expressing the embodiments and are convenient for understanding, the execution sequence of the steps is not completely represented, and the logical relationship should be set as the consideration
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all equivalent structures or equivalent flow transformations made by using the contents of the specification and the drawings, such as the mutual combination of technical features between various embodiments, or the direct or indirect application to other related technical fields, are included in the scope of the present invention.