NVOL是持續的閃光註冊表,通常稱為Eeprom仿真。它提供了一個基本的API,用於讀取和從閃存讀取索引鍵/值對,類似於註冊表。重要的是要提及的是,密鑰和值都存儲在Flash中,從而可以在運行時修改註冊表。 NVOL的某些功能包括:
該庫提供了兩個選項來管理數據存儲:選項1:每當更改時,立即將條目保存到閃存。選項2:將條目存儲在RAM中,並按需保存到閃存。
閃存的缺點是它不能用單個字節刪除或編寫。閃存只能刪除並寫入大塊。典型的擦除塊大小可能是4K或8K字節。對於NVOL,Flash實現應支持部分寫作,只要位從“ 1”(刪除狀態)更改為“ 0”(編程狀態),刪除的塊可能會被多次編寫。
對於閃光燈,該頁面被認為是可以刪除的最小塊大小。每個部門都可以由其中一個或多個頁面組成。
最初被抹去了第一部門。新的註冊表條目將依次添加到閃存中。更新條目後,舊條目將標記為無效,並在下一個可用的閃存地址上寫了一個新條目。一旦第一部門達到容量,所有有效的條目將復製到第二部門,然後刪除第一部門。這個過程重複自我。
NVOL有效地處理並跟踪有效的條目及其位置在Flash上。這些部門是動態管理的。
宏可用於創建NVOL的靜態實例,然後可以與API一起使用。聲明的一個例子是:
#define NVOL3_REGISTRY_START 0
#define NVOL3_REGISTRY_SECTOR_SIZE STORAGE_32K
#define NVOL3_REGISTRY_SECTOR_COUNT 2
#define REGISTRY_KEY_LENGTH 24
#define REGISTRY_VALUE_LENGT_MAX 224
NVOL3_INSTANCE_DECL(_regdef_nvol3_entry,
ramdrv_read, ramdrv_write, ramdrv_erase,
NVOL3_REGISTRY_START,
NVOL3_REGISTRY_START + NVOL3_REGISTRY_SECTOR_SIZE,
NVOL3_REGISTRY_SECTOR_SIZE,
REGISTRY_KEY_LENGTH, /*key_size*/
DICTIONARY_KEYSPEC_BINARY(6), /*dictionary key_type (24 char string)*/
53, /*hashsize*/
REGISTRY_VALUE_LENGT_MAX, /*data_size*/
0, /*local_size (no cache in RAM)*/
0, /*tallie*/
NVOL3_SECTOR_VERSION /*version*/
) ;
這在閃光燈的開頭創建了一個帶有兩個32K扇區的NVOL。鑰匙的總尺寸(包括入口標頭)為256個字節。這不是要求,但應考慮一致。查找字典的哈希尺寸為53。此外,此實例不會在RAM中存儲任何值( local_size = 0 ),因此在需要時始終從Flash中讀取它們。
在演示中,使用NVRAMDRV驅動程序,以模擬RAM中的閃存,訪問功能是為此實例配置的RAMDRV_READ,RAMDRV_WRITE和RAMDRV_ERASE。
現在_regdef_nvol3_entry可以與NVOL API一起使用。 NVOL API略有調整,因此提供了一個簡單的註冊表示例。
提供的測試示例可以編譯並在GitHub代碼空間中運行。只需打開此轉換的代碼空間,然後在打開的終端中make (如果未打開終端使用ctrl + `以打開終端)。現在,您可以通過在終端中鍵入./build/nvol來啟動NVOL示例。所有命令都可以在代碼空間的終端執行。
啟動示例程序時,將打開命令外殼,並顯示以下內容:
@navaro /workspaces/nvol (main) $ ./build/nvol
REG : : resetting _regdef_nvol3_entry
NVOL3 : : '_regdef_nvol3_entry' 0 / 255 records loaded
Navaro corshell Demo v 'Jan 16 2023'
use 'help' or '?' for help.
# >
首先,我們將運行一個簡單的腳本來用值填充我們的註冊表。在及時類型上:
source ./test/reg.sh
這應該在註冊表中充滿值。列出測試註冊表類型的所有命令? reg ,它應顯示以下列表:
# >? reg
reg [key] [value]
regadd <key> <value>
regdel <key>
regerase
regstats
regtest [repeat]
# >
現在,我們可以使用Reg命令查看和更新註冊表:
# >reg
player.age: Ancient
player.gender: Otherworldly
player.level: legendary
player.location: Mount Olympus
player.name: cool_cat
player.points: 9000
player.power: invisibility
player.species: Dragon
player.status: awakened
player.weapon: lightning bolt
test: 123
user.address: 123 Main St.
user.age: 30
user.children: 0
user.email: [email protected]
user.favorite_color: blue
user.gender: male
user.marital_status: single
user.name: John Smith
user.occupation: contributor
user.phone_number: 555-555-5555
21 entries found.
# >reg user.favorite_color yellow
OK
# >reg user.favorite_color
user.favorite_color: yellow
# >regdel user.gender
OK
# >reg player
player.age: Ancient
player.gender: Otherworldly
player.level: legendary
player.location: Mount Olympus
player.name: cool_cat
player.points: 9000
player.power: invisibility
player.species: Dragon
player.status: awakened
player.weapon: lightning bolt
10 entries found.
# >regstats
NVOL3 : : '_regdef_nvol3_entry' 20 / 255 records loaded
record : 256 recordsize
: 0x000000 1st sector version 0x0155 flags 0xaaaaffff
: 0x010000 2nd sector version 0x0000 flags 0xffffffff
: 0x010000 sector size
: 20 loaded
: 20 inuse
: 2 invalid
: 0 error
: 640 lookup table bytes
: 53 dict hash size
: dict hash - max 2, empty 34, used 19
這些命令均在src/registry/registrycmd.c中實現。該實施是直觀和自我解釋的,不應需要進一步的解釋。
外殼本身就是一個項目,但僅在此示例中包括出於演示目的。它很容易擴展。使用?查看為此示例實現的命令的完整列表。
在註冊表使用字符串索引條目的地方,字符串表使用整數值。這種方法需要更少的RAM資源。
對於此示例,還有一個腳本可以用值填充字符串表。在及時類型上:
source ./test/strtab.sh
同樣,我們現在可以使用一個簡單命令列出字符串表:
# >strtab
0000 ENGLISH
0001 The end of the world is our playground.
0002 The company is family. The family is the company.
0003 Escape the mundane. Embrace the extraordinary.
0004 Work hard, live easy.
0005 The future is now. Join us.
0006 There is no I in team. But there is in severance.
0007 We're not just a company. We're a movement.
0008 Success is a journey, not a destination.
0009 Innovation starts with you.
0010 Welcome to the beginning of something great.
0100 DUTCH
0101 Het einde van de wereld is onze speeltuin.
0102 Het bedrijf is familie. De familie is het bedrijf.
0103 Ontsnap aan het alledaagse. Omarm het buitengewone.
0104 Hard werken, makkelijk leven.
0105 De toekomst is nu. Doe met ons mee.
0106 Er is geen ik in team. Maar wel in ontslagvergoeding.
0107 We zijn niet alleen een bedrijf. We zijn een beweging.
0108 Succes is een reis, geen bestemming.
0109 Innovatie begint bij jou.
0110 Welkom bij het begin van iets groots.
0999 test
23 entries found.
# >
像註冊表一樣,字符串表示例用字符串替換庫將其自身註冊,以替換用字符串表中的字符串劃分為<>的索引值。例如:
# >echo "<1>"
The end of the world is our playground.
# >
該演示使用仿真驅動程序在RAM中進行Flash。這是在“ CRC/DRIVERS/RAMDRV.H/C”中實現的。
在同一目錄中,在“ spiflash.h/c”文件中,將提供真實閃存芯片的示例驅動程序。使用Chibios/hal Spi驅動程序對此進行了啟動,應該是將NVOL移植到您自己的平台的好起點。