JP2013003655A - Control device for writing data in flash memory - Google Patents

Control device for writing data in flash memory Download PDF

Info

Publication number
JP2013003655A
JP2013003655A JP2011131244A JP2011131244A JP2013003655A JP 2013003655 A JP2013003655 A JP 2013003655A JP 2011131244 A JP2011131244 A JP 2011131244A JP 2011131244 A JP2011131244 A JP 2011131244A JP 2013003655 A JP2013003655 A JP 2013003655A
Authority
JP
Japan
Prior art keywords
block
data
erasing
blocks
management
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
JP2011131244A
Other languages
Japanese (ja)
Inventor
Nobuya Uematsu
暢矢 植松
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.)
Denso Corp
Original Assignee
Denso Corp
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 Denso Corp filed Critical Denso Corp
Priority to JP2011131244A priority Critical patent/JP2013003655A/en
Publication of JP2013003655A publication Critical patent/JP2013003655A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Techniques For Improving Reliability Of Storages (AREA)

Abstract

PROBLEM TO BE SOLVED: To provide a technology for recording data in a flash memory, capable of further reducing the possibility of losing the stored data.SOLUTION: When data in a block 1 is erased, a block ID of a block 2 where the latest value of the data is stored is written in a management block, and then the data in the block 1 is erased. After a control device is recovered from reset, if there are two blocks having a block status that the block is in use, among the two blocks, data of the block (block 1) which is different from the block (block 2) having the block ID written in the management block is erased.

Description

本発明は、フラッシュメモリにデータの書き込みを行う制御装置に関するものである。   The present invention relates to a control device that writes data to a flash memory.

従来、データ消去の最小単位となるブロックを複数有するフラッシュメモリに対して追記方式でデータの読み出しおよび書き込みを行う制御装置が知られている。   2. Description of the Related Art Conventionally, there has been known a control device that reads and writes data by a write-once method with respect to a flash memory having a plurality of blocks as a minimum unit for data erasure.

フラッシュメモリでは、データ書き込みの最小単位のサイズ(例えば数バイト)に比べ、データ消去の最小単位(ブロック)のサイズが大きく(例えば数キロバイト)、また一旦書き込んだアドレスにデータを再書き込みするにはブロック全体の消去が必要になる。そこで、フラッシュメモリの使用にあたってはデータの記憶領域を固定せず、データを追記方式で管理することが多い。追記方式では、あるデータの値を更新する際には、ブロックの空き領域に当該データの最新の値を追記するようになっている。また、各ブロックには、当該消去対象ブロックのブロックステータス情報を記録する領域があり、複数のブロックのうち、使用中である旨のブロックステータス情報を有するブロックに、データの書き込みが行われるようになっている(例えば、特許文献1参照)。   In flash memory, the size of the minimum unit of data erasure (block) is larger (for example, several kilobytes) than the size of the minimum unit of data writing (for example, several bytes). The entire block needs to be erased. Therefore, when using a flash memory, the data storage area is not fixed and the data is often managed by a write-once method. In the write-once method, when updating the value of a certain data, the latest value of the data is added to the free area of the block. Each block has an area for recording block status information of the block to be erased, and data is written to a block having block status information indicating that the block is in use among a plurality of blocks. (For example, refer to Patent Document 1).

特開平9−281791号公報Japanese Patent Laid-Open No. 9-281791

特許文献1に記載のような方法でフラッシュメモリを使用することで、既存のEEPROMと同様にデータの読み出しおよび書き込みを行うことができる。しかし、特許文献1に記載のような方法では、電源が瞬断した際に、EEPROMと同様に保存したデータが消失する場合が発生する。   By using a flash memory by a method as described in Patent Document 1, data can be read and written in the same manner as an existing EEPROM. However, in the method as described in Patent Document 1, when the power supply is cut off, the stored data may be lost as in the case of the EEPROM.

また、フラッシュメモリはEEPROMよりも容量が大きいため、より多くのデータを保存することができる。従って、今後、今までは保存していなかったデータ、例として、データが消失すると、制御装置が提供する機能全体への影響が大きいデータ等、を保存する場合が想定される。その際は、データの消失の可能性を従来よりも低減させることが必要とされる。   Moreover, since the flash memory has a larger capacity than the EEPROM, more data can be stored. Therefore, it is assumed that data that has not been saved until now, for example, data that has a large influence on the entire function provided by the control device when data is lost, is assumed. In that case, it is necessary to reduce the possibility of data loss as compared with the prior art.

本発明は上記点に鑑み、フラッシュメモリにデータを記録する技術において、保存しているデータが消失する可能性をより低減させることを目的とする。   The present invention has been made in view of the above points, and it is an object of the present invention to further reduce the possibility of losing stored data in a technique for recording data in a flash memory.

上記目的を達成するための請求項1に記載の発明は、フラッシュメモリ(5)内において個々にデータ消去の単位となる複数のブロックのうち、使用中である旨のブロックステータス情報を保持しているブロックに対して追記方式でデータの書き込みを行う制御装置であって、前記複数のブロックのうち第1のブロックのデータ消去時に、消去対象の前記第1のブロックを特定可能な区別用データまたは前記複数のブロックのうちデータの最新値が保存されている第2のブロックを特定可能な区別用データを、不揮発性記憶媒体(5a)に書き込む消去前処理手段(110)と、前記消去前処理手段(110)によって前記区別用データが記録された後、前記第1のブロックのデータ消去を行う消去手段(120)と、前記制御装置がリセットから復帰した後、使用中である旨のブロックステータス情報を保持しているブロックが前記複数のブロック中で2個あったことに基づいて、前記不揮発性記憶媒体(5a)中の前記区別用データを参照する参照手段(230)と、
使用中である旨のブロックステータス情報を保持している前記2個のブロックのうち、前記参照手段(240)が参照した前記区別用データによれば消去対象となっている前記第1のブロックのデータ消去を行うか、または、前記参照手段(240)が参照した前記区別用データによればデータの最新値が保存されている前記第2のブロック以外のブロックのデータ消去を行う消去手段(240)と、を備えた制御装置である。
In order to achieve the above object, the invention according to claim 1 holds block status information indicating that it is in use among a plurality of blocks which are individually erased units in the flash memory (5). A control device that writes data to a block in a write-once manner, wherein the data for distinction that can identify the first block to be erased when erasing data of the first block among the plurality of blocks, or Pre-erase processing means (110) for writing, in the non-volatile storage medium (5a), distinction data that can identify the second block in which the latest data value is stored among the plurality of blocks, and the pre-erase processing After the distinction data is recorded by the means (110), the erasing means (120) for erasing the data in the first block, and the control device reset the data. After returning from the above, based on the fact that there are two blocks in the plurality of blocks that hold block status information indicating that they are in use, the distinguishing data in the nonvolatile storage medium (5a) Reference means (230) for referring to
Of the two blocks holding block status information indicating that they are in use, according to the distinguishing data referred to by the reference means (240), the first block to be erased Erasing means (240) for erasing data or erasing data of blocks other than the second block in which the latest value of the data is stored according to the distinguishing data referred to by the reference means (240) ).

また、請求項2に記載の発明は、フラッシュメモリ(5)内でエリア毎に複数個設けられて個々にデータ消去の単位となる複数のブロックのうち、各エリアにおいて使用中である旨のブロックステータス情報を保持しているブロックに対して追記方式でデータの書き込みを行う制御装置であって、複数のブロックのうち第1のブロックの消去時に、消去対象の前記第1のブロックを特定可能な区別用データ、または、前記第1のブロックと同じ第1のエリアに属する他のブロックのうちデータの最新値が保存されている第2のブロックを特定可能な区別用データを、不揮発性記憶媒体(5a)に書き込む消去前処理手段(110)と、前記消去前処理手段(110)によって前記区別用データが記録された後、前記第1のブロックを消去する消去手段(120)と、前記制御装置がリセットから復帰した後、使用中である旨のブロックステータス情報を保持しているブロックが前記第1のエリア内に2個あったことに基づいて、前記不揮発性記憶媒体(5a)中の前記区別用データを参照する参照手段(230)と、使用中である旨のブロックステータス情報を保持している前記第1のエリア内の前記2個のブロックのうち、前記参照手段(240)が参照した前記区別用データによれば消去対象となっている前記第1のブロックのデータ消去を行うか、または、前記参照手段(240)が参照した前記区別用データによればデータの最新値が保存されている前記第2のブロック以外のブロックのデータ消去を行う消去手段(240)と、を備えた制御装置である。   According to a second aspect of the present invention, a block indicating that a plurality of blocks are provided for each area in the flash memory (5) and are used in each area among a plurality of blocks each serving as a data erasing unit. A control device that writes data to a block having status information by a write-once method, and can identify the first block to be erased when erasing the first block among a plurality of blocks Non-volatile storage medium for distinguishing data or distinguishing data capable of identifying a second block in which the latest data value is stored among other blocks belonging to the same first area as the first block After the erasure preprocessing means (110) to be written into (5a) and the erasure preprocessing means (110) have recorded the distinguishing data, the first block is erased. Based on the fact that there are two blocks in the first area that hold the block status information indicating that it is in use after the leaving means (120) and the control device return from reset, Reference means (230) for referring to the distinguishing data in the nonvolatile storage medium (5a), and the two blocks in the first area holding block status information indicating that the data is being used. Of these, the data for the first block to be erased is erased according to the distinguishing data referenced by the reference means (240), or the distinguishing data referenced by the reference means (240) According to the data, the controller includes an erasing unit (240) for erasing data of blocks other than the second block in which the latest value of the data is stored.

