JP3727983B2 - Electronic camera - Google Patents

Electronic camera Download PDF

Info

Publication number
JP3727983B2
JP3727983B2 JP25124195A JP25124195A JP3727983B2 JP 3727983 B2 JP3727983 B2 JP 3727983B2 JP 25124195 A JP25124195 A JP 25124195A JP 25124195 A JP25124195 A JP 25124195A JP 3727983 B2 JP3727983 B2 JP 3727983B2
Authority
JP
Japan
Prior art keywords
data
sector
flash rom
writing
area
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.)
Expired - Fee Related
Application number
JP25124195A
Other languages
Japanese (ja)
Other versions
JPH0993523A (en
Inventor
武志 小川
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.)
Canon Inc
Original Assignee
Canon Inc
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 Canon Inc filed Critical Canon Inc
Priority to JP25124195A priority Critical patent/JP3727983B2/en
Priority to US08/710,946 priority patent/US5933847A/en
Publication of JPH0993523A publication Critical patent/JPH0993523A/en
Priority to US09/350,188 priority patent/US6604168B2/en
Application granted granted Critical
Publication of JP3727983B2 publication Critical patent/JP3727983B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Landscapes

  • Read Only Memory (AREA)
  • Memory System (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Description

【0001】
【発明の属する技術分野】
本発明は、フラッシュROMへデータ記憶が可能な電子カメラに関する。
【0002】
【従来の技術】
電子カメラにおいて、撮影して得られた画像データは内蔵するDRAM、あるいは外付けのメモリカード等の記憶媒体に保存するが、これらの記憶媒体は電力供給を遮断すると記憶内容が消滅してしまうため、電池などで常時バックアップする必要がある。また、記憶内容の保持に電気的なバックアップが不要な記憶媒体としては、磁気ディスクが挙げられるが、磁気ディスク装置は比較的大きいため、電子カメラの携帯性を損なうことになる。また、記憶内容の保持に電気的バックアップが不要な記憶媒体として、書き換えが可能なROM、即ちフラッシュROMがある。
【0003】
フラッシュROMは現在いろいろなタイプのものがあるが大きく分けてフラッシュDISK用に開発されたタイプとパーソナルコンピュータのBIOS用に開発されたものがある。
【0004】
前者は消去単位がハードディスクで一般的な512バイトであり、ファイルシステムとの整合性が非常に良い。後者のフラッシュROMは消去単位が例えば64Kなどといった大きなブロック単位でしか行えない様になっている。また、PROMの様に書き込み電圧として12V等の電圧が必要なものもある。後者のフラッシュROMの方が安価に入手できるがファイルシステムとの整合性が悪い為に特に小容量の記録メディアとしては使う事が出来なかった。
【0005】
【発明が解決しようとする課題】
以上のように、BIOS用に設計されたフラッシュROMは、その消去単位が大きく、ファイルシステムとの整合性が悪いが、安価で入手しやすい。従って、そのようなフラッシュROMをファイルシステムに適用できれば、記憶保持用の電源が不要で、安価で小容量、小型の記録メディアを提供することができ、電子カメラの記憶媒体としては都合が良い。
【0006】
本発明は、上記問題に鑑みてなされたものであり、消去単位の大きいフラッシュROMをファイルシステムと適合させることを可能とした電子カメラを提供することを目的とする。
【0007】
【課題を解決するための手段】
上記の目的を達成するための本発明の電子カメラは以下の構成を備える。即ち、
データをフラッシュROMに保存する電子カメラであって、
前記フラッシュROM内の消去単位である消去ブロックにおいて、有効なデータが書き込まれた領域の内容を当該消去ブロック外へ移動させる移動手段と、
前記移動手段の実行の後に前記消去ブロックの消去動作を行う消去手段と、
セルフタイマー撮影を行うためのタイマー手段とを備え、
前記移動手段及び消去手段の実行を前記タイマー手段による時間の計測中に実行する。
また、好ましくは、前記フラッシュROMに形成された、複数のデータ領域、及び各データ領域に対応する管理領域と、
データの書込み先を示す指定情報を伴う書込み指示を受けて、前記複数のデータ領域のうちの一つのデータ領域にデータを書き込むと共に、該指定情報を該データ領域に対応する管理領域に書き込む書込み手段と、
データの読み出し元を示す指定情報を伴う読出し指示を受けて、該指定情報が格納された管理領域を検索し、検索された管理領域に対応するデータ領域に格納されたデータを読み出す読出し手段とを更に備える。
【0008】
また、好ましくは、前記管理領域は、対応するデータ領域に書込みが可能であることを示す未使用状態と、データ領域に書き込まれたデータが有効であることを示す使用中状態と、データ領域に書き込まれたデータが無効であることを示す使用済状態の少なくとも3通りの状態のいずれかを示す状態情報を格納し、前記書込み手段は、状態情報が未使用状態となっている管理領域を検索して検索された管理領域及びこれに対応するデータ領域に前記指定情報及びデータを書き込み、該管理領域の状態情報を使用中に変更する。各データ領域について使用中、使用済、未使用の3状態を示すことにより、状態情報をチェックすることでデータの書込みが可能な領域、有効なデータが存在する領域を把握でき、電子カメラにおけるフラッシュROMの記憶管理をより適切に行えるからである
また、好ましくは、前記書込み手段は、前記書き込み指示に伴う指定情報を有する管理領域を検索し、検索された管理領域の状態情報を使用済状態に変更する。ある指定情報で特定されるデータ領域の内容を更新した場合に、更新前のデータ(即ち不要なデータ)であることを明示でき、電子カメラにおけるフラッシュROMの適切な記憶管理が行えるからである。
【0009】
また、好ましくは、前記移動手段は、フラッシュROM内の消去単位である消去ブロックにおいて、状態情報が使用中状態である全ての管理領域を検索し、検索された管理領域及び対応するデータ領域の内容を当該消去ブロック外へ移動させる
【0011】
また、好ましくは、電源の使用を管理する電源管理手段を更に備え、前記電源管理手段は、ストロボ充電、機構部分の駆動あるいはCCD駆動の少なくともいずれかに用いられる電源の電力を前記フラッシュROMへの書込みアクセスに割り振る。すろと簿充電や、機構部分の駆動、CCD駆動等に用いられる電源を、フラッシュROMの書込みアクセスに用いることができ、フラッシュROMへの書込み専用の電源を用意する必要が無くなるからである。
【0012】
前記電源管理手段は、前記電源による電力の供給を、前記ストロボ充電、機構部分の駆動、CCDの駆動、前記フラッシュROMの書込み処理に対して時分割に割り当てる。時分割で電源を割り当てるので、短い保留時間の後に必ず電源を確保できるようになり、各種動作の処理がスムーズに実行される。
【0013】
【発明の実施の形態】
以下に添付の図面を参照して本発明の実施の形態を説明する。
【0014】
[実施形態1]
<カメラシステムの構成>
図1は実施形態1におけるカメラシステムの構成を表すブロック図である。本カメラシステムは、電子カメラと、これに着脱可能な外部記憶媒体17、PC通信インターフェース19、及びPC通信インターフェース19を介して電子カメラと通信可能に接続されたパーソナルコンピュータ22から構成される。
【0015】
1はレンズであり、2はレンズ1を通った光を電気信号として出力するCCDユニットである。3はA/Dコンバータであり、CCDユニット2からのアナログ信号をデジタル信号へ変換する。4はSSGユニットであり、CCDユニット2とA/Dコンバータ3に同期信号を供給する。5はCPUであり、本カメラシステムにおける各種の制御を実現する。
【0016】
6は信号処理アクセラレータであり、信号処理を高速に実現する。7は電池であり、8は、電池7よりの電力を電子カメラ全体へ供給するためのDC/DCコンバータである。9は電源コントローラユニットであり、DC/DCコンバータ8をコントロールする。10はパネル操作・表示装置・電源のコントロールを行うマイクロコンピュータである。11はユーザへ各種の情報を表示する表示装置であり、液晶パネル等が用いられる。12はコントロールパネルであり、ユーザが直接操作するレリーズスイッチを含む。
【0017】
13はROMであり、OS等のシステムプログラムを格納する。14はDRAMであり、本電子カメラの主記憶である。15はフラッシュROMであり、内蔵記憶媒体として使用する。16はPCMCIAカードのインタフェース部、17はATAハードディスクなどの外部記憶媒体、18は拡張バスインタフェースである。19はPC通信インタフェースであり、パーソナルコンピュータ等を接続してデータの授受を行う。20はDMAコントローラ、21はストロボである。また、22はパーソナルコンピュータであり、PC通信インターフェース19を介して、電子カメラとの通信を行う。
【0018】
<撮影動作>
この電子カメラの撮影時の動作を簡単に説明する。コントロールパネル12のレリーズスイッチをユーザが押すと、CPU5がそのことを検出して撮影シーケンスを開始する。以下の動作は全てCPU5によるコントロールで行われることを前提とする。
【0019】
さて、レリーズスイッチの押下により、SSG4がCCD2を駆動する。CCD2から出力されるアナログ信号は、A/Dコンバータ3でデジタル信号へ変換される。A/Dコンバータ3の出力は、DMAコントローラ20によってDRAM14へDMA転送される。1フレーム分のDMA転送が終了した時点でCPU5は、信号処理シーケンスを開始する。
【0020】
信号処理シーケンスでは、フラッシュROM15から信号処理プログラムを主記憶(DRAM14)上に読み出し、主記憶上のデータを信号処理アクセラレータ6へ転送し信号処理を行う。但し、信号処理アクセラレータ6は信号処理の全てを行うわけではなく、CPU5で行う処理の特に時間のかかる処理などを助ける演算回路であり、CPU5の処理ソフトウェアと連携して動作する。信号処理の一部または全部が終了すると画像ファイルとしてフラッシュROM15へ記録する。この時記録するファイルフォーマットが圧縮処理を必用とするのであれば圧縮も行う。
【0021】
信号処理プログラムは、フラッシュROM15の中でファイルシステムが管理するファイルの1つである。カメラのプログラムはOSやファイルシステムといっしょにROM13に納められている。カメラのプログラムは、特定のファイル名のファイルをプログラムであると認識する。
【0022】
フラッシュROM15の中でファイルは不連続に配置されている上に、本実施形態のファイルシステムが頻繁に再配置を行うため、、フラッシュROM15内の制御プログラムををCPUが直接実行することはできない。従って、主記憶(DRAM14)に読み出して実行させなければならない。更に、主記憶はメモリマネージャが動的に記憶場所をアロケーションするため、、特定のアドレスに格納されることを想定したソフトウエアであってはならない。そのため、本実施形態で信号処理を行うプログラムのファイルは図41のような形式となっている。
【0023】
図41は本実施形態におけるフラッシュROMへの制御プログラムの格納状態を説明する図である。図41において、識別コードはファイルがプログラムであることを確認するためのコードである。ファイルは可変長のレコードの集合として表現されている。レコードには、始めに当該レコードに格納されている情報の種類を識別するIDがあり、次にそのレコードの大きさを示す値が格納されている。
【0024】
そして、プログラムのレコードとリロケーション情報のレコードがファイルに格納されている。プログラムコードは例えば図42のようなデータである。図42は相対アドレスで表現されたプログラムコードの一例を表す図である。図42では、0050番地にジャンプ命令があるが、CPUはこの命令を絶対番地へのジャンプ命令と認識する。この命令のオペランドは相対アドレスで表現されている。
【0025】
図42のリロケーション情報レコードのデータは図43のような形式で納められている。即ち、図42のプログラムの中で、絶対番地へ変換しなければならないデータ(相対アドレス表現になっているデータ)のプログラム番地を示すアドレステーブルがリロケーション情報として格納される。
【0026】
図41のファイルを主記憶にロードするための領域を確保すると、ROM13のOSのメモリマネージャがアドレスを決定する。メモリマネージャのアロケーションはC言語ではalloc関数に相当する機能である。メモリマネージャがプログラム用に8710番地を割り当てた場合図44のようにプログラムがロードされる。図44は図41のプログラムを主記憶の8710番地へマッピングした場合のプログラムコードを示す図である。ジャンプ命令のオペランドが実際の絶対番地に置き換えられている。この実アドレスへの変換をしながらプログラムを主記憶へ読み出すと言う作業を行うプログラムはROM13に格納されている。
【0027】
以上のように構成することにより、記憶媒体に信号処理ソフトウエアや圧縮ソフトウエアをファイル形式で格納することができる。その結果、カメラが最終ユーザの元へ届いてから、新しい信号処理アルゴリズムや、Windoiws(商標)のBMP形式やTIFF形式、あるいは将来新たに登場する形式等、多種多様なファイル形式への対応が可能となる。
【0028】
以上の様に、本実施形態1における電子カメラは、撮影画像をフラッシュROM15へファイルするものである。
【0029】
<デバイスドライバインタフェース>
図2は、本実施形態の電子カメラにおけるファイルシステムの階層構造を表す図である。最上位の層がユーザアプリケーション101である。ユーザアプリケーション101は電子カメラの内部で動くソフトウェアであり、ファイルをファイル名でオープンして読み書きした後クローズする。
【0030】
ユーザアプリケーション101から直接ファンクションコールによって呼び出されるのがファイルシステムAPI層102である。このファイルシステムAPI層102がドライブ名とファイルシステムを関連付けて管理している。各ドライブ毎にファイルシステムアーキテクチャ層をマウントする用に構成しているため、複数のファイルシステムアーキテクチャを混在させる事が可能となっている。
【0031】
ファイルシステムアーキテクチャ層103が実際のファイル管理を行う部分である。最下位の層がブロックデバイス層104である。ファイルシステムアーキテクチャ層103がブロックデバイス層104の提供するサービスを利用してファイル入出力を実現している。このブロックデバイス層104では、データをセクタという単位で管理しており、1セクタは例えば512バイトである。このブロックデバイス層104でデバイスごとの入出力制御の違いと、ヘッドやシリンダなどパラメータの違いを吸収している。このように構成しているため、同時に複数の種類のデバイスを混在させることができる。
【0032】
本実施形態の電子カメラでは、特にブロックデバイス層104におけるフラッシュROMの記憶管理方法に特徴を有する。
【0033】
図1で示したフラッシュROM11には、現在いろいろなタイプのものがあるが、大きく分けてフラッシュDISK用に開発されたタイプとパーソナルコンピュータのBIOS用に開発されたタイプがある。前者は消去単位がハードディスクで一般的な512バイトであり、ファイルシステムとの整合性が非常に良い。後者のフラッシュROMは消去単位が例えば64kなどといった大きなブロック単位でしか行えない様になっている。また、PROMの様に書き込み電圧として12V等の電圧が必要なものもある。しかしながら、後者のタイプのフラッシュROMは安価で入手が容易である。本実施形態では、後者の様な特徴を持つフラッシュROMでありながらファイルシステムに対してハードディスク同様のサービスを提供する。
【0034】
<フラッシュROMドライバインタフェース>
一般的にブロックデバイスがファイルシステムへ提供するサービスは以下の2つである。即ち、
(1)ロジカルセクタナンバーで指定したセクタからの読み出し
(2)ロジカルセクタナンバーで指定したセクタからの書き込み
である。そして、これに加えて
(3)ロジカルセクタナンバーで指定したセクタの開放
の機能があれば、フラッシュROMのドライバは必要に応じて不要なセクタを消去することが可能となるため、効率良くフラッシュROMを消去することができる。
【0035】
(3)に挙げた機能は、通常のDISKでは必要のない機能だが、キャッシュを持ったシステムだと、積極的にキャッシュリストから削除できるので、結果的にキャッシュのヒット率を上げる効果がある。ファイルシステムは、ファイルの消去等で不必要となったセクタを(3)の機能を用いてデバイスドライバへ通知する。フラッシュROMの消去は非常に時間がかかる処理だが、CPU時間をほとんど消費しないためバックグランド処理で行うのが良い。
【0036】
後述の<FATキャッシュ>においても説明するが、本実施形態のキャッシュは、新しいデータ(キャッシュ上に無いデータ)をアクセスする場合にキャッシュリストの中で最も古いデータを廃棄する。不要セクタをキャッシュリストの最後へ移動させる(即ち、最も古くアクセスしたデータがキャッシュの後ろへ移動する)ことで有効なデータがキャッシュから廃棄される可能性が低くなる。特にコンパイラー等の中間ファイルを多く生成するシステムでは、消去すべき中間ファイルがキャッシュに残っている可能性が高く、上記のキャッシュ管理はヒット率の向上に非常に有効である。
【0037】
図3は、デバイスドライバの管理ブロックをC言語で記述した宣言文を示す図である。構造体のNextは、次のデバイスへのリングポインタであり、メモリ中のデバイスを検索する目的で使用される。DevNameは、デバイスの名前として使用される。InitDevは、デバイスの初期化ルーチンへのポインタである。ShutDownは、デバイスのシャットダウンルーチンへのポインタである。ReadSectorは、ロジカルセクタを指定して媒体の内容をバッファへ転送するルーチンへのポインタである。WriteSectorは、ロジカルセクタを指定してバッファの内容を媒体へ転送する(書き込む)プログラムへのポインタである。ReleaseSectorはロジカルセクタを指定して、セクタを解放するルーチンへのポインタである。
【0038】
ファイルシステムは、この構造体を仲介してデバイスドライバを利用することになる。固定ディスクやフロッピーディスクの場合、ReleaseSectorには何も仕事をしないプログラムへのポインタが代入されている。または、ディスクキャッシュのキャッシュリストから指定セクタを削除するポインタでもよい。
【0039】
<フラッシュROM管理方法>
フラッシュROMに対するデータ書き込みは、上位層のファイルシステムからセクタ単位で行われる。図4は、フラッシュROM上のセクタ構造の例を示す図である。図4において、151はイレースブロックである。このイレースブロック151は消去の単位であり、フラッシュROMの技術用語ではセクタと呼ばれるものである。しかしながら、ファイルシステムが扱う単位である“論理セクタ”と区別する為に、ここではイレースブロックと呼ぶことにする。
【0040】
図4によれば、システム中に複数のフラッシュROM15が搭載されていて、各フラッシュROM15は複数のイレースブロック151によって構成される。更に、各イレースブロック151は消去回数カウンタ152と複数のセクタ153によって構成されている様子をあらわしている。消去回数カウンタ152は、イレースブロック151を消去した回数をカウントする為に用いる部分である。各セクタ153は、管理領域とデータ領域とを有する。管理領域は、論理セクタ番号を表すセクタ番号154と、セクタが有効利用されているかどうかを表わす使用中フラグ155と、セクタとしての利用が終了したことを表わす使用済みフラグ156とで構成される。また、データ領域は、512バイトのデータ部157によって構成されている。
【0041】
データ領域と管理領域は、隣り合って配置する必要は無く、図5の様にまとめて管理することも考えられる。図5は、管理領域用データと、データ領域とを分離して格納する構成を表す図である。セクタ番号テーブルには、複数のセクタ153の各セクタ番号154が格納される。また、フラグテーブルには、使用中フラグ155、使用済みフラグ156が格納される。更に、データテーブルには、データ部157の内容が格納される。以上のようなデータ構成をとることも可能であるが、少なくとも管理領域と、これに対応するデータ領域とは同じイレースブロック内に納めるのが好ましい。
【0042】
なお、システムは「使用中フラグ155」より「使用済みフラグ156」の方を優先的に評価する。図6は、各フラグの状態に対応した意味を示す図である。図中、FALSEは、消去後の状態と同じ値をとる。使用中フラグ155がTRUEであっても、使用済みフラグ156がTRUEであれば、当該セクタのデータは無効である。
【0043】
<フラッシュROMの論理セクタ書き換え>
フラッシュROMはPROM同様、データを書き換える為に、一度消去してから再書き込みをしなければならない。しかも、消去の最少単位が大きく(例えば64kバイト)消去時間が長い(例えば1秒)。そこで上位層のファイルシステムが、特定のセクタを書き換えようとした場合、消去済みの領域へ論理セクタを移動させることで、消去動作をせずに、見かけ上で論理セクタのデータ書き換えを実現する。
【0044】
図7はセクタの書き換え手順を説明する図である。同図を用いて、8番セクタ(論理セクタ番号が8のセクタ)の書き換えを例にして詳しく説明する。図7中、左側が書き換え前の状態であり((a)の状態)、右側が書き換え後の状態((b)の状態)である。また、図7において、管理領域中の数字は論理セクタ番号を表し、(使用中)は使用中フラグ155がTRUEで使用済みフラグ156がFALSEの状態、(使用済)は使用中フラグ155と使用済みフラグ156が共にTRUEの状態を示す。
【0045】
“セクタ番号8(使用中)”の場所に、8番セクタのデータが格納されている。今、8番セクタがFATやファイルの一部として利用されていて、その内容を変更したい場合に上位層から8番セクタの書き換え要求が発生したとする。書き換え要求が発生すると、フラッシュROMのデバイスドライバは、フラッシュROMの未使用セクタを検索し、その場所を新たな8番セクタの場所としてセクタ番号と更新後のデータを格納し、使用中フラグをTRUEにする。次に、以前8番セクタだったセクタの使用済みフラグをTRUEにする。このような手順で8番セクタのデータの書き換えが実現される。
【0046】
<ガベージコレクション>
以上の様な方法で論理セクタの書き換えを実行していくと、いずれフラッシュROMのほとんどの領域を“使用済セクタ”にしてしまうことになる。そこであるタイミングでフラッシュROMを一旦消去して“使用済セクタ”を“未使用セクタ”へ戻す必要がある。基本的なガベージコレクションの動作を図8を用いて説明する。図8は、本実施形態におけるフラッシュROMのガベージコレクション動作を説明する図である。
【0047】
図中(A)は、ガベージコレクション前の状態である。説明を簡単にするために、本例のフラッシュROMはセクタ6個分の大きさのイレースブロックで構成されているものとする。イレースブロック(1)には使用済セクタが3個と使用中セクタが3個あり、消去回数は5回である(消去回数カウンタ152の内容が5である)。イレースブロック(2)には使用中セクタが1個、使用済セクタが1個、未使用セクタが4個あり、消去回数は9回である。この状態からガベージコレクションを開始する。
【0048】
先ず、調整対象イレースブロックを選定する。ここで調整対象イレースブロックは消去を行う対象としてイレースブロックとなる。整理対象イレースブロックの選定は、使用済セクタをたくさん含むイレースブロックから優先的に選択すると整理効率が良い。しかし使用済セクタを含まない場合を別として消去回数の少ないイレースブロックを優先的に整理対象とする方法を取ればチップ内のイレースブロックを平均的に使用することができ、書き換え耐久を分散させることができる。選択手順の詳細についてはフローチャートを用いて後述する。
【0049】
今、イレースブロック(1)が整理対象として選定されたとする。次に、整理対照であるイレースブロック(1)の使用中セクタ(使用中フラグがTRUEで、使用済みフラグがFALSEのセクタ)を他のイレースブロックに移動させる。使用中セクタの移動手順は、セクタの書き換え時と同様に、他のイレースブロック中の未使用セクタを検索して、使用中セクタ内のデータ領域と管理領域の内容をコピーし、移動元の使用中セクタの使用済みフラグをTRUEにする。なお、未使用セクタが無い場合の処理は、後で述べる。
【0050】
図8の(B)は、イレースブロック(1)の使用中セクタをすべてイレースブロック(2)へ移動させた状態である。この結果、イレースブロック(1)には、使用済セクタしか存在しないことになる。
【0051】
次に、使用済セクタだけで構成されているイレースブロックを検索する。ここで、検索を行うのは、通常の書き換え動作の際に偶然イレースブロック内のセクタが全て使用済セクタとなっている場合があるからである。続いて検索されたイレースブロックに対して消去を行う。消去には時間がかかるが、複数のイレースブロックを同時に消去できるため、できるだけ一度に複数のイレースブロックを消去するのが良い。消去が終了すると消去回数カウンタへ消去前の値+1したものを書く。これでガベージコレクション完了である。
【0052】
図8の(C)がガベージコレクション終了時の状態である。イレースブロックをできるだけ同時に消去した方が効率が良いため、使用済セクタと未使用セクタがある限りたくさんのイレースブロックを同時に調整すると良い。極端に消去回数カウンタの値が他のイレースブロックより少ないものがあれば、使用済セクタを含んでいなくても整理さえすれば、書き換え耐久の分散を図れる。また、一度整理するとデータの配列が変わる為、書き換え耐久分散のきっかけとなる。
【0053】
<未使用セクタがない場合>
次にシステム中に使用済セクタが有るにもかかわらず未使用セクタが全く無くなってしまった場合のガベージコレクション手順を図9を使って説明する。図9は、未使用セクタが存在しない場合のガベージコレクションの動作を説明する図である。
【0054】
先ず、上述した基本的なガベージコレクション手順に従い、イレースブロック(1)を整理対象として選択する。次にイレースブロック(1)の使用中セクタを移動する為の未使用セクタを検索する。未使用セクタがある場合は、上述の基本的ガベージコレクションと同様にセクタの移動を行う。
【0055】
一方、検索の結果、未使用セクタが無ければ、DRAM14のヒープエリアからデータの退避に必要な大きさのメモリブロックをアロケーションする。そして調整対象イレースブロック内の使用中セクタをDRAM14へコピーする。この場合は、フラッシュROMの別の領域へセクタを移動する場合と違い、元のセクタの使用済フラグをTRUEにしない。なぜならこの時点で電子カメラの電池7が外れるなどの事故が起こった場合に、DRAM内のデータが消滅してしまい、データの修復ができなくなるからである。図9の(B)は、DRAM14の領域へコピーされたセクタを表現している。調整対象のイレースブロックの使用中セクタをすべて退避出来たら、その調整対象のイレースブロックを選択して消去する(図9の(C)参照)。消去が終わった後は未使用セクタがたくさん出来ているはずである。よって、次に未使用領域を検索してDRAM14へ待避してあったデータを復元する。図9の(D)は、ガベージコレクションが完了した状態を示している。
【0056】
上記の手順でガベージコレクションをした場合でも、イレースブロックを消去してからデータを復元するまでの間に電子カメラの電池7が外れるなどの事故が起こったらデータの修復をすることはできない。つまり、セクタのデータをDRAM14に退避する方法はできる限り取らない方が、よりシステムの安全性を保つことができる。一回、DRAMを使ってガベージコレクションを行えば未使用セクタができる。したがって、1度DRAM14を使ったガベージコレクションを行い、その後に通常のガベージコレクションを行えば、消去時間は余分にかかるが安全性を高めることができる。逆にDRAM14への退避を積極的に行う(例えばヒープ領域がある限り退避する)と、同時に整理できるイレースブロックが増える為効率を上げることができる。従って、安全性と効率のどちらを優先するかを指定できるように構成してもよい。またシステムの電源が電池7より供給されている場合は安全性優先、ACアダプタから供給されている場合は効率優先に自動的に切り替わるように構成してもよい。本処理については図36を参照して後述する。
【0057】
<イレースブロックを余分に1つ用意>
残り容量が極端に少なくなるとガベージコレクションが多発してシステムのパフォーマンスが極端に落ちる。総論理セクタ分を格納できるイレースブロック数よりも1つだけ余分にイレースブロックを使用すれば、そのような事態を避けることが可能である。仮に、1イレースブロックあたり127セクタ格納できるとして、全てのセクタが使用中となった場合、同じ1セクタを10回書換える場合を例にすると、余分イレースブロックがなければ、10回の消去と1270セクタの書き込みが発生する。しかし、イレースブロックを余分に1つ用意しておけば、10セクタの書き込みしか発生しない。
【0058】
よって、本実施形態では、イレースブロックの数はチップの構成で決まるので、最低1つのイレースブロックが余る様な総論理セクタ数を設計する。
【0059】
<ガベージコレクションのタイミング>
ガベージコレクションは消去動作を伴うために非常に時間がかかる。そのためガベージコレクションをいつ行うかによってカメラの使い勝ってを左右することとなる。例えば、セルフタイマーなどの数秒間撮影しなくても良い時にガベージコレクションを行えばユーザがストレスを感じることがない。
【0060】
<RAM上の記憶場所管理>
フラッシュROM15上ではセクタ番号と実際の記憶場所が関連していないために特定のセクタを読み書きする為にフラッシュROM15を検索しなければならない。そこでシステムがリブートする際に、フラッシュROM15における各セクタの格納アドレスを示す記憶場所管理テーブルをDRAM114上に作成しておくと、フラッシュROM15に対して高速なデータの読み書きを実現できる。一度、記憶場所管理テーブルを作成すれば、フラッシュROM15に対するセクタの書き込みやガベージコレクションによって記憶場所に変更が生じた場合に限って記憶場所管理テーブルの記憶位置を更新するだけで常に正しい記憶場所管理テーブルを維持することが可能である。
【0061】
図10は、DRAM上に作成された記憶場所管理テーブルを説明する図である。図中、右側にRAM上の作成した記憶場所管理テーブル140を示した。0セクタと4セクタは記憶場所不在を意味する値(NULL)が入っている。これらは、フォーマット後そのセクタに対する書き込みが全く無かったか、もしくは、ファイルシステムが開放したセクタである。
【0062】
ファイルシステムがファイルの消去などで不要となったセクタを解放する命令をドライバに出した場合のデバイスドライバの動作は次のようになる。まず、DRAM14上の記憶場所管理テーブル140の指定されたセクタのポインタを参照してフラッシュROM15上の現在使用中の該当するセクタを探し出す。そして、当該セクタの使用済フラグをTRUEにし、DRAM14上の記憶場所管理テーブル140の指定セクタのポインタへ不在値(NULL)を代入する。
【0063】
なお、ガベージコレクションの為にセクタの内容をDRAM14へ待避している場合は、記憶場所としてDRAMへのポインタが代入されている。また、同一論理セクタに対する同時操作を禁止する為のロック変数もテーブルに納めることが望ましい。
【0064】
<MS−DOSのファイル復元>
本電子カメラとパーソナルコンピュータ22で、記憶媒体上のデータ交換が出来ると都合が良い。本実施形態で説明したフラッシュROM管理方式を使用して、現在パーソナルコンピュータで普及しているMS−DOS(商標)と互換性があるファイルシステムを実装することができる。MS−DOSには一度消去したファイルを復元するユーティリティが付属している。ところが、本実施形態ではフラッシュROMの消去効率を向上させる為に、消去したセクタのデータ部を失ってしまう様な構成となっている。カメラで消去した媒体をパーソナルコンピュータで復元する事が原理的にできない構成になっているのである。
【0065】
パーソナルコンピュータでのファイル復元機能を禁止できれば、このような事故を防ぐことができる。本実施形態では、MS−DOSがファイル復元の時に使用するデータを破壊することでファイル復元機能を禁止する。これをいかに説明する。
【0066】
MS−DOS(商標)で、ファイルを消去するとディレクトリに空きスロットができる。ディレクトリにはファイル名/タイムスタンプ/最初のクラスタなどの情報が格納されている。図45はディレクトリスロットの特徴を表す図である。ディレクトリスロットの最後には、リストの最後であることを示すEndOfDirが格納されている。
【0067】
今、File Bを削除すると、ファイル名の先頭が削除を表すシンボルに置き換えられ、FATのクラスタチェーンが消去される。この様子を図46に示す。
【0068】
アンデリートプログラムは、2番目のスロットに残った情報を元に、ファイルの復元を試みる。逆にこの情報がなければ、ファイルの復元を防止できる。
【0069】
図47は本実施形態のDOS互換ファイルシステムでファイルを消去した後の状態を表している。本実施形態では、ディレクトリエントリテーブルの最後に格納されているファイルを消去したいファイルのエントリに上書きし、ディレクトリエントリテーブルの最後のファイルだった部分にEndOfDirを上書きするように構成する。こうすることにより、ファイル復元機能によるファイルの復元を防止できる。
【0070】
なお、ファイルの消去時にはMS−DOSと同様にセクタのデータをそのまま残しておき(セクタの開放を行わない)、ガベージコレクション時にまとめてFATとデータの関係を参照してしながら不要部分を消去する方法もある。
【0071】
<バックグランドで前処理>
あるフラッシュROMでは、消去前のデータが“0”になっている方が高速に消去処理できる。フラッシュROMの消去完了の確認は、データ書き込み時と同様にデータポーリングによって行われる。従って、このようなフラッシュROMを使う場合は、バックグランド処理で“使用済”となったセクタのデータを0に書き換える「前処理」を行うことで性能を向上させることができる。最も低いプライオリティのタスクとして実行するようにしておけば、スループットの低下にはつながらない。
【0072】
この前処理バックグラウンドでの“前処理済セクタ”管理の為にフラグを用意しておけば前処理の効率を上げることができる。
【0073】
そのために、セクタのとりうる状態として、「未使用」「使用中」「使用済」に加えて「前処理済」の4つの状態を表示できる管理フラグをフラッシュROMのセクタ内部へ用意すると効率が良い。
【0074】
図38は、本実施形態における消去処理速度向上のための前処理の制御手順を表すフローチャートである。同図において、ステップS2501にて、使用済でかつ前処理の済んでいないセクタを抽出する。これは、セクタ内の管理フラグが「使用済」となっていて、かつ「前処理済」となっていないセクタを抽出することで実現できる。ステップS2502において、抽出されたセクタに対してデータ「0」を上書きを開始する。ステップS2503では当該セクタについて前処理を終了したか否かを判断する。フラッシュROMへの書込みは1バイト単位であるので、1セクタ分のバイト数の書込みが必要となる。当該セクタに対する前処理が終了していなければステップS2504へ進み、他のタスクへ制御を移す。
【0075】
上述したように本処理は最もプライオリティの低いタスクで行われるので、CPU5がアイドル状態となったときに再び本処理が実行される。この場合処理はステップS2503へ戻る。この時点で、前回の書込みが終了していなければそのまま他のタスクへ処理を移行する。
【0076】
以上のようにして当該セクタの全バイトに対して「0」の書込みを終えると、ステップS2503からステップS2505へ進み、当該セクタの管理フラグを、「前処理済」を示す状態にセットする。そして、引き続き、他のセクタについて前処理を行うために、ステップS2501へ戻る。
【0077】
<FATキャッシュ>
本システムでは、書き込み発生の度に記憶場所を変更し、その度に「未使用セクタ」が発生する。そこで、使用頻度の多い部分を特に優先的にバッファリングするキャッシュが有ればトータルの書き込み頻度が激減する事が予想される。キャッシュとして用意するメモリは多ければ多いほど良いが、システムのメモリには限界がある。
【0078】
本来使用頻度の高いセクタのデータは、キャッシュ中に存在する確率も高いが、使用頻度の低いセクタを大量に読み書きした場合、当然キャッシュから吐き出されることになる。
【0079】
そこで、ファイルシステムが管理する管理領域を優先的にキャッシングする様に構成すれば、スループットの向上を期待できる。なぜならファイルシステムの管理領域は頻繁に更新されているからである。
【0080】
パーソナルコンピュータで普及しているMS−DOSのFATシステムの場合、720kや1.4Mといったフォーマット形式では1クラスタが1セクタで構成されている為、シーケンシャルにファイルを読む場合でも2回に1回はFATを読まなければならない。ファイルを書く場合は、さらにたくさんのFATアクセスが発生する。このため、システム中にたくさんのファイルがオープンされるとキャッシュのヒット率が落ちてしまう。
【0081】
アプリケーションソフトウェアにもよるが、FATシステムにおいてFATのみを対処にしたキャッシュは、DISK全体を対象にしたキャッシュに対して1/2のメモリで同等のヒット率を確保できる。図11はキャッシュソフトウエアの階層的な位置付けを表す図である。キャッシュのソフトウェアは図11の様にファイルシステムとフラッシュROMの中間的な場所となる。
【0082】
図12はキャッシュの主記憶上のデータ構造を表わす図である。片方向線形リスト構造でバッファ全体を管理している。検索方向順にデータが古くなっている。論理セクタ番号が12,11,6,5の順番でアクセスすれば、図12に示されるような順番となる。また、各セクタには、変更フラグが設けられており、キャッシュ上でデータの更新があった場合、変更フラグがFALSEからTRUEに変化する。このようなFATキャッシュの読み出し手順、及び書き込み手順を図13、14を参照して説明する。図13はFATキャッシュの読み出し手順を表すフローチャートである。図14はFATキャッシュの書込み手順を表すフローチャートである。
【0083】
図13において、ステップS1501でNセクタの読み出しを開始する。ステップS1502でNセクタがFATかどうかを判断する。FATでなければ、ステップS1509でフラッシュROM15からデータを読み出す。
【0084】
一方、ステップS1502でNセクタがFATならステップS1503へ進み、キャッシュリストを検索する。ここでは、図12で説明した片方向線形リストを検索することになる。キャッシュ中にNセクタが存在すればステップS1507へ進み、Nセクタのバッファからデータを読み出す。
【0085】
また、ステップS1503でNセクタがキャッシュリスト中に存在しなかった場合は、ステップS1504へ分岐し、最も長くアクセスされていないセクタのデータ(図12ではセクタ番号12のデータ)の吐き出しを行う。まず、ステップS1504では、キャッシュリストの最後の項の変更フラグを判断する。もし変更フラグがTRUEなら、ステップS1505へ進み、変更内容をフラッシュROM15へ書き込む。変更が無い(変更フラグがFALSEの場合)なら、そのままステップS1506へ制御を移す。読み出し手順の中で書き込みを行うのは奇妙に思うかもしれないが、バッファがキャッシュの吐き出しが起こるまで極力書き込み動作を行わない方が効率が良い。
【0086】
ステップS1506でフラッシュROM15からリスト最後のバッファへNセクタの内容を読み出す。ステップS1507でNセクタのバッファからデータを読み出す。ステップS1508でNセクタのバッファをキャッシュリストの先頭へ移動させる。これは、図12において、各セクタが有する「次のバッファー」(次のバッファーを示すアドレス)の値を変更することで達成される。FATキャッシュへのアクセスが行われる度にステップS1508の動作が繰り返されることで、自然にアクセスされないバッファがリストの先頭から最後に向かってシフトしていく。よって、ステップS1504でリスト最後のバッファを選ぶのは、最も古いバッファを吐き出す為である。
【0087】
次に図14を参照して書込み手順を説明する。
【0088】
ステップS1600でNセクタの書き込みを開始する。ステップS1601では、NセクタがFATかどうかを判断する。FATでなければ、ステップS1608へ進み、フラッシュROM15へのデータの書き込みを実行する。
【0089】
一方、ステップS1601でNセクタがFATならば、ステップS1602へ進み、キャッシュリストを検索する。キャッシュ中にNセクタが存在すればステップS1606へ進み、Nセクタのバッファへデータの書き込みを実行する。
【0090】
また、ステップS1602でNセクタがキャッシュリスト中に存在しなかった場合は、ステップS1603へ分岐し、バッファから最も長くアクセスされていないセクタの吐き出しを行うとともに、Nセクタをキャッシュに登録する。まず、ステップS1603でキャッシュリストの最後の項の変更フラグを判断する。もし変更フラグがTRUEなら、ステップS1604で変更内容をフラッシュROMへ書き込み、ステップS1605へ進む。また、変更が無いなら(変更フラグがFALSEなら)そのままステップS1605へ制御を移す。ステップS1605では、キャッシュリストの最後の項をNセクタとする。その後、ステップS1606で、Nセクタのバッファへデータの書込みを実行する。
【0091】
その後、ステップS1607でN、セクタのバッファをキャッシュリストの先頭へ移動させる。書き込み手順の中でフラッシュROMへの書き込みを行わないのは奇妙に思うかもしれないが、キャッシュの吐き出しが起こるまで極力書き込み動作を行わない方が効率が良い。
【0092】
また、ステップS1501及びステップS1601における、FATの判断であるが、ICカード等の完全に上位層(ファイルシステム)の情報を共有できないシステムでも、書き込みデータの内容を解析することでFAT領域の場所を特定できる。なぜならば、論理セクタOに相当する部分にFATの位置等の情報か格納されていることが決まっているからである。
【0093】
<フラッシュROMへの1バイトの書き込み>
フラッシュROM15に対する全ての(管理領域を含む)読み書きは、最終的に1バイトの読み書き命令によって実行される。フラッシュROM15の書き込みには、通常のPROM同様の時間がかかる。1バイトの書き込みが終了するまでは、同じチップへの書き込みはできない。書き込み終了信号として信号線が用意されているチップと特別な信号が用意されていないチップがある。後者の場合は、データポーリングと言う手法で書き込み終了を確認しなければならない。データポーリングとは、ベリファイに非常によく似た方法で、書き込みデータと読み出しデータが一致するまで待つビジー制御方法である。
【0094】
信号線によって書き込み終了を知ることが出来る場合は、CPU5への割り込みと併用して書き込み待ち中のCPUタイムを別のタスクへ割り当てることができる。
【0095】
上述のように、信号線が無いチップの場合は、データポーリングを行なわなければならない。データ書き込みの効率をあげる為にはいくつものチップに対してパイプライン的に書き込みを行い、データポーリング時間のロスを押さえなければならない。そのため、1バイトの書き込みが完了する前に次の動作へ制御を移す必要がある。新たな読み書きを行う前に以前の書き込みが完了しているかどうかを確認するのが良い。図15は、その様子をC言語で表現したものである。
【0096】
図15の1行目は、データ書き込みを行う関数の入り口である。最初の引数は最後に書き込んだアドレスとデータを保存するための構造体へのポインタ、第2の引数は書き込むアドレス、第2の引数は書き込むデータである。
【0097】
3行目では、最後に書き込んだアドレスを参照してチップに書かれたデータと最後に書いたデータを比較して、両者が一致するまでループを実行する。これがデータポーリングである。前回の書き込みが完了するとこのループから抜け出す。
【0098】
4行目で新しいアドレスへDataを書き込む。5行目と6行目で、今回書いたアドレスとデータを保存する。この情報は、次のデータポーリングで利用される。
【0099】
リスト7行目のRotateRdyQueueは、自タスクの次に実行されるべき同一プライオリティの実行可能状態のタスクへCPUを譲るオペレーティングシステムのシステムコールである。
【0100】
9行目は読み出し関数の入り口である。第1の引数はアドレスとデータを保存するための構造体へのポインタ、第2の引数は読み出すアドレスである。この関数は上位のプログラムに対して第2の引数で指定されたアドレスに格納されたデータを返す。
【0101】
11行目では、もし読み出そうとしたアドレスが最後に書き込んだアドレスなら戻す値は最後に書き込んだデータなので構造体の中に保存された情報を返す。12行目は3行目と同じようなデータポーリングである。データポーリングに成功しないと同じチップの別のアドレスを読むことができない。データポーリングが終わって13行目で指定したアドレスの内容を戻している。
【0102】
1チップへの書き込みを以上の様な構成にしておけば、チップ数と書き込みタスクを増やすだけで確実に見かけ上の書き込み速度を向上させることができる。また、全体のスループットを上げる為にわざとチップ数分のセクタバッファを用意(2チップなら2セクタ)して書き込む内容がバッファに溜まるまで処理しないようにすると効果がある。
【0103】
図15のプログラムの特徴的なところは、データポーリングをデータ書き込み直後に行うのではなく、次の書き込みの前に行うことである。そのために前回書いたアドレスとデータを保存しておくRAM領域をチップごとに確保し構造体「struct DEV」として格納しているのである。
【0104】
図39は、本実施形態におけるフラッシュROMへの1バイトデータの書込み手順を表すフローチャートである。本フローチャートは、1つのフラッシュROMチップへの書込みの制御手順を示している。ステップS2601では、前回の書込み処理が完了したか否かを判断する。前回の書込み処理が終了していなければステップS2604へ進み、そのまま他のタスクへ制御を移す。
【0105】
一方、前回の書込み処理が終了していれば、次の書込みデータを準備し、これをDRAM14へ保存する。上述のステップS2601における書込み終了の判断は、フラッシュROMに書き込まれたデータと、このステップS2602で保持されたデータとの比較によって行われる。
【0106】
続いて、ステップS2603において、データの書込みを開始する。以上のような処理によれば、複数のフラッシュROMチップに対して、複数のタスクで書き込みを行うような場合に、いわゆるラウンドロビン方式を適用した書き込み処理が可能となり、複数のROMチップに対して効率良くデータの書き込みが行える。なお、マルチタスクの管理プログラムは、上述のROM13に格納されている。組み込みようのリアルタイムOSとしては、VxWorks(商標)やpSOS(商標)等が市販されており、ROM13にこれらのようなリアルタイムOSが格納されている。
【0107】
<フラッシュROM書き込み電源の共有化>
データの書き込みや消去の際にPROM同様に12V等の特別な書き込み電圧を必要とするチップや、書き込み電圧を与えることで書き込みが高速になるチップがある。この様なチップを使用する場合に専用のDC/DCコンバータ等の電圧発生部を設けると電子カメラのコストアップにつながる。ところが、従来よりカメラにはストロボの充電や、機構部分やCCDの駆動等、特別な電圧が必要な部分がありDC/DCコンバータ等を搭載している。そこで、フラッシュROMの書き込み電圧とストロボ充電やメカ駆動を時分割多重で行うことで、少容量のDC/DCコンバータでシステムを構築でき、システムのコストを押さえることができる。
【0108】
図16は、DC/DCコンバータの出力容量を越えない様に電源を管理するプログラムをC言語で表現したものである。Line1〜6が1ステップのズームアップ関数で、Line7〜13がフラッシュROMへ1セクタ書き込む書き込み関数である。ズームアップ関数はLine3でDC/DCコンバータの資源管理用のセマフォ“SemDCDC”を獲得して、モータを1ステップ動かす関数をLine4で呼び出す。モータ駆動が終わるとDC/DCコンバータの資源管理用のセマフォ“SemDCDC”を開放する。セマフォはマルチタスクのオペレーティングシステムで資源を管理する為の一般的な方法であり、多くのオペレーティングシステムがシステムコールとして用意している。
【0109】
即ち、Line3で既に“SemDCDC”が他のタスクによって使用されていたとすると、他のタスクがセマフォ“SemDCDC”を開放するまでズームアップをしようとしたタスクの実行が保留される。
【0110】
書き込み関数はLine9でセマフォ“SemDCDC”を獲得し、フラッシュROMへ1セクタのデータを書き込む。Line11でデータポーリングを行い最後の書き込みが終了したことを確認したら、Line12でセマフォ“SemDCDC”を開放する。このようにプログラムを構成すれば、ズームアップとフラッシュROMの書き込みを同時に行うことは無くなる。ズームは1ステップ単位であり、書き込みはセクタ単位なので非常に短い保留時間の後に必ず電源を獲得できる。
【0111】
図16について更に説明すると、図16のLine1はズームアップする関数の入り口である。本関数には引数はない。Line3で電源の使用権利として宣言したSemDCDCの権利を一つ獲得する。この時、使用権利が1つもなければこの関数を呼び出したタスクの実行は保留される。電源の使用権利を別のタスクが解放すればZoomUpを呼び出したタスクが再び実行可能状態に戻る。そして、Line4のモーターを動かす関数を呼び出すことができる。そして、Line5で、電源使用権利を返却してこの関数の仕事は終了する。Line7は1セクタのデータをEEPROMに書き込む関数の入り口であり、Line9de電源利用権利を獲得してLine12で返却している。
【0112】
図40は、上述した電源の共有手順を説明するためのフローチャートである。同図において、ステップS1701で、電源コントローラ9によるDC/DCコンバータ8の出力電力の供給が解放されたか否かを判断する。ステップS1702では、電源確保のための指示の内容を解析し、この指示結果に従って、ステップS1703、1705、1707、1709のいずれかに分岐する。
【0113】
指示の内容が、CCD駆動電力の供給であれば、ステップS1703へ進み、CCD2に対してCCD駆動のための電力を供給する。そして、ステップS1704にて、CCD駆動の終了(即ち撮影動作の終了)を検出すると、ステップS1711へ進み、電源の解放を行う。また、ストロボの充電要求であれば、ステップS1705へ進み、電源コントローラ9に対してストロボ21に対する充電電力を提供させる。そして、ステップS1706でストロボの充電を完了したら、ステップS1711へ進み、電源の解放を行う。なお、充電の電力供給は、所定時間の充電を行う毎に他の電源供給のために電源を解放する。即ち、ストロボ21への充電を管理するプログラムは別個に所定のタスクに存在し、充電の完了はそのタスクによって管理される。
【0114】
指示の内容が、ズーム機構の駆動であれば、ステップS1707へ進み、ズーム機構の駆動系(不図示)へ電力供給を行う。そしてステップS1708で、1ステップのズーム動作を終えたらステップS1711へ進み、電源を解放する。更に、指示の内容がフラッシュROMへの書込みであれば、ステップS1709へ進み、フラッシュROM15への書込み電力を供給する。1セクタ分の書込みが終えたら、ステップS1710からステップS1711へ進み、電源を解放する。
【0115】
なお、ステップS1704、1706、1708、1710において、各動作の終了を待つが、この待ちループにおいて、他のタスクへの制御が移り、マルチタスク処理が遂行される。この管理処理は、各タスクから随時起動が可能であり、複数のタスクで同時に起動される可能性もある為、ステップS1701で電源解放のチェックを行っている。
【0116】
以上の図40のフローチャートによれば時分割で電源を利用することが可能となる。しかしながら、すべてのシステム(CCD/ストロボ/ズーム/フラッシュROM)が依存しあった1つのプログラムである。このようなソフトウエアを開発すると、開発/デバッグ/メンテナンスのコストが大きくなり、拡張性や柔軟性を保つのが難しくなる。
【0117】
そこで、電源を1つの資源に見立ててOSの提供する資源管理機能を用いることで開発効率を向上させることができる。そこで上述のセマフォによる資源管理を行う。即ち、CCDの駆動部、ストロボの駆動部、ズームの駆動部、フラッシュROMの駆動部のそれぞれの制御プログラムが、電源という資源(セマフォ)を獲得、解放することで、時分割された電源の割当てが行える。
【0118】
図48は本実施形態による電源の時分割利用を説明する図である。同図に示されるように、あるタスクA(例えばCCD)によって電源要求が発生したとき、電源セマフォが解放された状態にあれば、そのセマフォを獲得して、電源を占有する(ステップS2001〜S2003)。続いてステップS2004において、当該電源よりの電力供給を得て所定の処理を行うと、ステップS2005へ進んでセマフォを解放する。
【0119】
一方タスクAより遅れて電源獲得を要求したタスクBでは、ステップS2011における電源要求ではセマフォを獲得できず、ステップS2012により、セマフォの解放待ちとなる。そして、タスクAよりセマフォが解放されると、このセマフォをタスクBが獲得して、電源を占有する(ステップS2013)。その後タスクBで所定の処理を実行し(ステップS2014)、電源を解放する(ステップS2015)。
【0120】
以上のようなセマフォによる電源資源の管理により、電源の時分割利用が可能となる。
【0121】
なお、図48によれば、電源資源の利用権利を示すセマフォが一つしかないが、複数個のセマフォが存在するようにしても良いことは言うまでもない。
【0122】
<実施形態の電子カメラの動作説明>
図17は、本実施形態のリブートからサービスの開始までの動作手順を表わすフローチャートである。ステップS101でシステムがリブートすると、ステップS102でフラッシュROM15の管理領域をスキャンし、DRAM14上に記憶場所管理テーブル140を作成する。また、この処理と並行して、DRAM14上の未使用セクタカウンタ、使用済セクタカウンタ、使用中セクタカウンタへ、それぞれの状態に対応するセクタがいくつ有るかを数え、セットする。このカウンタは、後にフラッシュROM15に対して操作を行ったときに更新され、記憶効率を判断するのに用いられる。その後、ステップS103へ進み、各種のサービスを開始する。
【0123】
図18は、指定セクタの読み出しサービスの手順を表わすフローチャートである。まず、ステップS201でNセクタの読み出しを開始する。ステップS202では、Nセクタをロックする。セクタのロックはロック変数を使って行う。このロック変数は、記憶場所管理テーブル140で各セクタの記憶場所とともに管理される。ステップS202では、セクタが既に他のタスクによってロックされている場合、他のタスクによってアンロックされるのを待ち、他のタスクによってアンロックされた後で当該セクタのロックを行う。ロックしたセクタはステップS206でアンロックするまでの間、自タスクによって占有することが出来る。
【0124】
ステップS202で論理セクタをロックすると、ステップS203で記憶場所管理テーブルを参照して、当該セクタに有効なデータ記憶されているかどうかを確認する。有効なデータが記録されて無い場合は、ステップS204へ分岐する。ステップS204では、ダミーのデータ(例えば全部0など)をセクタの内容として読み出す。ステップS203で有効なデータが格納されていると判断された場合は、ステップS205へ分岐する。ステップS205では記録場所管理テーブルの値を元にフラッシュROM(または主記憶)からデータを読み出す。
【0125】
ここで、ガベージコレクションを実行中でNセクタが主記憶(DRAM14)へ退避されていた場合は、記憶場所管理テーブルのポインタは主記憶をポインティングとしている。また、図中点線で囲んだ部分はNセクタを占有している期間である。この様なロック機構によって1つのセクタ操作の安全性を保証している為、ガベージコレクションの途中でも操作中でないセクタを自由に読み出すことが可能となっている。
【0126】
図19は論理セクタの書き込みサービスの手順を表わすフローチャートである。ステップS301でNセクタの書き込みを開始する。ステップS302でステップS202と同様に、論理セクタのロックを行う。
【0127】
次に、ステップS303で、記憶場所管理テーブルを検索して、Nセクタに有効なデータが記録されているかどうかを判断する。有効なデータが記録されていればステップS304へ、記録されてないならばステップS305へそれぞれ分岐する。ステップS304では、それまで有効なデータとして記録されていたフラッシュROM(または主記憶)のデータを破棄する。ステップS304におけるデータ破棄の処理は、図21のフローチャートを用いて詳しく説明を加える。ステップS304の後ステップS305へ制御が移る。
【0128】
ステップS305では、フラッシュROM15においてNセクタを書き込むための記憶領域を獲得する。ステップS305における記憶領域の獲得手順は図23を用いて詳しく説明を加える。ステップS305で正常に記憶領域の獲得に成功すれば、ステップS308へ制御を移す。ステップS308では獲得したフラッシュROM15の領域へNセクタのデータを書き込む。
【0129】
一方、ステップS305でフラッシュROMに記憶場所が無い場合、即ち記憶領域の獲得に失敗した場合はステップS306へ分岐する。ステップS306はデータの退避用に主記憶を獲得する。主記憶の領域確保はオペレーティングシステムが提供するメモリ管理機能によって行う。これはC言語でalloc関数に相当する機能である。そして確保した領域を片方向線形リスト構造によって管理する。
【0130】
図20は主記憶上に獲得した退避データリストの様子である。(a)は退避データリストにデータが無い状態であり、リストには、END_OF_LIST が代入されている。(b)は退避データリストに、セクタ番号3,20,221の各セクタの内容が退避されている状態である。
【0131】
ステップS309で、記録場所管理テーブルを更新する。ここで、記録したフラッシュROM(または主記憶)へのポインタが代入される。ステップS310で論理セクタのアンロックを行う。図中点線で囲まれた期間その論理セクタを占有できる。ステップS311で記憶効率の評価を行う。記憶効率の評価手順については、図21のフローチャートを用いて詳しく説明を加える。記憶効率の評価の結果、記憶効率が悪化した場合は、ステップS312へ制御を移す。ステップS312では上述したガベージコレクションを行う。ガベージコレクションについては、図24のフローチャートを参照して詳しく説明を加える。ステップS313でNセクタの書き込みが終了してメインのルーチンへ復帰する。
【0132】
なお、記憶場所管理テーブルに納められるのは、記憶場所のポインタ(バス空間上のアドレス)である。図20の(b)の主記憶に待避されたデータの「次のデータへのポインタ」の次のフィールド(図中ではすぐ下に示されている)からは、図10の左側にあるフラッシュROM上のデータ構造と互換性がある。記憶場所管理テーブルに納められるのはこの互換部分へのポインタである。このように構成することにより、データの読み出しプログラム側でフラッシュROMと主記憶を単一のアルゴリズムで扱うことが可能となる。
【0133】
次に、指定されたセクタの記憶を破棄する手順(上述のステップS304)を説明する。図21は、記憶を破棄する手順を表わすフローチャートである。
【0134】
ステップS401で指定領域の記憶破棄を開始する。ステップS402では、指定されたセクタを記憶する領域が主記憶上にあるかどうかを判断する。主記憶上にあるならステップS405へ分岐する。ステップS405で待避セクタリスト(本例では、図20で示した片方向線形リスト)から指定領域を削除する。
【0135】
片方向線形リストからの指定領域の削除手順は、まずリストの先頭から検索方向順にリストをたどり、ポインタが自分をポインティングしている項を検出する。そして、この検出された項のポインタに現在自分がポインティングとしている値を代入することで実現する。そして、ステップS406で、リストから削除した主記憶領域をオペレーティングシステムへ返却する。オペレーティングシステムへの記憶領域の返却はC言語のfree関数に相当する機能である。
【0136】
一方、ステップS402で指定された領域が主記憶上でない(すなわちフラッシュROM上)ならステップS403へ分岐する。ステップS403では、指定されたフラッシュROM上のセクタの管理フラグを“使用済”へ変更する。これは、使用済みフラグをTRUEにセットすることで達成される。ステップS404では主記憶上の未使用セクタカウンタの値を1つ減少させる。ステップS407で復帰する。
【0137】
次に、記憶効率の評価手順(ステップS311)について説明する。図22は、記憶効率の評価手順を表わすフローチャートである。
【0138】
ステップS501で記憶効率の評価を開始する。ステップS502では、主記憶に設定された未使用セクタカウンタの値と使用済セクタカウンタの値を比較する。ここで、使用済セクタカウンタの値が未使用セクタカウンタの値に対して同じか上回った場合、上位プログラムに対して記憶効率の悪化をレポートする様に構成している(ステップS502、S504)。また、未使用セクタカウンタの値が使用済セクタカウンタの値よりも大きければ、評価結果を正常とし、正常復帰する(ステップS503)。
【0139】
次に、フラッシュROMの記憶領域の獲得手順(ステップS305)について説明する。図23はフラッシュROMの記憶領域の獲得手順を表わすフローチャートである。
【0140】
ステップS601でフラッシュROMの記憶領域の獲得を開始する。ステップS602で未使用セクタの検索権利を獲得する。ここでは、オペレーティングシステムの提供するセマフォの機能を使用して未使用セクタの検索権利を管理している。ここでは、ステップS602からステップS609/ステップS611までの点線で囲まれた処理期間だけ未使用セクタの検索権利を独占出来る。複数のタスクが同時に同一領域を獲得する様な事態を防ぐ為のしくみである。
【0141】
ステップS603でフラッシュROMの最初のセクタへポインタを移動する。ステップS603でそのセクタの管理フラグ(使用中フラグ、使用済みフラグ)を参照して、当該セクタの使用状態を判断する。使用済みか使用中ならステップS605へ分岐する。ステップS605で現在ポイントしているセクタが最後のセクタならステップS611へ分岐する。この場合、使用可能な領域がフラッシュROM15に存在しないことになるので、ステップS611で未使用セクタの検索権利を開放した後、ステップS612で異常復帰する。また、ステップS605で現在ポイントしているセクタが最後のセクタでなければ、ステップS606へ分岐する。ステップS606では、ポインタを次のセクタへ移動させてからステップS604へ戻る。
【0142】
ステップS604ポインタの示すセクタの管理フラグが未使用となっていればステップS607へ分岐する。ステップS607では、フラッシュROMの管理フラグを“使用中”へ変更する(使用中フラグをTRUEにする)。そして、ステップS608で、主記憶に設けた未使用セクタカウンタの値を1つ減少させる。この場合は、フラッシュROMへの記憶領域の獲得に成功しているので、ステップS609で未使用セクタの検索権利を開放し、ステップS610で正常復帰する。
【0143】
次に、ガベージコレクション(ステップS312)の手順について説明する。図24はガベージコレクションの手順を表わすフローチャートである。
【0144】
ステップS701でガベージコレクションを開始する。ステップS702では、整理対象のイレースブロック(以後、整理対象ブロック)を選出する。整理対象ブロックの選出手順については、図25のフローチャートを用いて詳しく説明を加える。ステップS703では、整理対象ブロックの未使用セクタを使用済化する。この使用済化の手順については、図26のフローチャートを用いて詳しく説明を加える。ここで、最初に整理対象ブロック内の未使用セクタを使用済化させる目的は、ガベージコレクション中であっても、他のタスクが整理対象ブロック内のセクタを含むセクタへの読み書きが可能な構成となっており、ガベージコレクション中に他のタスクによって整理対象ブロック内のセクタへ新たなデータが書き込まれることを防止する為である。
【0145】
ステップS704では、整理対象ブロック中の使用中セクタを他の記憶領域(即ち、他のイレースブロック)へ移動させる。使用中セクタを他の記憶領域へ移動させる処理については、図27のフローチャートを参照して詳しく説明を加える。
【0146】
続くステップS705では、使用中セクタの移動を終了した整理対象ブロックの消去を実行する。整理対象ブロックを消去する手順については、図28のフローチャートを参照して詳しく説明を加える。なお、この整理対象ブロックの消去において、消去回数カウンタ152の内容を主記憶にコピーしておく。ステップS705における整理対象ブロックの消去を終えると、ステップS706で主記憶に退避したデータをフラッシュROMの当該イレースブロックの消去回数カウンタへ戻す。そして、ステップS707でガベージコレクションから復帰する。
【0147】
次に、ガベージコレクションにおける整理対象ブロックの選出手順(ステップS702)について説明する。図25は整理対象ブロック選出する手順を表わすフローチャートである。
【0148】
まず、ステップS801で整理対象ブロックの選出を開始する。ステップS802で評価ポインタに最初のイレースブロックをセットする。同様に、ステップS803で、整理対象候補ポインタを最初のイレースブロックにセットする。
【0149】
次に、ステップS804で、評価ポインタの示すイレースブロックに使用済セクタが含まれているかどうかを判断する。使用済セクタが含まれていなければステップS804,ステップS805をスキップしてステップS807へ制御を移す。
【0150】
一方、ステップS804で評価ポインタの示すイレースブロックに使用済セクタが含まれている場合には、ステップS805へ制御を移す。ステップS805では、整理対象候補ポインタの示すイレースブロックの消去回数カウンタの値と評価ポインタの示すイレースブロックの消去回数カウンタの値を比較する。もし評価ポインタの示すイレースブロックの消去回数の方が少なければステップS806へ制御を移す。ステップS806では、整理対象候補ポインタへ評価ポインタを代入する。一方、ステップS805でもし評価ポインタの示すイレースプロックの消去回数のほうが多ければそのままステップS807へ制御を移す。
【0151】
ステップS807で評価ポインタが最後のイレースブロックを示しているかどうかを判断する。もし最後のイレースブロックでなければ、ステップS808で評価ポインタを次のイレースブロックへ移動させた後、ステップS804へ戻る。以上のように、ステップS804〜S808の処理を繰り返すことで、整理対象候補ポインタは、使用済みセクタを含み、消去回数の少ないイレースブロックを示すようになる。
【0152】
ステップS807で評価ポインタが最後のイレースブロックを示している場合はステップS809へ分岐する。ステップS809ではガベージコレクション処理(図24の処理)に復帰する。この時点の整理対象候補ポインタの示すイレースブロックが整理対象として選出される。
【0153】
次に、選択された整理対象ブロック内の未使用セクタを使用済み化する処理(ステップS703)について説明する。図26は、整理対象ブロックの未使用セクタを使用済み化する手順を表わすフローチャートである。
【0154】
ステップS901で処理を開始する。ステップS902で、整理対象ブロックの最初のセクタへポインタを移動させる。次に、ステップS903で、未使用セクタの検索権利を獲得する。これは、図23のフローチャートのステップS602と同様の効果があり、ステップS908までの点線で囲まれた間、未使用セクタの検索権利を独占する。即ち、整理対象ブロックの全セクタを対象にスキャンして未使用セクタを使用済セクタへ変更するまでの間、他のタスクが未使用セクタの検索をすることを禁止する。しかし、管理フラグのみの操作で未使用セクタを使用済セクタへ変更するので、検索権利の独占時間は短く、全体のスループットが低下することはない。
【0155】
ステップS904で、現在のポインタが示すセクタが未使用セクタかどうかを判断する。もし未使用セクタならステップS905へ分岐する。ステップS905でその記憶を廃棄する。ステップS905の処理手順は図21のフローチャートで説明した通りである。この処理により、未使用セクタが使用済みセクタに変更される。ステップS906では、ポインタが整理対象ブロックの最後のセクタを示しているかどうかを判断する。最後のセクタを示していればステップS908へ、そうでないならステップS907へ分岐する。ステップS907ではポインタを次のセクタへ移動させてステップS904へ制御を戻す。
【0156】
また、ステップS906でポインタが整理対象ブロック最後のセクタならステップS908で未使用セクタの検索権利を開放し、ステップS909でガベージコレクション処理(図24のフローチャート)へ復帰する。
【0157】
次に、整理対象ブロックの使用中セクタを他のイレースブロックの未使用セクタへ移動する処理(ステップS704)について説明する。図27は、整理対象ブロックの使用中セクタの移動手順を表わすフローチャートである。
【0158】
ステップS1000で処理を開始する。ステップS1001で整理対象ブロックの最初のセクタへポインタを移動させる。以下のステップS1002〜S1012では、ポインタが指し示すセクタについて処理を行う。
【0159】
ステップS1002で当該セクタの管理フラグ(使用中フラグ、使用済みフラグ)を判断する。ステップS1002で管理フラグの値が「使用中」となっていたらステップS1003へ制御を移し、「使用済」となっていたらステップS1012へ制御を移す。ステップS1003で、論理セクタをロックする。ロックしたセクタはステップS1011でアンロックされるまでの間、自タスクで占有される。
【0160】
ステップS1004では記憶領域を獲得する。ステップS1004における記憶領域の確保の手順は、図23のフローチャートで説明した通りである。ここで、整理対象ブロック内の各セクタは上記ステップS703の処理で、全て使用済み化されているので、確保される記憶領域は整理対象ブロック以外のイレースブロックとなる。
【0161】
記憶領域の獲得に成功すると、処理はステップS1008へ進む。ステップS1008では、獲得した領域へ当該セクタのデータをコピーする。そして、セクタの移動に従って、ステップS1009で記憶場所管理テーブル140を更新する。
【0162】
一方、ステップS1004で記憶領域の獲得に失敗した場合は、ステップS1005へ分岐する。ステップS1005では、データ退避用の記憶領域を主記憶(DRAM)より獲得する。データ退避用記憶領域の獲得は図19のフローチャートのステップS306で説明した通りである。ステップS1006では、獲得した領域へ当該セクタのデータをコピーする。そして、ステップS1007で記憶管理テーブルを更新する。ステップS1010で元の記憶を廃棄する。即ち、ポインタの指し示すセクタの使用済みフラグをTRUEにセットする。そして、ステップS1011で当該論理セクタをアンロックする。
【0163】
ステップS1012で、ポインタの指し示すセクタが、整理対象ブロックの最後のセクタかどうかを判断する。最後のセクタであればステップS1014へ、最後のセクタでなければステップS1013へそれぞれ分岐する。ステップS1013では、ポインタを次のセクタへ移動させて、ステップS1002へ戻り、次のセクタについて上述の処理を繰り返す。また、ステップS1014では、整理対象ブロック内の全てのセクタについて処理を終えているので、ガベージコレクション処理(図24のフローチャート)へ復帰する。
【0164】
次に、整理対象ブロックの消去処理(ステップS705)について説明する。図28は、整理対象となったイレースブロックの消去手順を表わすフローチャートである。
【0165】
ステップS1101で処理を開始する。ステップS1102で整理対象ブロックの消去回数カウンタを主記憶へコピーする。ステップS1103では整理対象ブロックの消去を実行する。ステップS1104では、主記憶へコピーした消去回数カウンタの値を1増加させた値をフラッシュROMへ書き込む。即ち、当該整理対象ブロックの消去カウンタの値を、消去処理前の値より1増加させる。その後、ステップS1105でガベージコレクション処理(図24のフローチャート)へ復帰する。
【0166】
上記図24で示されるガベージコレクション処理は、極力フラッシュROMを用いた処理であり、退避データの安全性が高い。しかしながら、上述の<未使用セクタが無い場合>の項で説明したように、積極的に主記憶(DRAM14)を用いて使用中セクタのデータを待避し、複数個のイレースブロックを消去すると消去処理の効率がよい。但し、DRAM14にデータを待避するので、待避中のデータに関して安全性が低下する(例えば電池が外れて電源供給が停止するとDRAMに待避したデータが失われることになる)。そこで、電源の種別を判断し、供給電源が電池の場合は待避データの安全性を重視し、ACアダプタの場合は電源供給が停止する危険性が少ないので消去処理の効率を重視するように構成してもよい。この場合の処理について図36を参照して説明する。
【0167】
図36は、電源種別に基づいてガベージコレクション処理を切り換える場合の処理手順を説明するフローチャートである。同図において、図24のフローチャートで示される処理と同じ処理を行うステップについては同一のステップ番号を付し、ここでは詳細な説明を省略する。
【0168】
ステップS1300においてガベージコレクション処理が起動されると、ステップS1301へ進み、当該装置への電源供給の形態を判断する。ここでは、図1の電源コントローラ9が、電源の供給元が電池7であるかACアダプタ23であるかを判断し、CPU5に通知する。電源種別が電池7であった場合は、ステップS1304へ進み、上述の図24で示したガベージコレクション処理を実行する。
【0169】
一方、ステップS1301において電源種別がACアダプタであった場合は、ステップS1302へ進む。ステップS1302では、図24のステップS702、S703、S704に相当する処理を実行し、選出した整理対象ブロック内の未使用セクタの使用済み化と使用中セクタの待避を行う。そして、ステップS1303において、主記憶(DRAM14)にセクタの待避を行うのに十分な空き領域があるか否かを判断し、十分な空き領域があればステップS1302へ戻る。ステップS1302では、前回の整理対象ブロックとは別の整理対象ブロックを選出して、上述の処理を繰り返す。
【0170】
DRAM14上に十分な空き領域が無くなると、ステップS1303からステップS1304へ進み、上述の処理で選出された整理対象ブロックの消去を行う。そして、ステップS706で主記憶に待避したデータをフラッシュROM15に戻して本処理を終了する。
【0171】
以上のように、図36の処理によれば、電源がACアダプタによって供給される場合は、主記憶の空き容量を積極的に利用してデータの待避を行い、複数の整理対象ブロックを選出して、一括して消去処理を行うことができ、消去処理の効率が向上する。
【0172】
なお、上記の処理では、電源種別に基づいて自動的にガベージコレクションの形態を切り換えるが、コントロールパネル12の操作により、マニュアルで切り換えるようにすることもできることはいうまでもない。
【0173】
次に、基本サービスの一つである論理セクタの解放手順について説明する。図29は、論理セクタの解放手順を表すフローチャートである。
【0174】
ステップS1201でNセクタの解放を開始する。ステップS1202でNセクタをロックする。この結果、ステップS1205でアンロックされるまでの間、自タスクで論理セクタを占有出来る。続いて、ステップS1203で当該セクタの記憶を廃棄する。この記憶の廃棄処理については、図21のフローチャートで説明した通りである。ステップS1204では、DRAM14の記憶場所管理テーブル140へ“不在”値を代入する。ステップS1205では、論理セクタをアンロックし、ステップS1206で復帰する。
【0175】
例えばMS−DOS(商標)等の一般のファイルシステムでは、ファイルの消去に際しては、当該ファイルに属するセクタをFATにおいて上書き可能とするのみで、各セクタを解放するということは行われない。よって、このようなファイルシステムに本実施形態のフラッシュROM管理システムを適用すると、ファイルシステム上では無効となったデータが、有効なセクタとして残されてしまうことになり、ガベージコレクション等の効率を低下させることになる。よって、ファイルシステムの指示(例えばファイル消去)に基づいて不要となったセクタを検出し、これを解放するように構成すれば、ガベージコレクションの効率をより向上させることができる。
【0176】
図37は、ファイルシステムよりファイル消去が指示された場合の、不要セクタの解放手順を表すフローチャートである。同図において、ステップS1401でファイルシステムよりファイル消去の指示があったか否かを判断する。ファイル消去の指示があった場合は、ステップS1402へ進み、消去すべく指示されたファイルに含まれるセクタを抽出する。セクタの抽出は、FATを参照することで抽出できる。そして、ステップS1403で、先のステップS1402で抽出された各セクタについて、上記図29のフローチャートで説明したセクタの解放処理を実行する。
【0177】
[実施形態2]
次に実施形態2について説明する。
【0178】
<ディスクコントローラエミュレーション>
上述の実施形態1で説明したフラッシュROMの記憶管理システムは、上位層から見た特徴がディスク媒体と良く似ている。従って、ディスクコントローラのエミュレーション機能を備えたシステムに組み込むことで、ディスクコントローラとディスク媒体をディスクコントローラエミュレーションと本実施形態の記憶管理システム(あるいは本実施形態の記憶管理システムを組み込んだICカード)へ置き換えることが可能となる。近年PCMCIAに代表されるICカードが普及しているが、ICカードへディスクコントローラエミュレーション機能と上記実施形態1の記憶管理システムを組込むことにより、リムーバルな記憶媒体として利用することが可能となる。第2の実施形態では、実施形態1の記憶管理システムをICカードへ組み込んだものについて説明する。
【0179】
図30は実施形態2におけるICカードの構成を表すブロック図である。同図において、200はICカード全体を示す。201はマイクロコンピュータであり、ディスクコントローラエミュレーション及び記憶管理を行う。202はROMであり、マイクロコンピュータ201のプログラムを格納する。203はRAMであり、マイクロコンピュータ201の主記憶として機能する。204はフラッシュROMであり、上記実施形態1で説明した記憶管理システムによってデータを蓄積する。即ち、フラッシュROM204は、図4で説明した管理領域とデータ領域とで管理される。
【0180】
205はコマンド/データ・ラッチ部であり、ホスト装置より受信した外部バスからのコマンドとシリンダ番号等を保持する。206はFIFOメモリであり、先入れ先出し方式でデータの入出力を行う。207はタプルROMであり、当該カードの特徴等を記憶しており、外部バスからのみ読み出しができる。
【0181】
上述の各構成の機能は、以降の動作説明でより明らかとなる。
【0182】
図31は、本実施形態2のICカードを利用する為のホストシステムの簡単なブロック図である。同図において、301はホストシステム側のマイクロコンピュータである。302はカードインターフェースであり、ホストシステムの内部バスとICカード200の外部バスを接続する。なお、カードインターフェース302は、ICカード200への電源供給を行うための電源供給線や、ICカード200からの割り込み要求(IRQ出力)を受け付けるための信号線も備えている。
【0183】
図32は、図31のホストシステムがICカードを接続する際の手順を示すフローチャートである。ステップS4100で処理を開始すると、ステップS4101でICカードへの電源供給を開始する。ステップS4102では、ICカード200内のタプルROM7から、タプル形式で格納されているデータを解析する。タプルROM7の内容を解析することで、接続されているICカードの特徴が分かる。
【0184】
ステップS4103では、ステップS4102で解析したタプル情報によって、接続されているICカードが内部バスへ接続可能かどうかを判断する。そして、接続可能ならステップS4104へ、接続不可能ならステップS4105へとそれぞれ分岐する。ステップS4104では、ICカード側のバスをホストの内蔵バスのメモリ空間とIO空間へマッピングする。この時点でホスト装置のバスの空間にディスクコントローラが有るのと同じ状態になる。
【0185】
図33はICカード200内のマイクロコンピュータ1のメインシーケンスを示すフローチャートである。ステップS4201でICカードの電源が投入されると、ステップS4202で記憶管理システムの初期化を行う。即ち、フラッシュROM204の全イレースブロックの論理セクタの状態を一旦読み出し、読み出した情報に従って主記憶用のRAM203へ記憶場所管理テーブルを作成する。ステップS4203で主記憶上のコマンドバッファとしてリング状のバッファを用意して初期化し、割り込み処理を許可する。この処理以降割り込みルーチンの動作が始まる。
【0186】
割り込みルーチンのシーケンスを図34のフローチャートに示す。割り込みルーチンの動作を理解した方が、図33のフローチャートの説明が容易となる為、ここで図34のフローチャートについて説明を行う。
【0187】
ホストシステムがコマンド/データ・ラッチ205へのコマンドのアドレスへコマンドを書き込むと、コマンド/データ・ラッチ205からマイクロコンピュータ201へ割り込みが発生する。コマンド/データ・ラッチ205は、ホストバスとICカード内部のバスのIOアドレス空間にマッピングされていて、コマンド/データはそれぞれ図35に示すようにIOアドレスが割り振られている。図35は、本実施形態のコマンド/データ・ラッチにおけるIO割り付けを示す図である。本例では、図35中のCommandのアドレスにコマンド(例えばデータの読出しを指示するReadSector(s))を書き込むことでマイクロコンピュータ201へ割り込みが発生する。
【0188】
割り込みが発生すると、マイクロコンピュータ201のソフトウェアは、図34のフローチャートのステップS4301へ制御を移す。ステップS4302では、コマンド/データ・ラッチ205に書き込まれたデータを読み出して、主記憶上のリングバッファへデータを格納する。ステップS4303で割り込みルーチンを終了して図33のフローチャートへ復帰する。
【0189】
図33のフローチャートの説明に戻る。ステップS4204でマイクロコンピュータ201はコマンドバッファの状態を判断する。コマンドバッファへデータが格納されていれば、ステップS4205へ分岐し、データが格納されていなければステップS4213へ分岐する。ステップS4213ではCPUを休止状態にする。多くのワンチップマイクロコンピュータは、命令の実行を休止して消費電流を減らす機能を備えているが、本実施形態のCPUもこの種の機能を備える。そして、IRQによる割り込み要求信号が入力されると、CPU201は休止状態から復帰して上述の割り込みルーチンを実行する。割り込みプログラムの実行が済んだ時点でステップS4213から復帰してステップS4204へ戻る。
【0190】
ステップS4204でコマンドバッファへデータが格納されていると、ステップS4205へ移行する。ステップS4206では、リングバッファからデータを読み出す。ステップS4206でコマンドを解釈する。Seekコマンドの場合はステップS4207、ReadSector(s)コマンドの場合はステップS4208へ、WriteSector(s)の場合はステップS4209へ、IdentifyDrvコマンドの場合はステップS4210へそれぞれ分岐する。他にもコマンドがあるが本実施形態の説明上重要でないものは省き、フローチャートを簡略化している。ステップS4207〜4210までのコマンドの実行を終了したらステップS4204まで戻り、上記の処理を繰り返す。
【0191】
ステップS4207では、Seekコマンドを実行する。SeekといってもフラッシュROMには、ディスクデバイスと違ってヘッドが無いので、次のコマンドに備えての妥当性等をチェックするだけである。ICカードのサポートするヘッド数を超えるヘッド位置などを指定された場合は、ディスク装置同様にエラーが発生する。
【0192】
ステップS4208はReadSector(s)コマンドに対する処理を行う。ReadSector(s)コマンドは、読み出すべきセクターの個数が図35のSectorCountで指定される。よって、ステップS4208では、指定された場所のセクタをSectroCount個読み出す行為を行う。本実施形態の記憶管理システムでは、リニアな論理セクタ番号を使って管理を行っているので、シリンダ/ヘッド/セクタ番号を元にリニアな論理セクタ番号を計算し、論理セクタの内容をFIFOメモリ206へ転送し、コマンド/データ・ラッチ205のSectorNumberのインクリメントも行う。FIFOメモリ206は、ICカード200の内部バスから書き込んだデータを外部バスから読み出すことができ、また外部バスから書き込んだデータをICカード内部バスから読み出す構成となったFIFOメモリである。
【0193】
ここで、上述のリニアな論理セクタ番号について説明する。一般にハードディスクに対して指定する番号は、セクタ、シリンダ、ヘッドのパラメータで決まる3次元の不連続な番号である。例えば、シリンダ数が1024個、ヘッド数が16個、セクタ数が63個のハードディスクの場合、セクタ数は1024×16×63=1032192個となる。
【0194】
このセクタを0番から1032192番としてアクセスできると良いのであるが、上記の3つのパラメータをすべて指定してアクセスするように設計されている。例えば、シリンダ500・ヘッド16・セクタ63の次は、シリンダ501・ヘッド0・セクタ1をアクセスするといった具合である。なお、これら3つのパラメータをそれぞれの頭文字をとってCHSパラメータと呼ぶ。
【0195】
MS−DOS(商標)のようなオペレーティングシステムでは、内部ではリニア(連続的)なセクタ番号を用いるが、デバイスドライバがこれをCHSパラメータに変換する。本実施形態のシステムでは、リニアなセクタ番号を用いるのでCHSパラメータの値を元にリニアなセクタ番号を求める。上記で挙げたハードディスクの場合は、
シリンダ番号×(16×63)+ヘッド番号×(63)+セクタ番号
を計算することで、リニアな論理セクタ番号が求まる。
【0196】
ステップS4209はデータラッチで指定された場所のセクタへデータを書き込む処理を行う。データは、FIFOメモリ206経由でホストシステムから受け取る。
【0197】
ステップS4210は、ICカード200がどのようなハードディスクをエミュレーションしているかという情報を返す処理を行う。すなわちシリンダ数やModelNumberなどハードディスクとしてのスペックを含むデータをFIFOメモリ206へ書き込む処理を行う。
【0198】
<ファイルシステムの解析>
以上説明した様に実施形態1で説明した記憶管理システムをICカードに組み込むことで、ATAハードディスク等の置き換え用途に使用できる。しかし、ATAコマンド等のFATキャッシュやファイル消去によって生じた不要セクタの開放といった処理を行う為の情報を上位システムからもらう手法が無い。ATAコマンドの空き部分を利用してセクタの開放コマンドとキャッシュするセクタ番号指定コマンドを追加実装することで、FATキャッシュと不要セクタ解放の機能が実現できる。そして、この様な機能があることを想定していない現状のMS−DOS等のシステムでも、FATキャッシュやセクタの開放を実現できた方が良いことは言うまでもない。
【0199】
FATシステムは論理セクタ番号0に相当する部分にFATの場所やサイズといった情報を格納している。本実施形態では、このセクタを読むことでFATの場所やサイズを取得し、FATキャッシュの処理に利用する。同様に本来書き込みデータの内容を理解しないはずのICカードであるが、ファイルシステムの為の情報(ディレクトリエントリやFAT)を解析することでICカードが自立的に不要セクタを判断して開放する等の処理に役立てることが出来る。もちろんFATに限った話では無く、HPFSやマッキントッシュ(商標)のファイルシステムでも書き込むデータの内容を解析すれば、不要セクタの検出が可能である。この様に構成することでATAハードディスクのインタフェースでも、ファイルシステムの動作に合わせた最適化処理を行うことを可能にする。
【0200】
また、本発明は、複数の機器から構成されるシステムに適用しても、1つの機器からなる装置に適用してもよい。また、本発明はシステム或は装置にプログラムを供給することによって達成される場合にも適用できることは言うまでもない。この場合、本発明に係るプログラムを格納した記憶媒体が、本発明を構成することになる。そして、該記憶媒体からそのプログラムをシステム或は装置に読み出すことによって、そのシステム或は装置が、予め定められた仕方で動作する。
【0201】
【発明の効果】
以上説明したように、本発明によれば、消去単位の大きいフラッシュROMをファイルシステムと適合させることを可能とした電子カメラが提供される。
【0202】
【図面の簡単な説明】
【図1】実施形態1におけるカメラシステムの構成を表すブロック図である。
【図2】本実施形態の電子カメラにおけるファイルシステムの階層構造を表す図である。
【図3】デバイスドライバの管理ブロックをC言語で記述した宣言文を示す図である。
【図4】フラッシュROM上のセクタ構造の例を示す図である。
【図5】管理領域用データと、データ領域とを分離して格納する構成を表す図である。
【図6】各フラグの状態に対応した意味を示す図である。
【図7】フラッシュROMにおけるセクタの書き換え手順を説明する図である。
【図8】本実施形態におけるフラッシュROMのガベージコレクション動作を説明する図である。
【図9】未使用セクタが存在しない場合のガベージコレクションの動作を説明する図である。
【図10】DRAM上に作成された記憶場所管理テーブルを説明する図である。
【図11】キャッシュソフトウエアの階層的な位置付けを表す図である。
【図12】キャッシュの主記憶上のデータ構造を表わす図である。
【図13】FATキャッシュの読み出し手順を表すフローチャートである。
【図14】FATキャッシュの書込み手順を表すフローチャートである。
【図15】データ書き込み完了を確認するための動作手順をC言語で表現した図である。
【図16】DC/DCコンバータの出力容量を越えない様に電源を管理するプログラムをC言語で表現した図である。
【図17】本実施形態のリブートからサービスの開始までの動作手順を表わすフローチャートである。
【図18】指定セクタの読み出しサービスの手順を表わすフローチャートである。
【図19】論理セクタの書き込みサービスの手順を表わすフローチャートである。
【図20】主記憶上に獲得した退避データリストの様子である。
【図21】記憶を破棄する手順を表わすフローチャートである。
【図22】記憶効率の評価手順を表わすフローチャートである。
【図23】フラッシュROMの記憶領域の獲得手順を表わすフローチャートである。
【図24】ガベージコレクションの手順を表わすフローチャートである。
【図25】整理対象ブロック選出する手順を表わすフローチャートである。
【図26】整理対象ブロックの未使用セクタを使用済み化する手順を表わすフローチャートである。
【図27】整理対象ブロックの使用中セクタの移動手順を表わすフローチャートである。
【図28】整理対象となったイレースブロックの消去手順を表わすフローチャートである。
【図29】論理セクタの解放手順を表すフローチャートである。
【図30】実施形態2におけるICカードの構成を表すブロック図である。
【図31】本実施形態2のICカードを利用する為のホストシステムの簡単なブロック図である。
【図32】図31のホストシステムがICカードを接続する際の手順を示すフローチャートである。
【図33】ICカード内のマイクロコンピュータのメインシーケンスを示すフローチャートである。
【図34】ICカード内のマイクロコンピュータの割り込み処理の手順を表すフローチャートである。
【図35】IOアドレスの割り付け状態を表す図である。
【図36】電源種別に基づいてガベージコレクション処理を切り換える場合の処理手順を説明するフローチャートである。
【図37】ファイルシステムよりファイル消去が指示された場合の、不要セクタの解放手順を表すフローチャートである。
【図38】本実施形態における消去処理速度向上のための前処理の制御手順を表すフローチャートである。
【図39】本実施形態におけるフラッシュROMへの1バイトデータの書込み手順を表すフローチャートである。
【図40】電源の共有手順を説明するためのフローチャートである。
【図41】本実施形態におけるフラッシュROMへの制御プログラムの格納状態を説明する図である。
【図42】相対アドレスで表現されたプログラムコードの一例を表す図である。
【図43】図42のリロケーション情報レコードのデータを格納するテーブルを表す図である。
【図44】図41のプログラムを主記憶の8710番地へマッピングした場合のプログラムコードを示す図である。
【図45】ディレクトリスロットの特徴を表す図である。
【図46】図45のディレクトリスロットにおいて、FileB が削除された状態を示す図である。
【図47】本実施形態のDOS互換ファイルシステムでファイルを消去した後の状態を表す図である。
【図48】本実施形態による電源資源(セマフォ)の時分割利用を説明するフローチャートである。
[0001]
BACKGROUND OF THE INVENTION
The present invention relates to an electronic camera capable of storing data in a flash ROM.
[0002]
[Prior art]
In an electronic camera, image data obtained by photographing is stored in a storage medium such as a built-in DRAM or an external memory card. However, the storage contents of these storage media disappear when power supply is cut off. It is necessary to always back up with batteries. In addition, a magnetic disk is an example of a storage medium that does not require electrical backup for holding stored contents. However, since the magnetic disk device is relatively large, the portability of the electronic camera is impaired. Further, a rewritable ROM, that is, a flash ROM, is available as a storage medium that does not require electrical backup for holding stored contents.
[0003]
There are various types of flash ROMs at present, and there are two types of flash ROMs: those developed for flash DISK and those developed for personal computer BIOS.
[0004]
In the former, the erase unit is 512 bytes, which is general for a hard disk, and the consistency with the file system is very good. The latter flash ROM can be performed only in large block units such as 64K. Some PROMs require a voltage such as 12V as a write voltage. The latter flash ROM can be obtained at a lower cost, but it cannot be used as a small-capacity recording medium because of its poor consistency with the file system.
[0005]
[Problems to be solved by the invention]
As described above, the flash ROM designed for the BIOS has a large erase unit and poor consistency with the file system, but is inexpensive and easily available. Therefore, if such a flash ROM can be applied to a file system, it is not necessary to use a power supply for storage, and an inexpensive, small-capacity, small-sized recording medium can be provided, which is convenient as a storage medium for an electronic camera.
[0006]
The present invention has been made in view of the above problems, and an object of the present invention is to provide an electronic camera capable of adapting a flash ROM having a large erase unit to a file system.
[0007]
[Means for Solving the Problems]
  In order to achieve the above object, an electronic camera of the present invention comprises the following arrangement. That is,
  An electronic camera that stores data in a flash ROM,
  In the erase block, which is an erase unit in the flash ROM, moving means for moving the contents of the area in which valid data is written out of the erase block;
  Erasing means for performing an erasing operation of the erase block after execution of the moving means;
  Timer means for performing self-timer shooting,
  The moving means and the erasing means are executed during the time measurement by the timer means.
  Also preferably,A plurality of data areas formed in the flash ROM, and a management area corresponding to each data area;
  Write means for receiving a write instruction accompanied by designation information indicating a data write destination, writing data to one of the plurality of data areas, and writing the designation information to a management area corresponding to the data area When,
  Receiving means for receiving a read instruction accompanied by designation information indicating a data read source, searching for a management area in which the designation information is stored, and reading data stored in a data area corresponding to the searched management areaMorePrepare.
[0008]
Preferably, the management area includes an unused state indicating that writing to the corresponding data area is possible, an in-use state indicating that data written to the data area is valid, and a data area. Stores state information indicating at least one of three used states indicating that the written data is invalid, and the writing unit searches for a management area in which the state information is in an unused state. Then, the designation information and data are written in the management area searched for and the data area corresponding thereto, and the status information of the management area is changed during use. By indicating the status of each data area in use, used, and unused, you can check the status information to check the area where data can be written and the area where valid data exists. This is because ROM storage management can be performed more appropriately.
Preferably, the writing unit searches for a management area having designation information accompanying the writing instruction, and changes the status information of the searched management area to a used state. This is because when the contents of a data area specified by certain designation information are updated, it can be clearly indicated that the data is not updated (that is, unnecessary data), and appropriate storage management of the flash ROM in the electronic camera can be performed.
[0009]
  Also preferably,The moving means isIn the erase block which is an erase unit in the flash ROM, all management areas whose status information is in use are searched, and the contents of the searched management area and the corresponding data area are out of the erase block.Move.
[0011]
Preferably, the apparatus further comprises power management means for managing the use of a power source, and the power management means supplies power to the flash ROM for power supply used for at least one of strobe charging, mechanism driving, and CCD driving. Allocate for write access. This is because it is possible to use the power source used for charging the book, driving the mechanism portion, driving the CCD, etc. for writing access to the flash ROM, and there is no need to prepare a power source dedicated to writing to the flash ROM.
[0012]
The power management means allocates the power supply by the power supply in a time-sharing manner to the strobe charging, the mechanism driving, the CCD driving, and the flash ROM writing process. Since power is allocated in a time-sharing manner, the power can always be secured after a short holding time, and various operations are executed smoothly.
[0013]
DETAILED DESCRIPTION OF THE INVENTION
Embodiments of the present invention will be described below with reference to the accompanying drawings.
[0014]
[Embodiment 1]
<Configuration of camera system>
FIG. 1 is a block diagram illustrating a configuration of a camera system according to the first embodiment. This camera system includes an electronic camera, an external storage medium 17 that can be attached to and detached from the electronic camera, a PC communication interface 19, and a personal computer 22 that is communicably connected to the electronic camera via the PC communication interface 19.
[0015]
Reference numeral 1 denotes a lens, and reference numeral 2 denotes a CCD unit that outputs light passing through the lens 1 as an electrical signal. An A / D converter 3 converts an analog signal from the CCD unit 2 into a digital signal. An SSG unit 4 supplies a synchronization signal to the CCD unit 2 and the A / D converter 3. Reference numeral 5 denotes a CPU, which implements various controls in the camera system.
[0016]
A signal processing accelerator 6 realizes signal processing at high speed. 7 is a battery, and 8 is a DC / DC converter for supplying electric power from the battery 7 to the entire electronic camera. A power controller unit 9 controls the DC / DC converter 8. A microcomputer 10 controls the panel operation, the display device, and the power source. Reference numeral 11 denotes a display device that displays various types of information to the user, and uses a liquid crystal panel or the like. A control panel 12 includes a release switch that is directly operated by the user.
[0017]
A ROM 13 stores a system program such as an OS. Reference numeral 14 denotes a DRAM which is a main memory of the electronic camera. A flash ROM 15 is used as a built-in storage medium. 16 is a PCMCIA card interface unit, 17 is an external storage medium such as an ATA hard disk, and 18 is an expansion bus interface. Reference numeral 19 denotes a PC communication interface, which exchanges data by connecting a personal computer or the like. 20 is a DMA controller, and 21 is a strobe. A personal computer 22 communicates with the electronic camera via the PC communication interface 19.
[0018]
<Shooting operation>
The operation of the electronic camera during shooting will be briefly described. When the user presses the release switch on the control panel 12, the CPU 5 detects this and starts the shooting sequence. It is assumed that the following operations are all controlled by the CPU 5.
[0019]
Now, when the release switch is pressed, the SSG 4 drives the CCD 2. The analog signal output from the CCD 2 is converted into a digital signal by the A / D converter 3. The output of the A / D converter 3 is DMA-transferred to the DRAM 14 by the DMA controller 20. When the DMA transfer for one frame is completed, the CPU 5 starts a signal processing sequence.
[0020]
In the signal processing sequence, a signal processing program is read from the flash ROM 15 onto the main memory (DRAM 14), and data on the main memory is transferred to the signal processing accelerator 6 to perform signal processing. However, the signal processing accelerator 6 does not perform all signal processing, but is an arithmetic circuit that helps particularly time-consuming processing performed by the CPU 5, and operates in cooperation with processing software of the CPU 5. When part or all of the signal processing is completed, it is recorded in the flash ROM 15 as an image file. If the file format to be recorded at this time requires compression processing, compression is also performed.
[0021]
The signal processing program is one of the files managed by the file system in the flash ROM 15. The camera program is stored in the ROM 13 together with the OS and the file system. The camera program recognizes a file having a specific file name as a program.
[0022]
Since the files are discontinuously arranged in the flash ROM 15 and the file system of this embodiment frequently rearranges, the CPU cannot directly execute the control program in the flash ROM 15. Therefore, it must be read and executed in the main memory (DRAM 14). Further, since the memory manager dynamically allocates the memory location, the main memory must not be software that is supposed to be stored at a specific address. Therefore, the file of the program that performs signal processing in this embodiment has a format as shown in FIG.
[0023]
FIG. 41 is a diagram for explaining the storage state of the control program in the flash ROM in this embodiment. In FIG. 41, the identification code is a code for confirming that the file is a program. A file is represented as a collection of variable-length records. Each record has an ID for identifying the type of information stored in the record first, and then a value indicating the size of the record.
[0024]
A program record and a relocation information record are stored in the file. The program code is, for example, data as shown in FIG. FIG. 42 is a diagram illustrating an example of a program code expressed by a relative address. In FIG. 42, there is a jump instruction at address 0050, but the CPU recognizes this instruction as a jump instruction to an absolute address. The operand of this instruction is expressed as a relative address.
[0025]
The data of the relocation information record in FIG. 42 is stored in a format as shown in FIG. That is, in the program of FIG. 42, an address table indicating a program address of data (data expressed in relative address expression) that must be converted to an absolute address is stored as relocation information.
[0026]
When an area for loading the file of FIG. 41 into the main memory is secured, the memory manager of the OS in the ROM 13 determines the address. The allocation of the memory manager is a function corresponding to the alloc function in the C language. When the memory manager allocates address 8710 for a program, the program is loaded as shown in FIG. FIG. 44 is a diagram showing program codes when the program of FIG. 41 is mapped to address 8710 in the main memory. The operand of the jump instruction has been replaced with the actual absolute address. A program for performing an operation of reading the program to the main memory while converting to the real address is stored in the ROM 13.
[0027]
With the configuration described above, signal processing software and compression software can be stored in a file format on a storage medium. As a result, after the camera arrives at the end user, it can support a variety of file formats, such as new signal processing algorithms, Windows (trademark) BMP format, TIFF format, and new formats that will appear in the future. It becomes.
[0028]
As described above, the electronic camera according to the first embodiment files captured images in the flash ROM 15.
[0029]
<Device driver interface>
FIG. 2 is a diagram showing a hierarchical structure of a file system in the electronic camera of this embodiment. The highest layer is the user application 101. The user application 101 is software that runs inside the electronic camera. The user application 101 opens a file with a file name, reads and writes it, and then closes the file.
[0030]
The file system API layer 102 is directly called from the user application 101 by a function call. The file system API layer 102 manages drive names and file systems in association with each other. Since each drive is configured to mount a file system architecture layer, a plurality of file system architectures can be mixed.
[0031]
The file system architecture layer 103 is a part that performs actual file management. The lowest layer is the block device layer 104. The file system architecture layer 103 implements file input / output using services provided by the block device layer 104. In the block device layer 104, data is managed in units of sectors, and one sector is, for example, 512 bytes. This block device layer 104 absorbs differences in input / output control for each device and parameters such as head and cylinder. Since it is configured in this way, a plurality of types of devices can be mixed at the same time.
[0032]
The electronic camera according to the present embodiment is particularly characterized by a flash ROM storage management method in the block device layer 104.
[0033]
There are various types of flash ROMs 11 shown in FIG. 1 at present, and there are broadly developed types for flash DISK and types developed for personal computer BIOS. In the former, the erase unit is 512 bytes, which is general for a hard disk, and the consistency with the file system is very good. The latter flash ROM can only be performed in large block units such as 64k. Some PROMs require a voltage such as 12V as a write voltage. However, the latter type of flash ROM is inexpensive and readily available. In the present embodiment, a hard disk-like service is provided to the file system even though it is a flash ROM having the latter feature.
[0034]
<Flash ROM driver interface>
In general, the block device provides the following two services to the file system. That is,
(1) Reading from the sector specified by the logical sector number
(2) Writing from the sector specified by the logical sector number
It is. And in addition to this
(3) Release the sector specified by the logical sector number
With this function, the flash ROM driver can erase unnecessary sectors as necessary, so that the flash ROM can be erased efficiently.
[0035]
The function listed in (3) is a function that is not necessary for normal DISK, but a system having a cache can be positively deleted from the cache list, resulting in an increase in the cache hit rate. The file system uses the function (3) to notify the device driver of sectors that are unnecessary due to file deletion or the like. Erasing the flash ROM is a very time-consuming process, but it is preferable to use a background process because it consumes little CPU time.
[0036]
As will be described later in <FAT Cache>, the cache of this embodiment discards the oldest data in the cache list when accessing new data (data not in the cache). Moving unnecessary sectors to the end of the cache list (that is, moving the oldest accessed data behind the cache) reduces the possibility of valid data being discarded from the cache. In particular, in a system that generates many intermediate files such as a compiler, there is a high possibility that an intermediate file to be deleted remains in the cache, and the above cache management is very effective in improving the hit rate.
[0037]
FIG. 3 is a diagram showing a declaration statement in which a device driver management block is described in C language. Next of the structure is a ring pointer to the next device, and is used for the purpose of searching for the device in the memory. DevName is used as the name of the device. InitDev is a pointer to the device initialization routine. ShutDown is a pointer to the device shutdown routine. ReadSector is a pointer to a routine for designating a logical sector and transferring the contents of the medium to a buffer. WriteSector is a pointer to a program that designates a logical sector and transfers (writes) the contents of the buffer to the medium. ReleaseSector is a pointer to a routine that designates a logical sector and releases the sector.
[0038]
The file system uses the device driver through this structure. In the case of a fixed disk or floppy disk, a pointer to a program that does nothing is assigned to ReleaseSector. Alternatively, it may be a pointer for deleting a specified sector from the cache list of the disk cache.
[0039]
<Flash ROM management method>
Data writing to the flash ROM is performed on a sector basis from the upper layer file system. FIG. 4 is a diagram showing an example of the sector structure on the flash ROM. In FIG. 4, 151 is an erase block. The erase block 151 is a unit of erasure and is called a sector in the technical term of the flash ROM. However, in order to distinguish it from the “logical sector” that is a unit handled by the file system, it is referred to as an erase block here.
[0040]
According to FIG. 4, a plurality of flash ROMs 15 are mounted in the system, and each flash ROM 15 includes a plurality of erase blocks 151. Further, each erase block 151 is shown to be composed of an erase number counter 152 and a plurality of sectors 153. The erase number counter 152 is a part used to count the number of times the erase block 151 has been erased. Each sector 153 has a management area and a data area. The management area includes a sector number 154 that represents a logical sector number, an in-use flag 155 that indicates whether the sector is being used effectively, and a used flag 156 that indicates that use as a sector has ended. The data area is composed of a 512-byte data portion 157.
[0041]
The data area and the management area do not have to be arranged next to each other, and may be managed together as shown in FIG. FIG. 5 is a diagram illustrating a configuration in which management area data and a data area are stored separately. Each sector number 154 of the plurality of sectors 153 is stored in the sector number table. The flag table stores a busy flag 155 and a used flag 156. Further, the contents of the data part 157 are stored in the data table. Although it is possible to adopt the data configuration as described above, it is preferable that at least the management area and the data area corresponding thereto be stored in the same erase block.
[0042]
  Note that the system preferentially evaluates the “used flag 156” over the “used flag 155”. FIG. 6 is a diagram illustrating the meaning corresponding to the state of each flag. In the figure, FALSE takes the same value as the state after erasure. Even if the in-use flag 155 is TRUE, the used flag 156 isTRUEIf so, the data in the sector is invalid.
[0043]
<Flash ROM logical sector rewriting>
The flash ROM, like the PROM, must be erased and rewritten in order to rewrite data. Moreover, the minimum unit of erasure is large (for example, 64 kbytes) and the erasure time is long (for example, 1 second). Therefore, when the upper layer file system attempts to rewrite a specific sector, the logical sector is moved to the erased area, thereby realizing logical rewriting of the data in the logical sector without performing an erasing operation.
[0044]
FIG. 7 is a diagram for explaining a sector rewrite procedure. A detailed description will be given using the figure as an example of rewriting of the eighth sector (sector whose logical sector number is 8). In FIG. 7, the left side is the state before rewriting (state (a)), and the right side is the state after rewriting (state (b)). In FIG. 7, numbers in the management area represent logical sector numbers, (in use) is in use flag 155 is TRUE and used flag 156 is FALSE, and (used) is in use with in-use flag 155. Both completed flags 156 indicate the state of TRUE.
[0045]
The data of sector 8 is stored at the location of “sector number 8 (in use)”. Now, assume that the 8th sector is used as part of the FAT or file, and when it is desired to change the contents, a rewrite request for the 8th sector is issued from the upper layer. When a rewrite request occurs, the device driver of the flash ROM searches for an unused sector in the flash ROM, stores the sector number and updated data with the location as the location of the new sector 8, and sets the in-use flag to TRUE. To. Next, the used flag of the sector which was the eighth sector before is set to TRUE. The rewriting of the data of the eighth sector is realized by such a procedure.
[0046]
<Garbage collection>
If the logical sector is rewritten by the method as described above, almost all areas of the flash ROM will eventually become “used sectors”. Therefore, it is necessary to erase the flash ROM once at a certain timing and return the “used sector” to the “unused sector”. The basic garbage collection operation will be described with reference to FIG. FIG. 8 is a diagram for explaining the garbage collection operation of the flash ROM in this embodiment.
[0047]
In the figure, (A) shows a state before garbage collection. In order to simplify the explanation, it is assumed that the flash ROM of this example is composed of erase blocks each having six sectors. In the erase block (1), there are three used sectors and three in-use sectors, and the number of erases is five (the contents of the erase number counter 152 is 5). The erase block (2) has one used sector, one used sector, four unused sectors, and the number of erasures is nine. Garbage collection starts from this state.
[0048]
First, an adjustment target erase block is selected. Here, the adjustment target erase block is an erase block to be erased. The selection of the erase block to be arranged is efficient if it is preferentially selected from the erase blocks including many used sectors. However, if the method of preferentially organizing erase blocks with a small number of erasures, except for cases where used sectors are not included, the erase blocks in the chip can be used on average and the rewriting endurance can be distributed. Can do. Details of the selection procedure will be described later using a flowchart.
[0049]
Assume that the erase block (1) is selected as an object to be organized. Next, the used sector (the sector whose used flag is TRUE and the used flag is FALSE) of the erase block (1) which is an arrangement control is moved to another erase block. In the same way as when rewriting sectors, the procedure for moving used sectors is to search for unused sectors in other erase blocks, copy the contents of the data area and management area in the used sectors, and use the move source. Set the used flag of the medium sector to TRUE. The processing when there is no unused sector will be described later.
[0050]
FIG. 8B shows a state where all the sectors in use of the erase block (1) are moved to the erase block (2). As a result, only the used sector exists in the erase block (1).
[0051]
Next, an erase block including only used sectors is searched. Here, the search is performed because all the sectors in the erase block accidentally become used sectors during the normal rewriting operation. Subsequently, the erase block searched is erased. Although it takes time to erase, since a plurality of erase blocks can be erased simultaneously, it is preferable to erase a plurality of erase blocks as much as possible. When erasure is completed, the value before erasure plus 1 is written to the erase count counter. This completes the garbage collection.
[0052]
FIG. 8C shows a state at the end of garbage collection. Since it is more efficient to erase erase blocks at the same time as much as possible, it is preferable to adjust a large number of erase blocks simultaneously as long as there are used and unused sectors. If there is an extremely small number of erasure counters than other erase blocks, it is possible to distribute rewriting durability as long as it is organized even if it does not include used sectors. In addition, once the data is arranged, the arrangement of the data changes, which is a trigger for rewriting endurance distribution.
[0053]
<When there is no unused sector>
Next, a garbage collection procedure when there are no unused sectors even though there are used sectors in the system will be described with reference to FIG. FIG. 9 is a diagram for explaining the operation of garbage collection when there is no unused sector.
[0054]
First, in accordance with the basic garbage collection procedure described above, the erase block (1) is selected as an organizing target. Next, an unused sector for moving the used sector of the erase block (1) is searched. If there is an unused sector, the sector is moved in the same manner as in the basic garbage collection described above.
[0055]
On the other hand, if there is no unused sector as a result of the search, a memory block having a size necessary for saving data is allocated from the heap area of the DRAM 14. Then, the sector in use in the adjustment target erase block is copied to the DRAM 14. In this case, unlike the case where the sector is moved to another area of the flash ROM, the used flag of the original sector is not set to TRUE. This is because, if an accident such as the removal of the battery 7 of the electronic camera occurs at this time, the data in the DRAM disappears and the data cannot be restored. FIG. 9B represents a sector copied to the area of the DRAM 14. When all the sectors in use of the adjustment target erase block have been saved, the adjustment target erase block is selected and erased (see FIG. 9C). After erasing is finished, there should be many unused sectors. Therefore, the unused area is searched next, and the data saved in the DRAM 14 is restored. FIG. 9D shows a state where garbage collection is completed.
[0056]
Even when garbage collection is performed according to the above procedure, data cannot be restored if an accident such as removal of the battery 7 of the electronic camera occurs between erasing the erase block and restoring the data. In other words, the system safety can be further maintained if the method of saving the sector data in the DRAM 14 is not taken as much as possible. Once garbage collection is performed using DRAM, unused sectors are formed. Therefore, if garbage collection is performed once using the DRAM 14, and then normal garbage collection is performed, the erasure time is extra, but safety can be improved. Conversely, if the saving to the DRAM 14 is positively performed (for example, saving as long as there is a heap area), the number of erase blocks that can be arranged at the same time increases, so that the efficiency can be increased. Therefore, it may be configured to be able to specify which of safety and efficiency is prioritized. Further, the system may be configured to automatically switch to safety priority when the system power is supplied from the battery 7, and efficiency priority when supplied from the AC adapter. This process will be described later with reference to FIG.
[0057]
<One extra erase block>
When the remaining capacity becomes extremely small, garbage collection occurs frequently and the performance of the system decreases extremely. By using one more erase block than the number of erase blocks that can store the total logical sector, such a situation can be avoided. Assuming that 127 sectors can be stored per erase block and all sectors are in use, and the same one sector is rewritten 10 times, for example, if there is no extra erase block, 10 erases and 1270 A sector write occurs. However, if one extra erase block is prepared, only 10 sectors are written.
[0058]
Therefore, in this embodiment, since the number of erase blocks is determined by the chip configuration, the total number of logical sectors in which at least one erase block remains is designed.
[0059]
  <Timing of garbage collection>
  Since garbage collection involves an erasing operation, it takes a very long time. Therefore, the usability of the camera depends on when garbage collection is performed. For example, selftimerIf garbage collection is performed when it is not necessary to shoot for a few seconds, the user will not feel stressed.
[0060]
<Storage location management on RAM>
Since the sector number is not related to the actual storage location on the flash ROM 15, the flash ROM 15 must be searched to read / write a specific sector. Therefore, when a storage location management table indicating the storage address of each sector in the flash ROM 15 is created on the DRAM 114 when the system is rebooted, high-speed data reading / writing from / to the flash ROM 15 can be realized. Once the storage location management table is created, the storage location management table is always correct only by updating the storage location management table only when the storage location is changed due to sector writing to the flash ROM 15 or garbage collection. Can be maintained.
[0061]
FIG. 10 is a diagram for explaining a storage location management table created on the DRAM. In the figure, the storage location management table 140 created on the RAM is shown on the right side. The 0 sector and the 4 sector contain a value (NULL) indicating the absence of a storage location. These are sectors that have not been written to that sector at all after formatting, or have been released by the file system.
[0062]
The operation of the device driver when the file system issues an instruction to the driver to release a sector that is no longer needed due to file erasure or the like is as follows. First, a corresponding sector currently in use on the flash ROM 15 is searched with reference to the designated sector pointer in the storage location management table 140 on the DRAM 14. Then, the used flag of the sector is set to TRUE, and an absent value (NULL) is substituted for the pointer of the designated sector in the storage location management table 140 on the DRAM 14.
[0063]
When the sector contents are saved in the DRAM 14 for garbage collection, a pointer to the DRAM is assigned as a storage location. It is also desirable to store in the table a lock variable for prohibiting simultaneous operations on the same logical sector.
[0064]
<File restoration of MS-DOS>
It is convenient if the electronic camera and the personal computer 22 can exchange data on a storage medium. By using the flash ROM management method described in this embodiment, a file system compatible with MS-DOS (trademark) that is currently popular in personal computers can be implemented. MS-DOS comes with a utility for restoring files once deleted. However, in this embodiment, the data portion of the erased sector is lost in order to improve the erase efficiency of the flash ROM. The medium erased by the camera cannot be restored by a personal computer in principle.
[0065]
If the file restoration function on a personal computer can be prohibited, such an accident can be prevented. In this embodiment, the file restoration function is prohibited by destroying data used by MS-DOS when restoring files. How to explain this.
[0066]
When a file is deleted with MS-DOS (trademark), an empty slot is created in the directory. The directory stores information such as file name / time stamp / first cluster. FIG. 45 shows the characteristics of the directory slot. EndOfDir indicating the end of the list is stored at the end of the directory slot.
[0067]
Now, when File B is deleted, the beginning of the file name is replaced with a symbol representing the deletion, and the FAT cluster chain is deleted. This is shown in FIG.
[0068]
The undelete program attempts to restore the file based on the information remaining in the second slot. Conversely, without this information, file restoration can be prevented.
[0069]
FIG. 47 shows a state after the file is erased by the DOS compatible file system of this embodiment. In this embodiment, the file stored at the end of the directory entry table is overwritten on the entry of the file to be deleted, and EndOfDir is overwritten on the portion of the directory entry table that was the last file. By doing so, file restoration by the file restoration function can be prevented.
[0070]
When erasing a file, the sector data is left as it is like MS-DOS (the sector is not released), and unnecessary portions are erased while referring to the relationship between the FAT and the data collectively at the time of garbage collection. There is also a method.
[0071]
<Pretreatment in the background>
In a certain flash ROM, if the data before erasure is “0”, erasure processing can be performed at high speed. Confirmation of completion of erasure of the flash ROM is performed by data polling in the same manner as when data is written. Accordingly, when such a flash ROM is used, performance can be improved by performing “preprocessing” in which the data of the sector “used” in the background processing is rewritten to 0. If the task is executed as the lowest priority task, the throughput will not decrease.
[0072]
If a flag is prepared for “pre-processed sector” management in the pre-processing background, the efficiency of the pre-processing can be improved.
[0073]
Therefore, it is efficient to prepare a management flag in the flash ROM sector that can display four states of “pre-processed” in addition to “unused”, “in use”, and “used” as possible states of the sector. good.
[0074]
FIG. 38 is a flowchart showing a preprocessing control procedure for improving the erase processing speed in the present embodiment. In the figure, in step S2501, sectors that have been used but not preprocessed are extracted. This can be realized by extracting a sector whose management flag in the sector is “used” and not “preprocessed”. In step S2502, overwriting of data “0” is started on the extracted sector. In step S2503, it is determined whether the preprocessing has been completed for the sector. Since writing to the flash ROM is performed in units of 1 byte, it is necessary to write the number of bytes for one sector. If the preprocessing for the sector has not been completed, the process advances to step S2504 to transfer control to another task.
[0075]
As described above, since this process is performed by the task with the lowest priority, this process is executed again when the CPU 5 enters an idle state. In this case, the process returns to step S2503. At this time, if the previous writing has not been completed, the processing is transferred to another task as it is.
[0076]
When writing of “0” is completed for all bytes in the sector as described above, the process advances from step S2503 to step S2505, and the management flag of the sector is set to a state indicating “preprocessed”. Subsequently, the process returns to step S2501 to perform pre-processing for other sectors.
[0077]
<FAT cash>
In this system, the storage location is changed each time a write occurs, and an “unused sector” is generated each time. Therefore, if there is a cache that preferentially buffers a part that is frequently used, it is expected that the total writing frequency will be drastically reduced. The more memory you have as a cache, the better, but the system memory is limited.
[0078]
The data of the sector that is frequently used originally has a high probability of being present in the cache. However, when a large number of sectors that are not used frequently are read and written, the data is naturally discharged from the cache.
[0079]
Therefore, if the management area managed by the file system is configured to be preferentially cached, an improvement in throughput can be expected. This is because the management area of the file system is frequently updated.
[0080]
In the case of the MS-DOS FAT system popular in personal computers, one cluster is composed of one sector in the format format such as 720k and 1.4M, so even when reading a file sequentially, once every two times. I have to read FAT. When writing a file, more FAT accesses occur. For this reason, the cache hit rate drops when many files are opened in the system.
[0081]
Although it depends on the application software, a cache that handles only FAT in the FAT system can secure an equivalent hit rate with 1/2 memory compared to a cache for the entire DISK. FIG. 11 is a diagram showing the hierarchical positioning of the cache software. As shown in FIG. 11, the cache software is an intermediate place between the file system and the flash ROM.
[0082]
FIG. 12 shows a data structure on the main memory of the cache. The entire buffer is managed with a one-way linear list structure. Data is stale in order of search direction. If the logical sector numbers are accessed in the order of 12, 11, 6, and 5, the order shown in FIG. 12 is obtained. Each sector is provided with a change flag. When data is updated on the cache, the change flag changes from FALSE to TRUE. Such FAT cache read and write procedures will be described with reference to FIGS. FIG. 13 is a flowchart showing a FAT cache read procedure. FIG. 14 is a flowchart showing a FAT cache write procedure.
[0083]
In FIG. 13, N sector reading is started in step S1501. In step S1502, it is determined whether the N sector is FAT. If not FAT, data is read from the flash ROM 15 in step S1509.
[0084]
On the other hand, if the N sector is FAT in step S1502, the process proceeds to step S1503 to search the cache list. Here, the one-way linear list described with reference to FIG. 12 is searched. If there are N sectors in the cache, the process advances to step S1507 to read data from the N sector buffer.
[0085]
If N sectors are not present in the cache list in step S1503, the process branches to step S1504, and data of the sector that has not been accessed for the longest time (data of sector number 12 in FIG. 12) is discharged. First, in step S1504, the change flag of the last item in the cache list is determined. If the change flag is TRUE, the process proceeds to step S1505, and the change contents are written in the flash ROM 15. If there is no change (if the change flag is FALSE), control is transferred to step S1506. Although it may seem strange to write during the read procedure, it is more efficient to do as little writing as possible until the buffer is flushed out.
[0086]
In step S1506, the contents of the N sector are read from the flash ROM 15 to the last buffer in the list. In step S1507, data is read from the N sector buffer. In step S1508, the N sector buffer is moved to the top of the cache list. This is achieved by changing the value of “next buffer” (address indicating the next buffer) of each sector in FIG. By repeating the operation in step S1508 every time the FAT cache is accessed, buffers that are not naturally accessed shift from the top of the list toward the end. Therefore, the reason why the last buffer in the list is selected in step S1504 is to discharge the oldest buffer.
[0087]
Next, the writing procedure will be described with reference to FIG.
[0088]
In step S1600, N sector writing is started. In step S1601, it is determined whether the N sector is FAT. If it is not FAT, the process advances to step S1608 to execute data writing to the flash ROM 15.
[0089]
On the other hand, if the N sector is FAT in step S1601, the process proceeds to step S1602, and the cache list is searched. If there are N sectors in the cache, the process proceeds to step S1606, where data is written to the N sector buffer.
[0090]
If N sectors are not present in the cache list in step S1602, the process branches to step S1603, and the sector that has not been accessed the longest from the buffer is discharged and the N sectors are registered in the cache. First, in step S1603, the change flag of the last item in the cache list is determined. If the change flag is TRUE, the change contents are written in the flash ROM in step S1604, and the process proceeds to step S1605. If there is no change (if the change flag is FALSE), control is passed directly to step S1605. In step S1605, the last item in the cache list is set to N sectors. After that, in step S1606, data is written to the N sector buffer.
[0091]
Thereafter, in step S1607, the N and sector buffers are moved to the top of the cache list. Although it may seem strange that writing to the flash ROM is not performed during the writing procedure, it is more efficient not to perform the writing operation as much as possible until the cache is discharged.
[0092]
In addition, in the determination of FAT in step S1501 and step S1601, the location of the FAT area can be determined by analyzing the content of the write data even in a system that cannot completely share information of the upper layer (file system) such as an IC card. Can be identified. This is because it is determined that information such as the FAT position is stored in a portion corresponding to the logical sector O.
[0093]
<Write 1 byte to flash ROM>
All reading / writing (including the management area) with respect to the flash ROM 15 is finally executed by a 1-byte reading / writing command. Writing to the flash ROM 15 takes the same time as a normal PROM. Until the writing of one byte is completed, writing to the same chip cannot be performed. There are a chip in which a signal line is prepared as a write end signal and a chip in which no special signal is prepared. In the latter case, the end of writing must be confirmed by a method called data polling. Data polling is a busy control method that waits until write data and read data match in a method very similar to verification.
[0094]
When the end of writing can be known by the signal line, the CPU time waiting for writing can be allocated to another task in combination with the interrupt to the CPU 5.
[0095]
As described above, in the case of a chip without a signal line, data polling must be performed. In order to increase the efficiency of data writing, data must be written in pipelines to several chips to reduce the loss of data polling time. Therefore, it is necessary to transfer control to the next operation before the writing of 1 byte is completed. It is a good idea to check if the previous write is complete before doing a new read / write. FIG. 15 represents the state in C language.
[0096]
The first line in FIG. 15 is an entry of a function for writing data. The first argument is a last written address and a pointer to a structure for storing data, the second argument is a write address, and the second argument is data to be written.
[0097]
In the third line, the last written address is referenced to compare the data written on the chip with the last written data, and the loop is executed until they match. This is data polling. Exit from this loop when the previous write is complete.
[0098]
Data is written to a new address in the fourth line. Save the address and data written this time in the 5th and 6th lines. This information is used in the next data polling.
[0099]
RotateRdyQueue in the seventh line of the list is an operating system call that yields the CPU to an executable task of the same priority to be executed next to its own task.
[0100]
The ninth line is the entrance to the read function. The first argument is a pointer to a structure for storing an address and data, and the second argument is an address to be read. This function returns the data stored at the address specified by the second argument to the upper program.
[0101]
In the eleventh line, if the address to be read is the last written address, the value to be returned is the last written data, so the information stored in the structure is returned. The 12th line is data polling similar to the 3rd line. If data polling is not successful, another address on the same chip cannot be read. The contents of the address specified in the 13th line are returned after the data polling is completed.
[0102]
If the writing to one chip is configured as described above, the apparent writing speed can be surely improved only by increasing the number of chips and the writing task. In order to increase the overall throughput, it is effective to prepare sector buffers as many as the number of chips (two sectors for two chips) so that processing is not performed until the contents to be written are accumulated in the buffer.
[0103]
The characteristic feature of the program of FIG. 15 is that data polling is not performed immediately after data writing but before the next writing. For this purpose, a RAM area for storing the previously written address and data is secured for each chip and stored as a structure “struct DEV”.
[0104]
FIG. 39 is a flowchart showing a procedure for writing 1-byte data to the flash ROM in this embodiment. This flowchart shows a control procedure for writing to one flash ROM chip. In step S2601, it is determined whether the previous writing process has been completed. If the previous writing process has not been completed, the process proceeds to step S2604, and the control is transferred to another task as it is.
[0105]
On the other hand, if the previous write process has been completed, the next write data is prepared and stored in the DRAM 14. The determination of the end of writing in step S2601 is made by comparing the data written in the flash ROM with the data held in step S2602.
[0106]
In step S2603, data writing is started. According to the above processing, when writing to a plurality of flash ROM chips with a plurality of tasks, a writing process using a so-called round robin method can be performed. Data can be written efficiently. The multitask management program is stored in the ROM 13 described above. As a real-time OS to be embedded, VxWorks (trademark), pSOS (trademark), and the like are commercially available, and such a real-time OS is stored in the ROM 13.
[0107]
<Sharing of flash ROM writing power supply>
There are chips that require a special write voltage such as 12 V when writing and erasing data, and chips that can be written at high speed by applying the write voltage. When such a chip is used, providing a voltage generator such as a dedicated DC / DC converter leads to an increase in the cost of the electronic camera. However, conventional cameras have parts that require special voltages, such as charging a strobe, driving a mechanism, and driving a CCD, and are equipped with a DC / DC converter or the like. Therefore, by performing time-division multiplexing of the flash ROM write voltage, strobe charging, and mechanical drive, a system can be constructed with a small-capacity DC / DC converter, and the system cost can be reduced.
[0108]
FIG. 16 represents a program for managing the power supply in C language so as not to exceed the output capacity of the DC / DC converter. Lines 1 to 6 are 1-step zoom-up functions, and Lines 7 to 13 are write functions for writing one sector to the flash ROM. The zoom-up function acquires a semaphore “SemDCDC” for resource management of the DC / DC converter in Line3, and calls a function for moving the motor by one step in Line4. When the motor driving is finished, the semaphore “SemDCDC” for resource management of the DC / DC converter is opened. A semaphore is a general method for managing resources in a multitasking operating system, and many operating systems provide system calls.
[0109]
In other words, if “SemDCDC” has already been used by another task in Line 3, execution of the task that attempted to zoom in is suspended until the other task releases the semaphore “SemDCDC”.
[0110]
The write function acquires a semaphore “SemDCDC” in Line 9 and writes one sector of data to the flash ROM. When it is confirmed that the last writing has been completed by performing data polling on the Line 11, the semaphore “SemDCDC” is released on the Line 12. If the program is configured in this way, zoom-in and flash ROM writing are not performed simultaneously. Since the zoom is performed in units of one step and the writing is performed in units of sectors, the power supply can always be obtained after a very short holding time.
[0111]
Further explaining FIG. 16, Line 1 in FIG. 16 is an entrance of a function for zooming up. This function has no arguments. Acquire one right of SemDCDC declared as the right to use the power supply in Line 3. At this time, if there is no usage right, the execution of the task that called this function is suspended. If another task releases the right to use the power supply, the task that called ZoomUp returns to the executable state. And the function which moves the motor of Line4 can be called. Then, in Line 5, the power usage right is returned and the work of this function ends. Line 7 is an entry point for a function for writing data of one sector to the EEPROM. The Line 9 de power usage right is acquired and returned by Line 12.
[0112]
FIG. 40 is a flowchart for explaining the above-described power sharing procedure. In the figure, in step S1701, it is determined whether or not the supply of output power from the DC / DC converter 8 by the power supply controller 9 has been released. In step S1702, the content of the instruction for securing the power supply is analyzed, and the process branches to one of steps S1703, 1705, 1707, and 1709 according to the instruction result.
[0113]
If the content of the instruction is supply of CCD drive power, the process advances to step S1703 to supply power for CCD drive to the CCD2. In step S1704, when the end of the CCD drive (ie, the end of the photographing operation) is detected, the process proceeds to step S1711 to release the power source. If it is a strobe charging request, the process advances to step S1705 to cause the power supply controller 9 to provide charging power for the strobe 21. When the charging of the strobe is completed in step S1706, the process proceeds to step S1711 and the power supply is released. In addition, the power supply for charging releases the power supply for supplying other power every time charging is performed for a predetermined time. That is, a program for managing charging of the flash 21 is separately present in a predetermined task, and completion of charging is managed by the task.
[0114]
If the content of the instruction is driving the zoom mechanism, the process advances to step S1707 to supply power to a drive system (not shown) of the zoom mechanism. In step S1708, when the one-step zoom operation is completed, the process proceeds to step S1711 to release the power. Further, if the content of the instruction is writing to the flash ROM, the process advances to step S1709 to supply writing power to the flash ROM 15. When writing for one sector is completed, the process advances from step S1710 to step S1711 to release the power.
[0115]
In steps S1704, 1706, 1708, and 1710, the end of each operation is waited. In this waiting loop, control to another task is transferred and multitask processing is performed. This management process can be started at any time from each task, and may be started simultaneously by a plurality of tasks, so the power release check is performed in step S1701.
[0116]
According to the flowchart of FIG. 40 described above, the power source can be used in a time-sharing manner. However, it is one program on which all systems (CCD / strobe / zoom / flash ROM) depended. When such software is developed, development / debug / maintenance costs increase, and it becomes difficult to maintain expandability and flexibility.
[0117]
Therefore, the development efficiency can be improved by using the resource management function provided by the OS with the power supply as one resource. Therefore, resource management is performed by the semaphore described above. In other words, the control programs of the CCD drive unit, strobe drive unit, zoom drive unit, and flash ROM drive unit acquire and release resources (semaphores) as power sources, thereby allocating time-division power sources. Can be done.
[0118]
FIG. 48 is a diagram for explaining time-sharing use of the power supply according to the present embodiment. As shown in the figure, when a power request is generated by a task A (for example, CCD), if the power semaphore is released, the semaphore is acquired and the power is occupied (steps S2001 to S2003). ). Subsequently, in step S2004, when power is supplied from the power source and predetermined processing is performed, the process proceeds to step S2005 to release the semaphore.
[0119]
On the other hand, task B, which requested power acquisition later than task A, cannot acquire a semaphore by the power request in step S2011, and waits for semaphore release in step S2012. When the semaphore is released from task A, task B acquires this semaphore and occupies the power supply (step S2013). Thereafter, a predetermined process is executed in task B (step S2014), and the power supply is released (step S2015).
[0120]
By managing the power supply resources by the semaphore as described above, the power supply can be used in a time-sharing manner.
[0121]
According to FIG. 48, there is only one semaphore indicating the right to use power resources, but it goes without saying that a plurality of semaphores may exist.
[0122]
<Description of Operation of Electronic Camera of Embodiment>
FIG. 17 is a flowchart showing an operation procedure from reboot to start of service according to the present embodiment. When the system reboots in step S101, the storage area management table 140 is created on the DRAM 14 by scanning the management area of the flash ROM 15 in step S102. In parallel with this processing, the number of sectors corresponding to each state is counted and set in the unused sector counter, used sector counter, and used sector counter on the DRAM 14. This counter is updated when an operation is performed on the flash ROM 15 later, and is used to determine the storage efficiency. Then, it progresses to step S103 and starts various services.
[0123]
FIG. 18 is a flowchart showing the procedure of the designated sector read service. First, reading of N sectors is started in step S201. In step S202, N sectors are locked. Sector locking is done using lock variables. This lock variable is managed together with the storage location of each sector in the storage location management table 140. In step S202, if the sector has already been locked by another task, it waits for the other task to unlock it, and then locks the sector after being unlocked by the other task. The locked sector can be occupied by its own task until it is unlocked in step S206.
[0124]
When the logical sector is locked in step S202, it is checked in step S203 whether valid data is stored in the sector with reference to the storage location management table. If no valid data is recorded, the process branches to step S204. In step S204, dummy data (for example, all 0s) is read as the contents of the sector. If it is determined in step S203 that valid data is stored, the process branches to step S205. In step S205, data is read from the flash ROM (or main memory) based on the values in the recording location management table.
[0125]
Here, when garbage collection is being performed and N sectors have been saved to the main memory (DRAM 14), the pointer of the storage location management table points to the main memory. Further, a portion surrounded by a dotted line in the figure is a period in which N sectors are occupied. Since such a locking mechanism guarantees the safety of one sector operation, it is possible to freely read a sector that is not being operated even during garbage collection.
[0126]
FIG. 19 is a flowchart showing the procedure of the logical sector write service. In step S301, N sector writing is started. In step S302, the logical sector is locked as in step S202.
[0127]
In step S303, the storage location management table is searched to determine whether valid data is recorded in the N sector. If valid data is recorded, the process branches to step S304, and if not recorded, the process branches to step S305. In step S304, the flash ROM (or main memory) data that has been recorded as valid data is discarded. The data discarding process in step S304 will be described in detail using the flowchart of FIG. After step S304, control is transferred to step S305.
[0128]
In step S305, a storage area for writing N sectors in the flash ROM 15 is acquired. The storage area acquisition procedure in step S305 will be described in detail with reference to FIG. If the storage area is successfully acquired in step S305, the control is transferred to step S308. In step S308, N sector data is written to the area of the acquired flash ROM 15.
[0129]
On the other hand, if there is no storage location in the flash ROM in step S305, that is, if acquisition of the storage area has failed, the process branches to step S306. In step S306, main memory is acquired for saving data. The main memory area is secured by a memory management function provided by the operating system. This is a function corresponding to the alloc function in C language. The secured area is managed by a one-way linear list structure.
[0130]
FIG. 20 shows the saved data list acquired on the main memory. (A) is a state where there is no data in the saved data list, and END_OF_LIST is assigned to the list. (B) is a state in which the contents of each sector of sector numbers 3, 20, and 221 are saved in the save data list.
[0131]
In step S309, the recording location management table is updated. Here, a pointer to the recorded flash ROM (or main memory) is substituted. In step S310, the logical sector is unlocked. The logical sector can be occupied for the period enclosed by the dotted line in the figure. In step S311, the storage efficiency is evaluated. The procedure for evaluating the storage efficiency will be described in detail using the flowchart of FIG. If the storage efficiency is deteriorated as a result of the evaluation of the storage efficiency, the control is moved to step S312. In step S312, the above-described garbage collection is performed. The garbage collection will be described in detail with reference to the flowchart of FIG. In step S313, the writing of the N sector is completed and the process returns to the main routine.
[0132]
Note that a storage location pointer (address on the bus space) is stored in the storage location management table. From the next field (shown immediately below in the figure) of the “pointer to the next data” of the data saved in the main memory of FIG. 20B, the flash ROM on the left side of FIG. Compatible with the data structure above. A pointer to this compatible part is stored in the storage location management table. With this configuration, the data read program side can handle the flash ROM and the main memory with a single algorithm.
[0133]
Next, a procedure for discarding the storage of the designated sector (the above-described step S304) will be described. FIG. 21 is a flowchart showing a procedure for discarding the memory.
[0134]
In step S401, memory discard of the designated area is started. In step S402, it is determined whether or not an area for storing the designated sector exists on the main memory. If it is in the main memory, the process branches to step S405. In step S405, the designated area is deleted from the save sector list (in this example, the one-way linear list shown in FIG. 20).
[0135]
In the procedure for deleting a designated area from a one-way linear list, the list is first traced from the top of the list in the order of search direction, and the term where the pointer is pointing is detected. This is realized by substituting the value currently pointed to by the pointer of the detected term. In step S406, the main storage area deleted from the list is returned to the operating system. Returning the storage area to the operating system is a function equivalent to a C free function.
[0136]
On the other hand, if the area specified in step S402 is not in the main memory (that is, in the flash ROM), the process branches to step S403. In step S403, the management flag of the sector on the designated flash ROM is changed to “used”. This is accomplished by setting the used flag to TRUE. In step S404, the value of the unused sector counter on the main memory is decreased by one. It returns in step S407.
[0137]
Next, the storage efficiency evaluation procedure (step S311) will be described. FIG. 22 is a flowchart showing a storage efficiency evaluation procedure.
[0138]
In step S501, evaluation of storage efficiency is started. In step S502, the value of the unused sector counter set in the main memory is compared with the value of the used sector counter. Here, when the value of the used sector counter is the same as or exceeds the value of the unused sector counter, the deterioration of the storage efficiency is reported to the upper program (steps S502 and S504). If the value of the unused sector counter is larger than the value of the used sector counter, the evaluation result is made normal and the normal state is restored (step S503).
[0139]
Next, the procedure for acquiring the storage area of the flash ROM (step S305) will be described. FIG. 23 is a flowchart showing the procedure for acquiring the storage area of the flash ROM.
[0140]
In step S601, acquisition of the storage area of the flash ROM is started. In step S602, an unused sector search right is acquired. Here, the search rights for unused sectors are managed using the semaphore function provided by the operating system. Here, the search rights for unused sectors can be monopolized only during the processing period surrounded by the dotted line from step S602 to step S609 / step S611. This is a mechanism to prevent situations where multiple tasks acquire the same area at the same time.
[0141]
In step S603, the pointer is moved to the first sector of the flash ROM. In step S603, with reference to the management flag (used flag, used flag) of the sector, the used state of the sector is determined. If it has been used or is in use, the process branches to step S605. If the sector currently pointed to in step S605 is the last sector, the process branches to step S611. In this case, since the usable area does not exist in the flash ROM 15, after the search right for the unused sector is released in step S611, an abnormal recovery is performed in step S612. If the sector currently pointed to is not the last sector in step S605, the process branches to step S606. In step S606, the pointer is moved to the next sector, and then the process returns to step S604.
[0142]
Step S604: If the sector management flag indicated by the pointer is unused, the process branches to step S607. In step S607, the flash ROM management flag is changed to “in use” (the in-use flag is set to TRUE). In step S608, the value of the unused sector counter provided in the main memory is decreased by one. In this case, since the storage area has been successfully acquired in the flash ROM, the unused sector search right is released in step S609, and normal recovery is performed in step S610.
[0143]
Next, the procedure of garbage collection (step S312) will be described. FIG. 24 is a flowchart showing a garbage collection procedure.
[0144]
In step S701, garbage collection is started. In step S702, an erase block to be sorted (hereinafter, a block to be sorted) is selected. The selection procedure of the arrangement target block will be described in detail using the flowchart of FIG. In step S703, unused sectors of the arrangement target block are used up. A detailed description will be given of the procedure of the end use with reference to the flowchart of FIG. Here, the purpose of making unused sectors in the organizing block first used is that the other tasks can read and write to the sector including the sector in the organizing block even during garbage collection. This is to prevent new data from being written to sectors in the organizing block by other tasks during garbage collection.
[0145]
In step S704, the sector in use in the organizing target block is moved to another storage area (that is, another erase block). The process of moving the sector in use to another storage area will be described in detail with reference to the flowchart of FIG.
[0146]
In a succeeding step S705, the rearrangement target block for which the movement of the sector in use is finished is deleted. The procedure for deleting the organizing target block will be described in detail with reference to the flowchart of FIG. In erasing the organizing target block, the contents of the erase count counter 152 are copied to the main memory. When the erasure of the target block in step S705 is completed, the data saved in the main memory in step S706 is returned to the erase block counter of the erase block in the flash ROM. In step S707, the process returns from the garbage collection.
[0147]
Next, a procedure for selecting a target block for garbage collection (step S702) will be described. FIG. 25 is a flowchart showing a procedure for selecting a block to be organized.
[0148]
First, in step S801, selection of an arrangement target block is started. In step S802, the first erase block is set in the evaluation pointer. Similarly, in step S803, the organizing target candidate pointer is set to the first erase block.
[0149]
In step S804, it is determined whether a used sector is included in the erase block indicated by the evaluation pointer. If the used sector is not included, step S804 and step S805 are skipped and control is passed to step S807.
[0150]
On the other hand, if a used sector is included in the erase block indicated by the evaluation pointer in step S804, control is transferred to step S805. In step S805, the erase block erase count counter value indicated by the organizing target candidate pointer is compared with the erase block erase count counter value indicated by the evaluation pointer. If the erase block erase count indicated by the evaluation pointer is smaller, control is passed to step S806. In step S806, an evaluation pointer is substituted into the organizing target candidate pointer. On the other hand, if it is determined in step S805 that the erase block erase count indicated by the evaluation pointer is greater, control is passed to step S807.
[0151]
In step S807, it is determined whether or not the evaluation pointer indicates the last erase block. If it is not the last erase block, the evaluation pointer is moved to the next erase block in step S808, and the process returns to step S804. As described above, by repeating the processes of steps S804 to S808, the organizing target candidate pointer indicates an erase block including a used sector and having a small number of erasures.
[0152]
If the evaluation pointer indicates the last erase block in step S807, the process branches to step S809. In step S809, the process returns to the garbage collection process (the process of FIG. 24). The erase block indicated by the organizing target candidate pointer at this time is selected as the organizing target.
[0153]
Next, a process (Step S703) for making unused sectors in the selected organization target block used will be described. FIG. 26 is a flowchart showing a procedure for making unused sectors of a reduction target block used.
[0154]
Processing starts in step S901. In step S902, the pointer is moved to the first sector of the arrangement target block. In step S903, the unused sector search right is acquired. This has the same effect as step S602 in the flowchart of FIG. 23, and monopolizes unused sector search rights while surrounded by the dotted line up to step S908. That is, other tasks are prohibited from searching for unused sectors until all sectors in the target block are scanned and the unused sectors are changed to used sectors. However, since the unused sector is changed to the used sector only by the operation of the management flag, the monopoly time of the search right is short and the overall throughput is not lowered.
[0155]
In step S904, it is determined whether the sector indicated by the current pointer is an unused sector. If it is an unused sector, the process branches to step S905. In step S905, the storage is discarded. The processing procedure of step S905 is as described in the flowchart of FIG. By this process, unused sectors are changed to used sectors. In step S906, it is determined whether the pointer indicates the last sector of the organization target block. If it indicates the last sector, the process branches to step S908; otherwise, the process branches to step S907. In step S907, the pointer is moved to the next sector, and control is returned to step S904.
[0156]
If the pointer is the last sector of the block to be organized in step S906, the unused sector search right is released in step S908, and the process returns to the garbage collection process (flowchart in FIG. 24) in step S909.
[0157]
Next, the process (step S704) of moving the used sector of the organizing block to an unused sector of another erase block will be described. FIG. 27 is a flowchart showing a procedure for moving the sector in use of the organizing target block.
[0158]
Processing starts in step S1000. In step S1001, the pointer is moved to the first sector of the organizing block. In the following steps S1002 to S1012, processing is performed for the sector indicated by the pointer.
[0159]
In step S1002, the management flag (used flag, used flag) of the sector is determined. If the value of the management flag is “in use” in step S1002, the control is transferred to step S1003, and if it is “used”, the control is transferred to step S1012. In step S1003, the logical sector is locked. The locked sector is occupied by its own task until it is unlocked in step S1011.
[0160]
In step S1004, a storage area is acquired. The procedure for securing the storage area in step S1004 is as described in the flowchart of FIG. Here, since all the sectors in the organizing target block have been used in the processing of step S703, the storage area to be secured is an erase block other than the organizing target block.
[0161]
If acquisition of the storage area is successful, the process proceeds to step S1008. In step S1008, the sector data is copied to the acquired area. Then, in accordance with the movement of the sector, the storage location management table 140 is updated in step S1009.
[0162]
On the other hand, if acquisition of the storage area has failed in step S1004, the process branches to step S1005. In step S1005, a storage area for saving data is acquired from the main memory (DRAM). Acquisition of the data saving storage area is as described in step S306 in the flowchart of FIG. In step S1006, the sector data is copied to the acquired area. In step S1007, the storage management table is updated. In step S1010, the original memory is discarded. That is, the used flag of the sector indicated by the pointer is set to TRUE. In step S1011, the logical sector is unlocked.
[0163]
In step S1012, it is determined whether the sector pointed to by the pointer is the last sector of the organizing block. If it is the last sector, the process branches to step S1014. If it is not the last sector, the process branches to step S1013. In step S1013, the pointer is moved to the next sector, the process returns to step S1002, and the above processing is repeated for the next sector. In step S1014, since processing has been completed for all sectors in the arrangement target block, the process returns to the garbage collection process (flowchart in FIG. 24).
[0164]
Next, the erasure process (step S705) of the organizing target block will be described. FIG. 28 is a flowchart showing the erase procedure for the erase block to be organized.
[0165]
Processing starts in step S1101. In step S1102, the erasure counter of the arrangement target block is copied to the main memory. In step S1103, the arrangement target block is erased. In step S1104, a value obtained by incrementing the value of the erase count counter copied to the main memory by 1 is written to the flash ROM. That is, the value of the erase counter of the organizing target block is increased by 1 from the value before the erase process. Thereafter, the process returns to the garbage collection process (the flowchart in FIG. 24) in step S1105.
[0166]
The garbage collection process shown in FIG. 24 is a process using a flash ROM as much as possible, and the safety of saved data is high. However, as described in the section <When there is no unused sector>, the main memory (DRAM 14) is actively used to save the data in the used sector and the erase process is performed when a plurality of erase blocks are erased. Is efficient. However, since the data is saved in the DRAM 14, the safety of the saved data is lowered (for example, when the battery is removed and the power supply is stopped, the data saved in the DRAM is lost). Therefore, the type of power supply is judged, and if the power supply is a battery, the safety of the saved data is emphasized. If the AC adapter is used, the risk of the power supply being stopped is low, so the efficiency of the erasure process is emphasized. May be. Processing in this case will be described with reference to FIG.
[0167]
FIG. 36 is a flowchart for explaining the processing procedure when the garbage collection processing is switched based on the power source type. In this figure, the same step numbers are assigned to steps that perform the same processes as those shown in the flowchart of FIG. 24, and detailed description thereof is omitted here.
[0168]
When the garbage collection process is started in step S1300, the process proceeds to step S1301 to determine the form of power supply to the apparatus. Here, the power supply controller 9 of FIG. 1 determines whether the power supply source is the battery 7 or the AC adapter 23 and notifies the CPU 5 of it. If the power supply type is battery 7, the process advances to step S1304 to execute the garbage collection process shown in FIG.
[0169]
On the other hand, if the power supply type is AC adapter in step S1301, the process proceeds to step S1302. In step S1302, processing corresponding to steps S702, S703, and S704 in FIG. 24 is executed, and unused sectors in the selected block to be rearranged are used and used sectors are saved. In step S1303, it is determined whether or not there is enough free space in the main memory (DRAM 14) to save the sector. If there is enough free space, the process returns to step S1302. In step S1302, a rearrangement target block different from the previous rearrangement target block is selected, and the above-described processing is repeated.
[0170]
When there is no sufficient free space on the DRAM 14, the process advances from step S1303 to step S1304, and the arrangement target block selected in the above process is erased. In step S706, the data saved in the main memory is returned to the flash ROM 15, and the process is terminated.
[0171]
As described above, according to the processing of FIG. 36, when power is supplied from the AC adapter, the free space of the main memory is actively used to save data, and a plurality of blocks to be organized are selected. Thus, the erasing process can be performed collectively, and the efficiency of the erasing process is improved.
[0172]
In the above processing, the garbage collection mode is automatically switched based on the power supply type, but it goes without saying that it can be switched manually by operating the control panel 12.
[0173]
Next, a procedure for releasing a logical sector, which is one of basic services, will be described. FIG. 29 is a flowchart showing a logical sector release procedure.
[0174]
In step S1201, release of N sectors is started. In step S1202, N sectors are locked. As a result, the logical sector can be occupied by its own task until it is unlocked in step S1205. In step S1203, the storage of the sector is discarded. This memory discarding process is as described in the flowchart of FIG. In step S 1204, the “absent” value is substituted into the storage location management table 140 of the DRAM 14. In step S1205, the logical sector is unlocked, and the process returns in step S1206.
[0175]
For example, in a general file system such as MS-DOS (trademark), when erasing a file, only the sector belonging to the file can be overwritten in the FAT, and each sector is not released. Therefore, when the flash ROM management system according to the present embodiment is applied to such a file system, data invalid on the file system is left as a valid sector, and the efficiency of garbage collection or the like is reduced. I will let you. Therefore, if it is configured to detect a sector that is no longer needed based on a file system instruction (for example, file deletion) and release it, the garbage collection efficiency can be further improved.
[0176]
FIG. 37 is a flowchart showing a procedure for releasing unnecessary sectors when file erasure is instructed by the file system. In the figure, it is determined in step S1401 whether or not a file deletion instruction is issued from the file system. If there is an instruction to delete the file, the process advances to step S1402 to extract a sector included in the file instructed to be deleted. The sector can be extracted by referring to the FAT. In step S1403, the sector release processing described in the flowchart of FIG. 29 is executed for each sector extracted in step S1402.
[0177]
[Embodiment 2]
Next, Embodiment 2 will be described.
[0178]
<Disk controller emulation>
The flash ROM storage management system described in the first embodiment is very similar to the disk medium in terms of the upper layer. Therefore, the disk controller and the disk medium are replaced with the disk controller emulation and the storage management system according to the present embodiment (or the IC card incorporating the storage management system according to the present embodiment) by incorporating the disk controller into a system having the emulation function of the disk controller. It becomes possible. In recent years, IC cards represented by PCMCIA have become widespread, but by incorporating the disk controller emulation function and the storage management system of the first embodiment into the IC card, it can be used as a removable storage medium. In the second embodiment, a case where the storage management system of the first embodiment is incorporated into an IC card will be described.
[0179]
FIG. 30 is a block diagram illustrating a configuration of an IC card according to the second embodiment. In the figure, reference numeral 200 denotes the entire IC card. A microcomputer 201 performs disk controller emulation and storage management. A ROM 202 stores a program for the microcomputer 201. A RAM 203 functions as a main memory of the microcomputer 201. A flash ROM 204 accumulates data by the storage management system described in the first embodiment. That is, the flash ROM 204 is managed by the management area and the data area described with reference to FIG.
[0180]
A command / data latch unit 205 holds a command from the external bus received from the host device, a cylinder number, and the like. Reference numeral 206 denotes a FIFO memory, which inputs and outputs data using a first-in first-out method. A tuple ROM 207 stores the characteristics of the card and can be read only from an external bus.
[0181]
The function of each configuration described above will become more apparent in the following description of the operation.
[0182]
FIG. 31 is a simple block diagram of a host system for using the IC card of the second embodiment. In the figure, reference numeral 301 denotes a microcomputer on the host system side. A card interface 302 connects the internal bus of the host system and the external bus of the IC card 200. The card interface 302 also includes a power supply line for supplying power to the IC card 200 and a signal line for receiving an interrupt request (IRQ output) from the IC card 200.
[0183]
FIG. 32 is a flowchart showing a procedure when the host system of FIG. 31 connects an IC card. When processing is started in step S4100, power supply to the IC card is started in step S4101. In step S4102, the data stored in the tuple format is analyzed from the tuple ROM 7 in the IC card 200. By analyzing the contents of the tuple ROM 7, the characteristics of the connected IC card can be understood.
[0184]
In step S4103, it is determined whether the connected IC card can be connected to the internal bus based on the tuple information analyzed in step S4102. If connection is possible, the process branches to step S4104, and if connection is not possible, the process branches to step S4105. In step S4104, the bus on the IC card side is mapped to the memory space and IO space of the internal bus of the host. At this point, the disk controller is in the host device bus space.
[0185]
FIG. 33 is a flowchart showing a main sequence of the microcomputer 1 in the IC card 200. When the power of the IC card is turned on in step S4201, the storage management system is initialized in step S4202. That is, the states of the logical sectors of all erase blocks in the flash ROM 204 are once read, and a storage location management table is created in the main storage RAM 203 according to the read information. In step S4203, a ring-shaped buffer is prepared and initialized as a command buffer on the main memory, and interrupt processing is permitted. After this process, the interrupt routine starts.
[0186]
The sequence of the interrupt routine is shown in the flowchart of FIG. Since the explanation of the flowchart of FIG. 33 becomes easier if the operation of the interrupt routine is understood, the flowchart of FIG. 34 will be explained here.
[0187]
When the host system writes a command to the address of the command to the command / data latch 205, an interrupt is generated from the command / data latch 205 to the microcomputer 201. The command / data latch 205 is mapped to the IO address space of the host bus and the bus inside the IC card, and each command / data is assigned an IO address as shown in FIG. FIG. 35 is a diagram showing IO allocation in the command / data latch of this embodiment. In this example, an interrupt is generated to the microcomputer 201 by writing a command (for example, ReadSector (s) for instructing data reading) to the address of Command in FIG.
[0188]
When an interrupt occurs, the software of the microcomputer 201 transfers control to step S4301 in the flowchart of FIG. In step S4302, the data written in the command / data latch 205 is read and stored in the ring buffer on the main memory. In step S4303, the interrupt routine is terminated and the process returns to the flowchart of FIG.
[0189]
Returning to the flowchart of FIG. In step S4204, the microcomputer 201 determines the state of the command buffer. If data is stored in the command buffer, the process branches to step S4205. If no data is stored, the process branches to step S4213. In step S4213, the CPU is put into a sleep state. Many one-chip microcomputers have a function of halting instruction execution and reducing current consumption, but the CPU of this embodiment also has this kind of function. When an interrupt request signal by IRQ is input, the CPU 201 returns from the sleep state and executes the above-described interrupt routine. When the interrupt program has been executed, the process returns from step S4213 to return to step S4204.
[0190]
If data is stored in the command buffer in step S4204, the process proceeds to step S4205. In step S4206, data is read from the ring buffer. In step S4206, the command is interpreted. In the case of the Seek command, the process branches to step S4208 in the case of the ReadSector (s) command, to step S4209 in the case of WriteSector (s), and to step S4210 in the case of the IdentifyDrv command. There are other commands, but those not important for the description of this embodiment are omitted, and the flowchart is simplified. When the execution of the commands in steps S4207 to 4210 is completed, the process returns to step S4204 to repeat the above processing.
[0191]
In step S4207, the Seek command is executed. Even though Seek does not have a head in a flash ROM unlike a disk device, it just checks the validity of the next command. When a head position exceeding the number of heads supported by the IC card is designated, an error occurs as in the disk device.
[0192]
In step S4208, processing for the ReadSector (s) command is performed. In the ReadSector (s) command, the number of sectors to be read is specified by SectorCount in FIG. Therefore, in step S4208, an act of reading SectroCount sectors at the designated location is performed. In the storage management system of this embodiment, since management is performed using linear logical sector numbers, linear logical sector numbers are calculated based on cylinder / head / sector numbers, and the contents of the logical sectors are stored in the FIFO memory 206. And SectorNumber of the command / data latch 205 is incremented. The FIFO memory 206 is a FIFO memory configured to read data written from the internal bus of the IC card 200 from the external bus and read data written from the external bus from the IC card internal bus.
[0193]
Here, the above-described linear logical sector number will be described. In general, a number designated for a hard disk is a three-dimensional discontinuous number determined by parameters of a sector, a cylinder, and a head. For example, in the case of a hard disk having 1024 cylinders, 16 heads, and 63 sectors, the number of sectors is 1024 × 16 × 63 = 1032192.
[0194]
Although it is preferable that this sector can be accessed from No. 0 to 1032192, it is designed to access by designating all the above three parameters. For example, after the cylinder 500, the head 16, and the sector 63, the cylinder 501, the head 0, and the sector 1 are accessed. These three parameters are referred to as CHS parameters by taking their initials.
[0195]
In an operating system such as MS-DOS (trademark), a linear (continuous) sector number is used internally, but the device driver converts this into a CHS parameter. In the system of this embodiment, linear sector numbers are used, and therefore linear sector numbers are obtained based on the value of the CHS parameter. For the hard disks listed above,
Cylinder number x (16 x 63) + head number x (63) + sector number
By calculating, a linear logical sector number is obtained.
[0196]
In step S4209, data is written to the sector at the location specified by the data latch. Data is received from the host system via the FIFO memory 206.
[0197]
In step S4210, a process of returning information indicating what kind of hard disk the IC card 200 is emulating is performed. That is, a process for writing data including specifications as a hard disk such as the number of cylinders and ModelNumber to the FIFO memory 206 is performed.
[0198]
<Analysis of file system>
As described above, by incorporating the storage management system described in the first embodiment into an IC card, it can be used for replacement of an ATA hard disk or the like. However, there is no method for obtaining information for processing such as FAT cache such as ATA command or release of unnecessary sectors caused by file erasure from the host system. By additionally mounting a sector release command and a sector number designation command to be cached by using an empty portion of the ATA command, a function of FAT cache and unnecessary sector release can be realized. Needless to say, it is better to realize the release of the FAT cache and the sector even in the current system such as MS-DOS which does not assume such a function.
[0199]
The FAT system stores information such as the FAT location and size in a portion corresponding to logical sector number 0. In this embodiment, by reading this sector, the FAT location and size are acquired and used for FAT cache processing. Similarly, it is an IC card that originally should not understand the contents of the write data, but by analyzing information for the file system (directory entry and FAT), the IC card autonomously determines and releases unnecessary sectors, etc. It can be used for processing. Of course, the present invention is not limited to the FAT, and unnecessary sectors can be detected by analyzing the contents of data to be written even in the HPFS or Macintosh (trademark) file system. With this configuration, it is possible to perform optimization processing in accordance with the operation of the file system even with the ATA hard disk interface.
[0200]
Further, the present invention may be applied to a system composed of a plurality of devices or an apparatus composed of a single device. Needless to say, the present invention can also be applied to a case where the present invention is achieved by supplying a program to a system or apparatus. In this case, the storage medium storing the program according to the present invention constitutes the present invention. Then, by reading the program from the storage medium to the system or apparatus, the system or apparatus operates in a predetermined manner.
[0201]
【The invention's effect】
As described above, according to the present invention, an electronic camera capable of adapting a flash ROM having a large erase unit to a file system is provided.
[0202]
[Brief description of the drawings]
FIG. 1 is a block diagram illustrating a configuration of a camera system according to a first embodiment.
FIG. 2 is a diagram illustrating a hierarchical structure of a file system in the electronic camera of the present embodiment.
FIG. 3 is a diagram showing a declaration statement in which a device driver management block is described in C language;
FIG. 4 is a diagram showing an example of a sector structure on a flash ROM.
FIG. 5 is a diagram illustrating a configuration in which management area data and a data area are stored separately.
FIG. 6 is a diagram showing meanings corresponding to states of flags.
FIG. 7 is a diagram for explaining a sector rewrite procedure in a flash ROM;
FIG. 8 is a diagram illustrating a garbage collection operation of the flash ROM in the present embodiment.
FIG. 9 is a diagram for explaining an operation of garbage collection when there is no unused sector;
FIG. 10 is a diagram illustrating a storage location management table created on a DRAM.
FIG. 11 is a diagram showing hierarchical positioning of cache software.
FIG. 12 is a diagram showing a data structure on a main memory of a cache.
FIG. 13 is a flowchart showing a FAT cache read procedure;
FIG. 14 is a flowchart showing a FAT cache write procedure;
FIG. 15 is a diagram expressing an operation procedure for confirming completion of data writing in C language.
FIG. 16 is a diagram expressing a program for managing a power supply in C language so as not to exceed the output capacity of the DC / DC converter.
FIG. 17 is a flowchart showing an operation procedure from reboot to service start according to the present embodiment.
FIG. 18 is a flowchart showing a procedure of a designated sector read service;
FIG. 19 is a flowchart showing a procedure of a logical sector write service.
FIG. 20 shows a state of a saved data list acquired on the main memory.
FIG. 21 is a flowchart showing a procedure for discarding storage.
FIG. 22 is a flowchart showing a procedure for evaluating storage efficiency.
FIG. 23 is a flowchart showing a procedure for acquiring a storage area of a flash ROM.
FIG. 24 is a flowchart showing a garbage collection procedure.
FIG. 25 is a flowchart showing a procedure for selecting a block to be organized.
FIG. 26 is a flowchart showing a procedure for making unused sectors of a reduction target block used.
FIG. 27 is a flowchart showing a procedure for moving a sector in use of a target block.
FIG. 28 is a flowchart showing an erase procedure for erase blocks to be organized.
FIG. 29 is a flowchart showing a logical sector release procedure.
30 is a block diagram illustrating a configuration of an IC card in Embodiment 2. FIG.
FIG. 31 is a simple block diagram of a host system for using the IC card of the second embodiment.
FIG. 32 is a flowchart showing a procedure when the host system of FIG. 31 connects an IC card.
FIG. 33 is a flowchart showing a main sequence of the microcomputer in the IC card.
FIG. 34 is a flowchart showing a procedure of interrupt processing of the microcomputer in the IC card.
FIG. 35 is a diagram illustrating an allocation state of an IO address.
FIG. 36 is a flowchart for describing a processing procedure when the garbage collection processing is switched based on a power supply type.
FIG. 37 is a flowchart showing a procedure for releasing unnecessary sectors when file erasure is instructed by the file system.
FIG. 38 is a flowchart showing a preprocessing control procedure for improving the erasure processing speed in the present embodiment.
FIG. 39 is a flowchart showing a procedure for writing 1-byte data to the flash ROM in the present embodiment.
FIG. 40 is a flowchart for explaining a power source sharing procedure;
FIG. 41 is a diagram for explaining a storage state of a control program in a flash ROM in the present embodiment.
FIG. 42 is a diagram illustrating an example of a program code expressed by a relative address.
43 is a diagram showing a table for storing data of the relocation information record of FIG. 42. FIG.
44 is a diagram showing program codes when the program of FIG. 41 is mapped to address 8710 in the main memory.
FIG. 45 is a diagram illustrating characteristics of a directory slot.
46 is a diagram showing a state in which FileB has been deleted in the directory slot of FIG. 45. FIG.
FIG. 47 is a diagram illustrating a state after a file is deleted by the DOS compatible file system according to the present embodiment.
FIG. 48 is a flowchart illustrating time-sharing use of power resources (semaphores) according to the present embodiment.

