JP2022083141A - Control device and processing method - Google Patents

Control device and processing method Download PDF

Info

Publication number
JP2022083141A
JP2022083141A JP2020194423A JP2020194423A JP2022083141A JP 2022083141 A JP2022083141 A JP 2022083141A JP 2020194423 A JP2020194423 A JP 2020194423A JP 2020194423 A JP2020194423 A JP 2020194423A JP 2022083141 A JP2022083141 A JP 2022083141A
Authority
JP
Japan
Prior art keywords
coroutine
function
area
memory
automatic variable
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
JP2020194423A
Other languages
Japanese (ja)
Inventor
信一 中島
Shinichi Nakajima
剛 宮崎
Takeshi Miyazaki
英治 高松
Eiji Takamatsu
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fuji Electric Co Ltd
Original Assignee
Fuji Electric Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fuji Electric Co Ltd filed Critical Fuji Electric Co Ltd
Priority to JP2020194423A priority Critical patent/JP2022083141A/en
Publication of JP2022083141A publication Critical patent/JP2022083141A/en
Pending legal-status Critical Current

Links

Images

Abstract

To provide a control device which can normally restart interrupted processing, when executing a coroutine function.SOLUTION: In a control device 100, a program 4 includes steps of: securing a retraction area 3e for retracting information on a coroutine function to a global area 3b of a memory 3, after the coroutine function is called; retracting an automatic variable included in the information on the coroutine function which is saved in a stack area 3d of the memory 3, to the retraction area 3e, before processing of the coroutine function is interrupted, after the coroutine function is called; and restoring the automatic variable retracted to the retraction area 3e, in the stack area 3d of the memory 3, before restarting the interrupted processing.SELECTED DRAWING: Figure 9

Description

この発明は、制御装置および処理方法に関し、特に、コルーチン関数を実行する制御装置および処理方法に関する。 The present invention relates to a control device and a processing method, and more particularly to a control device and a processing method for executing a coroutine function.

従来、コルーチン関数を実行する処理方法が知られている(たとえば、特許文献1参照)。 Conventionally, a processing method for executing a coroutine function is known (see, for example, Patent Document 1).

上記特許文献1には、コルーチン関数のプロセスが開示されている。通常の関数(サブルーチン関数など、関数Bとする)では、呼び出し元の関数(関数Aとする)から関数Bを呼び出した場合、呼び出された関数Bの処理が完了した後、処理は、呼び出し元の関数Aに復帰する。一方、コルーチン関数では、呼び出し元の関数Aからコルーチン関数(コルーチン関数Cとする)を呼び出した場合、コルーチン関数Cは、処理を実行した後に処理を中断する。これにより、処理は、呼び出し元の関数Aに復帰する。そして、呼び出し元の関数Aが、再びコルーチン関数Cを呼び出した場合、呼び出されたコルーチン関数Cは、処理を中断した時点から処理を再開する。 The above-mentioned Patent Document 1 discloses a process of a coroutine function. In a normal function (referred to as function B such as a subroutine function), when function B is called from the calling function (referred to as function A), the processing is performed after the processing of the called function B is completed. Return to the function A of. On the other hand, in the coroutine function, when the coroutine function (referred to as coroutine function C) is called from the calling function A, the coroutine function C interrupts the processing after executing the processing. As a result, the process returns to the calling function A. Then, when the calling function A calls the coroutine function C again, the called coroutine function C resumes the processing from the time when the processing is interrupted.

ここで、従来、C言語などのように、標準ライブラリとして、コルーチン関数が提供されていない言語がある。この場合、たとえばC言語では、switch-case文を用いて疑似的にコルーチン関数を実装する方法が知られている。この方法では、コルーチン関数内の複数の処理が、case節の単位に分割される。そして、1つのcase節内の処理が実行され、次回に処理されるcase節のラベルがメモリに保存された後、コルーチン関数が終了される。これにより、疑似的にコルーチン関数の処理の中断が実現されている。なお、コルーチン関数の自動変数などは、メモリのスタック領域に保存されている。そして、処理の再開時には、コルーチン関数の先頭から処理が実行される。そして、switch-case文の条件判断によって、処理の中断の前に保存されたラベルのcase節の処理が実行される。 Here, conventionally, there is a language such as C language in which a coroutine function is not provided as a standard library. In this case, for example, in C language, a method of implementing a coroutine function in a pseudo manner using a switch-case statement is known. In this method, a plurality of processes in a coroutine function are divided into units of case clauses. Then, the processing in one case clause is executed, the label of the case clause to be processed next time is saved in the memory, and then the coroutine function is terminated. As a result, the processing of the coroutine function is interrupted in a pseudo manner. The automatic variables of the coroutine function are stored in the stack area of the memory. Then, when the process is restarted, the process is executed from the beginning of the coroutine function. Then, the process of the case clause of the label saved before the interruption of the process is executed by the conditional determination of the switch-case statement.

特許第5421914号公報Japanese Patent No. 5421914

しかしながら、C言語のswitch-case文を用いて疑似的なコルーチン関数を実装した場合において、中断した処理を再開するためにコルーチン関数が呼び出された際、コルーチン関数の自動変数が保存されているメモリのスタック領域が初期化されるか、または、スタック領域に不定値が保存される。このため、中断した処理の再開時には、コルーチン関数の自動変数の値が、処理の中断前の値と異なっており、中断した処理を正常に再開できない場合があるという問題点がある。 However, when a pseudo coroutine function is implemented using the C language switch-case statement, the memory in which the automatic variables of the coroutine function are stored when the coroutine function is called to resume the interrupted processing. The stack area of is initialized, or an indefinite value is saved in the stack area. Therefore, when the interrupted processing is restarted, the value of the automatic variable of the coroutine function is different from the value before the processing is interrupted, and there is a problem that the interrupted processing may not be restarted normally.

この発明は、上記のような課題を解決するためになされたものであり、この発明の1つの目的は、コルーチン関数を実行する際に、中断した処理を正常に再開することが可能な制御装置および処理方法を提供することである。 The present invention has been made to solve the above-mentioned problems, and one object of the present invention is a control device capable of normally resuming interrupted processing when executing a coroutine function. And to provide a processing method.

上記目的を達成するために、この発明の第1の局面による制御装置は、処理を中断させた後、中断させた処理の続きから処理を再開させるコルーチン関数を実行する制御装置であって、コルーチン関数を含むプログラムが保存されるメモリと、プログラムを実行する制御部、とを備え、プログラムは、コルーチン関数が呼び出された後、メモリのグローバル領域にコルーチン関数の情報を退避させる退避領域を確保するステップと、コルーチン関数が呼び出された後、コルーチン関数の処理が中断される前に、メモリのスタック領域に保存されているコルーチン関数の情報に含まれる自動変数を、退避領域に退避させるステップと、中断された処理を再開する前に、退避領域に退避された自動変数を、メモリのスタック領域に復元するステップと、を含む。なお、「コルーチン関数」とは、標準ライブラリとして提供されるコルーチン関数に加えて、C言語のswitch-case文などを用いて実装された疑似的なコルーチン関数を含む概念である。 In order to achieve the above object, the control device according to the first aspect of the present invention is a control device that executes a coroutine function that suspends processing and then resumes processing from the continuation of the interrupted processing, and is a coroutine. A memory containing a program containing a function and a control unit for executing the program are provided, and the program secures a save area for saving the information of the coroutine function in the global area of the memory after the coroutine function is called. A step and a step to save the automatic variables contained in the information of the coroutine function stored in the stack area of the memory to the save area after the coroutine function is called and before the processing of the coroutine function is interrupted. Includes a step of restoring the coroutines saved in the save area to the memory stack area before resuming the interrupted processing. The "coroutine function" is a concept including a pseudo coroutine function implemented by using a switch-case statement in C language in addition to the coroutine function provided as a standard library.

この発明の第1の局面による制御装置では、上記のように、プログラムは、コルーチン関数が呼び出された後、コルーチン関数の処理が中断される前に、メモリのスタック領域に保存されているコルーチン関数の情報に含まれる自動変数を、退避領域に退避させるステップと、中断された処理を再開する前に、退避領域に退避された自動変数を、メモリのスタック領域に復元するステップと、を含む。これにより、メモリのスタック領域に保存されている自動変数がメモリのグローバル領域の退避領域に退避されるので、中断した処理を再開するためにコルーチン関数が呼び出された際、メモリのスタック領域が初期化されるかまたはスタック領域に不定値が保存されていても、メモリのグローバル領域の退避領域に退避された自動変数がメモリのスタック領域に復元される。その結果、コルーチン関数の中断した処理の再開時に、正確な自動変数に基づいて、処理を再開することができる。これにより、コルーチン関数を実行する際に、中断した処理を正常に再開することができる。 In the control device according to the first aspect of the present invention, as described above, the program is a coroutine function stored in a stack area of memory after the coroutine function is called and before the processing of the coroutine function is interrupted. It includes a step of saving the automatic variables included in the information of the above to the save area and a step of restoring the automatic variables saved in the save area to the stack area of the memory before restarting the interrupted processing. As a result, the automatic variables saved in the stack area of the memory are saved in the save area of the global area of the memory. Therefore, when the collout function is called to restart the interrupted processing, the stack area of the memory is initially set. Even if the variable value is changed or an indefinite value is stored in the stack area, the automatic variable saved in the save area of the global area of the memory is restored to the stack area of the memory. As a result, when the interrupted processing of the coroutine function is resumed, the processing can be resumed based on the exact automatic variable. As a result, when the coroutine function is executed, the interrupted processing can be resumed normally.

