私はAVRのEEPROMの寿命を最大化するArduinoライブラリに取り組んでいます。保存する変数の数を取得し、残りを実行します。これは私の試みですが、すべての場合に機能するとは限りません。
背景情報
Atmelによると、各メモリセルの定格は100,000回の書き込み/消去サイクルです。また、ウェアレベリングの実行方法を説明するアプリケーションノートも提供します。アプリケーションノートの概要は次のとおりです。
2つのメモリアドレス間で書き込みを交互に行うことにより、消去/書き込みを200,000サイクルに増やすことができます。3つのメモリアドレスにより、300,000回の消去/書き込みサイクルなどが可能になります。このプロセスを自動化するために、ステータスバッファを使用して、次の書き込みがどこにあるべきかを追跡します。ステータスバッファもパラメータバッファと同じ長さである必要があります。これは、ウェアレベリングも実行する必要があるためです。次の書き込みのインデックスを保存できないため、対応するインデックスをステータスバッファにインクリメントします。
これが例です。
<------------------- EEPROM -------------------->
0 N
-------------------------------------------------
Parameter Buffer | Status Buffer |
-------------------------------------------------
Initial state.
[ 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 ]
First write is a 7. The corresponding position
in the status buffer is changed to previous value + 1.
Both buffers are circular.
[ 7 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 ]
A second value, 4, is written to the parameter buffer
and the second element in the status buffer becomes
the previous element, 1 in this case, plus 1.
[ 7 | 4 | 0 | 0 | 0 | 0 | 1 | 2 | 0 | 0 | 0 | 0 ]
And so on
[ 7 | 4 | 9 | 0 | 0 | 0 | 1 | 2 | 3 | 0 | 0 | 0 ]
次の書き込みが発生する場所を決定するために、要素間の違いを調べます。前の要素+1が次の要素と等しくない場合、次の書き込みが発生する場所です。例えば:
Compute the differences by starting at the first
element in the status buffer and wrapping around.
General algo: previous element + 1 = current element
1st element: 0 + 1 = 1 = 1st element (move on)
2nd element: 1 + 1 = 2 = 2nd element (move on)
3rd element: 2 + 1 = 3 = 3rd element (move on)
4th element: 3 + 1 = 4 != 4th element (next write occurs here)
[ 7 | 4 | 9 | 0 | 0 | 0 | 1 | 2 | 3 | 0 | 0 | 0 ]
^ ^
| |
Another edge case to consider is when the incrementing values
wrap around at 256 because we are writing bytes. With the
following buffer we know the next write is at the 3rd element
because 255 + 1 = 0 != 250 assuming we are using byte arithmetic.
[ x | x | x | x | x | x | 254 | 255 | 250 | 251 | 252 | 253 ]
^
|
After we write at element 3 the status buffer is incremented
to the next value using byte arithmetic and looks like this.
255 + 1 = 0 (wrap around)
0 + 1 != 251 (next write is here)
[ x | x | x | x | x | x | 254 | 255 | 0 | 251 | 252 | 253 ]
^
|
上記の例は、1つの変数のEEPROMの寿命を延ばす方法を示しています。複数の変数の場合、EEPROMを同じデータ構造で、バッファが小さい複数のセグメントにセグメント化することを想像してください。
問題
私は上で説明したもののための作業コードを持っています。私の問題は、バッファ長が256以上の場合にアルゴリズムが機能しないことです。これが何が起こるかです。
Buffer length of 256. The last zero is from
the initial state of the buffer. At every index
previous element + 1 == next element. No way to
know where the next write should be.
<-------------- Status Buffer ------------>
[ 1 | 2 | ... | 253 | 254 | 255 | 0 ]
A similar problem occurs when the buffer length
is greater than 256. A lookup for a read will think
the next element is at the first 0 when it should be at
255.
<-------------------- Status Buffer ------------------>
[ 1 | 2 | ... | 253 | 254 | 255 | 0 | 0 | 0 ]
質問
上記の問題をどのように解決できますか?次の要素をどこに書くべきかを追跡するためのより良い方法はありますか?