Claims (7)

データをフラッシュROMに保存する電子カメラであって、
前記フラッシュROM内の消去単位である消去ブロックにおいて、有効なデータが書き込まれた領域の内容を当該消去ブロック外へ移動させる移動手段と、
前記移動手段の実行の後に前記消去ブロックの消去動作を行う消去手段と、
セルフタイマー撮影を行うためのタイマー手段とを備え、
前記移動手段及び消去手段の実行を前記タイマー手段による時間の計測中に実行することを特徴とする電子カメラ。
An electronic camera that stores data in a flash ROM,
In the erase block, which is an erase unit in the flash ROM, moving means for moving the contents of the area in which valid data is written out of the erase block;
Erasing means for performing an erasing operation of the erase block after execution of the moving means;
Timer means for performing self-timer shooting,
An electronic camera characterized in that the moving means and the erasing means are executed during the time measurement by the timer means .
前記フラッシュROMに形成された、複数のデータ領域、及び各データ領域に対応する管理領域と、
データの書込み先を示す指定情報を伴う書込み指示を受けて、前記複数のデータ領域のうちの一つのデータ領域にデータを書き込むと共に、該指定情報を該データ領域に対応する管理領域に書き込む書込み手段と、
データの読み出し元を示す指定情報を伴う読出し指示を受けて、該指定情報が格納された管理領域を検索し、検索された管理領域に対応するデータ領域に格納されたデータを読み出す読出し手段とを更に備えることを特徴とする請求項1に記載の電子カメラ。
A plurality of data areas formed in the flash ROM, and a management area corresponding to each data area;
Write means for receiving a write instruction accompanied by designation information indicating a data write destination, writing data to one of the plurality of data areas, and writing the designation information to a management area corresponding to the data area When,
Receiving means for receiving a read instruction accompanied by designation information indicating a data read source, searching for a management area in which the designation information is stored, and reading data stored in a data area corresponding to the searched management area The electronic camera according to claim 1, further comprising:
前記管理領域は、対応するデータ領域に書込みが可能であることを示す未使用状態と、データ領域に書き込まれたデータが有効であることを示す使用中状態と、データ領域に書き込まれたデータが無効であることを示す使用済状態の少なくとも3通りの状態のいずれかを示す状態情報を格納し、
前記書込み手段は、状態情報が未使用状態となっている管理領域を検索して検索された管理領域及びこれに対応するデータ領域に前記指定情報及びデータを書き込み、該管理領域の状態情報を使用中に変更することを特徴とする請求項に記載の電子カメラ。
The management area includes an unused state indicating that writing to the corresponding data area is possible, a busy state indicating that data written to the data area is valid, and data written to the data area. Stores status information indicating one of at least three used statuses indicating invalidity,
The writing means searches the management area in which the status information is in an unused state, writes the specified information and data in the searched management area and the data area corresponding thereto, and uses the status information of the management area The electronic camera according to claim 2 , wherein the electronic camera is changed inside.
前記書込み手段は、前記書き込み指示に伴う指定情報を有する管理領域を検索し、検索された管理領域の状態情報を使用済状態に変更することを特徴とする請求項に記載の電子カメラ。The electronic camera according to claim 3 , wherein the writing unit searches for a management area having designation information associated with the writing instruction, and changes state information of the searched management area to a used state. 前記移動手段は、フラッシュROM内の消去単位である消去ブロックにおいて、状態情報が使用中状態である全ての管理領域を検索し、検索された管理領域及び対応するデータ領域の内容を当該消去ブロック外へ移動させることを特徴とする請求項に記載の電子カメラ。The moving means searches all management areas whose status information is in use in an erase block which is an erase unit in the flash ROM, and stores the contents of the searched management area and the corresponding data area outside the erase block. The electronic camera according to claim 3 , wherein the electronic camera is moved. 電源の使用を管理する電源管理手段を更に備え、
前記電源管理手段は、ストロボ充電、機構部分の駆動あるいはCCD駆動の少なくともいずれかに用いられる電源の電力を前記フラッシュROMへの書込みアクセスに割り振ることを特徴とする請求項1乃至5のいずれかに記載の電子カメラ。
A power management means for managing power usage;
6. The power source managing means allocates power of a power source used for at least one of strobe charging, mechanism driving, and CCD driving to write access to the flash ROM. The electronic camera described.
前記電源管理手段は、前記電源による電力の供給を、前記ストロボ充電、機構部分の駆動、CCDの駆動、前記フラッシュROMの書込み処理に対して時分割に割り当てることを特徴とする請求項6に記載の電子カメラ。  7. The power management unit according to claim 6, wherein power supply by the power source is allocated in a time-sharing manner to the strobe charging, mechanism driving, CCD driving, and flash ROM writing processing. Electronic camera.
JP25124195A 1995-09-28 1995-09-28 Electronic camera Expired - Fee Related JP3727983B2 (en)