上記第1の局面による制御装置において、好ましくは、コルーチン関数の情報は、コルーチン関数のポインタ情報、コルーチン関数の中断位置、引数、および、戻り値をさらに含む。このように構成すれば、中断した処理の再開に必要なコルーチン関数のポインタ情報、コルーチン関数の中断位置、自動変数、引数、および、戻り値が、メモリのグローバル領域の退避領域に退避されるので、中断した処理を正常かつ確実に再開することができる。 In the control device according to the first aspect, preferably, the information of the coroutine function further includes the pointer information of the coroutine function, the interruption position of the coroutine function, the argument, and the return value. With this configuration, the pointer information of the coroutine function required to restart the interrupted processing, the interruption position of the coroutine function, the automatic variable, the argument, and the return value are saved in the save area of the global area of the memory. , The interrupted processing can be resumed normally and surely.

この場合、好ましくは、自動変数、引数、および、戻り値の各々の情報は、メモリ上の領域情報またはポインタ情報である。ここで、メモリのグローバル領域は、メモリのスタック領域と異なり自由に書き込みが可能であるので、自動変数、引数、および、戻り値の各々の情報を、メモリ上の領域情報またはポインタ情報のいずれでも書き込むことができる。 In this case, preferably, the information of each of the automatic variable, the argument, and the return value is the area information or the pointer information in the memory. Here, since the global area of the memory can be freely written unlike the stack area of the memory, each information of the automatic variable, the argument, and the return value can be either the area information or the pointer information on the memory. Can be written.

上記第1の局面による制御装置において、好ましくは、退避領域を確保するステップは、コルーチン関数の情報の大きさに応じて、退避領域を確保するステップを含む。ここで、コルーチン関数の情報を、コルーチン関数を呼び出す呼び出し元の関数のスタック領域に保存する場合、コルーチン関数の情報のための領域が固定サイズで確保される場合がある。この場合、コルーチン関数の構成(引数、自動変数および戻り値のそれぞれの個数)によっては、コルーチン関数の情報のために適切に領域を確保できない(過不足する)場合がある。そこで、上記のように構成することによって、メモリのグローバル領域では、退避領域を可変長により確保することができる(グローバル領域は、スタック領域に比べて領域のサイズの指定が容易である)ので、退避領域を適切に確保することができる。 In the control device according to the first aspect, preferably, the step of securing the save area includes a step of securing the save area according to the size of the information of the coroutine function. Here, when the information of the coroutine function is stored in the stack area of the calling function that calls the coroutine function, the area for the information of the coroutine function may be secured in a fixed size. In this case, depending on the configuration of the coroutine function (the number of each of the arguments, automatic variables, and return values), it may not be possible to properly secure an area (excess or deficiency) for the information of the coroutine function. Therefore, by configuring as described above, the save area can be secured by the variable length in the global area of the memory (the size of the area can be easily specified in the global area as compared with the stack area). The evacuation area can be secured appropriately.

上記第1の局面による制御装置において、好ましくは、プログラムは、自動変数をメモリのスタック領域に復元した後、自動変数が保存されていた領域を解放するステップをさらに含む。このように構成すれば、自動変数をメモリのスタック領域に復元した後にメモリの自動変数が保存されていた領域が解放されるので、コルーチン関数が複数設けられる場合において、解放後のメモリのグローバル領域を他のコルーチン関数の自動変数などを保存する領域として利用することができる。つまり、コルーチン関数の数が比較的多い場合でも、コルーチン関数を適切に実行することができる。 In the control device according to the first aspect, preferably, the program further includes a step of restoring the automatic variable to the stack area of the memory and then releasing the area where the automatic variable is stored. With this configuration, the area where the automatic variables in the memory are stored is released after the automatic variables are restored to the stack area of the memory. Therefore, when multiple coroutine functions are provided, the global area of the memory after release is released. Can be used as an area for storing automatic variables of other coroutine functions. That is, even if the number of coroutine functions is relatively large, the coroutine functions can be executed appropriately.

上記第1の局面による制御装置において、好ましくは、プログラムは、コルーチン関数を呼び出した後に、メモリのスタック領域における自動変数のアドレスリストをメモリのグローバル領域に作成するステップをさらに含み、自動変数を退避領域に退避させるステップは、作成されたアドレスリストに基づいて、自動変数を退避領域に退避させるステップを含み、自動変数をスタック領域に復元するステップは、作成されたアドレスリストに基づいて、自動変数を、メモリのスタック領域に復元するステップを含む。このように構成すれば、アドレスリストに基づいて自動変数の退避および復元が行われるので、自動変数を間違えることなく退避領域に退避させるとともにスタック領域に復元することができる。 In the control device according to the first aspect, preferably, the program further includes a step of creating an address list of automatic variables in the stack area of memory in the global area of memory after calling the coroutary function, and saves the automatic variables. The step to save to the area includes the step to save the automatic variable to the save area based on the created address list, and the step to restore the automatic variable to the stack area is based on the created address list. Includes a step to restore to the stack area of memory. With this configuration, the automatic variables are saved and restored based on the address list, so that the automatic variables can be saved in the save area and restored in the stack area without making a mistake.

この場合、好ましくは、プログラムは、自動変数を退避領域に退避させた後、自動変数のアドレスリストが保存されていた領域を解放するステップをさらに含む。このように構成すれば、自動変数を退避領域に退避させた後、自動変数のアドレスリストが保存されていた領域が解放されるので、コルーチン関数が複数設けられる場合において、解放後のメモリのグローバル領域を他のコルーチン関数のアドレスリストなどを保存する領域として利用することができる。つまり、コルーチン関数の数が比較的多い場合でも、コルーチン関数を適切に実行することができる。 In this case, preferably, the program further includes a step of saving the automatic variable in the save area and then releasing the area in which the address list of the automatic variable is stored. With this configuration, after the automatic variables are saved in the save area, the area where the address list of the automatic variables is saved is released. Therefore, when multiple coroutine functions are provided, the global memory after release is released. The area can be used as an area for storing the address list of other coroutine functions. That is, even if the number of coroutine functions is relatively large, the coroutine functions can be executed appropriately.

この発明の第2の局面による処理方法は、処理を中断させた後、中断させた処理の続きから処理を再開させるコルーチン関数を実行する処理方法であって、コルーチン関数を呼び出すステップと、コルーチン関数が呼び出された後、メモリのグローバル領域にコルーチン関数の情報を退避させる退避領域を確保するステップと、コルーチン関数が呼び出された後、コルーチン関数の処理が中断される前に、メモリのスタック領域に保存されているコルーチン関数の情報に含まれる自動変数を、退避領域に退避させるステップと、中断された処理を再開する前に、退避領域に退避された自動変数を、メモリのスタック領域に復元するステップと、を含む。 The processing method according to the second aspect of the present invention is a processing method for executing a coroutine function that suspends the processing and then resumes the processing from the continuation of the interrupted processing, the step of calling the coroutine function and the coroutine function. After the coroutine function is called, the step to secure a save area to save the information of the coroutine function in the global area of the memory, and after the coroutine function is called, before the processing of the coroutine function is interrupted, the stack area of the memory A step to save the automatic variables included in the saved coroutine function information to the save area, and restore the automatic variables saved in the save area to the stack area of the memory before restarting the interrupted processing. Including steps.

この発明の第2の局面による処理方法では、上記のように、コルーチン関数が呼び出された後、コルーチン関数の処理が中断される前に、メモリのスタック領域に保存されているコルーチン関数の情報に含まれる自動変数を、退避領域に退避させるステップと、中断された処理を再開する前に、退避領域に退避された自動変数を、メモリのスタック領域に復元するステップと、を含む。これにより、メモリのスタック領域に保存されている自動変数がメモリのグローバル領域の退避領域に退避されるので、中断した処理を再開するためにコルーチン関数が呼び出された際、メモリのスタック領域が初期化されるかまたはスタック領域に不定値が保存されていても、メモリのグローバル領域の退避領域に退避された自動変数がメモリのスタック領域に復元される。その結果、コルーチン関数の中断した処理の再開時に、正確な自動変数に基づいて、処理を再開することができる。これにより、コルーチン関数を実行する際に、中断した処理を正常に再開することが可能な処理方法を提供することができる。 In the processing method according to the second aspect of the present invention, as described above, after the coroutine function is called and before the processing of the coroutine function is interrupted, the information of the coroutine function stored in the stack area of the memory is used. It includes a step of saving the included automatic variables in the save area and a step of restoring the saved automatic variables in the save area to the stack area of the memory before restarting the interrupted processing. As a result, the automatic variables saved in the stack area of the memory are saved in the save area of the global area of the memory. Therefore, when the collout function is called to restart the interrupted processing, the stack area of the memory is initially set. Even if the variable value is changed or an indefinite value is stored in the stack area, the automatic variable saved in the save area of the global area of the memory is restored to the stack area of the memory. As a result, when the interrupted processing of the coroutine function is resumed, the processing can be resumed based on the exact automatic variable. This makes it possible to provide a processing method capable of normally resuming the interrupted processing when the coroutine function is executed.

本発明によれば、上記のように、コルーチン関数を実行する際に、中断した処理を正常に再開することができる。 According to the present invention, as described above, when the coroutine function is executed, the interrupted processing can be resumed normally.

