基础软件层
目前接触到的几款控制器,其厂商并没有提供simulink的基础软件库 一般为底层文件被封装为lib,留有供调用API接口 虽然能根据API接口开发基础软件库,但耗费时间过长得不偿失
应用层
所以可以将应用层封装为一个子系统,其输入输出作为和底层连接的变量 并将变量统一生成到一个或两个文件中,方便查找和修改
举例
新建一个m文件,添加两个变量类型Signal和Parameter,将其生成到Asw_Input文件里
Test = mpt. Signal;
Test. CoderInfo. StorageClass = 'Custom' ;
Test. CoderInfo. Alias = '' ;
Test. CoderInfo. Alignment = - 1 ;
Test. CoderInfo. CustomStorageClass = 'Global' ;
Test. CoderInfo. CustomAttributes. MemorySection = 'Default' ;
Test. CoderInfo. CustomAttributes. HeaderFile = 'Asw_Input.h' ;
Test. CoderInfo. CustomAttributes. DefinitionFile = 'Asw_Input.c' ;
Test. CoderInfo. CustomAttributes. Owner = '' ;
Test. CoderInfo. CustomAttributes. PersistenceLevel = 1 ;
Test. Description = '' ;
Test. DataType = 'int16' ;
Test. Min = [ ] ;
Test. Max = [ ] ;
Test. DocUnits = '' ;
Test. Dimensions = - 1 ;
Test. DimensionsMode = 'auto' ;
Test. Complexity = 'auto' ;
Test. SampleTime = - 1 ;
Test. InitialValue = '' ;
Test1 = mpt. Parameter;
Test1. Value = 900 ;
Test1. CoderInfo. StorageClass = 'Custom' ;
Test1. CoderInfo. Alias = '' ;
Test1. CoderInfo. Alignment = - 1 ;
Test1. CoderInfo. CustomStorageClass = 'Global' ;
Test1. CoderInfo. CustomAttributes. MemorySection = 'Default' ;
Test1. CoderInfo. CustomAttributes. HeaderFile = 'Asw_Input.h' ;
Test1. CoderInfo. CustomAttributes. DefinitionFile = 'Asw_Input.c' ;
Test1. CoderInfo. CustomAttributes. Owner = '' ;
Test1. CoderInfo. CustomAttributes. PersistenceLevel = 1 ;
Test1. Description = '' ;
Test1. DataType = 'uint16' ;
Test1. Min = [ ] ;
Test1. Max = [ ] ;
Test1. DocUnits = 'MV' ;
运行后,工作区会出现这两个变量 使用常量模块和信号线的Signal name must resolve to Simulink signal object,将变量和工作区变量进行连接,然后生成代码即可 生成代码后,可以看到和想象中的一样,此时就可以新建一个C文件,然后将变量与底层进行关联了,不需要再看模型生成的代码了