接着上回往下讲。 MISRA AC SLSF 058: Multirate systemsA. For multirate systems, Zero-Order Hold blocks shall be used to connect a system running at a higher rate to ones running a lower rate. The Zero-Order Hold block shall be set to the slower rate, with a separate Zero-Order Hold block used for each different rate.B. For multirate systems, Unit Delay blocks shall be used to connect a system running at a slower rate to one running a faster rate. The Unit Delay block shall be set to the slower rate.上述规则的优先级均为:Required。目标:Usability,Maintainability,Functionality【点评】这条规则再次展示了规则制定者只相信基础模块的作风,其实大可不必。Rate Transition模块已经是非常基础的模块了,直接用这个模块,勾选上“数据一致性”和“数据确定性”两个选项,实现的功能跟这条规则中使用的零阶保持、单元延迟一致,但却大大简化了设计门槛,用户可以无脑选中Rate Transition模块,而无需思考这个时候该用零阶保持还是单元延迟。另外,作为建模规范,使用Rate Transition也更方便自动化检查。这条规则的目标之一是Functionality,的确,是否遵守这条规则会影响到功能,当然,使用Rate Transition模块,勾上上图中的两个勾,一样可以满足功能上没问题。有意思的是,Model Advisor提供了查找用于处理速率转换的Unit Delay和Zero-Order Hold模块,并将其替换为Rate Transition模块的功能。MISRA AC SLSF 010: Arithmetic operation orderA. Sum block:There should be at least one positive(“+”).优先级:AdvisoryB. Product block: The first input should be multiply(“*”) when the block is configured as a divider.优先级:AdvisoryD. Product block: There shall always be at least one multiply(“*”).优先级:Required目标:Usability,Functionality,Maintainability【点评】这里对算术运算模块做了一些规定。3条规则中,2条Advisory,要求并不算高。对照MAB里面的jc-0121、jc-0610,除上述要求以外,还对输入数据的个数做了限制,比如: 限制输入个数不仅可以提高可读性,还有助于发现隐藏在计算过程中的数据溢出问题。MISRA AC SLSF 012: Switch blockA.When using the Switch block, the control input shall have a Boolean type and the switching criterion shall be set to “u2~=0”.优先级:Required目标:Usability,Portability【点评】Switch模块的输出标准给了几个选择,但实践中大家都很自觉的选择u2是否为零作为标准决定输出第一或者第三个输入。所以多数公司对这条规则应该是没有障碍的。MISRA AC SLSF 013: Multiport Switch blockA. A Multiport Switch block shall have at least two switched inputs or a single switched input fed by a multiplex signal with more than one element.B. The control input into the Multiport Switch block shall be an unsigned integer.C. The control input into the Multiport Switch block shall be configured for zero-based contiguous data port order.D. The default input for a Multiport Switch block shall always be enabled.优先级:上述规则优先级均为Required。目标:Usability,Portability【点评】多路选择开关,所以要求至少两路,没毛病。控制输入,数据类型要设置为无符号整数,有关这条规则,我试了一下,模块本身对数据类型并无要求,但是对数据范围有要求,比如,数据类型设置为有符号数,只要这个数据在其数值范围之内,模块工作正常;而如果输入给了负数,会报错,提示超出范围了。从这个模块设计上讲,并不会因为数据类型设置为有符号数而导致设计出错,但是,如果从索引值来看,的确采用无符号数更加合理,这个问题,你怎么看?欢迎留言讨论。Zero-based,MATLAB默认one-based index,而C语言是zero-based index,对于使用Simulink做仿真的用户,one-based index没有任何影响,而对于使用Simulink做软件开发的用户,为了避免混淆,还是非常有必要和C语言统一的,统一将可以设置索引基数的地方都设置为zero-based index。先更新到这里,上述规则,欢迎转发,欢迎留言讨论。