請求項1、2のように、第1のブロックのデータ消去時に、前処理として上記のような区別データを不揮発性記憶媒体(5a)に書き込んでおき、その後にデータ消去を行うようにする。そして、制御装置がリセットから復帰した後、使用中である旨のブロックステータス情報を保持しているブロックが2個あったことに基づいて、この区別用データを参照することで、消去対象の第1のブロックまたはデータの最新値が保存されている第2のブロックを特定できるので、上記2個のブロックのうち、区別用データによれば消去対象となっているブロックのデータ消去するか、区別用データによればデータの最新値が保存されているブロックではない方のブロックのデータ消去を行う。これにより、リセット前に消去しようとしていたブロックの消去が完了するので、使用中である旨のブロックステータス情報を保持しているブロックが、データの最新値が保存されている第2のブロック1個になり、どのブロックにデータの最新値が保存されているのかがわかるようになる。したがって、フラッシュメモリにデータを記録する技術において、記憶しているデータが消失する可能性をより低下させることができる。   As in the first and second aspects, at the time of data erasure of the first block, the above-mentioned distinction data is written in the nonvolatile storage medium (5a) as preprocessing, and thereafter data erasure is performed. Then, after the control device returns from the reset, based on the fact that there are two blocks that hold the block status information indicating that the control device is in use, this distinction data is referred to, so that Since the first block or the second block in which the latest value of the data is stored can be specified, the data of the block to be erased is distinguished or distinguished from the above two blocks according to the distinguishing data. According to the business data, the data of the block that is not the block in which the latest value of the data is stored is erased. As a result, the erasure of the block to be erased before the reset is completed, so that the block holding the block status information indicating that it is in use is one second block in which the latest value of the data is stored. It becomes possible to know in which block the latest value of the data is stored. Therefore, in the technique of recording data in the flash memory, the possibility that the stored data is lost can be further reduced.

また、請求項3に記載の発明は、請求項1または2に記載の制御装置において、前記不揮発性記憶媒体(5a)は、フラッシュメモリにおいてデータ消去の単位となる管理ブロックであり、前記消去前処理手段(110)によって前記区別用データが記録された後、前記管理ブロックにこれ以上区別用データを書き込む空き領域がない場合、前記複数のブロックのうち1つのブロックに、所定の管理ブロック消去中データを書き込む管理ブロック消去前処理手段(150)と、前記管理ブロック消去前処理手段(150)によって前記管理ブロック消去中データが書き込まれた後、前記管理ブロックのデータ消去を行う管理ブロック消去手段(160、260)と、前記管理ブロック消去手段が前記管理ブロックのデータ消去を行った後、前記管理ブロック消去中データを無効化する管理ブロック消去中データ無効化手段(170、270)と、前記管理ブロック消去手段(160)は、前記制御装置がリセットから復帰した後、前記1つのブロックに前記管理ブロック消去中データが記録されていることに基づいて、前記管理ブロックのデータ消去を行うことを特徴とする。このようにすることで、管理ブロックのデータ消去時にリセットが発生した場合も、リセットから復帰した後にデータ消去できるようになる。   According to a third aspect of the present invention, in the control device according to the first or second aspect, the non-volatile storage medium (5a) is a management block that is a unit of data erasure in a flash memory. After the discrimination data is recorded by the processing means (110), when there is no more free area to write the discrimination data in the management block, a predetermined management block is being erased in one of the plurality of blocks Management block erasing preprocessing means (150) for writing data, and management block erasing means for erasing data of the management block after the management block erasing data is written by the management block erasing preprocessing means (150). 160, 260), and after the management block erasing means erases the data of the management block, The management block erasing data invalidating means (170, 270) for invalidating the management block erasing data and the management block erasing means (160) are arranged in the one block after the control device returns from reset. The management block data is erased based on the fact that the management block erasing data is recorded. In this way, even when a reset occurs when erasing data in the management block, the data can be erased after returning from the reset.

なお、上記および特許請求の範囲における括弧内の符号は、特許請求の範囲に記載された用語と後述の実施形態に記載される当該用語を例示する具体物等との対応関係を示すものである。   In addition, the code | symbol in the bracket | parenthesis in the said and the claim shows the correspondence of the term described in the claim, and the concrete thing etc. which illustrate the said term described in embodiment mentioned later. .

本発明の第1実施形態に係るマイクロコントローラ1の構成図である。1 is a configuration diagram of a microcontroller 1 according to a first embodiment of the present invention. アプリケーションソフト、フラッシュドライバソフト、フラッシュコントローラ6、フラッシュメモリ5の階層構成の概念図である。2 is a conceptual diagram of a hierarchical configuration of application software, flash driver software, flash controller 6, and flash memory 5. FIG. データ消去前のブロック1、2、管理ブロックの内容を示す図である。It is a figure which shows the content of the blocks 1 and 2 before a data deletion, and a management block. ブロックのデータ消去時の処理を示すフローチャートである。It is a flowchart which shows the process at the time of the data erasure | elimination of a block. 区別用データ記録後のブロック1、2、管理ブロックの内容を示す図である。It is a figure which shows the content of the blocks 1 and 2 after management data recording, and the management block. 区別用データ無効化後のブロック1、2、管理ブロックの内容を示す図である。It is a figure which shows the content of the blocks 1 and 2 after a discrimination data invalidation, and a management block. ブロック1のデータ消去が中断したときのブロック1、2、管理ブロックの内容を示す図である。It is a figure which shows the content of the block 1, 2 when a data deletion of the block 1 is interrupted, and a management block. リセットから復帰した後に実行する処理のフローチャートである。It is a flowchart of the process performed after returning from reset. 管理ブロック消去中データをブロック2に記録したときのブロック1、2、管理ブロックの内容を示す図である。It is a figure which shows the content of the block 1, 2 when a management block erasing data is recorded on the block 2, and a management block. 管理ブロック消去中データを無効化したときのブロック1、2、管理ブロックの内容を示す図である。It is a figure which shows the content of the blocks 1 and 2 when a management block erasing data is invalidated, and a management block. 管理ブロックのデータ消去が中断したときのブロック1、2、管理ブロックの内容を示す図である。It is a figure which shows the contents of the blocks 1 and 2 when the data erasure of the management block is interrupted.

以下、本発明の一実施形態について説明する。図1に、本実施形態に係るマイクロコントローラ1(本発明の制御装置の一例に相当する)の構成を示す。このマイクロコントローラ1は、車両に搭載され、I/O2、ROM3、RAM4、フラッシュメモリ5、フラッシュコントローラ6、CPU7等を備えている。   Hereinafter, an embodiment of the present invention will be described. FIG. 1 shows a configuration of a microcontroller 1 (corresponding to an example of a control device of the present invention) according to the present embodiment. The microcontroller 1 is mounted on a vehicle and includes an I / O 2, a ROM 3, a RAM 4, a flash memory 5, a flash controller 6, a CPU 7, and the like.

I/O2は、マイクロコントローラ1の外部の装置と信号の授受を行うためのインターフェース装置である。ROM3は、CPU7が実行するための各種プログラム等があらかじめ記憶された不揮発性の記憶媒体である。RAM4は、CPU7の作業用のメモリ領域である。   The I / O 2 is an interface device for exchanging signals with a device external to the microcontroller 1. The ROM 3 is a non-volatile storage medium in which various programs to be executed by the CPU 7 are stored in advance. The RAM 4 is a working memory area for the CPU 7.

フラッシュメモリ5は、データ消去の最小単位となるブロックを複数個有して構成されている。各ブロックのサイズは数キロバイト(例えば、4キロバイト)であり、1つのブロック内のあるデータを消去するには、そのブロック全体のデータを消去する(すなわち、そのブロック全体のビットを1にとする)必要がある。しかし、1つのブロック内にある特定のビットを1から0に書き替える場合は、それよりも小さい単位(例えば2バイト単位、4バイト単位)でデータを書き換えることができる。   The flash memory 5 has a plurality of blocks which are the minimum unit of data erasure. The size of each block is several kilobytes (for example, 4 kilobytes), and in order to erase some data in one block, the data of the entire block is erased (that is, the bit of the entire block is set to 1). )There is a need. However, when a specific bit in one block is rewritten from 1 to 0, data can be rewritten in units smaller than that (for example, in units of 2 bytes or 4 bytes).

