Skip to content

Commit fedeca7

Browse files
committed
Finish the NvM
1 parent 12c58de commit fedeca7

File tree

1 file changed

+305
-25
lines changed

1 file changed

+305
-25
lines changed

autosar/memory/nvram_manager/index.md

Lines changed: 305 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,51 +1083,331 @@ NvM 模块提供的所有除了**NvM_CancelWriteAll**外的异步请求,需在
10831083
3. **DCM**模块通过使用**NvM_GetErrorStatus**,轮询写入请求是否完成。
10841084
4. 接受到成功响应 (**NVM_REQ_OK**) 后,**DCM**模块发出**NvM_SetBlockLockStatus**(\<BlockId\>, TRUE)。
10851085

1086-
### 7.2.24. Block Compression
1086+
### 7.2.24. 块压缩
10871087

1088-
The block data is compressed before it is written to NV memory. The type of compression (block split, compression, delta) is vendor-specific.
1088+
块数据在写入**NV存储器**之前会被压缩。压缩类型特定于供应商的,包括:块分割、压缩、增量。
10891089

1090-
The use-case is for larger data blocks with changes of only smaller junks (like drive cycle logging). The goal is that not the whole block needs to be written to NV memory to reduce the overall write-cycles.
1090+
该使用用例特别适用于仅更改较小内容的较大的数据块,例如:驾驶周期日志记录。 目标:是不需要将整个块写入 **NV内存**,以减少总体写入周期。
10911091

1092-
The block split would divide the block in multiple sub-blocks and only the changed subblocks would be written. Alternatively, only the changed delta could be written. Anyway, any data compression algorithm could be used.
1092+
块分割会将块划分为多个子块,并且仅写入更改的子块。或者只写入已改变的增量数据。无论采用哪种方式,可以使用任意的数据压缩算法进行压缩。
10931093

1094-
The drawback is always a higher runtime for writing or reading the data.
1094+
缺点主要为写入或读取数据的运行时间会较长。
10951095

10961096
![Figure7_9](Figure7_9.png)
10971097

1098-
In case the NvMBlockUseCompression is set to true, the NvM shall compress the stored data in NV memory.
1098+
如果**NvMBlockUseCompression**设置为**true****NvM**需压缩**NV内存**中存储的数据。
10991099

1100-
### 7.2.25. Block Ciphering
1100+
### 7.2.25. 块加密
11011101

1102-
For security purposes NvM supports synchronous encryption and decryption via CSM module using symmetric 16 byte aligned algorithms, e.g. AES128.
1102+
出于安全目的,**NvM**支持使用16字节对齐对称算法,通过**CSM**模块进行同步的数据加密和解密。算法如:**AES128**
11031103

1104-
The user always works with plain data, the NV RAM stores the ciphered data:
1104+
用户始终使用纯数据,**NVRAM**中存储加密数据:
11051105

1106-
* Write data: NvM encrypts the plain user data and then forwards the ciphered data to the device.
1107-
* Read data: NvM reads the ciphered data from device, decrypts the data and finally provides the plain data to the user.
1106+
* 写入数据:NvM加密明文用户数据,然后将加密数据存储到设备。
1107+
* 读取数据:NvM从设备读取加密数据,解密数据,最后将明文数据提供给用户。
11081108

1109-
To check the integrity of the ciphered data a CRC can be configured (as usual). NvM will then calculate the CRC over encrypted data and recalculate and check the CRC before decryption: the CRC always matches the ciphered data.
1109+
为了检查加密数据的完整性,可以像平时一样配置**CRC**。然后,**NvM**将计算加密数据的**CRC**,并在解密之前重新计算和检查**CRC****CRC**需始终与加密数据相匹配。
11101110

1111-
In case NvMBlockCipheringRef is given, the NvM shall before forwarding the write request to MemIf encrypt the plain data using Csm_Encrypt() with the CSM job given in NvMCsmEncryptionJobReference.
1111+
如果给出了 NvMBlockCipheringRefNvM 应在将写入请求转发到 MemIf 之前,使用 Csm_Encrypt() 和 NvMCsmEncryptionJobReference 中给出的 CSM 作业对纯数据进行加密。
11121112

1113-
The CRC calculation (if configured) shall be done over the encrypted data.
1113+
CRC的计算(如果配置)需在加密数据上完成。
11141114

1115-
In case Csm_Encrypt() returns a CRYPTO_E_BUSY, the NvM shall retry to redo the job. After NvMCsmRetryCounter times of retry the NvM shall abort the write job and set the NvM result to NVM_REQ_NOT_OK and signal an error via NvM_JobErrorNotification().
1115+
#### 7.2.25.1. 块加密
11161116