本実施形態による制御装置のブロック図である。It is a block diagram of the control device by this embodiment. 本実施形態による制御装置のメモリの構成を示す図である。It is a figure which shows the structure of the memory of the control device by this embodiment. 一般的なサブルーチン関数の処理を説明するためのシーケンス図である。It is a sequence diagram for demonstrating the processing of a general subroutine function. 一般的なコルーチン関数の処理を説明するためのシーケンス図である。It is a sequence diagram for demonstrating the processing of a general coroutine function. 本実施形態によるコルーチン関数の処理とメモリとの関係を説明するための図である。It is a figure for demonstrating the relationship between the processing of a coroutine function and a memory by this embodiment. 本実施形態による制御装置のメモリのブロックを説明するための図である。It is a figure for demonstrating the block of the memory of the control device by this embodiment. 本実施形態によるコルーチン関数の処理を例示した図である。It is a figure which illustrated the processing of the coroutine function by this embodiment. 本実施形態による自動変数のアドレスリスト(スタックフレーム定義)を説明するための図である。It is a figure for demonstrating the address list (stack frame definition) of an automatic variable by this embodiment. 本実施形態によるコルーチン関数の処理を説明するためのフロー図である。It is a flow diagram for demonstrating the processing of the coroutine function by this embodiment. 本実施形態によるコルーチン関数の記述例および実際のコード例を説明するための図である。It is a figure for demonstrating the description example of the coroutine function and the actual code example by this Embodiment. 本実施形態によるコルーチン関数の処理を説明するためのシーケンス図である。It is a sequence diagram for demonstrating the processing of a coroutine function by this embodiment. 本実施形態によるコルーチン関数の処理を説明するためのメモリ遷移図である。It is a memory transition diagram for demonstrating the processing of a coroutine function by this embodiment. 本実施形態による2つのコルーチン関数の処理を説明するためのシーケンス図である。It is a sequence diagram for demonstrating the processing of two coroutine functions by this embodiment. 本実施形態による2つのコルーチン関数の処理を説明するためのメモリ遷移図である。It is a memory transition diagram for demonstrating the processing of two coroutine functions by this embodiment. 本実施形態によるコルーチン関数およびサブコルーチン関数の処理を説明するためのシーケンス図である。It is a sequence diagram for demonstrating the processing of the coroutine function and the sub-coroutine function by this embodiment. 本実施形態によるコルーチン関数およびサブコルーチン関数の処理を説明するためのメモリ遷移図である。It is a memory transition diagram for demonstrating the processing of a coroutine function and a sub-coroutine function by this embodiment.

以下、本発明を具体化した実施形態を図面に基づいて説明する。 Hereinafter, embodiments embodying the present invention will be described with reference to the drawings.

図1~図16を参照して、本実施形態による制御装置100の構成について説明する。なお、制御装置100は、たとえば、組み込み機器に用いられる制御装置100である。 The configuration of the control device 100 according to the present embodiment will be described with reference to FIGS. 1 to 16. The control device 100 is, for example, a control device 100 used for an embedded device.

図1に示すように、制御装置100は、プリント基板1に設けられたマイコン2と、メモリ3とを備えている。メモリ3は、ROM(Read Only Memory)およびRAM(Random Access Memory)などから構成されている。また、メモリ3には、コルーチン関数を含むプログラム4が保存されている。マイコン2は、メモリ3に保存されたプログラム4を実行する。プログラム4は、C言語により記載されている。なお、マイコン2は、特許請求の範囲の「制御部」の一例である。 As shown in FIG. 1, the control device 100 includes a microcomputer 2 provided on the printed circuit board 1 and a memory 3. The memory 3 is composed of a ROM (Read Only Memory), a RAM (Random Access Memory), and the like. Further, the program 4 including the coroutine function is stored in the memory 3. The microcomputer 2 executes the program 4 stored in the memory 3. Program 4 is written in C language. The microcomputer 2 is an example of a "control unit" within the scope of claims.

図2に示すように、C言語によって取り扱われるメモリ3は、テキスト領域3aと、グローバル領域3b(静的領域)と、ヒープ領域3cと、スタック領域3dとを含む。そして、テキスト領域3aには、機械語に翻訳されたプログラム4が格納される。グローバル領域3bには、グローバル変数などの静的変数が格納される。ヒープ領域3cは、メモリ3の管理のために使用される。スタック領域3dは、C言語の自動変数(ローカル変数など)が格納される。また、ヒープ領域3cおよびスタック領域3dのサイズは、プログラム4中に変化する。 As shown in FIG. 2, the memory 3 handled by the C language includes a text area 3a, a global area 3b (static area), a heap area 3c, and a stack area 3d. Then, the program 4 translated into the machine language is stored in the text area 3a. Static variables such as global variables are stored in the global area 3b. The heap area 3c is used for managing the memory 3. C language automatic variables (local variables, etc.) are stored in the stack area 3d. Further, the sizes of the heap area 3c and the stack area 3d change during the program 4.

本実施形態では、制御装置100は、処理を中断させた後、中断させた処理の続きから処理を再開させる、C言語により実装された疑似的なコルーチン関数を実行するように構成されている。 In the present embodiment, the control device 100 is configured to execute a pseudo coroutine function implemented in C language, which suspends the processing and then resumes the processing from the continuation of the interrupted processing.

図3および図4を参照して、サブルーチン関数とコルーチン関数との差異について説明する。 The difference between the subroutine function and the coroutine function will be described with reference to FIGS. 3 and 4.

図3に示すように、サブルーチン関数は、func1関数からサブルーチン関数であるfunc2関数を呼び出すと(call)、func2関数は、func2関数に含まれるreturn文までの処理を実行する。一方、図4に示すように、コルーチン関数では、func1関数からコルーチン関数であるfunc2関数を呼び出すと(resume)、func2関数の途中まで処理を実行するとともに中断する(yield)。そして、再び、func1関数からfunc2関数を呼び出すと(resume)、前回の処理において中断された部分の続きから、処理が再開される。 As shown in FIG. 3, when the subroutine function calls the func2 function which is a subroutine function from the func1 function (call), the func2 function executes the processing up to the return statement included in the func2 function. On the other hand, as shown in FIG. 4, in the coroutine function, when the coroutine function func2 function is called from the func1 function (resume), the process is executed halfway through the func2 function and is interrupted (yeld). Then, when the func2 function is called again from the func1 function (resume), the processing is restarted from the continuation of the portion interrupted in the previous processing.

なお、C言語では、コルーチン関数が標準ライブラリとして提供されていない。そこで、本実施形態では、C言語のSwitch-case文を用いて、疑似的なコルーチン関数を実装する(図10参照)。具体的には、Switch-case文により実装された疑似的なコルーチン関数において、コルーチン関数の処理がcase節単位に分割される。そして、1つのcase節の処理が実行され、次回に処理するcase節のラベル(中断位置)がメモリ3に保存された後、処理は、コルーチン関数から復帰(離脱)する。これにより、C言語のSwitch-case文を用いて、疑似的なコルーチン関数が実装される。コルーチン関数の処理の再開時には、コルーチン関数が呼び出され、コルーチン関数の先頭から処理が開始される。そして、Switch文の条件判定に基づいて、前回の処理の中断時に保存されたcase節のラベル(中断位置)に対応するcase節から処理が実行される。 In C language, coroutine functions are not provided as a standard library. Therefore, in this embodiment, a pseudo coroutine function is implemented by using a C language Switch-case statement (see FIG. 10). Specifically, in the pseudo coroutine function implemented by the Switch-case statement, the processing of the coroutine function is divided into case clause units. Then, after the processing of one case clause is executed and the label (interruption position) of the case clause to be processed next time is saved in the memory 3, the processing returns (leaves) from the coroutine function. As a result, a pseudo coroutine function is implemented using a C language Switch-case statement. When the processing of the coroutine function is restarted, the coroutine function is called and the processing is started from the beginning of the coroutine function. Then, based on the condition determination of the Switch statement, the process is executed from the case clause corresponding to the label (interruption position) of the case clause saved at the time of the interruption of the previous process.

(プログラムの構成)
次に、本実施形態によるC言語で疑似的に実装されたコルーチン関数の構成(プログラム4の構成)について説明する。
(Program structure)
Next, the configuration (configuration of the program 4) of the coroutine function pseudo-implemented in the C language according to the present embodiment will be described.

本実施形態では、図5に示すように、C言語で疑似的に実装されたコルーチン関数の処理(プログラム4)は、コルーチン関数が呼び出された後、メモリ3のグローバル領域3bにコルーチン関数の情報を退避させる退避領域3eを確保するステップを含む。退避領域3eは、可変長のブロック単位で管理される。また、図6に示すように、ブロックの先頭には、使用情報フラグと、ブロックサイズとを含むブロック情報が保存されている。使用情報フラグは、未使用または使用中を示す。ブロックサイズは、ブロック情報と、割り当てられたメモリ領域のサイズの情報とを含む。 In the present embodiment, as shown in FIG. 5, in the processing of the coroutine function (program 4) pseudo-implemented in C language, the information of the coroutine function is stored in the global area 3b of the memory 3 after the coroutine function is called. Includes a step of securing a save area 3e to save. The save area 3e is managed in units of variable length blocks. Further, as shown in FIG. 6, block information including a usage information flag and a block size is stored at the head of the block. The usage information flag indicates unused or in use. The block size includes block information and information on the size of the allocated memory area.

退避領域3eを確保する処理では、退避領域3eの先頭から、ブロック情報が参照され、使用状況フラグが未使用であるブロックが検索される。そして、使用状況フラグが未使用であるブロックが見つかった場合、このブロックの使用状況フラグを使用中にするとともに、割り当てられたメモリ3の領域(ブロック)の先頭のアドレスを返す。また、使用状況フラグが未使用であるブロックが見つからなかった場合、ブロック情報において使用状況フラグが未使用であるブロックが再検索(順次検索)される。 In the process of securing the save area 3e, the block information is referred from the beginning of the save area 3e, and the block in which the usage status flag is not used is searched. Then, when a block whose usage status flag is unused is found, the usage status flag of this block is set to be in use, and the start address of the allocated memory 3 area (block) is returned. If a block whose usage status flag is unused is not found, the block whose usage status flag is not used is searched again (sequential search) in the block information.

また、本実施形態では、コルーチン関数の情報は、自動変数に加えて、コルーチン関数のポインタ情報、コルーチン関数の中断位置、引数、および、戻り値をさらに含む。また、自動変数、引数、および、戻り値の各々の情報は、メモリ3上の領域情報またはポインタ情報である。なお、自動変数の領域情報、引数の領域情報、および、戻り値の領域情報は、退避領域3eの範囲内でサイズを変更することが可能である。また、自動変数のポインタ情報、引数のポインタ情報、および、戻り値のポインタ情報の参照先は、退避領域3eにおいて確保された、各々に必要なサイズを有する領域である。 Further, in the present embodiment, the information of the coroutine function further includes the pointer information of the coroutine function, the interruption position of the coroutine function, the argument, and the return value in addition to the automatic variable. Further, each information of the automatic variable, the argument, and the return value is the area information or the pointer information on the memory 3. The size of the area information of the automatic variable, the area information of the argument, and the area information of the return value can be changed within the range of the save area 3e. Further, the reference destination of the pointer information of the automatic variable, the pointer information of the argument, and the pointer information of the return value is an area secured in the save area 3e and having a size required for each.

