1. Field of the Invention
The present invention relates to an apparatus for detecting abnormal execution of program, which detects abnormality in execution state of a program, and particularly to an apparatus for detecting abnormality in execution state of a control program in an electronic control unit for automobile.
2. Description of the Related Art
FIG. 3 is a block diagram showing the conventional structure of a door lock control system to which the present invention is applied. This control system is constructed so that a data processor (an electronic control unit 3 for automobile) controls an electric instrument (a door lock motor 5) to be controlled according to input from input means (a door lock switch 1), and a CPU 3a of the electronic control unit 3 controls the door lock motor 5 based on a predetermined control program.
In the control program, generally, a series of predetermined operations (predetermined process) is repeated to perform a control operation, as shown in FIG. 4. In the series of the operations, a plurality of sub-routines (sub-routines SR1 to SR4) are executed. Here, in the sub-routine SR1, reading of input from the door lock switch 1 is performed; in the sub-routine SR2, filtering is performed in which whether the input from the door lock switch 1 is not a noise but right is detected; in the sub-routine SR3, control determining operation for detetermining control of the door lock motor 5 in accordance with the input from the door lock switch 1 is performed; and in the sub-routine SR4, the detetermined control is output to the door lock motor 5 and an outputting operation for drive-controlling the door lock motor 5 is performed.
In this electronic control unit 3, as shown in FIG. 4, when the electronic control unit 3 is actuated and an initial operation is performed in step ST1, sequential steps ST2 to ST5 are repeated, whereby the sub-routines SR1 to SR4 are repeatedly executed. As a result, the control operation of the door lock motor 5 is performed based on the input from the door lock switch 1.
In the CPU 3a of the electronic control unit 3 for executing this control program, during execution of the control program, the memory of the program counter which indicates an executing position of the program (current position) is often disturbed by abnormality of a ROM or effects of noise, so that each of the sub-routines SR1 to SR4 is not normally completed and the executing position of the program can be moved to the unexpected wrong position. In this case, there is possibility that runaway of the CPU 3a (electronic control unit 3) is caused.
For example, as shown in FIG. 5, in a series of the operations, in case that step ST3 which must execute the sub-routine SR2 is not executed but step ST4 is executed after the sub-routine SR1 is completed in step ST2, as the sub-routine SR2 is not executed, difference occurs among the various data in the control program and a wrong operation or runaway can occur. Further, to the contrary, there is also a case that each of the sub-routines SR1 to SR4 is wrongly repeated and unnecessarily executed in a series of the operations, which may also cause the wrong operation or the like.
However, in the above-described conventional art, in case that any one of the sub-routines SR1 to SR4 to be executed is not executed or in case that any one of the sub-routines SR1 to SR4 is unnecessarily executed repeatedly in a series of the operations to be repeatedly executed of the control program, measures to meet the respective cases are not taken. Therefore, there is a problem that the wrong operation and runaway of the electronic control unit 3 caused by not suitably executing the predetermined sub-routines SR1 to SR4 to be executed thoroughly cannot be prevented.
In view of the above problem, an object of the present invention is to provide an apparatus for detecting abnormal execution of program, which can previously prevent the wrong operation and runaway of a data processor caused by not suitably executing sub-routines to be executed thoroughly in a predetermined process of the control program.
In order to achieve the above object, according to the invention, there is provided an apparatus for detecting abnormal execution of program, which detects abnormality in execution state of program in a data processor that performs a predetermined data processing by executing a program having a plurality of sub-routines to be executed in a predetermined process, comprising: memory means which is provided in the data processor and stores a set value representing the number of the sub-routines to be executed in the process of the program; counting means which is provided in the data processor and counts the number of the sub-routines that have been actually executed in the process of the program; and detecting means which is provided in the data processor, compares the set value stored in the memory means with a count value of the counting means in the last step of the process and then detects that the execution state of the program is abnormal in case that the two values are different from each other.