Priority Applications (3)

Application Number Priority Date Filing Date Title
JP25124195A JP3727983B2 (en) 1995-09-28 1995-09-28 Electronic camera
US08/710,946 US5933847A (en) 1995-09-28 1996-09-24 Selecting erase method based on type of power supply for flash EEPROM
US09/350,188 US6604168B2 (en) 1995-09-28 1999-07-09 Flash eeprom management using ratio of used to unused sectors

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP25124195A JP3727983B2 (en) 1995-09-28 1995-09-28 Electronic camera

Publications (2)

Publication Number Publication Date
JPH0993523A JPH0993523A (en) 1997-04-04
JP3727983B2 true JP3727983B2 (en) 2005-12-21

Family

ID=17219834

Family Applications (1)

Application Number Title Priority Date Filing Date
JP25124195A Expired - Fee Related JP3727983B2 (en) 1995-09-28 1995-09-28 Electronic camera

Country Status (1)

Country Link
JP (1) JP3727983B2 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP1514189A1 (en) 2002-06-20 2005-03-16 Tokyo Electron Device Limited Memory device, memory managing method and program
JP4794530B2 (en) * 2007-10-26 2011-10-19 ルネサスエレクトロニクス株式会社 Semiconductor device and mobile phone

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH02248170A (en) * 1989-03-22 1990-10-03 Toshiba Corp Electronic camera
JPH0348582A (en) * 1989-07-17 1991-03-01 Konica Corp Still video camera
JPH04313978A (en) * 1991-04-12 1992-11-05 Canon Inc Still picture recorder
JP2582487B2 (en) * 1991-07-12 1997-02-19 インターナショナル・ビジネス・マシーンズ・コーポレイション External storage system using semiconductor memory and control method thereof
JP3407317B2 (en) * 1991-11-28 2003-05-19 株式会社日立製作所 Storage device using flash memory
US5740395A (en) * 1992-10-30 1998-04-14 Intel Corporation Method and apparatus for cleaning up a solid state memory disk storing floating sector data
US5404485A (en) * 1993-03-08 1995-04-04 M-Systems Flash Disk Pioneers Ltd. Flash file system
JP3839856B2 (en) * 1994-02-23 2006-11-01 キヤノン株式会社 Data processing device

