NVRAM增加dummy模式,并通过generate_dummy_nvram函数进行行为控制

This commit is contained in:
Matthew GONG
2020-03-25 15:49:31 +08:00
parent 0fa9729bd5
commit a33fac79fb
6 changed files with 45 additions and 2 deletions
+2 -1
View File
@@ -17,8 +17,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- clean code, and move all tests to test directory
## [0.2.0] - 2020-03-22
## [0.2.0] - 2020-03-25
### Added
- add hal_api for uart/nvram/ctrls/sens
- dummy mode for nvram in MIL simulation
+11
View File
@@ -168,6 +168,17 @@ hal_nvram_cancel_Start_wrapper用于调用单例初始化函数initialize_nvram_
hal_nvram_cancel_Outputs_wrapper用于实现取消nvram_id进程从start address开始的读写作业。返回值是零表示完成取消,非零值表示错误。
### sim模式
为了在仿真中验证使用NVRAM模块的逻辑是否正确,增加了sim模式。
系统根据VariantNVRAM变量选择是工作在sfun模式还是dummy(sim)模式。
在sim模式下,读写NVRAM变成了读写全局信号量nvram_sim。
使用generate_dummy_nvram函数可以在base workspace下生产Variant变量、全局信号量与初始值,控制仿真方式。
因此不同测试可以通过不同参数调用generate_dummy_nvram来选择不同的默认nvram内容。
此外,每次写操作时会记录当前的nvram,结果在nvram_sim_last变量中。
## hal_api_ctrls库
hal_api_ctrls.slx实现了对输入输出设备的抽象操作。
+26
View File
@@ -0,0 +1,26 @@
function generate_dummy_nvram(use_nvram, val)
VariantNVRAM = Simulink.Variant;
VariantNVRAM.Condition = 'use_nvram == 1';
assignin('base','VariantNVRAM',VariantNVRAM);
assignin('base','use_nvram',use_nvram);
if use_nvram == 0
nvram_sim = Simulink.Signal;
nvram_sim.CoderInfo.StorageClass = 'Auto';
nvram_sim.Description = '';
nvram_sim.DataType = 'uint8';
nvram_sim.Min = [];
nvram_sim.Max = [];
nvram_sim.DocUnits = '';
nvram_sim.Dimensions = -1;
nvram_sim.DimensionsMode = 'Fixed';
nvram_sim.Complexity = 'real';
nvram_sim.SampleTime = -1;
nvram_sim.InitialValue = 'nvram_sim_init';
assignin('base','nvram_sim_init',val);
assignin('base','nvram_sim',nvram_sim);
end
end
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+6 -1
View File
@@ -2,11 +2,16 @@ cd('..');
addpath template
addpath param
%% Test mavlink_sim
%% Test nvram_in_sim_mode
generate_dummy_nvram(0,uint8(zeros(100,1)));
fcn = 'hal_template';
feval(fcn, [], [], [], 'compile');
while strcmp(get_param(fcn, 'SimulationStatus'),'paused')
feval(fcn, [], [], [], 'term');
end
%% Test nvram_in_sfun_mode
generate_dummy_nvram(1);
fcn = 'hal_template';
slbuild(fcn);