また、本実施形態では、図5に示すように、退避領域3eを確保するステップは、コルーチン関数の情報の大きさに応じて、メモリ3のグローバル領域3bに退避領域3eを確保するステップを含む。ここで、コルーチン関数の情報を、コルーチン関数を呼び出す呼出元関数のスタック領域3dに確保した場合、スタック領域3dのサイズ(最大値)は、プログラム4のコンパイル時に決定される。このため、コルーチン関数の情報を保存するためのスタック領域3dのサイズは、コンパイル時に決定されたスタック領域3dの最大値未満となるので、同時に実行可能なコルーチン関数の数が制限される。一方、本実施形態では、コルーチン関数の情報がグローバル領域3bの退避領域3eに保存される。スタック領域3dに比べてグローバル領域3bのサイズの指定が容易であるので、本実施形態では、同時に実行可能なコルーチン関数の数が制限されるのを抑制することが可能になる。 Further, in the present embodiment, as shown in FIG. 5, the step of securing the save area 3e includes a step of securing the save area 3e in the global area 3b of the memory 3 according to the size of the information of the coroutine function. .. Here, when the information of the coroutine function is secured in the stack area 3d of the calling function that calls the coroutine function, the size (maximum value) of the stack area 3d is determined at the time of compiling the program 4. Therefore, the size of the stack area 3d for storing the information of the coroutine function is smaller than the maximum value of the stack area 3d determined at compile time, so that the number of coroutine functions that can be executed at the same time is limited. On the other hand, in the present embodiment, the information of the coroutine function is stored in the save area 3e of the global area 3b. Since it is easier to specify the size of the global area 3b as compared with the stack area 3d, in the present embodiment, it is possible to suppress the limitation on the number of coroutine functions that can be executed at the same time.

また、本実施形態では、プログラム4は、コルーチン関数が呼び出された後、コルーチン関数の処理が中断される前に、メモリ3のスタック領域3dに保存されているコルーチン関数の情報に含まれる自動変数を、退避領域3eに退避させるステップを含む。なお、自動変数は、コルーチン関数の情報(以下、Co情報と言う場合がある)の内部の自動変数領域に退避されてもよいし、Co情報とは別個に確保された領域に退避されてもよい。 Further, in the present embodiment, the program 4 is an automatic variable included in the information of the coroutine function stored in the stack area 3d of the memory 3 after the coroutine function is called and before the processing of the coroutine function is interrupted. Is included in the evacuation area 3e. The automatic variable may be saved in the automatic variable area inside the coroutine function information (hereinafter, may be referred to as Co information), or may be saved in the area reserved separately from the Co information. good.

また、本実施形態では、プログラム4は、中断された処理を再開する前に、退避領域3eに退避された自動変数を、メモリ3のスタック領域3dに復元するステップを含む。 Further, in the present embodiment, the program 4 includes a step of restoring the automatic variables saved in the save area 3e to the stack area 3d of the memory 3 before restarting the interrupted process.

図7に示す例では、コルーチン関数1とコルーチン関数2とが実行される。コルーチン関数1の実行時には、コルーチン関数1の自動変数1-1および自動変数1-2が、メモリ3のスタック領域3dに保存されている。コルーチン関数1の処理が中断される前に、スタック領域3dに保存されている自動変数1-1および自動変数1-2は、退避領域3eに退避される。なお、図7の例では、自動変数1-1および自動変数1-2は、コルーチン関数1の情報であるCo情報1(ポインタ情報、コルーチン関数の中断位置、引数、および、戻り値など)が保存される領域とは異なる領域に退避されている。 In the example shown in FIG. 7, the coroutine function 1 and the coroutine function 2 are executed. When the coroutine function 1 is executed, the automatic variables 1-1 and 1-2 of the coroutine function 1 are stored in the stack area 3d of the memory 3. Before the processing of the coroutine function 1 is interrupted, the automatic variables 1-1 and the automatic variables 1-2 stored in the stack area 3d are saved in the save area 3e. In the example of FIG. 7, the automatic variable 1-1 and the automatic variable 1-2 have Co information 1 (pointer information, interruption position of the coroutine function, argument, return value, etc.) which is information of the coroutine function 1. It is saved in an area different from the saved area.

次に、コルーチン関数2の実行時には、コルーチン関数2の自動変数2-1および自動変数2-2が、メモリ3のスタック領域3dに保存されている。コルーチン関数2の処理が中断される前に、スタック領域3dに保存されている自動変数2-1および自動変数2-2は、退避領域3eに退避される。 Next, when the coroutine function 2 is executed, the automatic variable 2-1 and the automatic variable 2-2 of the coroutine function 2 are stored in the stack area 3d of the memory 3. Before the processing of the coroutine function 2 is interrupted, the automatic variables 2-1 and the automatic variables 2-2 stored in the stack area 3d are saved in the save area 3e.

コルーチン関数1の再開時には、スタック領域3dに保存されている自動変数1-1および自動変数1-2が、メモリ3のスタック領域3dに復元される。コルーチン関数2の再開時も、同様である。 When the coroutine function 1 is restarted, the automatic variables 1-1 and 1-2 stored in the stack area 3d are restored to the stack area 3d of the memory 3. The same applies when the coroutine function 2 is restarted.

また、本実施形態では、プログラム4は、自動変数をメモリ3のスタック領域3dに復元した後、自動変数が保存されていた領域(退避領域3e)を解放するステップをさらに含む。具体的には、図6に示すように、退避領域3eの先頭アドレスから、開放する領域が含まれるブロックのブロック情報を参照して、このブロックの使用状況フラグを未使用にする。 Further, in the present embodiment, the program 4 further includes a step of restoring the area (save area 3e) in which the automatic variable is stored after restoring the automatic variable to the stack area 3d of the memory 3. Specifically, as shown in FIG. 6, the usage status flag of this block is unused by referring to the block information of the block including the area to be released from the start address of the save area 3e.

また、本実施形態では、図8に示すように、プログラム4は、コルーチン関数を呼び出した後に、メモリ3のスタック領域3dにおける自動変数のアドレスリストAL(スタックフレーム定義)を作成するステップをさらに含む。具体的には、メモリ3のグローバル領域3bに、アドレスリストALの情報を保存するために必要な定義領域3fが確保される。そして、退避する自動変数のスタック領域3d上のアドレス値(ポインタ)がアドレスリストAL(スタックフレーム定義)としてグローバル領域3bに保存される。 Further, in the present embodiment, as shown in FIG. 8, the program 4 further includes a step of creating an address list AL (stack frame definition) of automatic variables in the stack area 3d of the memory 3 after calling the coroutine function. .. Specifically, the definition area 3f necessary for storing the information of the address list AL is secured in the global area 3b of the memory 3. Then, the address value (pointer) on the stack area 3d of the automatic variable to be saved is stored in the global area 3b as the address list AL (stack frame definition).

たとえば、図8(a)に示す例では、スタック領域3dに、自動変数A、自動変数Bおよび自動変数C(図8では、各々、A、BおよびCと記載する)が保存されている。そして、グローバル領域3bに、アドレスリストALとして、自動変数Aのポインタ、自動変数Bのポインタおよび自動変数Cのポインタが保存されている。なお、自動変数Aのポインタ、自動変数Bのポインタおよび自動変数Cのポインタは、図8に示される順に限られず、任意の順に保存される。 For example, in the example shown in FIG. 8A, the automatic variable A, the automatic variable B, and the automatic variable C (referred to as A, B, and C, respectively in FIG. 8) are stored in the stack area 3d. Then, in the global area 3b, the pointer of the automatic variable A, the pointer of the automatic variable B, and the pointer of the automatic variable C are stored as the address list AL. The pointer of the automatic variable A, the pointer of the automatic variable B, and the pointer of the automatic variable C are not limited to the order shown in FIG. 8, and are stored in any order.

そして、本実施形態では、図8(c)に示すように、自動変数をグローバル領域3bに退避させるステップは、作成されたアドレスリストALに基づいて、自動変数を退避領域3eに退避させるステップを含む。具体的には、メモリ3のグローバル領域3bにコルーチン関数の情報(自動変数)を退避させる退避領域3eを確保する。そして、アドレスリストALで定義された順に、ポインタが参照した自動変数の値を、退避領域3eに保存する。 Then, in the present embodiment, as shown in FIG. 8C, the step of saving the automatic variable to the global area 3b is a step of saving the automatic variable to the save area 3e based on the created address list AL. include. Specifically, a save area 3e for saving coroutine function information (automatic variable) is secured in the global area 3b of the memory 3. Then, the values of the automatic variables referenced by the pointer are stored in the save area 3e in the order defined in the address list AL.

たとえば、図8(c)に示す例では、スタック領域3dに自動変数A、自動変数Bおよび自動変数Cが保存されている。そして、ポインタが参照した自動変数Aの値が、退避領域3eに保存される。これにより、グローバル領域3bに、自動変数Aの値が退避される。自動変数Bおよび自動変数Cについても同様である。 For example, in the example shown in FIG. 8C, the automatic variable A, the automatic variable B, and the automatic variable C are stored in the stack area 3d. Then, the value of the automatic variable A referenced by the pointer is stored in the save area 3e. As a result, the value of the automatic variable A is saved in the global area 3b. The same applies to the automatic variable B and the automatic variable C.

