Working with the different management types
Native block
如果想要定义一个native block, 需要配置NvMBlockManagementType为NVM_BLOCK_NATIVE。你可以选择配ROM blcok,但是只能配置一个rom data block。而我们的NvMNvBlockNum 必须配置为1。
下面又是栗子了。
车辆仪表盘从车辆刚开始使用之后的速度,转速,发动机机温等数据的平均值,如果车停了,最新算出的数据需要保存到非易失内存里,供下次启动时使用。
为了完成这一目的,我们定义一个结构体如下,用于存储对应的数据。
struct AvVehicleState
{
unsigned char Speed; /* unit: km/h */
unsigned int EngineRotation; /* unit: rpm */
float EngineTemperature; /* unit: degrees Celsius */
};
我们在ROM里定义一个保存默认值的变量。
const struct AvVehicleState DefAvVehicleState={0,0,0};
在RAM中也定义一个变量
struct AvVehicleState CurAvVehicleState;
在NVRAM Manager中把CurAvVehicleState作为我们的ram地址,也就是NvMRamBlockDataAddress要配置成CurAvVehicleState的地址。NvMNvBlockLength就是结构体AvVehicleState的大小。Note:The actual size of a structure depends on the byt