これら複数個のブロックのそれぞれは、複数(M個)のエリアのいずれかに属するようになっている。例えば、図1の例では、ブロック1、2がエリア1に属し、ブロック3、4がエリア2に属している。1つのエリアに属するブロックの数は、2の場合もあれば、3以上の場合もある。どのブロックがどのエリアに属するかの情報は、あらかじめROM3に記録されている。   Each of the plurality of blocks belongs to one of a plurality (M) of areas. For example, in the example of FIG. 1, blocks 1 and 2 belong to area 1 and blocks 3 and 4 belong to area 2. The number of blocks belonging to one area may be 2 or 3 or more. Information about which block belongs to which area is recorded in the ROM 3 in advance.

エリアは、フラッシュメモリ5に書き込むレコードの記録先を、そのレコードが含むデータの種別に応じて仕分けするために設けられた領域である。例えば、ドアの開閉回数、エンジンの開閉回数等の、値が変化する頻度(すなわち、更新の頻度)が高い種別のデータは、エリア2に記録し、ソフトのバージョン等の、値が変化する頻度が低い種別のデータは、エリア1に記録する等の区分けを行う。どの種別のデータがどのエリアに記録されるかの情報は、データIDとエリアとの対応関係を示すエリア対応テーブルとして、ROM3に記録されている。   The area is an area provided for sorting the recording destinations of records to be written in the flash memory 5 according to the type of data included in the records. For example, data of a type with a high value change frequency (that is, update frequency) such as the number of times of opening and closing the door and the number of times of opening and closing the engine is recorded in the area 2 and the frequency of the value change such as the software version The type of data with a low is classified such as being recorded in area 1. Information on which type of data is recorded in which area is recorded in the ROM 3 as an area correspondence table indicating the correspondence between the data ID and the area.

各エリア内において、同じエリアに属する複数のブロックは、CPU7およびフラッシュコントローラ6によって、1番目のブロックが使用され、1番目のブロックの使用が終了すると次に2番目のブロックが使用されるという風に、順番に書き込みに使用されるようになっている。   In each area, a plurality of blocks belonging to the same area are used by the CPU 7 and the flash controller 6 so that the first block is used, and when the use of the first block is finished, the second block is used next. In turn, they are used for writing.

複数のブロックのそれぞれは、一部の領域がブロックステータス領域として使用され、他の領域がデータ領域を有している。各ブロックステータス領域にはブロックステータス情報が記録されるようになっており、ブロックステータス情報は、当該ブロックが使用中のブロックであるか使用済みのブロックであるか未使用のブロックであるかを判別することができる。各ブロックは、CPU7およびフラッシュコントローラ6によって、当該ブロックの使用を始める際に、使用中である旨のブロックステータス情報がブロックステータス領域に書き込まれる。また、使用中のブロック(使用中である旨のブロックステータス情報を有するブロック)のデータ領域には、先頭のアドレスから順にレコードが順次記録されるようになっている。そして、当該ブロックが更にレコードを書き込む空き領域がない満杯状態になった場合、使用済みである旨のブロックステータス情報がブロックステータス領域に書き込まれる。また、当該ブロックのデータ消去を行うことで、当該ブロックのブロックステータス情報は、未使用である旨のブロックステータス情報となる。   In each of the plurality of blocks, a part of the area is used as a block status area, and the other area has a data area. Block status information is recorded in each block status area, and the block status information determines whether the block is a used block, a used block, or an unused block. can do. When each block starts to use the block by the CPU 7 and the flash controller 6, block status information indicating that the block is in use is written in the block status area. Further, records are sequentially recorded in order from the head address in the data area of the block in use (the block having block status information indicating that it is in use). Then, when the block is in a full state where there is no empty area to which further records are to be written, block status information indicating that the block has been used is written to the block status area. Further, by erasing the data of the block, the block status information of the block becomes block status information indicating that the block is unused.

なお、レコードのデータサイズは、固定でも可変でもよいが、本実施形態では固定とする。また、レコードのデータサイズは、典型的には数十バイト程度の長さである。したがって、典型的には、1つのブロック内には、数十個〜数百個程度のレコードが記録可能である。   Note that the data size of the record may be fixed or variable, but is fixed in the present embodiment. The data size of the record is typically about several tens of bytes. Therefore, typically, several tens to several hundreds of records can be recorded in one block.

また、フラッシュメモリ5は、どのエリアにも属さないブロックとして、管理ブロック5aを1つ有している。この管理ブロックは、他のブロック同様、データ消去の最小単位であり、また、レコードが記録可能となっている。この管理ブロック5aには、後述するように、各エリアのブロックのデータ消去直前に、そのエリアでデータの最新値が記録されているブロックの情報が書き込まれるようになっている。   Further, the flash memory 5 has one management block 5a as a block that does not belong to any area. This management block, like the other blocks, is the minimum unit for data erasure, and records can be recorded. In this management block 5a, as will be described later, immediately before data erasure of a block in each area, information of a block in which the latest data value is recorded in that area is written.

フラッシュコントローラ6は、CPU7の制御に従ってフラッシュメモリ5内の各ブロックに対してデータの読み出しおよび書き込みを行う周知の装置である。具体的には、CPU7から特定のブロックの特定のアドレスのデータの読み出し指令を受けると、当該アドレスに記録されたデータの内容をフラッシュメモリ5から読み出し、読み出した内容をCPU7に出力する。   The flash controller 6 is a known device that reads and writes data from and to each block in the flash memory 5 under the control of the CPU 7. Specifically, when the CPU 7 receives a command to read data at a specific address in a specific block, the content of the data recorded at the address is read from the flash memory 5 and the read content is output to the CPU 7.

また、CPU7から特定のブロックの特定のアドレスに特定のデータの書き込むよう書き込み指令を受けると、フラッシュメモリ5の当該ブロックの当該アドレス位置へ、当該特定のデータを書き込む。また、CPU7からブロックの消去命令を受けると、フラッシュメモリ5の当該ブロックの全データの消去を行う。   Further, when a write command is received from the CPU 7 to write specific data to a specific address of a specific block, the specific data is written to the address position of the block of the flash memory 5. When a block erase command is received from the CPU 7, all data in the block of the flash memory 5 is erased.

CPU7は、ROM3に記録されたプログラムを実行することで、種々の処理を実現し、その処理において、必要に応じ、I/O2を用いて外部と信号の授受を行い、ROM3からデータを読み出し、RAM4を作業領域として用い、フラッシュコントローラ6に上記のような各種指令を出力することで、フラッシュメモリ5へのデータの読み出しおよび書き込みを行う。   The CPU 7 implements various processes by executing the programs recorded in the ROM 3, and in that process, exchanges signals with the outside using the I / O 2 as necessary, reads data from the ROM 3, The RAM 4 is used as a work area, and various commands as described above are output to the flash controller 6 to read and write data to the flash memory 5.

以下、簡単のため、CPU7がフラッシュコントローラ6に読み出し指令を出力し、その読み出し指令に従ってフラッシュコントローラ6がフラッシュメモリ5のブロックからデータを読み出してCPU7に出力する作動については、単に、CPU7がフラッシュメモリ5のブロックからデータを読み出すと記載する。また、簡単のため、CPU7がフラッシュコントローラ6に書き込み指令を出力し、その書き込み指令に従ってフラッシュコントローラ6がフラッシュメモリ5のブロックにデータを書き込む作動については、単に、CPU7がフラッシュメモリ5のブロックにデータを書き込むと記載する。   Hereinafter, for the sake of simplicity, the CPU 7 outputs a read command to the flash controller 6, and the flash controller 6 reads data from the block of the flash memory 5 in accordance with the read command and outputs it to the CPU 7. It is described that data is read from the block 5. For simplicity, the CPU 7 outputs a write command to the flash controller 6 and the flash controller 6 writes data to the block of the flash memory 5 in accordance with the write command. To write.

図1に示すように、ROM3には、CPU7が実行するプログラムとして、フラッシュドライバソフト、および、複数のアプリケーションソフトが格納されている。図2に、アプリケーションソフト、フラッシュドライバソフト、フラッシュコントローラ6、フラッシュメモリ5の階層構成を概念的に示す。   As shown in FIG. 1, the ROM 3 stores flash driver software and a plurality of application software as programs executed by the CPU 7. FIG. 2 conceptually shows the hierarchical structure of application software, flash driver software, flash controller 6 and flash memory 5.

CPU7は、これらアプリケーションソフトを実行することで、例えば、I/O2を介してドア開閉センサから信号を受け取って車両のドアの開閉を検出し、車両のエンジンの始動を検知するセンサから信号を受け取ってエンジンECUの始動を検出する。   By executing these application software, for example, the CPU 7 receives a signal from a door opening / closing sensor via the I / O 2 to detect opening / closing of the vehicle door, and receives a signal from a sensor that detects the start of the vehicle engine. Then, the start of the engine ECU is detected.

