simulink模型逻辑与生成代码简单比较

                           模型与生成代码对照

1、以下以一个简单的模型为例将模型与生成的代码做一个对照

生成代码中会有一个维持着整个状态的 结构体变量

DW_PS_SearchKey_T PS_SearchKey_DW;  //全局变量

void PS_SearchKey_step(void)

{

// 模型的四个输入 非模型之间传递的输入 是在模型ADD的输入

  uint8_T BrakeSw_prev;

  uint8_T PushButtonStatus_prev;

  uint8_T DR_Ajar_prev;

  uint8_T IGN_Status_prev;

 

//系统计时后面有用到after(maxtime,tick) 比如5 可作为整个局部系统的计时

  if (PS_SearchKey_DW.temporalCounter_i1 < 65535U) {

    PS_SearchKey_DW.temporalCounter_i1++;

  }

//给模型的四个信号赋初值

  BrakeSw_prev = PS_SearchKey_DW.BrakeSw_start;

  PS_SearchKey_DW.BrakeSw_start = get_BrakeSw();

  PushButtonStatus_prev = PS_SearchKey_DW.PushButtonStatus_start;

  PS_SearchKey_DW.PushButtonStatus_start = get_PushButtonStatus();

  DR_Ajar_prev = PS_SearchKey_DW.DR_Ajar_start;

  PS_SearchKey_DW.DR_Ajar_start = get_DR_Ajar();

  IGN_Status_prev = PS_SearchKey_DW.IGN_Status_start;

  PS_SearchKey_DW.IGN_Status_start = get_IGN_Status();

//判断是不是第一次进入模型 如果是第一次进入会执行 默认转移

//然后执行默认转移模块中的 enter (状态被激活时执行) 

if (PS_SearchKey_DW.is_active_c81_PS_SearchKey == 0U) {

    PS_SearchKey_DW.is_active_c81_PS_SearchKey = 1U;

    PS_SearchKey_DW.is_c81_PS_SearchKey = PS_SearchKey_IN_IDLE(A); // 进入模型的初始状态机

    //状态的切换都是以switch 的形试

    set_PS_KeyInCarFlag((uint16_T)((uint8_T)mFALSE));

    set_KeySearchRqst_PS(((uint8_T)KEYSEARCH_NULL));

     set_PEPS1_W_KeyNotDetected(((uint8_T)WARNING));

}

else

{   

   // 开始执行状态机的切换

   

switch (PS_SearchKey_DW.is_c81_PS_SearchKey)

{

 Case A:

if(1||2||3||4)

{

   执行B的 enter

   PS_SearchKey_DW.is_c81_PS_SearchKey = B

}else{} Break;

 Case B:

 If(5)

{

    执行F的enter

    PS_SearchKey_DW.is_c81_PS_SearchKey = F;

}

else

{

       执行10

      执行C的enter

      PS_SearchKey_DW.is_c81_PS_SearchKey = C;

}break;

Case C:

If(8)

{

  执行F的enter;

 PS_SearchKey_DW.is_c81_PS_SearchKey = F;

}

else if(9)

{

   执行B的 enter

   PS_SearchKey_DW.is_c81_PS_SearchKey = B;

}

else

{

   If(13)

    {

         执行D的enter

        PS_SearchKey_DW.is_c81_PS_SearchKey = D;

}

}

Case D:

 {

 If(11)

{

     执行F的enter;

     PS_SearchKey_DW.is_c81_PS_SearchKey = F;

}

else

{

       If(13)

    {

        PS_SearchKey_DW.is_c81_PS_SearchKey = E;

       清空条件13中的累加值

   }

}

}

 

Case F:

{

执行F的enter;

If(15)

{

       执行A的enter;

PS_SearchKey_DW.is_c81_PS_SearchKey = A; //然后在循环

}

else

{

       If( 7 || 5)

       {

         执行B的 enter

         PS_SearchKey_DW.is_c81_PS_SearchKey = B

    }

}
}

Default:   //其实就是执行的最后一个模块的处理

If(12)

{

         执行D的enter

      PS_SearchKey_DW.is_c81_PS_SearchKey = D;

}

else

{

     If(14)

   {

              执行A的enter;

           PS_SearchKey_DW.is_c81_PS_SearchKey = A; //然后在循环

}

}

}

}

 

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值