1117-
In case Csm_Encrypt() returns any other error than CRYPTO_E_BUSY or CRYPTO_E_OK, the NvM shall abort the write job and set the NvM result to NVM_REQ_NOT_OK and signal an error via NvM_JobErrorNotification().
1117+
如果**Csm_Encrypt**返回**CRYPTO_E_BUSY****NvM**需重试加解密作业。在**NvMCsmRetryCounter**次重试失败后,**NvM**需中止写入作业,并将**NvM**结果设置为**NVM_REQ_NOT_OK**,并通过**NvM_JobErrorNotification**发出错误信号。
11181118

1119-
In case Csm_Encrypt() returns successfully with CRYPTO_E_OK, the NvM shall continue the write job (e.g. with the CRC calculation) with the new length given in NvMNvBlockNVRAMDataLength.
1119+
如果**Csm_Encrypt**返回除了**CRYPTO_E_BUSY**或者**CRYPTO_E_OK**之外的任何其他错误,**NvM**需立即中止写入作业,并将**NvM**结果设置为**NVM_REQ_NOT_OK**,并通过**NvM_JobErrorNotification**发出错误信号。
11201120

1121-
In case of the returned length in resultLengthPtr is different to the NvMNvBlockNVRAMDataLength the development error NVM_E_BLOCK_CHIPHER_LENGTH_MISSMATCH shall be triggerd.
1121+
如果**Csm_Encrypt**成功操作,并返回**CRYPTO_E_OK****NvM**需使用**NvMNvBlockNVRAMDataLength**中给定的新长度继续写入作业。例如:进行**CRC**计算。
11221122

1123-
In case NvMBlockCipheringRef is given, the NvM shall before forwarding the read request to application decrypt the stored data using Csm_Decrypt() with the CSM job given in NvMCsmDecryptionJobReference. The CRC check (if configured) shall be done over the encrypted data. If the CRC does not match, NvM will not decrypt the data but abort the job with NVM_REQ_INTEGRITY_FAILED.
1123+
如果**resultLengthPtr**中返回的长度与**NvMNvBlockNVRAMDataLength**不同,则应触发开发错误**NVM_E_BLOCK_CHIPHER_LENGTH_MISSMATCH**
11241124

1125-
In case Csm_Decrypt() returns a CRYPTO_E_BUSY, the NvM shall retry to redo the job. After NvMCsmRetryCounter times of retry the NvM shall abort the read job and set the NvM result to NVM_REQ_NOT_OK and signal an error via NvM_JobErrorNotification().
1125+
#### 7.2.25.2. 块解密
11261126

1127-
In case Csm_Decrypt() returns any other error than CRYPTO_E_BUSY or CRYPTO_E_OK, the NvM shall abort the read job and set the NvM result to NVM_REQ_NOT_OK and signal an error via NvM_JobErrorNotification().
1127+
如果给出了**NvMBlockCipheringRef****NvM**需在将读取请求转发给应用程序之前,通过**NvMCsmDecryptionJobReference**中给出的**CSM**作业,使用**Csm_Decrypt**来解密存储的数据。**CRC**检查(如果配置)需针对加密数据进行。如果**CRC**不匹配,**NvM**将不会解密数据,而是以**NVM_REQ_INTEGRITY_FAILED**中止作业。
11281128

1129-
In case Csm_Decrypt() returns successfully with CRYPTO_E_OK, the NvM shall continue the read job with the new length given in NvMNvBlock Length.
1129+
如果**Csm_Decrypt**返回**CRYPTO_E_BUSY****NvM**需重试解密作业。在**NvMCsmRetryCounter**次重试失败后,**NvM**需中止读取作业,并将**NvM**结果设置为**NVM_REQ_NOT_OK**,并通过 **NvM_JobErrorNotification**发出错误信号。
11301130