そして、本実施形態では、プログラム4は、自動変数(の値)を、退避領域3eに退避させるステップの後、アドレスリストALが保存されていた領域を解放するステップをさらに含む。 Then, in the present embodiment, the program 4 further includes a step of releasing the area in which the address list AL is stored after the step of saving the automatic variable (value) in the save area 3e.

また、本実施形態では、図8(b)に示すように、自動変数をスタック領域3dに復元するステップは、作成されたアドレスリストALに基づいて、自動変数を、メモリ3のスタック領域3dに復元するステップを含む。具体的には、退避領域3eから、処理の中断前に退避した自動変数の値を取得する。そして、自動変数を、アドレスリストALに定義された順に、ポインタが示すスタック領域3dの部分に保存する。 Further, in the present embodiment, as shown in FIG. 8B, in the step of restoring the automatic variable to the stack area 3d, the automatic variable is transferred to the stack area 3d of the memory 3 based on the created address list AL. Includes steps to restore. Specifically, the value of the automatic variable saved before the processing is interrupted is acquired from the save area 3e. Then, the automatic variables are stored in the stack area 3d indicated by the pointer in the order defined in the address list AL.

たとえば、図8(b)に示す例では、退避領域3eに中断前の自動変数Aの値、自動変数Bの値および自動変数Cの値が保存されている。そして、自動変数Aの値を、アドレスリストALの自動変数Aのポインタが示すスタック領域3dの部分に保存する。これにより、スタック領域3dに、自動変数Aの値が復元される。自動変数Bおよび自動変数Cについても同様である。自動変数A~Cがメモリ3のスタック領域3dに復元された後、自動変数A~Cが保存されていた領域(グローバル領域3bの部分)が解放される。 For example, in the example shown in FIG. 8B, the value of the automatic variable A, the value of the automatic variable B, and the value of the automatic variable C before the interruption are stored in the save area 3e. Then, the value of the automatic variable A is stored in the stack area 3d indicated by the pointer of the automatic variable A in the address list AL. As a result, the value of the automatic variable A is restored to the stack area 3d. The same applies to the automatic variable B and the automatic variable C. After the automatic variables A to C are restored to the stack area 3d of the memory 3, the area where the automatic variables A to C are stored (the part of the global area 3b) is released.

次に、本実施形態のコルーチン関数の処理方法について説明する。なお、以下の処理は、マイコン2によって行われる。 Next, a processing method of the coroutine function of the present embodiment will be described. The following processing is performed by the microcomputer 2.

まず、図9、図11および図12に示すように、ステップS1(図10のco_begin)において、コルーチン関数が呼び出される。 First, as shown in FIGS. 9, 11 and 12, the coroutine function is called in step S1 (co_begin in FIG. 10).

次に、ステップS2(図10のdefine_frame)において、コルーチン関数が呼び出された後、メモリ3のグローバル領域3bに、メモリ3のスタック領域3dにおける自動変数のアドレスリストALを保存するための領域を確保する。そして、コルーチン関数を呼び出した後に、アドレスリストALをこの領域に作成する。 Next, in step S2 (define_frame in FIG. 10), after the coroutine function is called, an area for storing the address list AL of the automatic variable in the stack area 3d of the memory 3 is secured in the global area 3b of the memory 3. do. Then, after calling the coroutine function, the address list AL is created in this area.

次に、ステップS3(図10のSwitch)において、Switch文によって、コルーチン関数の処理の中断位置が判定される。 Next, in step S3 (Switch in FIG. 10), the switch statement determines the interruption position of the processing of the coroutine function.

ステップS3において、初めてコルーチン関数が実行される(図10のcase0)と判定された場合、ステップS4において、図10のcase()節の処理が実行される。つまり、「hello world!!」が図示しないディスプレイに表示される。 When it is determined in step S3 that the coroutine function is executed for the first time (case 0 in FIG. 10), the process in the case () clause in FIG. 10 is executed in step S4. That is, "hello world !!" is displayed on a display (not shown).

次に、図10(コルーチン関数の記述例)に示すように、「co_yield()」によって、コルーチン関数の処理の中断が指令される。具体的には、ステップS5(図10のsave_value)において、コルーチン関数のためのスタック領域3dに保存された自動変数がグローバル領域3bの退避領域3eに退避される。詳細には、メモリ3のグローバル領域3bにコルーチン関数の情報(自動変数、コルーチン関数のポインタ情報、コルーチン関数の中断位置、引数、および、戻り値)を退避させる退避領域3eを確保した後、スタック領域3dの自動変数がグローバル領域3bの退避領域3eに退避される。 Next, as shown in FIG. 10 (a description example of the coroutine function), "co_yeld ()" commands the interruption of the processing of the coroutine function. Specifically, in step S5 (save_value in FIG. 10), the automatic variables stored in the stack area 3d for the coroutine function are saved in the save area 3e of the global area 3b. Specifically, after securing the save area 3e for saving the coroutine function information (automatic variable, coroutine function pointer information, coroutine function interruption position, argument, and return value) in the global area 3b of the memory 3, the stack. The automatic variables in the area 3d are saved in the save area 3e in the global area 3b.

次に、ステップS6(図10の_state=_LINE_)において、中断位置(コルーチン関数が中断した位置)が、メモリ3の退避領域3eに退避(保存)される。 Next, in step S6 (_state = _LINE_ in FIG. 10), the interruption position (the position where the coroutine function is interrupted) is saved (saved) in the save area 3e of the memory 3.

次に、ステップS7(図10のreturn)において、コルーチン関数が中断(終了)される。 Next, in step S7 (return in FIG. 10), the coroutine function is interrupted (finished).

ステップS3において、コルーチン関数が再開(1回目の再開)されたと判定された場合(図10のcase_LINE_)、ステップS8において、メモリ3のグローバル領域3bに退避されていた自動変数が、スタック領域3dに復元される(図10のload_value())。その後、メモリ3のグローバル領域3bにおいて、自動変数が保存されていた領域が解放される。 When it is determined in step S3 that the coroutine function has been restarted (first restart) (case_LINE_ in FIG. 10), in step S8, the automatic variable saved in the global area 3b of the memory 3 is moved to the stack area 3d. It is restored (load_varie () in FIG. 10). After that, in the global area 3b of the memory 3, the area where the automatic variable is stored is released.

次に、ステップS9において、図10のcase_LINE_節の処理が実行される。つまり、「hi world!」が図示しないディスプレイに表示される。 Next, in step S9, the process of the case_LINE_ clause of FIG. 10 is executed. That is, "hi world!" Is displayed on a display (not shown).

次に、図10に示すように、「co_yield()」によって、コルーチン関数の処理の中断が指令される。具体的には、ステップS10(図10のsave_value)において、コルーチン関数のためのスタック領域3dに保存された自動変数がグローバル領域3bの退避領域3eに退避される。詳細には、メモリ3のグローバル領域3bにコルーチン関数の情報(自動変数、コルーチン関数のポインタ情報、コルーチン関数の中断位置、引数、および、戻り値)を退避させる退避領域3eを確保した後、スタック領域3dの自動変数がグローバル領域3bの退避領域3eに退避される。 Next, as shown in FIG. 10, "co_yield ()" commands the interruption of the processing of the coroutine function. Specifically, in step S10 (save_value in FIG. 10), the automatic variables stored in the stack area 3d for the coroutine function are saved in the save area 3e of the global area 3b. Specifically, after securing the save area 3e for saving the coroutine function information (automatic variable, coroutine function pointer information, coroutine function interruption position, argument, and return value) in the global area 3b of the memory 3, the stack. The automatic variables in the area 3d are saved in the save area 3e in the global area 3b.

次に、ステップS11(図10の_state=_LINE_)において、中断位置(コルーチン関数が中断した位置)が、メモリ3の退避領域3eに退避される。 Next, in step S11 (_state = _LINE_ in FIG. 10), the interruption position (the position where the coroutine function is interrupted) is saved in the save area 3e of the memory 3.

次に、ステップS12(図10のreturn)において、コルーチン関数が中断(終了)される。 Next, in step S12 (return in FIG. 10), the coroutine function is interrupted (finished).

ステップS3において、コルーチン関数が再開(2回目の再開)されたと判定された場合(図10のcase_LINE_)、ステップS13において、メモリ3のグローバル領域3bに退避されていた自動変数が、スタック領域3dに復元される(図10のload_value())。その後、メモリ3のグローバル領域3bにおいて、自動変数が保存されていた領域が解放される。 When it is determined in step S3 that the coroutine function has been restarted (second restart) (case_LINE_ in FIG. 10), in step S13, the automatic variable saved in the global area 3b of the memory 3 is moved to the stack area 3d. It is restored (load_varie () in FIG. 10). After that, in the global area 3b of the memory 3, the area where the automatic variable is stored is released.

次に、ステップS14において、図10のcase_LINE_節の処理が実行される。つまり、「:)」が図示しないディスプレイに表示される。 Next, in step S14, the process of the case_LINE_ clause of FIG. 10 is executed. That is, ":)" is displayed on a display (not shown).

次に、図10に示すように、「co_end」によって、コルーチン関数の処理の終了が指令される。具体的には、ステップS15(図10の_state=_LINE_)において、中断位置(コルーチン関数が終了した位置)が、メモリ3の退避領域3eに退避される。 Next, as shown in FIG. 10, "co_end" commands the end of the processing of the coroutine function. Specifically, in step S15 (_state = _LINE_ in FIG. 10), the interruption position (the position where the coroutine function ends) is saved in the save area 3e of the memory 3.

次に、ステップS16(図10のreturn)において、コルーチン関数が終了される。また、自動変数が保存されていた領域(グローバル領域3bの部分)が解放される。 Next, in step S16 (return in FIG. 10), the coroutine function is terminated. In addition, the area where the automatic variables are stored (the part of the global area 3b) is released.