Also Published As

Publication number Publication date
JPH0993523A (en) 1997-04-04

Similar Documents

Publication Publication Date Title
US5933847A (en) Selecting erase method based on type of power supply for flash EEPROM
EP1686482B1 (en) File recording device
US6115799A (en) Information processing apparatus and associated method for managing a memory using a next fit and for reducing a memory fragmentation problem
KR100951107B1 (en) Method for managing files for optimal performance
KR100877448B1 (en) Nonvolatile storage system
JP3727982B2 (en) Flash ROM management method and apparatus
US6378033B1 (en) Electronic device, control method thereof and storage medium
US7523280B2 (en) Storage managing system, storage managing apparatus, and storage managing method
EP0522780A2 (en) Control method for a computer memory device
JP2003208412A (en) Circuit group control system
WO2010134300A1 (en) Memory controller, nonvolatile storage device, accessing device, nonvolatile storage system, and method and program for writing data
JP2004334419A (en) Magnetic disk device, file management system, and its method
JP3324572B2 (en) Information processing apparatus and recording medium recording program to be executed by computer
US7376758B2 (en) I/O dependency graphs
JPH0997218A (en) Method and device for managing flash rom and computer control equipment
JP3703181B2 (en) Flash ROM management method and apparatus
US5678024A (en) Method and system for dynamic performance resource management within a computer based system
JPH0997205A (en) Method, device for managing flash rom and computer control equipment
JPH0997207A (en) Method, device for managing flash rom and computer control equipment
JPH0997206A (en) Method, device for managing flash rom and computer control equipment
JP3727983B2 (en) Electronic camera
JPH0997199A (en) Method and device for flash rom management and computer controller
JPH0997314A (en) Ic card device
JP2006228138A (en) Semiconductor storage device, storage control method, and information equipment
EP0418723A2 (en) Buffered disk unit and method of transferring data therein

Legal Events

Date Code Title Description
A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20050415

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20050614

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20050704

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20050902

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20050926

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20050930

R150 Certificate of patent or registration of utility model

Free format text: JAPANESE INTERMEDIATE CODE: R150

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20091007

Year of fee payment: 4

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20091007

Year of fee payment: 4

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20101007

Year of fee payment: 5

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20101007

Year of fee payment: 5

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20111007

Year of fee payment: 6

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20111007

Year of fee payment: 6

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20121007

Year of fee payment: 7

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20131007

Year of fee payment: 8

LAPS Cancellation because of no payment of annual fees