これらのようなアプリケーションを実行したときの処理により、フラッシュメモリ5にデータを記録する必要が発生する場合がある。例えば、エンジンを始動した回数を、その回数が変化する度にフラッシュメモリ5に記録する必要が発生し、ドアを開閉した回数を、その回数が変化する度にフラッシュメモリ5に記録する必要が発生する。   There is a case where it is necessary to record data in the flash memory 5 by processing when such an application is executed. For example, the number of times the engine is started needs to be recorded in the flash memory 5 every time the number of times changes, and the number of times the door is opened and closed needs to be recorded in the flash memory 5 every time the number of times changes. To do.

このように、CPU7がアプリケーションソフトの実行において書き込みデータの書き込みの必要が発生すると、書き込みデータの書き込み要求をRAM4またはCPU7のレジスタに出力する(書き込む)。この書き込み要求は、書き込みデータの種別を示すデータID(例えば、エンジンを始動した回数か、ドアを開閉した回数かの別)と、書き込みデータの値とを含むデータである。   As described above, when the CPU 7 needs to write the write data when executing the application software, the write request for the write data is output (written) to the RAM 4 or the register of the CPU 7. This write request is data including a data ID indicating the type of write data (for example, whether the engine has been started or the number of times the door has been opened and closed) and the value of the write data.

すると、CPU7は、書き込み要求が出力されたことに基づいて、フラッシュドライバソフトの実行を開始し、その実行処理において、書き込み要求中のデータIDに基づいて、書き込み先のエリアを決定し、当該エリア中で、使用中の旨のブロックステータス情報が記録されているブロックを特定し、特定したブロックに書き込みデータの値を記録するため、フラッシュコントローラ6に必要な指令を出力する。これにより、フラッシュコントローラ6によって書き込みデータがレコードとしてブロックのデータ領域に追記方式で記録される。   Then, the CPU 7 starts execution of the flash driver software based on the output of the write request, and determines the write destination area based on the data ID in the write request in the execution process. Among them, a block in which block status information indicating that it is in use is specified, and a command necessary for the flash controller 6 is output to record the value of write data in the specified block. As a result, the write data is recorded as a record by the flash controller 6 in the data area of the block by the write-once method.

ここで、追記方式について説明する。追記方式では、あるデータIDのデータの値が、すでにブロックのある領域に記録されており、新たに当該データの値を更新するときには、当該領域に新たな値を上書き記録するのではなく、当該ブロックの空き領域に当該データの最新値を追加記録する。   Here, the additional recording method will be described. In the write-once method, the data value of a certain data ID is already recorded in a certain area of the block, and when a new value of the data is updated, the new value is not overwritten and recorded in the area. The latest value of the data is additionally recorded in the free area of the block.

以下では、簡単のため、CPU7が、ある特定のアドレスにデータを書き込む書き込み指令をフラッシュコントローラ6に出力する処理を、単に、CPU7が、ブロックの特定のアドレスにデータを書き込むと記載する。また同様に、CPU7が、ある特定のアドレスからデータを読み出す読み出し指令をフラッシュコントローラ6に出力し、フラッシュコントローラ6から当該データを取得する処理を、単に、CPU7が、ある特定のアドレスからデータを読み出すと記載する。   In the following, for the sake of simplicity, the process in which the CPU 7 outputs a write command for writing data to a specific address to the flash controller 6 is simply described as the CPU 7 writing data to a specific address of the block. Similarly, the CPU 7 outputs a read command for reading data from a specific address to the flash controller 6, and the CPU 7 simply reads the data from the specific address in the process of acquiring the data from the flash controller 6. It describes.

以下、上記のような構成のマイクロコントローラ1の具体的な作動例について説明する。本例では、ブロック1およびブロック2のみを有するエリア1に、あるデータIDのデータの値を書き込む作動について説明するが、他のエリアにデータの値を書き込む場合も同様の作動を行う。   Hereinafter, a specific operation example of the microcontroller 1 having the above configuration will be described. In this example, the operation of writing the data value of a certain data ID in the area 1 having only the block 1 and the block 2 will be described, but the same operation is performed when writing the data value in another area.

まず、CPU7は、あるデータの値をエリア1に書き込むとき、エリア1内のブロック1、2に保存されているブロックステータス情報を参照し、使用中である旨のブロックステータス情報を有しているブロックに、データの値およびデータIDを有するレコードを追記方式で書き込む。通常、使用中である旨のブロックステータス情報を有するブロックは、1つのエリア内で1つだけであり、同じエリア中の他のブロックのブロックステータス情報は未使用か使用済みとなっている。   First, when the CPU 7 writes a value of certain data in the area 1, the CPU 7 refers to the block status information stored in the blocks 1 and 2 in the area 1 and has block status information indicating that the data is being used. A record having a data value and a data ID is written to the block by a write-once method. Normally, there is only one block having block status information indicating that it is in use, and block status information of other blocks in the same area is unused or used.

本例では、エリア1に属するブロック2が使用中である旨のブロックステータス情報を有しているとする。この場合、データの値が更新される度、最新の値がブロック2に順次追加されてく。そして、ブロック2にこれ以上レコードを記録できない満杯状態になると(図3参照)、CPU7は、ブロック1(第1のブロックの一例に相当する)のデータ消去を行うため、フラッシュドライバソフトの処理の一部として、図4に示す処理を実行する。   In this example, it is assumed that the block 2 belonging to area 1 has block status information indicating that it is in use. In this case, the latest value is sequentially added to the block 2 every time the data value is updated. Then, when the block 2 is full so that no more records can be recorded (see FIG. 3), the CPU 7 erases the data in the block 1 (corresponding to an example of the first block). As a part, the process shown in FIG. 4 is executed.

まずステップ110では、消去の前処理として、データの最新値が記録されているブロック2(第2のブロックの一例に相当する)のブロックIDと当該ブロック2が属するエリア1のエリアIDとの組を、区別用データとして、管理ブロックの空き領域に書き込む。ブロックIDは、フラッシュメモリ5中のブロックを一意に区別するために各ブロックに割り当てられた識別子であり、エリアIDは、フラッシュメモリ5中のエリアを一意に区別するために各エリアに割り当てられた識別子である。この際、区別用データには、当該区別用データが有効である旨のデータも含める(図5参照)。   First, in step 110, as a pre-erase process, a set of a block ID of block 2 (corresponding to an example of a second block) in which the latest data value is recorded and an area ID of area 1 to which the block 2 belongs is set. Are written in the free area of the management block as the data for discrimination. The block ID is an identifier assigned to each block in order to uniquely distinguish the block in the flash memory 5, and the area ID is assigned to each area in order to uniquely distinguish the area in the flash memory 5. It is an identifier. At this time, the data for discrimination includes data indicating that the data for discrimination is valid (see FIG. 5).

続いてステップ120では、消去対象のブロック1のデータ消去を実行する。具体的には、フラッシュコントローラ6にブロック1の消去命令を出力する。これにより、フラッシュコントローラ6は、ブロック1のデータ消去を行い、データ消去が完了したら、その旨をCPU7に通知する。   Subsequently, in step 120, data erasure of the block 1 to be erased is executed. Specifically, the block 1 erase command is output to the flash controller 6. As a result, the flash controller 6 erases the data in the block 1, and when the data erase is completed, notifies the CPU 7 to that effect.

フラッシュコントローラ6からデータ消去完了の通知を受けた後、CPU7は、ステップ130に進んで、直前のステップ110で管理ブロックに書き込んだ区別用データを無効化する(図6参照)。具体的には、当該区別用データ中で、当該区別用データが有効である旨のデータを、無効である旨のデータに書き換える。なお、ブロックのある領域に値を一旦書き込んでも、その値を構成するビット列のうち一部を1から0に書き替えるような1→0タイプの書き換えは可能であり、上記のような有効である旨のデータから無効である旨のデータへの書き換えは、そのような1→0タイプの書き換えである。   After receiving the data erasure completion notification from the flash controller 6, the CPU 7 proceeds to step 130 and invalidates the discrimination data written in the management block in the immediately preceding step 110 (see FIG. 6). Specifically, in the data for discrimination, data indicating that the data for discrimination is valid is rewritten to data indicating that it is invalid. Note that even if a value is once written in a certain area of the block, 1 → 0 type rewriting in which a part of the bit string constituting the value is rewritten from 1 to 0 is possible, which is effective as described above. The rewriting from the data indicating that the data is invalid to the data indicating that the data is invalid is such a 1 → 0 type rewriting.

続いてステップ140では、管理ブロックが満杯状態になっているか否か、すなわち、管理ブロックに新たに区別用データを書き込む空き領域が無いかあるかを判定する。本例では、図6に示すように、まだ管理ブロックに空き領域があるので、管理ブロックが満杯状態でないと判定して図4の処理を終了する。   Subsequently, in step 140, it is determined whether or not the management block is full, that is, whether or not there is a free area in the management block in which new discrimination data is written. In this example, as shown in FIG. 6, since there is still an empty area in the management block, it is determined that the management block is not full, and the processing in FIG. 4 is terminated.