なお、ステップS16におけるコルーチン関数の終了後、ステップS3において、コルーチン関数が再開されたと判定された場合、ステップS16において、コルーチン関数が終了した位置がメモリ3の退避領域3eに退避されているため、コルーチン関数の処理が実行されずにコルーチン関数が終了する。 If it is determined in step S3 that the coroutine function has been restarted after the end of the coroutine function in step S16, the position where the coroutine function has ended is saved in the save area 3e of the memory 3 in step S16. The coroutine function ends without executing the processing of the coroutine function.

(複数のコルーチン関数)
次に、図13および図14を参照して、複数のコルーチン関数を実行する場合の動作について説明する。以下では、コルーチン関数1およびコルーチン関数2が実行される場合について説明する。
(Multiple coroutine functions)
Next, the operation when a plurality of coroutine functions are executed will be described with reference to FIGS. 13 and 14. The case where the coroutine function 1 and the coroutine function 2 are executed will be described below.

まず、コルーチン関数1が呼び出される(ステップS21)。そして、コルーチン関数1が呼び出された後、メモリ3のグローバル領域3bに、アドレスリストALを保存するための領域を確保するとともに、アドレスリストAL(Co情報1)をこの領域に作成する。 First, the coroutine function 1 is called (step S21). Then, after the coroutine function 1 is called, an area for storing the address list AL is secured in the global area 3b of the memory 3, and the address list AL (Co information 1) is created in this area.

次に、コルーチン関数1の処理が実行される(ステップS22)。コルーチン関数1の処理の実行中において、自動変数1-1は、スタック領域3dに保存されている。なお、図14では、グローバル領域3b(退避領域3e)に自動変数1-1が保存され、スタック領域3dに自動変数1-1が復元される図が示されているが、初回のコルーチン関数1の処理の実行時には、自動変数1-1の復元および自動変数1-1が保存されていた領域の解放は、不要である。 Next, the process of the coroutine function 1 is executed (step S22). During the execution of the processing of the coroutine function 1, the automatic variable 1-1 is stored in the stack area 3d. Although FIG. 14 shows a diagram in which the automatic variable 1-1 is stored in the global area 3b (save area 3e) and the automatic variable 1-1 is restored in the stack area 3d, the first coroutine function 1 is shown. At the time of executing the process of, it is not necessary to restore the automatic variable 1-1 and release the area in which the automatic variable 1-1 is stored.

次に、コルーチン関数1の処理が中断(ステップS23)される。これにより、スタック領域3dに保存された自動変数1-1が、グローバル領域3bの退避領域3eに退避される。また、中断位置(コルーチン関数が中断した位置)が、メモリ3の退避領域3e(Co情報1)に退避される。 Next, the processing of the coroutine function 1 is interrupted (step S23). As a result, the automatic variable 1-1 stored in the stack area 3d is saved in the save area 3e of the global area 3b. Further, the interrupted position (the position where the coroutine function is interrupted) is saved in the save area 3e (Co information 1) of the memory 3.

次に、コルーチン関数2が呼び出される(ステップS24)。そして、コルーチン関数2が呼び出された後、メモリ3のグローバル領域3bに、アドレスリストALを保存するための領域を確保するとともに、アドレスリストAL(Co情報2)をこの領域に作成する。 Next, the coroutine function 2 is called (step S24). Then, after the coroutine function 2 is called, an area for storing the address list AL is secured in the global area 3b of the memory 3, and the address list AL (Co information 2) is created in this area.

次に、コルーチン関数2の処理が実行される(ステップS25)。コルーチン関数2の処理の実行中において、自動変数2-1は、スタック領域3dに保存されている。なお、図14では、グローバル領域3b(退避領域3e)に自動変数2-1が保存され、スタック領域3dに自動変数2-1が復元される図が示されているが、初回のコルーチン関数2の処理の実行時には、自動変数2-1の復元および自動変数2-1が保存されていた領域の解放は、不要である。 Next, the process of the coroutine function 2 is executed (step S25). During the execution of the processing of the coroutine function 2, the automatic variable 2-1 is stored in the stack area 3d. Although FIG. 14 shows a diagram in which the automatic variable 2-1 is stored in the global area 3b (save area 3e) and the automatic variable 2-1 is restored in the stack area 3d, the first coroutine function 2 is shown. At the time of executing the process of, it is not necessary to restore the automatic variable 2-1 and release the area in which the automatic variable 2-1 is stored.

次に、コルーチン関数2の処理が中断(ステップS26)される。これにより、スタック領域3dに保存された自動変数2-1が、グローバル領域3bの退避領域3eに退避される。また、中断位置(コルーチン関数が中断した位置)が、メモリ3の退避領域3e(Co情報2)に退避される。 Next, the processing of the coroutine function 2 is interrupted (step S26). As a result, the automatic variable 2-1 stored in the stack area 3d is saved in the save area 3e of the global area 3b. Further, the interrupted position (the position where the coroutine function is interrupted) is saved in the save area 3e (Co information 2) of the memory 3.

次に、コルーチン関数1が再び呼び出されて、コルーチン関数1の処理が再開される(ステップS27)。これにより、メモリ3のグローバル領域3bに退避されていた自動変数1-1が、スタック領域3dに復元される。その後、メモリ3のグローバル領域3bにおいて、自動変数1-1が保存されていた領域が解放される。なお、その後の、コルーチン関数1の中断の処理は、上記と同様である。 Next, the coroutine function 1 is called again, and the processing of the coroutine function 1 is restarted (step S27). As a result, the automatic variable 1-1 saved in the global area 3b of the memory 3 is restored to the stack area 3d. After that, in the global area 3b of the memory 3, the area in which the automatic variable 1-1 is stored is released. The subsequent processing of interruption of the coroutine function 1 is the same as described above.

次に、コルーチン関数2が再び呼び出されて、コルーチン関数2の処理が再開される(ステップS28)。これにより、メモリ3のグローバル領域3bに退避されていた自動変数2-1が、スタック領域3dに復元される。その後、メモリ3のグローバル領域3bにおいて、自動変数2-1が保存されていた領域が解放される。なお、その後の、コルーチン関数2の中断の処理は、上記と同様である。 Next, the coroutine function 2 is called again, and the processing of the coroutine function 2 is restarted (step S28). As a result, the automatic variable 2-1 saved in the global area 3b of the memory 3 is restored to the stack area 3d. After that, in the global area 3b of the memory 3, the area in which the automatic variable 2-1 is stored is released. The subsequent processing of interruption of the coroutine function 2 is the same as described above.

(サブコルーチン関数)
次に、図15および図16を参照して、コルーチン関数からサブコルーチン関数を呼び出す場合の動作について説明する。以下では、コルーチン関数1およびサブコルーチン関数であるコルーチン関数1-1が実行される場合について説明する。
(Subcoroutine function)
Next, the operation when the subcoroutine function is called from the coroutine function will be described with reference to FIGS. 15 and 16. Hereinafter, a case where the coroutine function 1 and the coroutine function 1-1, which is a subcoroutine function, is executed will be described.

まず、コルーチン関数1が呼び出される(ステップS31)。そして、コルーチン関数1が呼び出された後、メモリ3のグローバル領域3bに、アドレスリストALを保存するための領域を確保するとともに、アドレスリストAL(Co情報1)をこの領域に作成する。 First, the coroutine function 1 is called (step S31). Then, after the coroutine function 1 is called, an area for storing the address list AL is secured in the global area 3b of the memory 3, and the address list AL (Co information 1) is created in this area.

次に、コルーチン関数1-1が呼び出される(ステップS32)される。 Next, the coroutine function 1-1 is called (step S32).

次に、コルーチン関数1-1が起動され(ステップS33)、メモリ3のグローバル領域3bに、アドレスリストALを保存するための領域を確保するとともに、アドレスリストAL(Co情報1-1)をこの領域に作成する。 Next, the coroutine function 1-1 is activated (step S33), an area for storing the address list AL is secured in the global area 3b of the memory 3, and the address list AL (Co information 1-1) is stored. Create in the area.

次に、コルーチン関数1-1の処理が実行される(ステップS34)。コルーチン関数1-1の処理の実行中において、自動変数1-1-1は、スタック領域3dに保存されている。なお、図16では、退避領域3eに自動変数1-1-1が保存され、スタック領域3dに自動変数1-1-1が復元される図が示されているが、初回のコルーチン関数1-1-1の処理の実行時には、自動変数1-1-1の復元および自動変数1-1-1が保存されていた領域の解放は、不要である。 Next, the process of the coroutine function 1-1 is executed (step S34). During the execution of the processing of the coroutine function 1-1, the automatic variable 1-1-1 is stored in the stack area 3d. Although FIG. 16 shows a diagram in which the automatic variable 1-1-1 is stored in the save area 3e and the automatic variable 1-1-1 is restored in the stack area 3d, the first coroutine function 1- When executing the process 1-1, it is not necessary to restore the automatic variable 1-1-1 and release the area in which the automatic variable 1-1-1 is stored.

次に、コルーチン関数1-1の処理が中断(ステップS35)される。これにより、スタック領域3dに保存された自動変数1-1が、グローバル領域3bの退避領域3eに退避される。また、中断位置(コルーチン関数が中断した位置)が、メモリ3の退避領域3e(Co情報1-1)に退避される。 Next, the processing of the coroutine function 1-1 is interrupted (step S35). As a result, the automatic variable 1-1 stored in the stack area 3d is saved in the save area 3e of the global area 3b. Further, the interrupted position (the position where the coroutine function is interrupted) is saved in the save area 3e (Co information 1-1) of the memory 3.