1131-
In case of the returned length in resultLengthPtr is different to the NvMNvBlockLength the development error NVM_E_BLOCK_CHIPHER_LENGTH_MISSMATCH shall be
1132-
triggerd.
1133-
1131+
如果**Csm_Decrypt**返回除了**CRYPTO_E_BUSY**或者**CRYPTO_E_OK**之外的任何其他错误,**NvM**需立即中止读取作业,并将**NvM**结果设置为**NVM_REQ_NOT_OK**,并通过**NvM_JobErrorNotification**发出错误信号。
1132+
1133+
如果**Csm_Decrypt**成功操作,并返回**CRYPTO_E_OK****NvM**需使用**NvMNvBlockLength**中给定的新长度继续读取作业。
1134+
1135+
如果**resultLengthPtr**中返回的长度与**NvMNvBlockLength**不同,则应触发开发错误**NVM_E_BLOCK_CHIPHER_LENGTH_MISSMATCH**
1136+
1137+
# 8. API规范
1138+
1139+
## 8.1. 同步请求函数定义
1140+
1141+
### 8.1.1. NvM_Init
1142+
1143+
**说明**: 用于重置所有内部变量。
1144+
1145+
```C
1146+
void NvM_Init (
1147+
const NvM_ConfigType* ConfigPtr
1148+
)
1149+
```
1150+
1151+
### 8.1.2. NvM_SetDataIndex
1152+
1153+
**说明**: 设置数据集NVRAM块(**Dataset NVRAM blocks**)的**DataIndex**。
1154+
1155+
```C
1156+
Std_ReturnType NvM_SetDataIndex (
1157+
NvM_BlockIdType BlockId,
1158+
uint8 DataIndex
1159+
)
1160+
```
1161+
1162+
### 8.1.3. NvM_GetDataIndex
1163+
1164+
**说明**: 获取数据集NVRAM块(**Dataset NVRAM blocks**)当前设置的**DataIndex**。
1165+
1166+
```C
1167+
Std_ReturnType NvM_GetDataIndex (
1168+
NvM_BlockIdType BlockId,
1169+
uint8* DataIndexPtr
1170+
)
1171+
```
1172+
1173+
### 8.1.4. NvM_SetBlockProtection
1174+
1175+
**说明**: 设置或者重置**NV块**的写保护。
1176+
1177+
```C
1178+
Std_ReturnType NvM_SetBlockProtection (
1179+
NvM_BlockIdType BlockId,
1180+
boolean ProtectionEnabled
1181+
)
1182+
```
1183+
1184+
### 8.1.5. NvM_GetErrorStatus
1185+
1186+
**说明**: 读取NvM块相关错误/状态信息。
1187+
1188+
```C
1189+
Std_ReturnType NvM_GetErrorStatus (
1190+
NvM_BlockIdType BlockId,
1191+
NvM_RequestResultType* RequestResultPtr
1192+
)
1193+
```
1194+
1195+
### 8.1.6. NvM_GetVersionInfo
1196+
1197+
**说明**: 获取NvM模块的版本信息。
1198+
1199+
```C
1200+
void NvM_GetVersionInfo (
1201+
Std_VersionInfoType* versioninfo
1202+
)
1203+
```
1204+
1205+
### 8.1.7. NvM_SetRamBlockStatus
1206+
1207+
**说明**: 设置**永久RAM块**的**RAM块状态**,或者**NVRAM块**的显式同步状态。
1208+
1209+
```C
1210+
Std_ReturnType NvM_SetRamBlockStatus (
1211+
NvM_BlockIdType BlockId,
1212+
boolean BlockChanged
1213+
)
1214+
```
1215+
1216+
### 8.1.8. NvM_SetBlockLockStatus
1217+
1218+
**说明**: 设置**永久RAM块**或**NVRAM块**的显式同步的锁定状态。
1219+
1220+
```C
1221+
void NvM_SetBlockLockStatus (
1222+
NvM_BlockIdType BlockId,
1223+
boolean BlockLocked
1224+
)
1225+
```
1226+
1227+
### 8.1.9. NvM_CancelJobs
1228+
1229+
**说明**: 取消**NV块**中所有待处理(**pending**)的作业。
1230+
1231+
```C
1232+
Std_ReturnType NvM_CancelJobs (
1233+
NvM_BlockIdType BlockId
1234+
)
1235+
```
1236+
1237+
## 8.2. 异步单块请求函数说明
1238+
1239+
### 8.2.1. NvM_ReadBlock
1240+
1241+
**说明**: 将**NV块**的数据复制到其对应的**RAM块**。
1242+
1243+
```C
1244+
Std_ReturnType NvM_ReadBlock (
1245+
NvM_BlockIdType BlockId,
1246+
void* NvM_DstPtr
1247+
)
1248+
```
1249+
1250+
### 8.2.2. NvM_WriteBlock
1251+
1252+
**说明**: 将R**AM块**的数据复制到其对应的**NV块**。
1253+
1254+
```C
1255+
Std_ReturnType NvM_WriteBlock (
1256+
NvM_BlockIdType BlockId,
1257+
const void* NvM_SrcPtr
1258+
)
1259+
```
1260+
1261+
### 8.2.3. NvM_RestoreBlockDefaults
1262+
1263+
**说明**: 将默认数据恢复到相应的**RAM块**中。
1264+
1265+
```C
1266+
Std_ReturnType NvM_RestoreBlockDefaults (
1267+
NvM_BlockIdType BlockId,
1268+
void* NvM_DestPtr
1269+
)
1270+
```
1271+
1272+
### 8.2.4. NvM_EraseNvBlock
1273+
1274+
**说明**: 擦除**NV块**。
1275+
1276+
```C
1277+
Std_ReturnType NvM_EraseNvBlock (
1278+
NvM_BlockIdType BlockId
1279+
)
1280+
```
1281+
1282+
### 8.2.5. NvM_InvalidateNvBlock
1283+
1284+
**说明**: 使**NV块**无效。
1285+
1286+
```C
1287+
Std_ReturnType NvM_InvalidateNvBlock (
1288+
NvM_BlockIdType BlockId
1289+
)
1290+
```
1291+
1292+
### 8.2.6. NvM_ReadPRAMBlock
1293+
1294+
**说明**: 将**NV块**的数据复制到其对应的**永久RAM块**。
1295+
1296+
```C
1297+
Std_ReturnType NvM_ReadPRAMBlock (
1298+
NvM_BlockIdType BlockId
1299+
)
1300+
```
1301+
1302+
### 8.2.7. NvM_WritePRAMBlock
1303+
1304+
**说明**: 将**永久RAM块**的数据复制到其对应的**NV块**。
1305+
1306+
```C
1307+
Std_ReturnType NvM_WritePRAMBlock (
1308+
NvM_BlockIdType BlockId
1309+
)
1310+
```
1311+
1312+
### 8.2.8. NvM_RestorePRAMBlockDefaults
1313+
1314+
**说明**: 将默认数据恢复到其对应的**永久RAM块**中。
1315+
1316+
```C
1317+
Std_ReturnType NvM_RestorePRAMBlockDefaults (
1318+
NvM_BlockIdType BlockId
1319+
)
1320+
```
1321+
1322+
## 8.3. 异步多块请求函数说明
1323+
1324+
### 8.3.1. NvM_ReadAll
1325+
1326+
**说明**: 发起多块读请求。
1327+
1328+
```C
1329+
void NvM_ReadAll (
1330+
void
1331+
)
1332+
```
1333+
1334+
### 8.3.2. NvM_WriteAll
1335+
1336+
**说明**: 发起多块写请求。
1337+
1338+
```C
1339+
void NvM_WriteAll (
1340+
void
1341+
)
1342+
```
1343+
1344+
### 8.3.3. NvM_CancelWriteAll
1345+
1346+
**说明**: 取消正在运行的**NvM_WriteAll**请求。
1347+
1348+
```C
1349+
void NvM_CancelWriteAll (
1350+
void
1351+
)
1352+
```
1353+
1354+
### 8.3.4. NvM_ValidateAll
1355+
1356+
**说明**: 发起多块验证请求。
1357+
1358+
```C
1359+
void NvM_ValidateAll (
1360+
void
1361+
)
1362+
```
1363+
1364+
### 8.3.5. NvM_FirstInitAll
1365+
1366+
**说明**: 发起多块优先初始化请求。 该函数的工作并不关心块是否存在于非易失性存储器中,或者在处理它时它是否有效(即未损坏)。
1367+
```C
1368+
void NvM_FirstInitAll (
1369+
void
1370+
)
1371+
```
1372+
1373+
## 8.4. 回调通知函数
1374+
1375+
### 8.4.1. NvM_JobEndNotification
1376+
1377+
**说明**: 底层内存抽象使用此函数来表示作业结束且没有错误。
1378+
1379+
```C
1380+
void NvM_JobEndNotification (
1381+
void
1382+
)
1383+
```
1384+
1385+
### 8.4.2. NvM_JobErrorNotification
1386+
1387+
**说明**: 底层内存抽象使用函数来表示作业结束并出现错误。
1388+
1389+
```C
1390+
void NvM_JobErrorNotification (
1391+
void
1392+
)
1393+
```
1394+
1395+
## 8.5. 周期性函数
1396+
1397+
### 8.4.2. NvM_MainFunction
1398+
1399+
**说明**: 用于执行**NvM**作业处理的服务。
1400+
1401+
```C
1402+
void NvM_MainFunction (
1403+
void
1404+
)
1405+
```
1406+
1407+
<section id="wechat">
1408+
1409+
<h4>微信扫一扫,获取更多及时资讯</h4>
1410+
1411+
<img src="wechat.png" alt="微信扫一扫"/>
1412+
1413+
</section>

0 commit comments

Comments
 (0)