JP2022083141A - Control device and processing method - Google Patents
Control device and processing method Download PDFInfo
- 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
Links
Images
Abstract
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
ここで、従来、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.
しかしながら、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.
以下、本発明を具体化した実施形態を図面に基づいて説明する。 Hereinafter, embodiments embodying the present invention will be described with reference to the drawings.
図1~図16を参照して、本実施形態による制御装置100の構成について説明する。なお、制御装置100は、たとえば、組み込み機器に用いられる制御装置100である。
The configuration of the
図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
図2に示すように、C言語によって取り扱われるメモリ3は、テキスト領域3aと、グローバル領域3b(静的領域)と、ヒープ領域3cと、スタック領域3dとを含む。そして、テキスト領域3aには、機械語に翻訳されたプログラム4が格納される。グローバル領域3bには、グローバル変数などの静的変数が格納される。ヒープ領域3cは、メモリ3の管理のために使用される。スタック領域3dは、C言語の自動変数(ローカル変数など)が格納される。また、ヒープ領域3cおよびスタック領域3dのサイズは、プログラム4中に変化する。
As shown in FIG. 2, the
本実施形態では、制御装置100は、処理を中断させた後、中断させた処理の続きから処理を再開させる、C言語により実装された疑似的なコルーチン関数を実行するように構成されている。
In the present embodiment, the
図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
(プログラムの構成)
次に、本実施形態による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
退避領域3eを確保する処理では、退避領域3eの先頭から、ブロック情報が参照され、使用状況フラグが未使用であるブロックが検索される。そして、使用状況フラグが未使用であるブロックが見つかった場合、このブロックの使用状況フラグを使用中にするとともに、割り当てられたメモリ3の領域(ブロック)の先頭のアドレスを返す。また、使用状況フラグが未使用であるブロックが見つからなかった場合、ブロック情報において使用状況フラグが未使用であるブロックが再検索(順次検索)される。
In the process of securing the
また、本実施形態では、コルーチン関数の情報は、自動変数に加えて、コルーチン関数のポインタ情報、コルーチン関数の中断位置、引数、および、戻り値をさらに含む。また、自動変数、引数、および、戻り値の各々の情報は、メモリ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
また、本実施形態では、図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
また、本実施形態では、プログラム4は、コルーチン関数が呼び出された後、コルーチン関数の処理が中断される前に、メモリ3のスタック領域3dに保存されているコルーチン関数の情報に含まれる自動変数を、退避領域3eに退避させるステップを含む。なお、自動変数は、コルーチン関数の情報(以下、Co情報と言う場合がある)の内部の自動変数領域に退避されてもよいし、Co情報とは別個に確保された領域に退避されてもよい。
Further, in the present embodiment, the
また、本実施形態では、プログラム4は、中断された処理を再開する前に、退避領域3eに退避された自動変数を、メモリ3のスタック領域3dに復元するステップを含む。
Further, in the present embodiment, the
図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
次に、コルーチン関数2の実行時には、コルーチン関数2の自動変数2-1および自動変数2-2が、メモリ3のスタック領域3dに保存されている。コルーチン関数2の処理が中断される前に、スタック領域3dに保存されている自動変数2-1および自動変数2-2は、退避領域3eに退避される。
Next, when the
コルーチン関数1の再開時には、スタック領域3dに保存されている自動変数1-1および自動変数1-2が、メモリ3のスタック領域3dに復元される。コルーチン関数2の再開時も、同様である。
When the
また、本実施形態では、プログラム4は、自動変数をメモリ3のスタック領域3dに復元した後、自動変数が保存されていた領域(退避領域3e)を解放するステップをさらに含む。具体的には、図6に示すように、退避領域3eの先頭アドレスから、開放する領域が含まれるブロックのブロック情報を参照して、このブロックの使用状況フラグを未使用にする。
Further, in the present embodiment, the
また、本実施形態では、図8に示すように、プログラム4は、コルーチン関数を呼び出した後に、メモリ3のスタック領域3dにおける自動変数のアドレスリストAL(スタックフレーム定義)を作成するステップをさらに含む。具体的には、メモリ3のグローバル領域3bに、アドレスリストALの情報を保存するために必要な定義領域3fが確保される。そして、退避する自動変数のスタック領域3d上のアドレス値(ポインタ)がアドレスリストAL(スタックフレーム定義)としてグローバル領域3bに保存される。
Further, in the present embodiment, as shown in FIG. 8, the
たとえば、図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
そして、本実施形態では、図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
たとえば、図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
そして、本実施形態では、プログラム4は、自動変数(の値)を、退避領域3eに退避させるステップの後、アドレスリストALが保存されていた領域を解放するステップをさらに含む。
Then, in the present embodiment, the
また、本実施形態では、図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
たとえば、図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
次に、本実施形態のコルーチン関数の処理方法について説明する。なお、以下の処理は、マイコン2によって行われる。
Next, a processing method of the coroutine function of the present embodiment will be described. The following processing is performed by the
まず、図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
次に、ステップ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 (
次に、図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
次に、ステップ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
次に、ステップ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
次に、ステップ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
次に、ステップ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
次に、ステップ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
次に、ステップ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
次に、ステップ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
なお、ステップ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
(複数のコルーチン関数)
次に、図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
まず、コルーチン関数1が呼び出される(ステップS21)。そして、コルーチン関数1が呼び出された後、メモリ3のグローバル領域3bに、アドレスリストALを保存するための領域を確保するとともに、アドレスリストAL(Co情報1)をこの領域に作成する。
First, the
次に、コルーチン関数1の処理が実行される(ステップS22)。コルーチン関数1の処理の実行中において、自動変数1-1は、スタック領域3dに保存されている。なお、図14では、グローバル領域3b(退避領域3e)に自動変数1-1が保存され、スタック領域3dに自動変数1-1が復元される図が示されているが、初回のコルーチン関数1の処理の実行時には、自動変数1-1の復元および自動変数1-1が保存されていた領域の解放は、不要である。
Next, the process of the
次に、コルーチン関数1の処理が中断(ステップS23)される。これにより、スタック領域3dに保存された自動変数1-1が、グローバル領域3bの退避領域3eに退避される。また、中断位置(コルーチン関数が中断した位置)が、メモリ3の退避領域3e(Co情報1)に退避される。
Next, the processing of the
次に、コルーチン関数2が呼び出される(ステップS24)。そして、コルーチン関数2が呼び出された後、メモリ3のグローバル領域3bに、アドレスリストALを保存するための領域を確保するとともに、アドレスリストAL(Co情報2)をこの領域に作成する。
Next, the
次に、コルーチン関数2の処理が実行される(ステップS25)。コルーチン関数2の処理の実行中において、自動変数2-1は、スタック領域3dに保存されている。なお、図14では、グローバル領域3b(退避領域3e)に自動変数2-1が保存され、スタック領域3dに自動変数2-1が復元される図が示されているが、初回のコルーチン関数2の処理の実行時には、自動変数2-1の復元および自動変数2-1が保存されていた領域の解放は、不要である。
Next, the process of the
次に、コルーチン関数2の処理が中断(ステップS26)される。これにより、スタック領域3dに保存された自動変数2-1が、グローバル領域3bの退避領域3eに退避される。また、中断位置(コルーチン関数が中断した位置)が、メモリ3の退避領域3e(Co情報2)に退避される。
Next, the processing of the
次に、コルーチン関数1が再び呼び出されて、コルーチン関数1の処理が再開される(ステップS27)。これにより、メモリ3のグローバル領域3bに退避されていた自動変数1-1が、スタック領域3dに復元される。その後、メモリ3のグローバル領域3bにおいて、自動変数1-1が保存されていた領域が解放される。なお、その後の、コルーチン関数1の中断の処理は、上記と同様である。
Next, the
次に、コルーチン関数2が再び呼び出されて、コルーチン関数2の処理が再開される(ステップS28)。これにより、メモリ3のグローバル領域3bに退避されていた自動変数2-1が、スタック領域3dに復元される。その後、メモリ3のグローバル領域3bにおいて、自動変数2-1が保存されていた領域が解放される。なお、その後の、コルーチン関数2の中断の処理は、上記と同様である。
Next, the
(サブコルーチン関数)
次に、図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
まず、コルーチン関数1が呼び出される(ステップS31)。そして、コルーチン関数1が呼び出された後、メモリ3のグローバル領域3bに、アドレスリストALを保存するための領域を確保するとともに、アドレスリストAL(Co情報1)をこの領域に作成する。
First, the
次に、コルーチン関数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
次に、コルーチン関数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
次に、コルーチン関数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
次に、コルーチン関数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
[本実施形態の効果]
本実施形態では、以下のような効果を得ることができる。
[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
また、本実施形態では、上記のように、コルーチン関数の情報は、コルーチン関数のポインタ情報、コルーチン関数の中断位置、引数、および、戻り値をさらに含む。これにより、中断した処理の再開に必要なコルーチン関数のポインタ情報、コルーチン関数の中断位置、自動変数、引数、および、戻り値が、メモリ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
また、本実施形態では、上記のように、自動変数、引数、および、戻り値の各々の情報は、メモリ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
また、本実施形態では、上記のように、退避領域3eを確保するステップは、コルーチン関数の情報の大きさに応じて、退避領域3eを確保するステップを含む。ここで、コルーチン関数の情報を、コルーチン関数を呼び出す呼び出し元の関数のスタック領域3dに保存する場合、コルーチン関数の情報のための領域が固定サイズで確保される場合がある。この場合、コルーチン関数の構成(引数、自動変数および戻り値のそれぞれの個数)によっては、コルーチン関数の情報のために適切に領域を確保できない(過不足する)場合がある。そこで、上記のように構成することによって、メモリ3のグローバル領域3bでは、退避領域3eを可変長により確保することができる(グローバル領域3bは、スタック領域3dに比べて領域のサイズの指定が容易である)ので、退避領域3eを適切に確保することができる。
Further, in the present embodiment, as described above, the step of securing the
また、本実施形態では、上記のように、プログラム4は、自動変数をメモリ3のスタック領域3dに復元した後、自動変数が保存されていた領域を解放するステップをさらに含む。これにより、自動変数をメモリ3のスタック領域3dに復元した後にメモリ3の自動変数が保存されていた領域が解放されるので、コルーチン関数が複数設けられる場合において、解放後のメモリ3のグローバル領域3bを他のコルーチン関数の自動変数などを保存する領域として利用することができる。つまり、コルーチン関数の数が比較的多い場合でも、コルーチン関数を適切に実行することができる。
Further, in the present embodiment, as described above, the
また、本実施形態では、上記のように、プログラム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
また、本実施形態では、上記のように、プログラム4は、自動変数を退避領域3eに退避させた後、自動変数のアドレスリストALが保存されていた領域を解放するステップをさらに含む。これにより、自動変数を退避領域3eに退避させた後、自動変数のアドレスリストALが保存されていた領域が解放されるので、コルーチン関数が複数設けられる場合において、解放後のメモリ3のグローバル領域3bを他のコルーチン関数のアドレスリストALなどを保存する領域として利用することができる。つまり、コルーチン関数の数が比較的多い場合でも、コルーチン関数を適切に実行することができる。
Further, in the present embodiment, as described above, the
[変形例]
なお、今回開示された実施形態は、すべての点で例示であって制限的なものではないと考えられるべきである。本発明の範囲は、上記した実施形態の説明ではなく特許請求の範囲によって示され、さらに特許請求の範囲と均等の意味および範囲内でのすべての変更(変形例)が含まれる。
[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
2 マイコン(制御部)
3 メモリ
3b グローバル領域
3d スタック領域
3e 退避領域
4 プログラム
100 制御装置
AL アドレスリスト
2 Microcomputer (control unit)
3
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~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.
前記コルーチン関数を呼び出すステップと、
前記コルーチン関数が呼び出された後、メモリのグローバル領域に前記コルーチン関数の情報を退避させる退避領域を確保するステップと、
前記コルーチン関数が呼び出された後、前記コルーチン関数の処理が中断される前に、前記メモリのスタック領域に保存されている前記コルーチン関数の情報に含まれる自動変数を、前記退避領域に退避させるステップと、
前記中断された処理を再開する前に、前記退避領域に退避された前記自動変数を、前記メモリの前記スタック領域に復元するステップと、を含む、処理方法。
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.
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) |
-
2020
- 2020-11-24 JP JP2020194423A patent/JP2022083141A/en active Pending
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 |