このような図4の処理により、ブロック1のデータ消去が実現する。その後CPU7は、ブロック2に記録されている各種データの最新値をブロック1にコピーし、ブロック2のブロックステータス領域のブロックステータス情報を、使用済みである旨のブロックステータス情報に書き換える(これも1→0タイプの書き換えである)と共に、ブロック1のブロックステータス領域に、使用中である旨のブロックステータス情報を書き込む。これにより、以後ブロック1に、エリア1用のデータの最新値が順次記録されていく。   By such processing of FIG. 4, data erasure of block 1 is realized. Thereafter, the CPU 7 copies the latest values of various data recorded in the block 2 to the block 1 and rewrites the block status information in the block status area of the block 2 to the block status information indicating that it has been used (this is also 1 In addition, the block status information indicating that the block is in use is written in the block status area of block 1. As a result, the latest value of the data for area 1 is sequentially recorded in block 1 thereafter.

ここで、図4のステップ120でブロック1のデータ消去を行っている途中に、マイクロコントローラ1がリセットした場合について説明する。リセットの原因は、マイクロコントローラ1の暴走、マイクロコントローラ1の外部からのリセット要求、CPU7が実行しているプログラムによるソフトウェアリセット要求、マイクロコントローラ1への電力供給の瞬断等、様々である。   Here, the case where the microcontroller 1 is reset during the data erasure of the block 1 in step 120 of FIG. 4 will be described. The cause of the reset is various, such as a runaway of the microcontroller 1, a reset request from the outside of the microcontroller 1, a software reset request by a program executed by the CPU 7, and an instantaneous interruption of power supply to the microcontroller 1.

マイクロコントローラ1がリセットした場合、ブロック1のデータ消去が中断してしまうので、ブロック1の記憶領域は、完全に消去された状態(全ビットが1となっている状態)ではなく、中途半端に消去された状態になっている。   When the microcontroller 1 is reset, the data erasure of the block 1 is interrupted, so that the storage area of the block 1 is not completely erased (a state where all bits are 1) but halfway. It has been erased.

あるブロックのデータ消去が途中で終わってしまった場合に、そのブロック内のデータ構成がどのようなっているかは、消去前のデータ構成、中断のタイミング、フラッシュコントローラ6によるデータ消去の手順(例えば、フラッシュコントローラ6がランダムな順序で当該ブロックの各ビットを1にするようなものであってもよい)等によって様々である。したがって、場合によっては、図7に示すように、データ消去が中断したブロック1のブロックステータス領域のブロックステータス情報が、使用中である旨のブロックステータス情報に、たまたま変化してしまう場合がある。   When the data erasure of a block is finished halfway, the data structure in the block is determined according to the data structure before erasure, the timing of interruption, the data erasing procedure by the flash controller 6 (for example, The flash controller 6 may be such that each bit of the block is set to 1 in a random order). Accordingly, in some cases, as shown in FIG. 7, the block status information in the block status area of the block 1 in which data erasure is interrupted may happen to change to block status information indicating that it is in use.

この方法でフラッシュメモリを使用すれば、既存のEEPROMと同等の性能を提供することが可能になると共に、EEPROMと同様にデータが消失する場合がある。そして、フラッシュメモリはEEPROMよりも多くのデータを保存することができるため、今までは保存していなかった消失してはいけないデータを保存する場合が想定される。その際は、データの消失の可能性を従来よりも低減させることが望ましい。   If a flash memory is used in this manner, performance equivalent to that of an existing EEPROM can be provided, and data may be lost as in the case of an EEPROM. Since the flash memory can store more data than the EEPROM, it is assumed that data that has not been stored so far and should not be lost is stored. In that case, it is desirable to reduce the possibility of data loss compared to the prior art.

本実施形態では、この課題を解消するため、マイクロコントローラ1がリセットから復帰したときに、CPU7が、図8に示す処理を実行するようになっている。   In the present embodiment, in order to solve this problem, the CPU 7 executes the processing shown in FIG. 8 when the microcontroller 1 returns from reset.

この図8の処理においてCPU7は、まずステップ210で、全エリアに渡って、使用中である旨のブロックステータス情報を有するブロックを検索する。続いてステップ210で、その検索結果に従って、使用中である旨のブロックステータス情報を有するブロックが1エリア内に2個以上あるようなエリアが存在するか否かを判定する。存在しないと判定した場合、ステップ230、240をバイパスしてステップ250に進む。   In the process of FIG. 8, the CPU 7 first searches for a block having block status information indicating that it is in use in all areas in step 210. Subsequently, in step 210, it is determined whether there is an area in which there are two or more blocks having block status information indicating that the block is being used in accordance with the search result. If it is determined that it does not exist, the process bypasses steps 230 and 240 and proceeds to step 250.

図7の例の場合、エリア1が、使用中である旨のブロックステータス情報を有するブロックを2つ(ブロック1とブロック2)を有していると判定し、ステップ230に進む。ステップ230では、管理ブロック中に記録された区別用データを参照する。   In the case of the example in FIG. 7, it is determined that the area 1 has two blocks (block 1 and block 2) having block status information indicating that the area 1 is in use, and the process proceeds to step 230. In step 230, the discrimination data recorded in the management block is referred to.

管理ブロック中に複数個の区別用データが記録されている場合は、最後に記録された区別用データを参照するようになっていてもよいし、有効である(すなわち、無効になっていない)区別用データを参照するようになっていてもよい。ブロックの消去は2ブロック以上同時に行うことはほとんどないので、管理ブロックには、有効である区別用データは1つしかないことがほとんどである。図7の例では、ブロック2のブロックIDと、エリア1のエリアIDを有する区別用データを参照する。   When a plurality of pieces of distinguishing data are recorded in the management block, the last recorded distinguishing data may be referred to and valid (that is, not invalidated). Reference data may be referred to. Since two or more blocks are hardly erased at the same time, in most cases, the management block has only one effective discrimination data. In the example of FIG. 7, reference is made to the distinguishing data having the block ID of block 2 and the area ID of area 1.

続いてステップ240では、参照した区別用データに基づいて消去対象のブロックを特定する。参照した区別用データに基づいて消去対象のブロックを特定する方法は、以下の通りである。区別用データには、図4のステップ110の説明で述べた通り、ブロック1のデータ消去の時点でデータの最新値が記録されているブロック2のブロックIDが記録されている。また、図7に示した通り、使用中である旨のブロックステータス情報を有しているのは、当該ブロック2と、データ消去が中断してしまったブロック1である。   Subsequently, in step 240, a block to be erased is specified based on the referenced discrimination data. A method for specifying a block to be erased based on the referenced discrimination data is as follows. As described in the description of step 110 in FIG. 4, the block ID of the block 2 in which the latest value of the data is recorded at the time of erasing the data of the block 1 is recorded in the discrimination data. Further, as shown in FIG. 7, the block status information indicating that the block is being used is the block 2 and the block 1 in which data erasure has been interrupted.

したがって、CPU7は、エリア1内で使用中である旨のブロックステータス情報を有している2個のブロック1、2のうち、参照した区別用データに含まれるブロックIDのブロック2ではない方のブロック1を、消去対象のブロックとして特定する。   Therefore, the CPU 7 is one of the two blocks 1 and 2 having the block status information indicating that the block ID is being used in the area 1 and is not the block 2 having the block ID included in the referenced discrimination data. Block 1 is specified as a block to be erased.

更にステップ240では、特定した消去対象のブロック1の消去命令をフラッシュコントローラ6に出力する。これにより、フラッシュコントローラ6は、当該消去対象のブロック1のデータ消去を行い、データ消去が完了したら、その旨をCPU7に通知する。また更にステップ240では、ステップ230で参照した区別用データを、図4のステップ130と同じ方法で、無効化する。この結果、ブロック1のデータ構成は、図7に示すような中途半端な消去状態から、図6に示すような完全に消去された状態に復帰する。   Further, in step 240, an erase command for the identified block 1 to be erased is output to the flash controller 6. Thereby, the flash controller 6 erases the data of the block 1 to be erased, and notifies the CPU 7 when the data erase is completed. In step 240, the discrimination data referred to in step 230 is invalidated by the same method as in step 130 of FIG. As a result, the data structure of the block 1 returns from the halfway erased state as shown in FIG. 7 to the completely erased state as shown in FIG.

このように、ブロック1のデータ消去時に、前処理として上記のような区別データを管理ブロック5aに書き込んでおき、その後にデータ消去を行うようにする。そして、制御装置がリセットから復帰した後、使用中である旨のブロックステータス情報を保持しているブロックが2個あったことに基づいて、この区別用データを参照することで、データの最新値が保存されているブロック2を特定できるので、上記2個のブロックのうち、区別用データによればデータの最新値が保存されているブロックではない方のブロックのデータ消去を行う。これにより、リセット前に消去しようとしていたブロックの消去が完了するので、使用中である旨のブロックステータス情報を保持しているブロックが、データの最新値が保存されているブロック2の1個になり、どのブロックにデータの最新値が保存されているのかがわかるようになる。そして、当該データの値が必要になるときには、ブロック2からデータの最新値を読み出すことができる。   In this way, at the time of data erasure of block 1, the above-mentioned distinction data is written in the management block 5a as preprocessing, and thereafter data erasure is performed. Then, after the control device returns from reset, based on the fact that there are two blocks that hold block status information indicating that the controller is in use, the latest value of the data can be obtained by referring to this distinguishing data. Therefore, the block 2 in which the latest value of the data is not stored is deleted from the two blocks according to the distinguishing data. This completes the erasure of the block that was to be erased before the reset, so that the block holding the block status information indicating that it is in use becomes one of the blocks 2 in which the latest data values are stored. Thus, it can be seen in which block the latest value of the data is stored. When the data value is required, the latest value of the data can be read from the block 2.

ブロック1のデータ消去が完了した旨の通知をフラッシュコントローラ6から受けたCPU7は、続いてステップ250に進み、あらかじめ定められた所定のエリア(本例ではエリア1とする)内で使用中のブロック(使用中の旨のブロックステータス情報を有するブロック)に、管理ブロック消去中データが含まれているか否かを判定する。図6の例では、ブロック2に管理ブロック消去中データが含まれていないので、図8の処理を終了する。管理ブロック消去中データについては後述する。   The CPU 7 that has received notification from the flash controller 6 that data erasure of the block 1 has been completed, then proceeds to step 250, where the block being used in a predetermined area (referred to as area 1 in this example) is determined. It is determined whether or not the management block erasing data is included in (the block having block status information indicating that it is in use). In the example of FIG. 6, the management block erasing data is not included in the block 2, so the processing of FIG. The management block erasing data will be described later.

なお、ステップ240でブロックのデータ消去を行った場合は、図8の処理の終了後、消去を行ったブロック1に対し、ブロック2に記録されている各種データの最新値をブロック1にコピーし、さらに、コピー元のブロック2のブロックステータス情報を、使用済みである旨のブロックステータス情報に書き換え、また、コピー先のブロック1のブロックステータス領域に、使用中である旨のブロックステータス情報を書き込み込む。これにより、以後ブロック1に、エリア1用のデータの最新値が順次記録されていく。   If the block data is erased in step 240, the latest values of various data recorded in block 2 are copied to block 1 after the process of FIG. Further, the block status information of the copy source block 2 is rewritten to the block status information indicating that it has been used, and the block status information indicating that it is being used is written to the block status area of the copy destination block 1 Include. As a result, the latest value of the data for area 1 is sequentially recorded in block 1 thereafter.

次に、図4のステップ110の処理の結果、管理ブロックが満杯状態になった場合について説明する。この場合は、ステップ130でいずれかのブロック(管理ブロック以外)の消去完了後に、図4のステップ140で、管理ブロックが満杯状態になったと判定し、ステップ150に進む。   Next, a case where the management block becomes full as a result of the processing of step 110 in FIG. 4 will be described. In this case, after completion of erasure of any block (other than the management block) in step 130, it is determined in step 140 in FIG. 4 that the management block is full, and the process proceeds to step 150.

ステップ150では、管理ブロック消去の前処理として、図9に示すように、あらかじめ定められた所定のエリア(本例ではエリア1とする)のブロック1、2のうち、使用中のブロック(使用中の旨のブロックステータス情報を有するブロック)であるブロック2の空き領域に、管理ブロック消去中データを記録する。なお、管理ブロック消去中データは、当該管理ブロック消去中データが有効である旨の有効データを含む。   In step 150, as pre-processing for management block erasure, as shown in FIG. 9, among the blocks 1 and 2 in a predetermined area (referred to as area 1 in this example), a block in use (in use) The management block erasing data is recorded in the empty area of the block 2, which is a block having block status information to the effect. The management block erasing data includes valid data indicating that the management block erasing data is valid.

続いてステップ160では、管理ブロックのデータ消去を実行する。具体的には、フラッシュコントローラ6に管理ブロックの消去命令を出力する。これにより、フラッシュコントローラ6は、管理ブロックのデータ消去を行い、データ消去が完了したら、その旨をCPU7に通知する。   In step 160, the management block data is erased. Specifically, a management block erase command is output to the flash controller 6. Thereby, the flash controller 6 erases the data in the management block, and when the data erase is completed, notifies the CPU 7 to that effect.

フラッシュコントローラ6からデータ消去完了の通知を受けた後、CPU7は、ステップ170に進んで、直前のステップ150で管理ブロックに書き込んだ管理ブロック消去中データを無効化する(図10参照)。具体的には、当該区別用データ中で、当該区別用データが有効である旨のデータを、無効である旨のデータに書き換える(これも1→0タイプの書き換えである)。ステップ170の後、図4の処理が終了する。   After receiving the data erasure completion notification from the flash controller 6, the CPU 7 proceeds to step 170 and invalidates the management block erasing data written in the management block in the immediately preceding step 150 (see FIG. 10). Specifically, in the data for discrimination, data indicating that the data for discrimination is valid is rewritten to data indicating that it is invalid (this is also a 1 → 0 type rewrite). After step 170, the process of FIG. 4 ends.

ここで、図4のステップ160で管理ブロックのデータ消去を行っている途中に、マイクロコントローラ1がリセットした場合について説明する。   Here, a case where the microcontroller 1 is reset while the management block data is being erased in step 160 of FIG. 4 will be described.

マイクロコントローラ1がリセットした場合、図11に例示するように、管理ブロックのデータ消去が途中で中断してしまうので、管理ブロックの記憶領域は、完全に消去された状態ではなく、中途半端に消去された状態になっている。   When the microcontroller 1 is reset, as illustrated in FIG. 11, the data erasure of the management block is interrupted halfway, so the storage area of the management block is erased halfway rather than completely erased. It is in the state that was done.

このような中途半端に消去された状態を解消するため、リセットから復帰後にCPU7実行する図8の処理では、ステップ250で、あらかじめ定められた所定のエリア1内で使用中のブロック2に、管理ブロック消去中データが含まれていると判定し、続いてステップ260に進む。   In order to eliminate such a halfway erased state, in the process of FIG. 8 executed by the CPU 7 after returning from the reset, in step 250, the block 2 in use in the predetermined area 1 is managed. It is determined that block erasing data is included, and then the process proceeds to step 260.

ステップ260では、管理ブロックのデータ消去を実行する。具体的には、フラッシュコントローラ6に管理ブロックの消去命令を出力する。これにより、フラッシュコントローラ6は、管理ブロックのデータ消去を行い、データ消去が完了したら、その旨をCPU7に通知する。   In step 260, the management block data is erased. Specifically, a management block erase command is output to the flash controller 6. Thereby, the flash controller 6 erases the data in the management block, and when the data erase is completed, notifies the CPU 7 to that effect.

フラッシュコントローラ6からデータ消去完了の通知を受けた後、CPU7は、ステップ270に進んで、上記管理ブロック消去中データを、図4のステップ170と同じ方法で無効化する。これにより、管理ブロックのデータ構成は、図10の状態に復帰する。ステップ270の後、図8の処理は終了する。   After receiving the notification of the completion of data erasure from the flash controller 6, the CPU 7 proceeds to step 270 and invalidates the management block erasing data in the same manner as in step 170 of FIG. Thereby, the data structure of the management block returns to the state shown in FIG. After step 270, the process of FIG. 8 ends.

このように、区別用データが記録された後、管理ブロックにこれ以上区別用データを書き込む空き領域がない場合、所定のエリアの使用中のブロック2に、所定の管理ブロック消去中データを書き込み、その後に、管理ブロックのデータ消去を行い、その後、管理ブロック消去中データを無効化する。そして、マイクロコントローラ1がリセットから復帰した後、上記ブロック2に管理ブロック消去中データが記録されていることに基づいて、管理ブロックのデータ消去を行い、その後、管理ブロック消去中データを無効化する。このようにすることで、管理ブロックのデータ消去時にリセットが発生した場合も、リセットから復帰した後にデータ消去できるようになる。   In this way, after the discrimination data is recorded, if there is no more free area to write the discrimination data in the management block, the predetermined management block erasing data is written to the block 2 in use in the predetermined area, Thereafter, the management block data is erased, and then the management block erasing data is invalidated. After the microcontroller 1 returns from the reset, the management block data is erased based on the fact that the management block erase data is recorded in the block 2, and then the management block erase data is invalidated. . In this way, even when a reset occurs when erasing data in the management block, the data can be erased after returning from the reset.

なお、上記実施形態においては、マイクロコントローラ1のCPU7が、ステップ110を実行することで消去前処理手段の一例として機能し、ステップ120を実行することで消去手段の一例として機能し、ステップ230を実行することで参照手段の一例として機能し、ステップ240を実行することで消去手段の一例として機能し、ステップ150を実行することで管理ブロック消去前処理手段の一例として機能し、ステップ160、260を実行することで管理ブロック消去手段の一例として機能し、ステップ170、270を実行することで管理ブロック消去中データ無効化手段の一例として機能する。   In the above embodiment, the CPU 7 of the microcontroller 1 functions as an example of the pre-erase processing unit by executing step 110, and functions as an example of the erasing unit by executing step 120. Execution functions as an example of a reference unit, execution of step 240 functions as an example of an erasure unit, execution of step 150 functions as an example of a management block erasure preprocessing unit, and steps 160 and 260 Is executed as an example of the management block erasing unit, and the steps 170 and 270 are executed as an example of the management block erasing data invalidating unit.

(他の実施形態)
以上、本発明の実施形態について説明したが、本発明の範囲は、上記実施形態のみに限定されるものではなく、本発明の各発明特定事項の機能を実現し得る種々の形態を包含するものである。例えば、以下のような形態も許容される。
(Other embodiments)
As mentioned above, although embodiment of this invention was described, the scope of the present invention is not limited only to the said embodiment, The various form which can implement | achieve the function of each invention specific matter of this invention is included. It is. For example, the following forms are also acceptable.

(1)上記実施形態においては、フラッシュメモリ5中のブロックは複数のエリアのいずれかに振り分けられているが、フラッシュメモリ5は、必ずしもこのように複数のエリアにエリア分けされていなくてもよい。   (1) In the above embodiment, the blocks in the flash memory 5 are allocated to any of a plurality of areas, but the flash memory 5 does not necessarily have to be divided into a plurality of areas in this way. .

(2)また、上記実施形態では、区別用データを記録する記憶媒体として、フラッシュメモリ5の管理ブロックを採用しているが、区別用データを記録する記憶媒体は、EEPROMでもよいし、他のフラッシュメモリ5以外のフラッシュメモリでもよい。つまり、区別用データを記録する記憶媒体は、不揮発性の記憶媒体なら、どのようなものであってもよい。なお、EEPROMを採用する場合、区別用データを無効にするためには、単純に当該区別用データを消去してもよい。   (2) In the above embodiment, the management block of the flash memory 5 is employed as the storage medium for recording the discrimination data. However, the storage medium for recording the discrimination data may be an EEPROM, A flash memory other than the flash memory 5 may be used. In other words, the storage medium for recording the discrimination data may be any nonvolatile storage medium. In the case of adopting an EEPROM, in order to invalidate the discrimination data, the discrimination data may be simply deleted.

(3)上記実施形態では、ステップ110で管理ブロックに書き込む区別用データは、エリア1内でデータの最新値が保存されたブロック2のブロックIDを含むようになっており、CPU7は、リセットから復帰時に、エリア1内で使用中の旨のブロックステータス情報を有する2つのブロック1、2のうち、当該区別用データ内の当該ブロックIDのブロック2ではない方のブロック1の消去を行うようになっている。   (3) In the above embodiment, the distinguishing data written to the management block in step 110 includes the block ID of the block 2 in which the latest value of the data is stored in the area 1. At the time of return, of the two blocks 1 and 2 having block status information indicating that they are in use in the area 1, the block 1 that is not the block 2 with the block ID in the discrimination data is deleted. It has become.

しかし、このようなものに限らず、本発明においては、ブロックステータス情報を有する2つのブロック1、2のうち、どちらが消去中でどちらがデータの最新値が保存されているかがわかればよい。   However, the present invention is not limited to this, and in the present invention, it is only necessary to know which of the two blocks 1 and 2 having block status information is erasing and which is storing the latest data value.

したがって、ステップ110で管理ブロックに書き込む区別用データは、エリア1内で消去対象のブロック1のブロックIDを含むようになっており、CPU7は、リセットから復帰時に、エリア1内で使用中の旨のブロックステータス情報を有する2つのブロック1、2のうち、当該区別用データ内の当該ブロックIDのブロック1の消去を行うようになっていても、結果は同じことになる。   Therefore, the distinguishing data written to the management block in step 110 includes the block ID of the block 1 to be erased in the area 1, and the CPU 7 is in use in the area 1 when returning from reset. Among the two blocks 1 and 2 having the block status information, the result is the same even if the block 1 with the block ID in the discrimination data is erased.

(4)上記実施形態では、CPU7およびフラッシュコントローラ6がブロック1のデータ消去を行うのは、ブロック2が満杯状態になった場合であったが、ブロック1のデータ消去のタイミングは、必ずしもこのようなものに限られない。例えば、アプリケーションがブロック1の消去要求を出力したことに基づいて、CPU7およびフラッシュコントローラ6がブロック1のデータ消去を行うようになっていてもよい。そして、そのようなデータ消去の場合でも、図3に示した処理を行うが、図3、図8の処理が終了したときにデータコピーは行わない。   (4) In the above embodiment, the CPU 7 and the flash controller 6 erase the data in the block 1 when the block 2 is full. However, the timing for erasing the data in the block 1 is not necessarily like this. Not limited to anything. For example, the CPU 7 and the flash controller 6 may perform data erasure of the block 1 based on the application outputting the erase request of the block 1. Even in the case of such data erasure, the processing shown in FIG. 3 is performed, but data copying is not performed when the processing in FIGS. 3 and 8 is completed.

(5)また、上記の実施形態において、CPU7がプログラムを実行することで実現している各機能は、それらの機能を有するハードウェア(例えば回路構成をプログラムすることが可能なFPGA)を用いて実現するようになっていてもよい。   (5) In the above embodiment, each function realized by the CPU 7 executing the program is performed using hardware having these functions (for example, an FPGA capable of programming a circuit configuration). It may be realized.

1 マイクロコントローラ
2 I/O
3 ROM
4 RAM
5 フラッシュメモリ
5a 管理ブロック
6 フラッシュコントローラ
7 CPU
1 Microcontroller 2 I / O
3 ROM
4 RAM
5 Flash memory 5a Management block 6 Flash controller 7 CPU

Claims (3)

フラッシュメモリ(5)内において個々にデータ消去の単位となる複数のブロックのうち、使用中である旨のブロックステータス情報を保持しているブロックに対して追記方式でデータの書き込みを行う制御装置であって、
前記複数のブロックのうち第1のブロックのデータ消去時に、消去対象の前記第1のブロックを特定可能な区別用データまたは前記複数のブロックのうちデータの最新値が保存されている第2のブロックを特定可能な区別用データを、不揮発性記憶媒体(5a)に書き込む消去前処理手段(110)と、
前記消去前処理手段(110)によって前記区別用データが記録された後、前記第1のブロックのデータ消去を行う消去手段(120)と、
前記制御装置がリセットから復帰した後、使用中である旨のブロックステータス情報を保持しているブロックが前記複数のブロック中で2個あったことに基づいて、前記不揮発性記憶媒体(5a)中の前記区別用データを参照する参照手段(230)と、
使用中である旨のブロックステータス情報を保持している前記2個のブロックのうち、前記参照手段(240)が参照した前記区別用データによれば消去対象となっている前記第1のブロックのデータ消去を行うか、または、前記参照手段(240)が参照した前記区別用データによればデータの最新値が保存されている前記第2のブロック以外のブロックのデータ消去を行う消去手段(240)と、を備えた制御装置。
A control device that writes data in a write-once mode to a block that holds block status information indicating that it is in use among a plurality of blocks that are individually erased in the flash memory (5). There,
The distinction data that can identify the first block to be erased when the data of the first block of the plurality of blocks is erased, or the second block in which the latest value of the data among the plurality of blocks is stored Erasure preprocessing means (110) for writing the distinguishing data capable of specifying the data into the nonvolatile storage medium (5a),
An erasing unit (120) for erasing data of the first block after the data for discrimination is recorded by the pre-erase processing unit (110);
In the nonvolatile storage medium (5a) based on the fact that there are two blocks in the plurality of blocks that hold the block status information indicating that the controller is in use after returning from reset. Reference means (230) for referring to the distinguishing data of
Of the two blocks holding block status information indicating that they are in use, according to the distinguishing data referred to by the reference means (240), the first block to be erased Erasing means (240) for erasing data or erasing data of blocks other than the second block in which the latest value of the data is stored according to the distinguishing data referred to by the reference means (240) And a control device.
フラッシュメモリ(5)内でエリア毎に複数個設けられて個々にデータ消去の単位となる複数のブロックのうち、各エリアにおいて使用中である旨のブロックステータス情報を保持しているブロックに対して追記方式でデータの書き込みを行う制御装置であって、
複数のブロックのうち第1のブロックの消去時に、消去対象の前記第1のブロックを特定可能な区別用データ、または、前記第1のブロックと同じ第1のエリアに属する他のブロックのうちデータの最新値が保存されている第2のブロックを特定可能な区別用データを、不揮発性記憶媒体(5a)に書き込む消去前処理手段(110)と、
前記消去前処理手段(110)によって前記区別用データが記録された後、前記第1のブロックを消去する消去手段(120)と、
前記制御装置がリセットから復帰した後、使用中である旨のブロックステータス情報を保持しているブロックが前記第1のエリア内に2個あったことに基づいて、前記不揮発性記憶媒体(5a)中の前記区別用データを参照する参照手段(230)と、
使用中である旨のブロックステータス情報を保持している前記第1のエリア内の前記2個のブロックのうち、前記参照手段(240)が参照した前記区別用データによれば消去対象となっている前記第1のブロックのデータ消去を行うか、または、前記参照手段(240)が参照した前記区別用データによればデータの最新値が保存されている前記第2のブロック以外のブロックのデータ消去を行う消去手段(240)と、を備えた制御装置。
Among a plurality of blocks provided for each area in the flash memory (5) and individually serving as a data erasing unit, a block holding block status information indicating that the area is in use A control device for writing data by a write-once method,
Discrimination data that can identify the first block to be erased when erasing the first block among a plurality of blocks, or data among other blocks belonging to the same first area as the first block Pre-erase processing means (110) for writing, in the nonvolatile storage medium (5a), the distinguishing data that can identify the second block in which the latest value of
An erasing unit (120) for erasing the first block after the identification data is recorded by the erasing preprocessing unit (110);
After the controller returns from reset, the nonvolatile storage medium (5a) is based on the fact that there are two blocks in the first area that hold block status information indicating that they are in use. Reference means (230) for referring to the distinguishing data therein,
Of the two blocks in the first area holding the block status information indicating that they are in use, the distinction data referred to by the reference means (240) is to be erased. The data of the block other than the second block in which the latest value of the data is stored according to the data for discrimination referred to by the reference means (240) is deleted. An erasing means (240) for erasing.
前記不揮発性記憶媒体(5a)は、フラッシュメモリにおいてデータ消去の単位となる管理ブロックであり、
前記消去前処理手段(110)によって前記区別用データが記録された後、前記管理ブロックにこれ以上区別用データを書き込む空き領域がない場合、前記複数のブロックのうち1つのブロックに、所定の管理ブロック消去中データを書き込む管理ブロック消去前処理手段(150)と、
前記管理ブロック消去前処理手段(150)によって前記管理ブロック消去中データが書き込まれた後、前記管理ブロックのデータ消去を行う管理ブロック消去手段(160、260)と、
前記管理ブロック消去手段が前記管理ブロックのデータ消去を行った後、前記管理ブロック消去中データを無効化する管理ブロック消去中データ無効化手段(170、270)と、
前記管理ブロック消去手段(160)は、前記制御装置がリセットから復帰した後、前記1つのブロックに前記管理ブロック消去中データが記録されていることに基づいて、前記管理ブロックのデータ消去を行うことを特徴とする請求項1または2に記載の制御装置。
The nonvolatile storage medium (5a) is a management block that is a unit of data erasure in the flash memory,
After the discrimination data is recorded by the pre-erase processing means (110), if there is no more free space to write the discrimination data in the management block, one block among the plurality of blocks has a predetermined management Management block erasure preprocessing means (150) for writing data during block erasure;
Management block erasing means (160, 260) for erasing data of the management block after the management block erasing data is written by the management block erasing preprocessing means (150);
Management block erasing data invalidating means (170, 270) for invalidating the management block erasing data after the management block erasing means erases the data of the management block;
The management block erasing means (160) performs data erasure of the management block based on the fact that the management block erasing data is recorded in the one block after the control device returns from reset. The control device according to claim 1, wherein:
JP2011131244A 2011-06-13 2011-06-13 Control device for writing data in flash memory Pending JP2013003655A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2011131244A JP2013003655A (en) 2011-06-13 2011-06-13 Control device for writing data in flash memory

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2011131244A JP2013003655A (en) 2011-06-13 2011-06-13 Control device for writing data in flash memory

Publications (1)

Publication Number Publication Date
JP2013003655A true JP2013003655A (en) 2013-01-07

Family

ID=47672199

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2011131244A Pending JP2013003655A (en) 2011-06-13 2011-06-13 Control device for writing data in flash memory

Country Status (1)

Country Link
JP (1) JP2013003655A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
DE102013208990A1 (en) 2012-05-17 2013-11-21 Denso Corporation gas sensor
US9659658B2 (en) 2014-05-13 2017-05-23 Samsung Electronics Co., Ltd. Nonvolatile memory device, storage device including the nonvolatile memory device, and operating method of the storage device

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH10134586A (en) * 1996-10-23 1998-05-22 Sharp Corp Nonvolatile semiconductor memory device
JP2000222292A (en) * 1999-02-04 2000-08-11 Nec Saitama Ltd Data managing method utilizing flash memory
JP2001101087A (en) * 1999-09-29 2001-04-13 Sharp Corp Memory and memory controlling method
JP2001210084A (en) * 1999-12-22 2001-08-03 Texas Instr Inc <Ti> Power interruption processing system for non-volatile memory and method
JP2001250388A (en) * 2000-03-06 2001-09-14 Fujitsu Ltd Non-volatile memory storing erasion operation information
JP2002312253A (en) * 2001-04-17 2002-10-25 Denso Corp Portable information terminal device
JP2003150441A (en) * 2001-11-14 2003-05-23 Nippon Telegr & Teleph Corp <Ntt> Data management method, device thereof, data management program, and storage medium storing data management program
JP2003187585A (en) * 2001-11-23 2003-07-04 M-Systems Flash Disk Pioneers Ltd Method for detecting partially erased unit in flash device
JP2004118937A (en) * 2002-09-26 2004-04-15 Renesas Technology Corp Nonvolatile memory and data storage device having the same
JP2010134822A (en) * 2008-12-08 2010-06-17 Riso Kagaku Corp Semiconductor memory device

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH10134586A (en) * 1996-10-23 1998-05-22 Sharp Corp Nonvolatile semiconductor memory device
JP2000222292A (en) * 1999-02-04 2000-08-11 Nec Saitama Ltd Data managing method utilizing flash memory
JP2001101087A (en) * 1999-09-29 2001-04-13 Sharp Corp Memory and memory controlling method
JP2001210084A (en) * 1999-12-22 2001-08-03 Texas Instr Inc <Ti> Power interruption processing system for non-volatile memory and method
JP2001250388A (en) * 2000-03-06 2001-09-14 Fujitsu Ltd Non-volatile memory storing erasion operation information
JP2002312253A (en) * 2001-04-17 2002-10-25 Denso Corp Portable information terminal device
JP2003150441A (en) * 2001-11-14 2003-05-23 Nippon Telegr & Teleph Corp <Ntt> Data management method, device thereof, data management program, and storage medium storing data management program
JP2003187585A (en) * 2001-11-23 2003-07-04 M-Systems Flash Disk Pioneers Ltd Method for detecting partially erased unit in flash device
JP2004118937A (en) * 2002-09-26 2004-04-15 Renesas Technology Corp Nonvolatile memory and data storage device having the same
JP2010134822A (en) * 2008-12-08 2010-06-17 Riso Kagaku Corp Semiconductor memory device

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
DE102013208990A1 (en) 2012-05-17 2013-11-21 Denso Corporation gas sensor
US9659658B2 (en) 2014-05-13 2017-05-23 Samsung Electronics Co., Ltd. Nonvolatile memory device, storage device including the nonvolatile memory device, and operating method of the storage device

Similar Documents

Publication Publication Date Title
KR100453053B1 (en) Flash memory file system
JP3692313B2 (en) Nonvolatile memory control method
US6839823B1 (en) Increased reliability of data stored on flash memory in applications sensitive to power-loss
US5832493A (en) Flash file management system
KR100725390B1 (en) Apparatus and method for storing data in nonvolatile cache memory considering update ratio
US20070043900A1 (en) Flash memory management method and flash memory system
US20080126712A1 (en) Semiconductor memory system having a snapshot function
US20100241819A1 (en) Controller and memory system
JP2005242897A (en) Flash disk drive
KR100370893B1 (en) Flash memory unit and control method of flash memory
JP2010020586A (en) Data processing device
CN109669889B (en) Light Nor Flash control method and device
US6510495B1 (en) Data write method into nonvolatile memory, information processing device and recording medium
JP2010287049A (en) Memory system and memory system management method
JP2009205689A (en) Flash disk device
JP4242245B2 (en) Flash ROM control device
JP4175881B2 (en) Nonvolatile memory storage method and storage device
JP5541194B2 (en) Control device for reading and writing data to flash memory
JP2013003655A (en) Control device for writing data in flash memory
JP4661369B2 (en) Memory controller
JPH06349286A (en) Writing controller and control method for flash memory
JP4794530B2 (en) Semiconductor device and mobile phone
JPH11272569A (en) Data restoration system for outer storage device using flash memory
JP5491201B2 (en) Semiconductor recording apparatus and semiconductor recording system
JP3904182B2 (en) Data management system and data management method using the same

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20140326

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20140912

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20140924

A02 Decision of refusal

Free format text: JAPANESE INTERMEDIATE CODE: A02

Effective date: 20150203