次に、コルーチン関数1の処理が再開(ステップS36)される。具体的には、グローバル領域3bの退避領域3eに保存されている自動変数1-1をスタック領域3dに復元(保存)し、スタック領域3dに保存されていた自動変数1-1を用いて、処理を実行する。また、自動変数1-1が保存されていた、退避領域3eを解放する。そして、コルーチン関数1の処理の中断時には、スタック領域3dに保存された自動変数1-1が、グローバル領域3bの退避領域3eに退避される。また、中断位置(コルーチン関数が中断した位置)が、メモリ3の退避領域3e(Co情報1)に退避される。 Next, the processing of the coroutine function 1 is restarted (step S36). Specifically, the automatic variable 1-1 stored in the save area 3e of the global area 3b is restored (saved) in the stack area 3d, and the automatic variable 1-1 stored in the stack area 3d is used. Execute the process. In addition, the save area 3e in which the automatic variable 1-1 is stored is released. Then, when the processing of the coroutine function 1 is interrupted, the automatic variable 1-1 stored in the stack area 3d is saved in the save area 3e of the global area 3b. Further, the interrupted position (the position where the coroutine function is interrupted) is saved in the save area 3e (Co information 1) of the memory 3.

[本実施形態の効果]
本実施形態では、以下のような効果を得ることができる。
[Effect of this embodiment]
In this embodiment, the following effects can be obtained.

本実施形態では、上記のように、プログラム4は、コルーチン関数が呼び出された後、コルーチン関数の処理が中断される前に、メモリ3のスタック領域3dに保存されているコルーチン関数の情報に含まれる自動変数を、退避領域3eに退避させるステップと、中断された処理を再開する前に、退避領域3eに退避された自動変数を、メモリ3のスタック領域3dに復元するステップと、を含む。これにより、メモリ3のスタック領域3dに保存されている自動変数がメモリ3のグローバル領域3bの退避領域3eに退避されるので、中断した処理を再開するためにコルーチン関数が呼び出された際、メモリ3のスタック領域3dが初期化されるかまたはスタック領域3dに不定値が保存されていても、メモリ3のグローバル領域3bの退避領域3eに退避された自動変数がメモリ3のスタック領域3dに復元される。その結果、コルーチン関数の中断した処理の再開時に、正確な自動変数に基づいて、処理を再開することができる。これにより、コルーチン関数を実行する際に、中断した処理を正常に再開することができる。 In the present embodiment, as described above, the program 4 is included in the information of the coroutine function stored in the stack area 3d of the memory 3 after the coroutine function is called and before the processing of the coroutine function is interrupted. It includes a step of saving the automatic variables saved in the save area 3e and a step of restoring the automatic variables saved in the save area 3e to the stack area 3d of the memory 3 before restarting the interrupted processing. As a result, the automatic variables stored in the stack area 3d of the memory 3 are saved in the save area 3e of the global area 3b of the memory 3. Therefore, when the collout function is called to restart the interrupted processing, the memory Even if the stack area 3d of 3 is initialized or an indefinite value is stored in the stack area 3d, the automatic variables saved in the save area 3e of the global area 3b of the memory 3 are restored to the stack area 3d of the memory 3. Will be done. As a result, when the interrupted processing of the coroutine function is resumed, the processing can be resumed based on the exact automatic variable. As a result, when the coroutine function is executed, the interrupted processing can be resumed normally.

また、本実施形態では、上記のように、コルーチン関数の情報は、コルーチン関数のポインタ情報、コルーチン関数の中断位置、引数、および、戻り値をさらに含む。これにより、中断した処理の再開に必要なコルーチン関数のポインタ情報、コルーチン関数の中断位置、自動変数、引数、および、戻り値が、メモリ3のグローバル領域3bの退避領域3eに退避されるので、中断した処理を正常かつ確実に再開することができる。 Further, in the present embodiment, as described above, the information of the coroutine function further includes the pointer information of the coroutine function, the interruption position of the coroutine function, the argument, and the return value. As a result, the pointer information of the coroutine function required for resuming the interrupted processing, the interruption position of the coroutine function, the automatic variable, the argument, and the return value are saved in the save area 3e of the global area 3b of the memory 3. The interrupted processing can be resumed normally and reliably.

また、本実施形態では、上記のように、自動変数、引数、および、戻り値の各々の情報は、メモリ3上の領域情報またはポインタ情報である。ここで、メモリ3のグローバル領域3bは、メモリ3のスタック領域3dと異なり自由に書き込みが可能であるので、自動変数、引数、および、戻り値の各々の情報を、メモリ3上の領域情報またはポインタ情報のいずれでも書き込むことができる。 Further, in the present embodiment, as described above, the information of each of the automatic variable, the argument, and the return value is the area information or the pointer information on the memory 3. Here, since the global area 3b of the memory 3 can be freely written unlike the stack area 3d of the memory 3, each information of the automatic variable, the argument, and the return value can be used as the area information on the memory 3 or the area information on the memory 3. Any of the pointer information can be written.

また、本実施形態では、上記のように、退避領域3eを確保するステップは、コルーチン関数の情報の大きさに応じて、退避領域3eを確保するステップを含む。ここで、コルーチン関数の情報を、コルーチン関数を呼び出す呼び出し元の関数のスタック領域3dに保存する場合、コルーチン関数の情報のための領域が固定サイズで確保される場合がある。この場合、コルーチン関数の構成(引数、自動変数および戻り値のそれぞれの個数)によっては、コルーチン関数の情報のために適切に領域を確保できない(過不足する)場合がある。そこで、上記のように構成することによって、メモリ3のグローバル領域3bでは、退避領域3eを可変長により確保することができる(グローバル領域3bは、スタック領域3dに比べて領域のサイズの指定が容易である)ので、退避領域3eを適切に確保することができる。 Further, in the present embodiment, as described above, the step of securing the save area 3e includes a step of securing the save area 3e according to the size of the information of the coroutine function. Here, when the information of the coroutine function is stored in the stack area 3d of the calling function that calls the coroutine function, the area for the information of the coroutine function may be secured in a fixed size. In this case, depending on the configuration of the coroutine function (the number of each of the arguments, automatic variables, and return values), it may not be possible to properly secure an area (excess or deficiency) for the information of the coroutine function. Therefore, by configuring as described above, the save area 3e can be secured by the variable length in the global area 3b of the memory 3 (in the global area 3b, it is easier to specify the size of the area as compared with the stack area 3d. Therefore, the evacuation area 3e can be appropriately secured.

また、本実施形態では、上記のように、プログラム4は、自動変数をメモリ3のスタック領域3dに復元した後、自動変数が保存されていた領域を解放するステップをさらに含む。これにより、自動変数をメモリ3のスタック領域3dに復元した後にメモリ3の自動変数が保存されていた領域が解放されるので、コルーチン関数が複数設けられる場合において、解放後のメモリ3のグローバル領域3bを他のコルーチン関数の自動変数などを保存する領域として利用することができる。つまり、コルーチン関数の数が比較的多い場合でも、コルーチン関数を適切に実行することができる。 Further, in the present embodiment, as described above, the program 4 further includes a step of restoring the area in which the automatic variable is stored after restoring the automatic variable in the stack area 3d of the memory 3. As a result, the area where the automatic variables of the memory 3 are stored is released after the automatic variables are restored to the stack area 3d of the memory 3. Therefore, when a plurality of coroutine functions are provided, the global area of the memory 3 after the release is released. 3b can be used as an area for storing automatic variables of other coroutine functions. That is, even if the number of coroutine functions is relatively large, the coroutine functions can be executed appropriately.

また、本実施形態では、上記のように、プログラム4は、コルーチン関数を呼び出した後に、メモリ3のスタック領域3dにおける自動変数のアドレスリストALをメモリ3のグローバル領域3bに作成するステップをさらに含む。そして、自動変数を退避領域3eに退避させるステップは、作成されたアドレスリストALに基づいて、自動変数を退避領域3eに退避させるステップを含む。また、自動変数をスタック領域3dに復元するステップは、作成されたアドレスリストALに基づいて、自動変数を、メモリ3のスタック領域3dに復元するステップを含む。これにより、アドレスリストALに基づいて自動変数の退避および復元が行われるので、自動変数を間違えることなく退避領域3eに退避させるとともにスタック領域3dに復元することができる。 Further, in the present embodiment, as described above, the program 4 further includes a step of creating an address list AL of automatic variables in the stack area 3d of the memory 3 in the global area 3b of the memory 3 after calling the coroutine function. .. The step of saving the automatic variable to the save area 3e includes a step of saving the automatic variable to the save area 3e based on the created address list AL. Further, the step of restoring the automatic variable to the stack area 3d includes a step of restoring the automatic variable to the stack area 3d of the memory 3 based on the created address list AL. As a result, the automatic variables are saved and restored based on the address list AL, so that the automatic variables can be saved in the save area 3e and restored in the stack area 3d without making a mistake.

また、本実施形態では、上記のように、プログラム4は、自動変数を退避領域3eに退避させた後、自動変数のアドレスリストALが保存されていた領域を解放するステップをさらに含む。これにより、自動変数を退避領域3eに退避させた後、自動変数のアドレスリストALが保存されていた領域が解放されるので、コルーチン関数が複数設けられる場合において、解放後のメモリ3のグローバル領域3bを他のコルーチン関数のアドレスリストALなどを保存する領域として利用することができる。つまり、コルーチン関数の数が比較的多い場合でも、コルーチン関数を適切に実行することができる。 Further, in the present embodiment, as described above, the program 4 further includes a step of saving the automatic variable in the save area 3e and then releasing the area in which the address list AL of the automatic variable is stored. As a result, after the automatic variable is saved in the save area 3e, the area in which the address list AL of the automatic variable is saved is released. Therefore, when a plurality of coroutine functions are provided, the global area of the memory 3 after release is released. 3b can be used as an area for storing the address list AL of other coroutine functions. That is, even if the number of coroutine functions is relatively large, the coroutine functions can be executed appropriately.

[変形例]
なお、今回開示された実施形態は、すべての点で例示であって制限的なものではないと考えられるべきである。本発明の範囲は、上記した実施形態の説明ではなく特許請求の範囲によって示され、さらに特許請求の範囲と均等の意味および範囲内でのすべての変更(変形例)が含まれる。
[Modification example]
It should be noted that the embodiments disclosed this time are exemplary in all respects and are not considered to be restrictive. The scope of the present invention is shown by the scope of claims rather than the description of the above-described embodiment, and further includes all modifications (modifications) within the meaning and scope equivalent to the scope of claims.

たとえば、上記実施形態では、コルーチン関数が、C言語によって疑似的に実装されている例を示したが、本発明はこれに限られない。たとえば、コルーチン関数をC言語以外の言語によって実装してもよい。 For example, in the above embodiment, an example in which a coroutine function is pseudo-implemented by the C language is shown, but the present invention is not limited to this. For example, the coroutine function may be implemented in a language other than C language.

また、上記実施形態では、コルーチン関数が、C言語のSwitch-case文によって疑似的に実装されている例を示したが、本発明はこれに限られない。たとえば、コルーチン関数をC言語のSwitch-case文以外の文(命令文)を用いて実装してもよい。 Further, in the above embodiment, an example in which the coroutine function is pseudo-implemented by the Switch-case statement in C language is shown, but the present invention is not limited to this. For example, the coroutine function may be implemented by using a statement (instruction statement) other than the Switch-case statement in C language.

また、上記実施形態では、コルーチン関数の情報が、自動変数、コルーチン関数のポインタ情報、コルーチン関数の中断位置、引数、および、戻り値を含む例を示したが、本発明はこれに限られない。本発明では、コルーチン関数の情報として、上記の情報以外の情報を含んでいてもよい。 Further, in the above embodiment, an example is shown in which the information of the coroutine function includes an automatic variable, pointer information of the coroutine function, a break position of the coroutine function, an argument, and a return value, but the present invention is not limited to this. .. In the present invention, the information of the coroutine function may include information other than the above information.

また、上記実施形態の図12などでは、メモリ3のグローバル領域3b上において、自動変数が、Co情報が保存される領域以外の領域に保存される例を示したが、本発明はこれに限られない。たとえば、自動変数を、Co情報内の自動変数のための領域に保存してもよい。 Further, in FIG. 12 and the like of the above embodiment, an example is shown in which the automatic variable is stored in an area other than the area in which the Co information is stored on the global area 3b of the memory 3, but the present invention is limited to this. I can't. For example, the automatic variable may be stored in the area for the automatic variable in the Co information.

2 マイコン(制御部)
3 メモリ
3b グローバル領域
3d スタック領域
3e 退避領域
4 プログラム
100 制御装置
AL アドレスリスト
2 Microcomputer (control unit)
3 Memory 3b Global area 3d Stack area 3e Evacuation area 4 Program 100 Controller AL address list

Claims (8)

処理を中断させた後、中断させた処理の続きから処理を再開させるコルーチン関数を実行する制御装置であって、
前記コルーチン関数を含むプログラムが保存されるメモリと、
前記プログラムを実行する制御部、とを備え、
前記プログラムは、
前記コルーチン関数が呼び出された後、前記メモリのグローバル領域に前記コルーチン関数の情報を退避させる退避領域を確保するステップと、
前記コルーチン関数が呼び出された後、前記コルーチン関数の処理が中断される前に、前記メモリのスタック領域に保存されている前記コルーチン関数の情報に含まれる自動変数を、前記退避領域に退避させるステップと、
前記中断された処理を再開する前に、前記退避領域に退避された前記自動変数を、前記メモリの前記スタック領域に復元するステップと、を含む、制御装置。
A control device that executes a coroutine function that suspends processing and then resumes processing from the continuation of the interrupted processing.
The memory in which the program containing the coroutine function is stored, and
It is equipped with a control unit that executes the program.
The program
After the coroutine function is called, a step of securing a save area for saving the information of the coroutine function in the global area of the memory, and a step of securing the save area.
A step of saving an automatic variable included in the information of the coroutine function stored in the stack area of the memory to the save area after the coroutine function is called and before the processing of the coroutine function is interrupted. When,
A control device including a step of restoring the automatic variable saved in the save area to the stack area of the memory before restarting the interrupted process.
前記コルーチン関数の情報は、前記コルーチン関数のポインタ情報、前記コルーチン関数の中断位置、引数、および、戻り値をさらに含む、請求項1に記載の制御装置。 The control device according to claim 1, wherein the information of the coroutine function further includes pointer information of the coroutine function, an interruption position of the coroutine function, an argument, and a return value. 前記自動変数、前記引数、および、前記戻り値の各々の情報は、前記メモリ上の領域情報またはポインタ情報である、請求項2に記載の制御装置。 The control device according to claim 2, wherein the information of each of the automatic variable, the argument, and the return value is area information or pointer information on the memory. 前記退避領域を確保するステップは、前記コルーチン関数の情報の大きさに応じて、前記退避領域を確保するステップを含む、請求項1~3のいずれか1項に記載の制御装置。 The control device according to any one of claims 1 to 3, wherein the step of securing the save area includes a step of securing the save area according to the magnitude of information of the coroutine function. 前記プログラムは、前記自動変数を前記メモリの前記スタック領域に復元した後、前記自動変数が保存されていた領域を解放するステップをさらに含む、請求項1~4のいずれか1項に記載の制御装置。 The control according to any one of claims 1 to 4, further comprising a step of restoring the automatic variable to the stack area of the memory and then releasing the area in which the automatic variable is stored. Device. 前記プログラムは、前記コルーチン関数を呼び出した後に、前記メモリの前記スタック領域における前記自動変数のアドレスリストを前記メモリの前記グローバル領域に作成するステップをさらに含み、
前記自動変数を前記退避領域に退避させるステップは、作成された前記アドレスリストに基づいて、前記自動変数を前記退避領域に退避させるステップを含み、
前記自動変数を前記スタック領域に復元するステップは、作成された前記アドレスリストに基づいて、前記自動変数を、前記メモリの前記スタック領域に復元するステップを含む、請求項1~5のいずれか1項に記載の制御装置。
The program further comprises, after calling the coroutine function, creating an address list of the automatic variables in the stack area of the memory in the global area of the memory.
The step of saving the automatic variable to the save area includes a step of saving the automatic variable to the save area based on the created address list.
One of claims 1 to 5, wherein the step of restoring the automatic variable to the stack area includes a step of restoring the automatic variable to the stack area of the memory based on the created address list. The control device described in the section.
前記プログラムは、前記自動変数を前記退避領域に退避させた後、前記自動変数の前記アドレスリストが保存されていた領域を解放するステップをさらに含む、請求項6に記載の制御装置。 The control device according to claim 6, wherein the program further includes a step of saving the automatic variable in the save area and then releasing the area in which the address list of the automatic variable is stored. 処理を中断させた後、中断させた処理の続きから処理を再開させるコルーチン関数を実行する処理方法であって、
前記コルーチン関数を呼び出すステップと、
前記コルーチン関数が呼び出された後、メモリのグローバル領域に前記コルーチン関数の情報を退避させる退避領域を確保するステップと、
前記コルーチン関数が呼び出された後、前記コルーチン関数の処理が中断される前に、前記メモリのスタック領域に保存されている前記コルーチン関数の情報に含まれる自動変数を、前記退避領域に退避させるステップと、
前記中断された処理を再開する前に、前記退避領域に退避された前記自動変数を、前記メモリの前記スタック領域に復元するステップと、を含む、処理方法。



It is a processing method that executes a coroutine function that resumes processing from the continuation of the interrupted processing after suspending the processing.
The step of calling the coroutine function and
After the coroutine function is called, a step of securing a save area for saving the information of the coroutine function in the global area of the memory, and
A step of saving an automatic variable included in the information of the coroutine function stored in the stack area of the memory to the save area after the coroutine function is called and before the processing of the coroutine function is interrupted. When,
A processing method comprising a step of restoring the automatic variable saved in the save area to the stack area of the memory before restarting the interrupted process.



JP2020194423A 2020-11-24 2020-11-24 Control device and processing method Pending JP2022083141A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2020194423A JP2022083141A (en) 2020-11-24 2020-11-24 Control device and processing method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2020194423A JP2022083141A (en) 2020-11-24 2020-11-24 Control device and processing method

Publications (1)

Publication Number Publication Date
JP2022083141A true JP2022083141A (en) 2022-06-03

Family

ID=81811727

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2020194423A Pending JP2022083141A (en) 2020-11-24 2020-11-24 Control device and processing method

Country Status (1)

Country Link
JP (1) JP2022083141A (en)

Similar Documents

Publication Publication Date Title
US8499289B2 (en) Method, device and system for realizing kernel online patching
GB2478733A (en) Stack management with multiple levels of exception
JP2005284491A (en) Starting time shortening system for computer
US7434222B2 (en) Task context switching RTOS
CN103617060A (en) Method for accelerating starting procedure of embedded software by using super state storage
JP2022083141A (en) Control device and processing method
US5953529A (en) Data processor with a debug device and a stack area control unit and corresponding data processing method
JP2001256062A (en) Interruption processing method and operation processor using the same
GB2452735A (en) Loading and executing programs in parallel during boot loading
JP2004272844A (en) Method for controlling interruption
EP1227401B1 (en) Task management device, method and program therefor
JPS59114602A (en) Programmable controller
CN109932997A (en) A kind of programmable logic controller (PLC) core system
CN112905235B (en) MCU program execution method and chip
JP2005284925A (en) Computer system and program update method
KR100280404B1 (en) How to Support Multiple Interrupt Service Routines in DSP
CN114691181A (en) Hot upgrading method, device, equipment, distributed system and storage medium
JPH1021067A (en) Dynamic correction method for program
JPH02270032A (en) Loading system
JPH07134656A (en) Interruption control method and multi-task system for realizing the same
JPH11316691A (en) Execution method for operating system and information processor using the method
JPH03110635A (en) Process control method for operating system
JP2000315162A (en) Control block processor and computer readable recording medium recording control block processing program
JPH0883188A (en) Multitask processing computer
JPS6356728A (en) Execution system for program correction

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20231016