/* * VFControl.cpp * * Academic License - for use in teaching, academic research, and meeting * course requirements at degree granting institutions only. Not for * government, commercial, or other organizational use. * * Code generation for model "VFControl". * * Model version : 1.1 * Simulink Coder version : 24.1 (R2024a) 19-Nov-2023 * C++ source code generated on : Wed Oct 16 11:33:22 2024 * * Target selection: speedgoat.tlc * Note: GRT includes extra infrastructure and instrumentation for prototyping * Embedded hardware selection: Intel->x86-64 (Linux 64) * Code generation objectives: Unspecified * Validation result: Not run */ #include "VFControl.h" #include "VFControl_cal.h" #include "rtwtypes.h" #include #include #include "rt_hypotd_snf.h" #include "rt_invd4x4_snf.h" #include "rt_look.h" #include "rt_look1d.h" #include "rt_remd_snf.h" #include "rt_modd_snf.h" #include "VFControl_private.h" #include "rt_TDelayInterpolate.h" #include "look1_pbinlxpw.h" #include "PWMGenerator.h" extern "C" { #include "rt_nonfinite.h" } /* Block signals (default storage) */ B_VFControl_T VFControl_B; /* Block states (default storage) */ DW_VFControl_T VFControl_DW; /* Real-time model */ RT_MODEL_VFControl_T VFControl_M_ = RT_MODEL_VFControl_T(); RT_MODEL_VFControl_T *const VFControl_M = &VFControl_M_; /* Model step function for TID0 */ void VFControl_step0(void) /* Sample time: [0.0s, 0.0s] */ { real_T tmp[16]; real_T tmp_0[16]; real_T Bias; real_T RLinv_m; real_T tmp_1; real_T tmp_2; real_T xk1; int32_T i; int32_T i_0; int32_T tmp_3; /* Reset subsysRan breadcrumbs */ srClearBC(VFControl_DW.Saturation_SubsysRanBC); /* Reset subsysRan breadcrumbs */ srClearBC(VFControl_DW.Rotorreferenceframe_SubsysRan_i); /* Reset subsysRan breadcrumbs */ srClearBC(VFControl_DW.Stationaryreferenceframe_Subs_n); /* Reset subsysRan breadcrumbs */ srClearBC(VFControl_DW.Synchronousreferenceframe_Sub_k); /* Reset subsysRan breadcrumbs */ srClearBC(VFControl_DW.Rotorreferenceframe_SubsysRanBC); /* Reset subsysRan breadcrumbs */ srClearBC(VFControl_DW.Stationaryreferenceframe_Subsys); /* Reset subsysRan breadcrumbs */ srClearBC(VFControl_DW.Synchronousreferenceframe_Subsy); /* Reset subsysRan breadcrumbs */ srClearBC(VFControl_DW.sinbetacosbetasinthcosth_Subsys); /* Reset subsysRan breadcrumbs */ srClearBC(VFControl_DW.sinthrcosthr_SubsysRanBC); /* Reset subsysRan breadcrumbs */ srClearBC(VFControl_DW.sinthrcosthr1_SubsysRanBC); /* UnitDelay: '/fluxes' */ xk1 = VFControl_DW.fluxes_DSTATE[0]; VFControl_B.xk1[0] = xk1; /* Gain: '/Gain' */ xk1 *= VFControl_cal->Gain_Gain; VFControl_B.Gain[0] = xk1; /* UnitDelay: '/fluxes' */ Bias = VFControl_DW.fluxes_DSTATE_l[0]; VFControl_B.fluxes[0] = Bias; /* Sum: '/Sum2' */ VFControl_B.Sum2[0] = xk1 - Bias; /* UnitDelay: '/fluxes' */ xk1 = VFControl_DW.fluxes_DSTATE[1]; VFControl_B.xk1[1] = xk1; /* Gain: '/Gain' */ xk1 *= VFControl_cal->Gain_Gain; VFControl_B.Gain[1] = xk1; /* UnitDelay: '/fluxes' */ Bias = VFControl_DW.fluxes_DSTATE_l[1]; VFControl_B.fluxes[1] = Bias; /* Sum: '/Sum2' */ VFControl_B.Sum2[1] = xk1 - Bias; /* UnitDelay: '/fluxes' */ xk1 = VFControl_DW.fluxes_DSTATE[2]; VFControl_B.xk1[2] = xk1; /* Gain: '/Gain' */ xk1 *= VFControl_cal->Gain_Gain; VFControl_B.Gain[2] = xk1; /* UnitDelay: '/fluxes' */ Bias = VFControl_DW.fluxes_DSTATE_l[2]; VFControl_B.fluxes[2] = Bias; /* Sum: '/Sum2' */ VFControl_B.Sum2[2] = xk1 - Bias; /* UnitDelay: '/fluxes' */ xk1 = VFControl_DW.fluxes_DSTATE[3]; VFControl_B.xk1[3] = xk1; /* Gain: '/Gain' */ xk1 *= VFControl_cal->Gain_Gain; VFControl_B.Gain[3] = xk1; /* UnitDelay: '/fluxes' */ Bias = VFControl_DW.fluxes_DSTATE_l[3]; VFControl_B.fluxes[3] = Bias; /* Sum: '/Sum2' */ VFControl_B.Sum2[3] = xk1 - Bias; /* Outputs for Enabled SubSystem: '/Saturation' incorporates: * EnablePort: '/Enable' */ /* Constant: '/Constant' */ if (VFControl_cal->Constant_Value_e > 0.0) { /* UnitDelay: '/Delay' */ VFControl_B.Delay = VFControl_DW.Delay_DSTATE; /* SignalConversion generated from: '/Math Function' incorporates: * Constant: '/u2' * * About SignalConversion generated from '/Math Function': * Operator: reciprocal */ VFControl_B.TmpSignalConversionAtMathFuncti[0] = VFControl_cal->u2_Value[0]; VFControl_B.TmpSignalConversionAtMathFuncti[1] = VFControl_cal->u2_Value[1]; VFControl_B.TmpSignalConversionAtMathFuncti[2] = VFControl_B.Delay; /* Math: '/Math Function' * * About '/Math Function': * Operator: reciprocal */ xk1 = VFControl_B.TmpSignalConversionAtMathFuncti[0]; xk1 = 1.0 / xk1; /* Math: '/Math Function' * * About '/Math Function': * Operator: reciprocal */ VFControl_B.MathFunction_p[0] = xk1; /* Math: '/Math Function' * * About '/Math Function': * Operator: reciprocal */ xk1 = VFControl_B.TmpSignalConversionAtMathFuncti[1]; xk1 = 1.0 / xk1; /* Math: '/Math Function' * * About '/Math Function': * Operator: reciprocal */ VFControl_B.MathFunction_p[1] = xk1; /* Math: '/Math Function' * * About '/Math Function': * Operator: reciprocal */ xk1 = VFControl_B.TmpSignalConversionAtMathFuncti[2]; xk1 = 1.0 / xk1; /* Math: '/Math Function' * * About '/Math Function': * Operator: reciprocal */ VFControl_B.MathFunction_p[2] = xk1; /* Sum: '/Sum2' */ xk1 = VFControl_B.MathFunction_p[0]; xk1 += VFControl_B.MathFunction_p[1]; xk1 += VFControl_B.MathFunction_p[2]; /* Sum: '/Sum2' */ VFControl_B.Sum2_i = xk1; /* Math: '/Math Function1' * * About '/Math Function1': * Operator: reciprocal */ xk1 = VFControl_B.Sum2_i; /* Math: '/Math Function1' * * About '/Math Function1': * Operator: reciprocal */ VFControl_B.MathFunction1 = 1.0 / xk1; /* Product: '/Product2' incorporates: * Constant: '/u1' */ VFControl_B.Product2_m[0] = VFControl_cal->u1_Value[0] * VFControl_B.MathFunction1; VFControl_B.Product2_m[1] = VFControl_cal->u1_Value[1] * VFControl_B.MathFunction1; /* Product: '/Product' */ VFControl_B.Product_c[0] = VFControl_B.Sum2[0] * VFControl_B.Product2_m[0]; VFControl_B.Product_c[1] = VFControl_B.Product2_m[1] * VFControl_B.Sum2[2]; /* Sum: '/Sum2' */ xk1 = VFControl_B.Product_c[0]; xk1 += VFControl_B.Product_c[1]; /* Sum: '/Sum2' */ VFControl_B.phimq = xk1; /* Product: '/Product1' */ VFControl_B.Product1_j[0] = VFControl_B.Product2_m[0] * VFControl_B.Sum2[1]; VFControl_B.Product1_j[1] = VFControl_B.Product2_m[1] * VFControl_B.Sum2[3]; /* Sum: '/Sum1' */ xk1 = VFControl_B.Product1_j[0]; xk1 += VFControl_B.Product1_j[1]; /* Sum: '/Sum1' */ VFControl_B.phimd = xk1; /* Math: '/Math Function' */ VFControl_B.Phisat = rt_hypotd_snf(VFControl_B.phimq, VFControl_B.phimd); /* Lookup_n-D: '/1-D Lookup Table' incorporates: * Math: '/Math Function' */ VFControl_B.Isat = look1_pbinlxpw(VFControl_B.Phisat, VFControl_cal->uDLookupTable_bp01Data, VFControl_cal->uDLookupTable_tableData, &VFControl_DW.m_bpIndex_b, 1U); /* Switch: '/Switch' */ if (VFControl_B.Isat != 0.0) { /* Product: '/Product' */ VFControl_B.Lm = VFControl_B.Phisat / VFControl_B.Isat; /* Switch: '/Switch' */ VFControl_B.Switch_g = VFControl_B.Lm; } else { /* Switch: '/Switch' incorporates: * Constant: '/Constant1' */ VFControl_B.Switch_g = VFControl_cal->Constant1_Value; } /* End of Switch: '/Switch' */ /* Assignment: '/Lm in rows[1,3] & col[1,3]' incorporates: * Constant: '/u1' */ std::memcpy(&VFControl_B.Lminrows13col13[0], &VFControl_cal->u1_Value_d[0], sizeof(real_T) << 4U); /* Assignment: '/Lm in rows[1,3] & col[1,3]' */ VFControl_B.Lminrows13col13[0] = VFControl_B.Switch_g; VFControl_B.Lminrows13col13[2] = VFControl_B.Switch_g; VFControl_B.Lminrows13col13[8] = VFControl_B.Switch_g; VFControl_B.Lminrows13col13[10] = VFControl_B.Switch_g; /* Assignment: '/Lm in rows[2,4] & col[2,4]' incorporates: * Assignment: '/Lm in rows[1,3] & col[1,3]' */ std::memcpy(&VFControl_B.Lminrows24col24[0], &VFControl_B.Lminrows13col13[0], sizeof(real_T) << 4U); /* Assignment: '/Lm in rows[2,4] & col[2,4]' */ VFControl_B.Lminrows24col24[5] = VFControl_B.Switch_g; VFControl_B.Lminrows24col24[7] = VFControl_B.Switch_g; VFControl_B.Lminrows24col24[13] = VFControl_B.Switch_g; VFControl_B.Lminrows24col24[15] = VFControl_B.Switch_g; for (i = 0; i < 16; i++) { /* Sum: '/Sum2' incorporates: * Assignment: '/Lm in rows[2,4] & col[2,4]' * Constant: '/u5' */ VFControl_B.Sum2_e[i] = VFControl_B.Lminrows24col24[i] + VFControl_cal->u5_Value[i]; } /* Product: '/inversion' incorporates: * Sum: '/Sum2' */ rt_invd4x4_snf(VFControl_B.Sum2_e, VFControl_B.Linv_h); /* Product: '/Product1' incorporates: * Constant: '/u1' * Product: '/inversion' */ std::memcpy(&tmp[0], &VFControl_cal->u1_Value_e[0], sizeof(real_T) << 4U); std::memcpy(&tmp_0[0], &VFControl_B.Linv_h[0], sizeof(real_T) << 4U); for (i = 0; i < 4; i++) { /* Product: '/Product1' */ tmp_3 = i << 2; xk1 = tmp_0[tmp_3]; Bias = tmp_0[tmp_3 + 1]; tmp_1 = tmp_0[tmp_3 + 2]; tmp_2 = tmp_0[tmp_3 + 3]; for (i_0 = 0; i_0 < 4; i_0++) { /* Product: '/Product1' */ RLinv_m = xk1 * tmp[i_0]; RLinv_m += tmp[i_0 + 4] * Bias; RLinv_m += tmp[i_0 + 8] * tmp_1; RLinv_m += tmp[i_0 + 12] * tmp_2; /* Product: '/Product1' */ VFControl_B.RLinv_m[i_0 + tmp_3] = RLinv_m; } } /* Update for UnitDelay: '/Delay' */ VFControl_DW.Delay_DSTATE = VFControl_B.Switch_g; srUpdateBC(VFControl_DW.Saturation_SubsysRanBC); } /* End of Constant: '/Constant' */ /* End of Outputs for SubSystem: '/Saturation' */ for (i = 0; i < 16; i++) { /* Switch: '/Switch' incorporates: * Constant: '/Constant1' */ if (VFControl_cal->Constant1_Value_k >= VFControl_cal->Switch_Threshold) { /* Switch: '/Switch' incorporates: * Product: '/inversion' */ xk1 = VFControl_B.Linv_h[i]; } else { /* Switch: '/Switch' incorporates: * Constant: '/Constant2' */ xk1 = VFControl_cal->Constant2_Value[i]; } /* End of Switch: '/Switch' */ /* Switch: '/Switch' */ VFControl_B.Linv[i] = xk1; /* Product: '/Product3' incorporates: * Switch: '/Switch' */ tmp[i] = xk1; } /* Product: '/Product3' */ Bias = VFControl_B.xk1[0]; tmp_1 = VFControl_B.xk1[1]; tmp_2 = VFControl_B.xk1[2]; RLinv_m = VFControl_B.xk1[3]; for (i = 0; i < 4; i++) { xk1 = tmp[i] * Bias; xk1 += tmp[i + 4] * tmp_1; xk1 += tmp[i + 8] * tmp_2; xk1 += tmp[i + 12] * RLinv_m; /* Product: '/Product3' */ VFControl_B.Product3[i] = xk1; } /* DiscreteIntegrator: '/Rotor angle thetam' */ VFControl_B.Rotoranglethetam = VFControl_DW.Rotoranglethetam_DSTATE; /* UnitDelay: '/wm_delay' */ VFControl_B.wm_delay = VFControl_DW.wm_delay_DSTATE; /* Gain: '/F2' */ VFControl_B.F2 = VFControl_cal->F2_Gain * VFControl_B.wm_delay; /* UnitDelay: '/wm_predict' */ VFControl_B.wm_predict = VFControl_DW.wm_predict_DSTATE; /* Sum: '/Sum1' */ VFControl_B.Sum1 = VFControl_B.F2 - VFControl_B.wm_predict; /* Outputs for Enabled SubSystem: '/sin(thr),cos(thr)' incorporates: * EnablePort: '/Enable' */ /* Constant: '/Constant' */ if (VFControl_cal->Constant_Value_b) { VFControl_DW.sinthrcosthr_MODE = true; /* Constant: '/Constant' */ VFControl_B.Constant_e[0] = VFControl_cal->Constant_Value[0]; VFControl_B.Constant_e[1] = VFControl_cal->Constant_Value[1]; /* Gain: '/Gain1' */ VFControl_B.Gain1_e = VFControl_cal->Gain1_Gain * VFControl_B.Sum1; /* Trigonometry: '/Trigonometric Function' */ xk1 = VFControl_B.Rotoranglethetam; Bias = std::sin(xk1); xk1 = std::cos(xk1); /* Trigonometry: '/Trigonometric Function' */ VFControl_B.TrigonometricFunction_o1_d = Bias; /* Trigonometry: '/Trigonometric Function' */ VFControl_B.TrigonometricFunction_o2_j = xk1; /* Assignment: '/W(1,2)=wr' incorporates: * Constant: '/u1' */ std::memcpy(&VFControl_B.W12wr[0], &VFControl_cal->u1_Value_j[0], sizeof (real_T) << 4U); /* Assignment: '/W(1,2)=wr' */ VFControl_B.W12wr[4] = VFControl_B.Sum1; /* Assignment: '/W(2,1)=-wr' incorporates: * Assignment: '/W(1,2)=wr' */ std::memcpy(&VFControl_B.W21wr[0], &VFControl_B.W12wr[0], sizeof(real_T) << 4U); /* Assignment: '/W(2,1)=-wr' */ VFControl_B.W21wr[1] = VFControl_B.Gain1_e; srUpdateBC(VFControl_DW.sinthrcosthr_SubsysRanBC); } else if (VFControl_DW.sinthrcosthr_MODE) { /* Disable for Trigonometry: '/Trigonometric Function' incorporates: * Outport: '/sin(thr),cos(thr)' */ VFControl_B.TrigonometricFunction_o1_d = VFControl_cal->sinthrcosthr_Y0; /* Disable for Trigonometry: '/Trigonometric Function' incorporates: * Outport: '/sin(thr),cos(thr)' */ VFControl_B.TrigonometricFunction_o2_j = VFControl_cal->sinthrcosthr_Y0; /* Disable for Outport: '/sin(thr),cos(thr)' incorporates: * Constant: '/Constant' */ VFControl_B.Constant_e[0] = VFControl_cal->sinthrcosthr_Y0; VFControl_B.Constant_e[1] = VFControl_cal->sinthrcosthr_Y0; for (i = 0; i < 16; i++) { /* Disable for Assignment: '/W(2,1)=-wr' incorporates: * Outport: '/W' */ VFControl_B.W21wr[i] = VFControl_cal->W_Y0_m; } VFControl_DW.sinthrcosthr_MODE = false; } /* End of Constant: '/Constant' */ /* End of Outputs for SubSystem: '/sin(thr),cos(thr)' */ /* Outputs for Enabled SubSystem: '/sin(thr),cos(thr)1' incorporates: * EnablePort: '/Enable' */ /* Constant: '/Constant1' */ if (VFControl_cal->Constant1_Value_kj) { VFControl_DW.sinthrcosthr1_MODE = true; /* Constant: '/Constant' */ VFControl_B.Constant[0] = VFControl_cal->Constant_Value_n[0]; VFControl_B.Constant[1] = VFControl_cal->Constant_Value_n[1]; /* Gain: '/Gain3' */ VFControl_B.Gain3_e = VFControl_cal->Gain3_Gain * VFControl_B.Sum1; /* Trigonometry: '/Trigonometric Function' */ xk1 = VFControl_B.Rotoranglethetam; Bias = std::sin(xk1); xk1 = std::cos(xk1); /* Trigonometry: '/Trigonometric Function' */ VFControl_B.TrigonometricFunction_o1 = Bias; /* Trigonometry: '/Trigonometric Function' */ VFControl_B.TrigonometricFunction_o2 = xk1; /* Assignment: '/W(3,4)=-wr' incorporates: * Constant: '/u4' */ std::memcpy(&VFControl_B.W34wr[0], &VFControl_cal->u4_Value[0], sizeof (real_T) << 4U); /* Assignment: '/W(3,4)=-wr' */ VFControl_B.W34wr[14] = VFControl_B.Gain3_e; /* Assignment: '/W(4,3)=wr' incorporates: * Assignment: '/W(3,4)=-wr' */ std::memcpy(&VFControl_B.W43wr[0], &VFControl_B.W34wr[0], sizeof(real_T) << 4U); /* Assignment: '/W(4,3)=wr' */ VFControl_B.W43wr[11] = VFControl_B.Sum1; srUpdateBC(VFControl_DW.sinthrcosthr1_SubsysRanBC); } else if (VFControl_DW.sinthrcosthr1_MODE) { /* Disable for Trigonometry: '/Trigonometric Function' incorporates: * Outport: '/sin(thr),cos(thr)' */ VFControl_B.TrigonometricFunction_o1 = VFControl_cal->sinthrcosthr_Y0_h; /* Disable for Trigonometry: '/Trigonometric Function' incorporates: * Outport: '/sin(thr),cos(thr)' */ VFControl_B.TrigonometricFunction_o2 = VFControl_cal->sinthrcosthr_Y0_h; /* Disable for Outport: '/sin(thr),cos(thr)' incorporates: * Constant: '/Constant' */ VFControl_B.Constant[0] = VFControl_cal->sinthrcosthr_Y0_h; VFControl_B.Constant[1] = VFControl_cal->sinthrcosthr_Y0_h; VFControl_DW.sinthrcosthr1_MODE = false; } /* End of Constant: '/Constant1' */ /* End of Outputs for SubSystem: '/sin(thr),cos(thr)1' */ /* Outputs for Enabled SubSystem: '/sin(beta),cos(beta),sin(th),cos(th)' incorporates: * EnablePort: '/Enable' */ /* Constant: '/Constant3' */ if (VFControl_cal->Constant3_Value_h) { /* DigitalClock: '/Digital Clock' */ VFControl_B.DigitalClock_kx = VFControl_M->Timing.t[1]; /* Sum: '/Sum' incorporates: * Constant: '/we' */ VFControl_B.wewr = VFControl_cal->we_Value - VFControl_B.Sum1; /* Gain: '/Gain2' */ VFControl_B.Gain2_k = VFControl_cal->Gain2_Gain * VFControl_B.wewr; /* Gain: '/web_psb' */ VFControl_B.th = VFControl_cal->web_psb_Gain * VFControl_B.DigitalClock_kx; /* Sum: '/Sum1' */ VFControl_B.beta = VFControl_B.th - VFControl_B.Rotoranglethetam; /* Trigonometry: '/Trigonometric Function' */ xk1 = VFControl_B.th; Bias = std::sin(xk1); xk1 = std::cos(xk1); /* Trigonometry: '/Trigonometric Function' */ VFControl_B.TrigonometricFunction_o1_dn = Bias; /* Trigonometry: '/Trigonometric Function' */ VFControl_B.TrigonometricFunction_o2_k = xk1; /* Trigonometry: '/Trigonometric Function1' */ xk1 = VFControl_B.beta; Bias = std::sin(xk1); xk1 = std::cos(xk1); /* Trigonometry: '/Trigonometric Function1' */ VFControl_B.TrigonometricFunction1_o1 = Bias; /* Trigonometry: '/Trigonometric Function1' */ VFControl_B.TrigonometricFunction1_o2 = xk1; /* Assignment: '/W(3,4)=1-wr' incorporates: * Constant: '/u3' */ std::memcpy(&VFControl_B.W341wr[0], &VFControl_cal->u3_Value[0], sizeof (real_T) << 4U); /* Assignment: '/W(3,4)=1-wr' */ VFControl_B.W341wr[14] = VFControl_B.wewr; /* Assignment: '/W(4,3)=wr-1' incorporates: * Assignment: '/W(3,4)=1-wr' */ std::memcpy(&VFControl_B.W43wr1[0], &VFControl_B.W341wr[0], sizeof(real_T) << 4U); /* Assignment: '/W(4,3)=wr-1' */ VFControl_B.W43wr1[11] = VFControl_B.Gain2_k; srUpdateBC(VFControl_DW.sinbetacosbetasinthcosth_Subsys); } /* End of Constant: '/Constant3' */ /* End of Outputs for SubSystem: '/sin(beta),cos(beta),sin(th),cos(th)' */ /* MultiPortSwitch: '/Multiport Switch' incorporates: * Constant: '/Constant2' */ switch (static_cast(VFControl_cal->Constant2_Value_n)) { case 1: /* MultiPortSwitch: '/Multiport Switch' */ VFControl_B.MultiportSwitch[0] = VFControl_B.TrigonometricFunction_o1_d; VFControl_B.MultiportSwitch[1] = VFControl_B.TrigonometricFunction_o2_j; VFControl_B.MultiportSwitch[2] = VFControl_B.Constant_e[0]; VFControl_B.MultiportSwitch[3] = VFControl_B.Constant_e[1]; break; case 2: /* MultiPortSwitch: '/Multiport Switch' */ VFControl_B.MultiportSwitch[0] = VFControl_B.TrigonometricFunction_o1; VFControl_B.MultiportSwitch[1] = VFControl_B.TrigonometricFunction_o2; VFControl_B.MultiportSwitch[2] = VFControl_B.Constant[0]; VFControl_B.MultiportSwitch[3] = VFControl_B.Constant[1]; break; default: /* MultiPortSwitch: '/Multiport Switch' */ VFControl_B.MultiportSwitch[0] = VFControl_B.TrigonometricFunction1_o1; VFControl_B.MultiportSwitch[1] = VFControl_B.TrigonometricFunction1_o2; VFControl_B.MultiportSwitch[2] = VFControl_B.TrigonometricFunction_o1_dn; VFControl_B.MultiportSwitch[3] = VFControl_B.TrigonometricFunction_o2_k; break; } /* End of MultiPortSwitch: '/Multiport Switch' */ /* Outputs for Enabled SubSystem: '/Rotor reference frame' incorporates: * EnablePort: '/Enable' */ /* Constant: '/Constant' */ if (VFControl_cal->Constant_Value_px) { VFControl_DW.Rotorreferenceframe_MODE = true; /* Fcn: '/ira' */ VFControl_B.ira_p = VFControl_B.Product3[2]; /* Fcn: '/irb' */ VFControl_B.irb_n = -(1.7320508075688772 * VFControl_B.Product3[3] + VFControl_B.Product3[2]) / 2.0; /* Fcn: '/isa' */ VFControl_B.isa_m = VFControl_B.Product3[0] * VFControl_B.MultiportSwitch[1] + VFControl_B.MultiportSwitch[0] * VFControl_B.Product3[1]; /* Fcn: '/isb' */ VFControl_B.isb_p = ((1.7320508075688772 * VFControl_B.MultiportSwitch[0] - VFControl_B.MultiportSwitch[1]) * VFControl_B.Product3[0] + (-1.7320508075688772 * VFControl_B.MultiportSwitch[1] - VFControl_B.MultiportSwitch[0]) * VFControl_B.Product3[1]) / 2.0; srUpdateBC(VFControl_DW.Rotorreferenceframe_SubsysRanBC); } else if (VFControl_DW.Rotorreferenceframe_MODE) { /* Disable for Fcn: '/ira' incorporates: * Outport: '/ira,irb' */ VFControl_B.ira_p = VFControl_cal->irairb_Y0; /* Disable for Fcn: '/irb' incorporates: * Outport: '/ira,irb' */ VFControl_B.irb_n = VFControl_cal->irairb_Y0; /* Disable for Fcn: '/isa' incorporates: * Outport: '/isa,isb' */ VFControl_B.isa_m = VFControl_cal->isaisb_Y0; /* Disable for Fcn: '/isb' incorporates: * Outport: '/isa,isb' */ VFControl_B.isb_p = VFControl_cal->isaisb_Y0; VFControl_DW.Rotorreferenceframe_MODE = false; } /* End of Constant: '/Constant' */ /* End of Outputs for SubSystem: '/Rotor reference frame' */ /* Outputs for Enabled SubSystem: '/Stationary reference frame' incorporates: * EnablePort: '/Enable' */ /* Constant: '/Constant1' */ if (VFControl_cal->Constant1_Value_b) { VFControl_DW.Stationaryreferenceframe_MODE = true; /* Fcn: '/ira' */ VFControl_B.ira_g = VFControl_B.MultiportSwitch[1] * VFControl_B.Product3[2] - VFControl_B.MultiportSwitch[0] * VFControl_B.Product3[3]; /* Fcn: '/irb' */ VFControl_B.irb_g = ((-VFControl_B.MultiportSwitch[1] - 1.7320508075688772 * VFControl_B.MultiportSwitch[0]) * VFControl_B.Product3[2] + (VFControl_B.MultiportSwitch [0] - 1.7320508075688772 * VFControl_B.MultiportSwitch[1]) * VFControl_B.Product3[3]) / 2.0; /* Fcn: '/isa' */ VFControl_B.isa_a = VFControl_B.Product3[0]; /* Fcn: '/isb' */ VFControl_B.isb_f = -(1.7320508075688772 * VFControl_B.Product3[1] + VFControl_B.Product3[0]) / 2.0; srUpdateBC(VFControl_DW.Stationaryreferenceframe_Subsys); } else if (VFControl_DW.Stationaryreferenceframe_MODE) { /* Disable for Fcn: '/ira' incorporates: * Outport: '/ira,irb' */ VFControl_B.ira_g = VFControl_cal->irairb_Y0_d; /* Disable for Fcn: '/irb' incorporates: * Outport: '/ira,irb' */ VFControl_B.irb_g = VFControl_cal->irairb_Y0_d; /* Disable for Fcn: '/isa' incorporates: * Outport: '/isa,isb' */ VFControl_B.isa_a = VFControl_cal->isaisb_Y0_k; /* Disable for Fcn: '/isb' incorporates: * Outport: '/isa,isb' */ VFControl_B.isb_f = VFControl_cal->isaisb_Y0_k; VFControl_DW.Stationaryreferenceframe_MODE = false; } /* End of Constant: '/Constant1' */ /* End of Outputs for SubSystem: '/Stationary reference frame' */ /* Outputs for Enabled SubSystem: '/Synchronous reference frame' incorporates: * EnablePort: '/Enable' */ /* Constant: '/Constant2' */ if (VFControl_cal->Constant2_Value_d) { VFControl_DW.Synchronousreferenceframe_MODE = true; /* Fcn: '/ira' */ VFControl_B.ira = VFControl_B.MultiportSwitch[1] * VFControl_B.Product3[2] + VFControl_B.MultiportSwitch[0] * VFControl_B.Product3[3]; /* Fcn: '/irb' */ VFControl_B.irb = ((1.7320508075688772 * VFControl_B.MultiportSwitch[0] - VFControl_B.MultiportSwitch[1]) * VFControl_B.Product3[2] + (-1.7320508075688772 * VFControl_B.MultiportSwitch[1] - VFControl_B.MultiportSwitch[0]) * VFControl_B.Product3[3]) / 2.0; /* Fcn: '/isa' */ VFControl_B.isa = VFControl_B.Product3[0] * VFControl_B.MultiportSwitch[3] + VFControl_B.Product3[1] * VFControl_B.MultiportSwitch[2]; /* Fcn: '/isb' */ VFControl_B.isb = ((1.7320508075688772 * VFControl_B.MultiportSwitch[2] - VFControl_B.MultiportSwitch[3]) * VFControl_B.Product3[0] + (-1.7320508075688772 * VFControl_B.MultiportSwitch[3] - VFControl_B.MultiportSwitch[2]) * VFControl_B.Product3[1]) / 2.0; srUpdateBC(VFControl_DW.Synchronousreferenceframe_Subsy); } else if (VFControl_DW.Synchronousreferenceframe_MODE) { /* Disable for Fcn: '/ira' incorporates: * Outport: '/ira,irb' */ VFControl_B.ira = VFControl_cal->irairb_Y0_h; /* Disable for Fcn: '/irb' incorporates: * Outport: '/ira,irb' */ VFControl_B.irb = VFControl_cal->irairb_Y0_h; /* Disable for Fcn: '/isa' incorporates: * Outport: '/isa,isb' */ VFControl_B.isa = VFControl_cal->isaisb_Y0_m; /* Disable for Fcn: '/isb' incorporates: * Outport: '/isa,isb' */ VFControl_B.isb = VFControl_cal->isaisb_Y0_m; VFControl_DW.Synchronousreferenceframe_MODE = false; } /* End of Constant: '/Constant2' */ /* End of Outputs for SubSystem: '/Synchronous reference frame' */ /* MultiPortSwitch: '/Multiport Switch' incorporates: * Constant: '/Constant3' */ switch (static_cast(VFControl_cal->Constant3_Value_e)) { case 1: /* MultiPortSwitch: '/Multiport Switch' */ VFControl_B.MultiportSwitch_p[0] = VFControl_B.ira_p; VFControl_B.MultiportSwitch_p[1] = VFControl_B.irb_n; break; case 2: /* MultiPortSwitch: '/Multiport Switch' */ VFControl_B.MultiportSwitch_p[0] = VFControl_B.ira_g; VFControl_B.MultiportSwitch_p[1] = VFControl_B.irb_g; break; default: /* MultiPortSwitch: '/Multiport Switch' */ VFControl_B.MultiportSwitch_p[0] = VFControl_B.ira; VFControl_B.MultiportSwitch_p[1] = VFControl_B.irb; break; } /* End of MultiPortSwitch: '/Multiport Switch' */ /* MultiPortSwitch: '/Multiport Switch1' incorporates: * Constant: '/Constant4' */ switch (static_cast(VFControl_cal->Constant4_Value_c)) { case 1: /* MultiPortSwitch: '/Multiport Switch1' */ VFControl_B.MultiportSwitch1[0] = VFControl_B.isa_m; VFControl_B.MultiportSwitch1[1] = VFControl_B.isb_p; break; case 2: /* MultiPortSwitch: '/Multiport Switch1' */ VFControl_B.MultiportSwitch1[0] = VFControl_B.isa_a; VFControl_B.MultiportSwitch1[1] = VFControl_B.isb_f; break; default: /* MultiPortSwitch: '/Multiport Switch1' */ VFControl_B.MultiportSwitch1[0] = VFControl_B.isa; VFControl_B.MultiportSwitch1[1] = VFControl_B.isb; break; } /* End of MultiPortSwitch: '/Multiport Switch1' */ /* Gain: '/ib' */ VFControl_B.ib[0] = VFControl_cal->ib_Gain * VFControl_B.MultiportSwitch_p[0]; xk1 = VFControl_cal->ib_Gain * VFControl_B.MultiportSwitch1[0]; VFControl_B.ib[2] = xk1; /* Gain: '/Gain Vr_Vs1' */ VFControl_B.GainVr_Vs1[0] = VFControl_cal->GainVr_Vs1_Gain[0] * xk1; /* Gain: '/ib' */ VFControl_B.ib[1] = VFControl_cal->ib_Gain * VFControl_B.MultiportSwitch_p[1]; xk1 = VFControl_cal->ib_Gain * VFControl_B.MultiportSwitch1[1]; VFControl_B.ib[3] = xk1; /* Gain: '/Gain Vr_Vs1' */ VFControl_B.GainVr_Vs1[1] = VFControl_cal->GainVr_Vs1_Gain[1] * xk1; /* S-Function (sfun_spssw_discc): '/State-Space' incorporates: * Constant: '/DC' * Constant: '/SwitchCurrents' */ /* S-Function block: /State-Space */ { real_T accum; /* Circuit has switches */ int_T *switch_status = (int_T*) VFControl_DW.StateSpace_PWORK.SWITCH_STATUS; int_T *switch_status_init = (int_T*) VFControl_DW.StateSpace_PWORK.SWITCH_STATUS_INIT; int_T *SwitchChange = (int_T*) VFControl_DW.StateSpace_PWORK.SW_CHG; int_T *gState = (int_T*) VFControl_DW.StateSpace_PWORK.G_STATE; real_T *yswitch = (real_T*)VFControl_DW.StateSpace_PWORK.Y_SWITCH; int_T *switchTypes = (int_T*) VFControl_DW.StateSpace_PWORK.SWITCH_TYPES; int_T *idxOutSw = (int_T*) VFControl_DW.StateSpace_PWORK.IDX_OUT_SW; real_T *DxCol = (real_T*)VFControl_DW.StateSpace_PWORK.DX_COL; real_T *tmp2 = (real_T*)VFControl_DW.StateSpace_PWORK.TMP2; real_T *uswlast = (real_T*)VFControl_DW.StateSpace_PWORK.USWLAST; int_T newState; int_T swChanged = 0; int loopsToDo = 20; real_T temp; /* keep an initial copy of switch_status*/ memcpy(switch_status_init, switch_status, 6 * sizeof(int_T)); memcpy(uswlast, &VFControl_B.StateSpace_o1[0], 6*sizeof(real_T)); do { if (loopsToDo == 1) { /* Need to reset some variables: */ swChanged = 0; /* return to the original switch status*/ { int_T i1; for (i1=0; i1 < 6; i1++) { swChanged = ((SwitchChange[i1] = switch_status_init[i1] - switch_status[i1]) != 0) ? 1 : swChanged; switch_status[i1] = switch_status_init[i1]; } } } else { /* * Compute outputs: * --------------- */ real_T *Ds = (real_T*)VFControl_DW.StateSpace_PWORK.DS; { int_T i1; real_T *y0 = &VFControl_B.StateSpace_o1[0]; for (i1=0; i1 < 14; i1++) { accum = 0.0; { int_T i2; const real_T *u0 = &VFControl_cal->SwitchCurrents_Value[0]; for (i2=0; i2 < 6; i2++) { accum += *(Ds++) * u0[i2]; } accum += *(Ds++) * VFControl_B.GainVr_Vs1[0]; accum += *(Ds++) * VFControl_B.GainVr_Vs1[1]; accum += *(Ds++) * VFControl_cal->DCVoltageSource_Amplitude; } y0[i1] = accum; } } swChanged = 0; { int_T i1; real_T *y0 = &VFControl_B.StateSpace_o1[0]; for (i1=0; i1 < 6; i1++) { newState = ((y0[i1] > 0.0) && (gState[i1] > 0)) || (y0[i1] < 0.0) ? 1 : (((y0[i1] > 0.0) && gState[i1] == 0) ? 0 : switch_status[i1]); swChanged = ((SwitchChange[i1] = newState - switch_status[i1]) != 0) ? 1 : swChanged; switch_status[i1] = newState;/* Keep new state */ } } } /* * Compute new As, Bs, Cs and Ds matrixes: * -------------------------------------- */ if (swChanged) { real_T *Ds = (real_T*)VFControl_DW.StateSpace_PWORK.DS; real_T a1; { int_T i1; for (i1=0; i1 < 6; i1++) { if (SwitchChange[i1] != 0) { a1 = 1000.0*SwitchChange[i1]; temp = 1/(1-Ds[i1*10]*a1); { int_T i2; for (i2=0; i2 < 14; i2++) { DxCol[i2]= Ds[i2 * 9 + i1]*temp*a1; } } DxCol[i1] = temp; /* Copy row nSw of Ds into tmp2 and zero it out in Ds */ memcpy(tmp2, &Ds[i1 * 9], 9 * sizeof(real_T)); memset(&Ds[i1 * 9], '\0', 9 * sizeof(real_T)); /* Cs = Cs + DxCol * tmp1, Ds = Ds + DxCol * tmp2 *******************/ { int_T i2; for (i2=0; i2 < 14; i2++) { a1 = DxCol[i2]; { int_T i3; for (i3=0; i3 < 9; i3++) { Ds[i2 * 9 + i3] += a1 * tmp2[i3]; } } } } } } } } /* if (swChanged) */ } while (swChanged > 0 && --loopsToDo > 0); if (loopsToDo == 0) { real_T *Ds = (real_T*)VFControl_DW.StateSpace_PWORK.DS; { int_T i1; real_T *y0 = &VFControl_B.StateSpace_o1[0]; for (i1=0; i1 < 14; i1++) { accum = 0.0; { int_T i2; const real_T *u0 = &VFControl_cal->SwitchCurrents_Value[0]; for (i2=0; i2 < 6; i2++) { accum += *(Ds++) * u0[i2]; } accum += *(Ds++) * VFControl_B.GainVr_Vs1[0]; accum += *(Ds++) * VFControl_B.GainVr_Vs1[1]; accum += *(Ds++) * VFControl_cal->DCVoltageSource_Amplitude; } y0[i1] = accum; } } } /* Output new switches states */ { int_T i1; real_T *y1 = &VFControl_B.StateSpace_o2[0]; for (i1=0; i1 < 6; i1++) { y1[i1] = (real_T)switch_status[i1]; } } } /* Gain: '/1-1' */ VFControl_B.iqsids[0] = VFControl_cal->u1_Gain[0] * VFControl_B.Product3[0]; VFControl_B.iqsids[1] = VFControl_cal->u1_Gain[1] * VFControl_B.Product3[1]; /* Product: '/Mult1' */ VFControl_B.Mult1[0] = VFControl_B.iqsids[0] * VFControl_B.xk1[1]; VFControl_B.Mult1[1] = VFControl_B.xk1[0] * VFControl_B.iqsids[1]; /* Switch: '/Switch2' incorporates: * Constant: '/Constant5' */ if (VFControl_cal->Constant5_Value >= VFControl_cal->Switch2_Threshold) { /* Switch: '/Switch2' */ VFControl_B.Switch2 = VFControl_B.Switch_g; } else { /* Switch: '/Switch2' incorporates: * Constant: '/Lm_nosat' */ VFControl_B.Switch2 = VFControl_cal->Lm_nosat_Value; } /* End of Switch: '/Switch2' */ /* Sum: '/Sum2' */ xk1 = VFControl_B.Mult1[0]; /* Gain: '/Gain Vr_Vs' */ Bias = VFControl_cal->GainVr_Vs_Gain[0] * VFControl_B.StateSpace_o1[6]; VFControl_B.GainVr_Vs[0] = Bias; /* Gain: '/1_Vb' incorporates: * Constant: '/Constant6' */ VFControl_B.u_Vb[0] = VFControl_cal->u_Vb_Gain * VFControl_cal->Constant6_Value[0]; VFControl_B.u_Vb[2] = VFControl_cal->u_Vb_Gain * Bias; /* Sum: '/Sum2' */ xk1 += VFControl_B.Mult1[1]; /* Gain: '/Gain Vr_Vs' */ Bias = VFControl_cal->GainVr_Vs_Gain[1] * VFControl_B.StateSpace_o1[7]; VFControl_B.GainVr_Vs[1] = Bias; /* Gain: '/1_Vb' incorporates: * Constant: '/Constant6' */ VFControl_B.u_Vb[1] = VFControl_cal->u_Vb_Gain * VFControl_cal->Constant6_Value[1]; VFControl_B.u_Vb[3] = VFControl_cal->u_Vb_Gain * Bias; /* Sum: '/Sum2' */ VFControl_B.Sum2_k = xk1; /* Outputs for Enabled SubSystem: '/Rotor reference frame' incorporates: * EnablePort: '/Enable' */ /* Constant: '/Constant' */ if (VFControl_cal->Constant_Value_j) { VFControl_DW.Rotorreferenceframe_MODE_m = true; /* Fcn: '/vdr' */ VFControl_B.vdr_l = -0.57735026918962573 * VFControl_B.u_Vb[1]; /* Fcn: '/vds' */ VFControl_B.vds_f = ((VFControl_B.MultiportSwitch[0] - 1.7320508075688772 * VFControl_B.MultiportSwitch[1]) * VFControl_B.u_Vb[3] + 2.0 * VFControl_B.MultiportSwitch[0] * VFControl_B.u_Vb[2]) * 0.33333333333333331; /* Fcn: '/vqr' */ VFControl_B.vqr_j = (2.0 * VFControl_B.u_Vb[0] + VFControl_B.u_Vb[1]) * 0.33333333333333331; /* Fcn: '/vqs' */ VFControl_B.vqs_l = ((1.7320508075688772 * VFControl_B.MultiportSwitch[0] + VFControl_B.MultiportSwitch[1]) * VFControl_B.u_Vb[3] + 2.0 * VFControl_B.MultiportSwitch[1] * VFControl_B.u_Vb[2]) * 0.33333333333333331; srUpdateBC(VFControl_DW.Rotorreferenceframe_SubsysRan_i); } else if (VFControl_DW.Rotorreferenceframe_MODE_m) { /* Disable for Fcn: '/vqr' incorporates: * Outport: '/vqr,vdr' */ VFControl_B.vqr_j = VFControl_cal->vqrvdr_Y0; /* Disable for Fcn: '/vdr' incorporates: * Outport: '/vqr,vdr' */ VFControl_B.vdr_l = VFControl_cal->vqrvdr_Y0; /* Disable for Fcn: '/vqs' incorporates: * Outport: '/vqs,vds' */ VFControl_B.vqs_l = VFControl_cal->vqsvds_Y0; /* Disable for Fcn: '/vds' incorporates: * Outport: '/vqs,vds' */ VFControl_B.vds_f = VFControl_cal->vqsvds_Y0; VFControl_DW.Rotorreferenceframe_MODE_m = false; } /* End of Constant: '/Constant' */ /* End of Outputs for SubSystem: '/Rotor reference frame' */ /* Outputs for Enabled SubSystem: '/Stationary reference frame' incorporates: * EnablePort: '/Enable' */ /* Constant: '/Constant1' */ if (VFControl_cal->Constant1_Value_f) { VFControl_DW.Stationaryreferenceframe_MODE_p = true; /* Fcn: '/vdr' */ VFControl_B.vdr_p = ((-VFControl_B.MultiportSwitch[0] - 1.7320508075688772 * VFControl_B.MultiportSwitch[1]) * VFControl_B.u_Vb[1] + -2.0 * VFControl_B.MultiportSwitch[0] * VFControl_B.u_Vb[0]) * 0.33333333333333331; /* Fcn: '/vds' */ VFControl_B.vds_i = -0.57735026918962573 * VFControl_B.u_Vb[3]; /* Fcn: '/vqr' */ VFControl_B.vqr_l = ((VFControl_B.MultiportSwitch[1] - 1.7320508075688772 * VFControl_B.MultiportSwitch[0]) * VFControl_B.u_Vb[1] + 2.0 * VFControl_B.MultiportSwitch[1] * VFControl_B.u_Vb[0]) * 0.33333333333333331; /* Fcn: '/vqs' */ VFControl_B.vqs_i = (2.0 * VFControl_B.u_Vb[2] + VFControl_B.u_Vb[3]) * 0.33333333333333331; srUpdateBC(VFControl_DW.Stationaryreferenceframe_Subs_n); } else if (VFControl_DW.Stationaryreferenceframe_MODE_p) { /* Disable for Fcn: '/vqr' incorporates: * Outport: '/vqr,vdr' */ VFControl_B.vqr_l = VFControl_cal->vqrvdr_Y0_a; /* Disable for Fcn: '/vdr' incorporates: * Outport: '/vqr,vdr' */ VFControl_B.vdr_p = VFControl_cal->vqrvdr_Y0_a; /* Disable for Fcn: '/vqs' incorporates: * Outport: '/vqs,vds' */ VFControl_B.vqs_i = VFControl_cal->vqsvds_Y0_m; /* Disable for Fcn: '/vds' incorporates: * Outport: '/vqs,vds' */ VFControl_B.vds_i = VFControl_cal->vqsvds_Y0_m; VFControl_DW.Stationaryreferenceframe_MODE_p = false; } /* End of Constant: '/Constant1' */ /* End of Outputs for SubSystem: '/Stationary reference frame' */ /* Outputs for Enabled SubSystem: '/Synchronous reference frame' incorporates: * EnablePort: '/Enable' */ /* Constant: '/Constant2' */ if (VFControl_cal->Constant2_Value_kn) { VFControl_DW.Synchronousreferenceframe_MOD_l = true; /* Fcn: '/vdr' */ VFControl_B.vdr = ((VFControl_B.MultiportSwitch[0] - 1.7320508075688772 * VFControl_B.MultiportSwitch[1]) * VFControl_B.u_Vb[1] + 2.0 * VFControl_B.MultiportSwitch[0] * VFControl_B.u_Vb[0]) / 3.0; /* Fcn: '/vds' */ VFControl_B.vds = ((VFControl_B.MultiportSwitch[2] - 1.7320508075688772 * VFControl_B.MultiportSwitch[3]) * VFControl_B.u_Vb[3] + 2.0 * VFControl_B.MultiportSwitch[2] * VFControl_B.u_Vb[2]) / 3.0; /* Fcn: '/vqr' */ VFControl_B.vqr = ((1.7320508075688772 * VFControl_B.MultiportSwitch[0] + VFControl_B.MultiportSwitch[1]) * VFControl_B.u_Vb[1] + 2.0 * VFControl_B.MultiportSwitch[1] * VFControl_B.u_Vb[0]) / 3.0; /* Fcn: '/vqs' */ VFControl_B.vqs = ((1.7320508075688772 * VFControl_B.MultiportSwitch[2] + VFControl_B.MultiportSwitch[3]) * VFControl_B.u_Vb[3] + 2.0 * VFControl_B.MultiportSwitch[3] * VFControl_B.u_Vb[2]) / 3.0; srUpdateBC(VFControl_DW.Synchronousreferenceframe_Sub_k); } else if (VFControl_DW.Synchronousreferenceframe_MOD_l) { /* Disable for Fcn: '/vqr' incorporates: * Outport: '/vqr,vdr' */ VFControl_B.vqr = VFControl_cal->vqrvdr_Y0_am; /* Disable for Fcn: '/vdr' incorporates: * Outport: '/vqr,vdr' */ VFControl_B.vdr = VFControl_cal->vqrvdr_Y0_am; /* Disable for Fcn: '/vqs' incorporates: * Outport: '/vqs,vds' */ VFControl_B.vqs = VFControl_cal->vqsvds_Y0_p; /* Disable for Fcn: '/vds' incorporates: * Outport: '/vqs,vds' */ VFControl_B.vds = VFControl_cal->vqsvds_Y0_p; VFControl_DW.Synchronousreferenceframe_MOD_l = false; } /* End of Constant: '/Constant2' */ /* End of Outputs for SubSystem: '/Synchronous reference frame' */ /* MultiPortSwitch: '/Multiport Switch1' incorporates: * Constant: '/Constant4' */ switch (static_cast(VFControl_cal->Constant4_Value_i)) { case 1: /* MultiPortSwitch: '/Multiport Switch1' */ VFControl_B.MultiportSwitch1_f[0] = VFControl_B.vqs_l; VFControl_B.MultiportSwitch1_f[1] = VFControl_B.vds_f; break; case 2: /* MultiPortSwitch: '/Multiport Switch1' */ VFControl_B.MultiportSwitch1_f[0] = VFControl_B.vqs_i; VFControl_B.MultiportSwitch1_f[1] = VFControl_B.vds_i; break; default: /* MultiPortSwitch: '/Multiport Switch1' */ VFControl_B.MultiportSwitch1_f[0] = VFControl_B.vqs; VFControl_B.MultiportSwitch1_f[1] = VFControl_B.vds; break; } /* End of MultiPortSwitch: '/Multiport Switch1' */ /* MultiPortSwitch: '/Multiport Switch' incorporates: * Constant: '/Constant3' */ switch (static_cast(VFControl_cal->Constant3_Value_g)) { case 1: /* MultiPortSwitch: '/Multiport Switch' */ VFControl_B.MultiportSwitch_p2[0] = VFControl_B.vqr_j; VFControl_B.MultiportSwitch_p2[1] = VFControl_B.vdr_l; break; case 2: /* MultiPortSwitch: '/Multiport Switch' */ VFControl_B.MultiportSwitch_p2[0] = VFControl_B.vqr_l; VFControl_B.MultiportSwitch_p2[1] = VFControl_B.vdr_p; break; default: /* MultiPortSwitch: '/Multiport Switch' */ VFControl_B.MultiportSwitch_p2[0] = VFControl_B.vqr; VFControl_B.MultiportSwitch_p2[1] = VFControl_B.vdr; break; } /* End of MultiPortSwitch: '/Multiport Switch' */ /* UnitDelay: '/voltages' */ VFControl_B.voltages[0] = VFControl_DW.voltages_DSTATE[0]; VFControl_B.voltages[1] = VFControl_DW.voltages_DSTATE[1]; VFControl_B.voltages[2] = VFControl_DW.voltages_DSTATE[2]; VFControl_B.voltages[3] = VFControl_DW.voltages_DSTATE[3]; /* DigitalClock: '/Digital Clock' */ VFControl_B.DigitalClock = VFControl_M->Timing.t[1]; /* Switch: '/IC' incorporates: * Constant: '/Constant3' * Switch: '/Switch1' */ if (VFControl_B.DigitalClock >= VFControl_cal->IC_Threshold) { /* Sum: '/sum' */ VFControl_B.ukuk1[0] = VFControl_B.MultiportSwitch1_f[0] + VFControl_B.voltages[0]; VFControl_B.ukuk1[2] = VFControl_B.MultiportSwitch_p2[0] + VFControl_B.voltages[2]; VFControl_B.ukuk1[1] = VFControl_B.MultiportSwitch1_f[1] + VFControl_B.voltages[1]; VFControl_B.ukuk1[3] = VFControl_B.MultiportSwitch_p2[1] + VFControl_B.voltages[3]; if (VFControl_cal->Constant3_Value >= VFControl_cal->Switch1_Threshold) { /* Switch: '/Switch1' incorporates: * Product: '/Product1' */ std::memcpy(&VFControl_B.RLinv[0], &VFControl_B.RLinv_m[0], sizeof(real_T) << 4U); } else { /* Switch: '/Switch1' incorporates: * Constant: '/Constant4' */ std::memcpy(&VFControl_B.RLinv[0], &VFControl_cal->Constant4_Value[0], sizeof(real_T) << 4U); } /* MultiPortSwitch: '/Multiport Switch1' incorporates: * Constant: '/Constant3' * Constant: '/Constant4' * Switch: '/Switch1' */ switch (static_cast(VFControl_cal->Constant4_Value_e)) { case 1: /* MultiPortSwitch: '/Multiport Switch1' incorporates: * Assignment: '/W(2,1)=-wr' */ std::memcpy(&VFControl_B.MultiportSwitch1_l[0], &VFControl_B.W21wr[0], sizeof(real_T) << 4U); break; case 2: /* MultiPortSwitch: '/Multiport Switch1' incorporates: * Assignment: '/W(4,3)=wr' */ std::memcpy(&VFControl_B.MultiportSwitch1_l[0], &VFControl_B.W43wr[0], sizeof(real_T) << 4U); break; default: /* MultiPortSwitch: '/Multiport Switch1' incorporates: * Assignment: '/W(4,3)=wr-1' */ std::memcpy(&VFControl_B.MultiportSwitch1_l[0], &VFControl_B.W43wr1[0], sizeof(real_T) << 4U); break; } /* End of MultiPortSwitch: '/Multiport Switch1' */ for (i = 0; i < 16; i++) { /* Sum: '/Sum1' incorporates: * MultiPortSwitch: '/Multiport Switch1' * Switch: '/Switch1' */ xk1 = (0.0 - VFControl_B.MultiportSwitch1_l[i]) - VFControl_B.RLinv[i]; VFControl_B.A[i] = xk1; /* Gain: '/wbase*Ts//2' incorporates: * Sum: '/Sum1' */ xk1 *= VFControl_cal->wbaseTs2_Gain; VFControl_B.wbaseTs2[i] = xk1; /* Sum: '/Sum1' incorporates: * Constant: '/u5' * Gain: '/wbase*Ts//2' */ VFControl_B.Sum1_k[i] = VFControl_cal->u5_Value_l[i] - xk1; } /* Product: '/inversion' incorporates: * Sum: '/Sum1' */ rt_invd4x4_snf(VFControl_B.Sum1_k, VFControl_B.inversion); for (i = 0; i < 16; i++) { /* Gain: '/wbase*Ts//2 ' incorporates: * Product: '/inversion' */ xk1 = VFControl_cal->wbaseTs2_Gain_c * VFControl_B.inversion[i]; VFControl_B.wbaseTs2_c[i] = xk1; /* Product: '/Product1' incorporates: * Gain: '/wbase*Ts//2 ' */ tmp[i] = xk1; } /* Product: '/Product1' */ Bias = VFControl_B.ukuk1[0]; tmp_1 = VFControl_B.ukuk1[1]; tmp_2 = VFControl_B.ukuk1[2]; RLinv_m = VFControl_B.ukuk1[3]; for (i = 0; i < 4; i++) { xk1 = tmp[i] * Bias; xk1 += tmp[i + 4] * tmp_1; xk1 += tmp[i + 8] * tmp_2; xk1 += tmp[i + 12] * RLinv_m; /* Product: '/Product1' */ VFControl_B.Product1_d[i] = xk1; } for (i = 0; i < 16; i++) { /* Sum: '/Sum5' incorporates: * Constant: '/u5' * Gain: '/wbase*Ts//2' */ xk1 = VFControl_cal->u5_Value_l[i] + VFControl_B.wbaseTs2[i]; VFControl_B.Sum5[i] = xk1; /* Product: '/Product4' incorporates: * Product: '/inversion' * Sum: '/Sum5' */ tmp[i] = VFControl_B.inversion[i]; tmp_0[i] = xk1; } for (i = 0; i < 4; i++) { /* Product: '/Product4' */ tmp_3 = i << 2; xk1 = tmp_0[tmp_3]; Bias = tmp_0[tmp_3 + 1]; tmp_1 = tmp_0[tmp_3 + 2]; tmp_2 = tmp_0[tmp_3 + 3]; for (i_0 = 0; i_0 < 4; i_0++) { /* Product: '/Product4' */ RLinv_m = xk1 * tmp[i_0]; RLinv_m += tmp[i_0 + 4] * Bias; RLinv_m += tmp[i_0 + 8] * tmp_1; RLinv_m += tmp[i_0 + 12] * tmp_2; /* Product: '/Product4' */ VFControl_B.Product4_k[i_0 + tmp_3] = RLinv_m; } } /* Product: '/Product2' incorporates: * Product: '/Product4' */ std::memcpy(&tmp[0], &VFControl_B.Product4_k[0], sizeof(real_T) << 4U); Bias = VFControl_B.xk1[0]; tmp_1 = VFControl_B.xk1[1]; tmp_2 = VFControl_B.xk1[2]; RLinv_m = VFControl_B.xk1[3]; for (i = 0; i < 4; i++) { xk1 = tmp[i] * Bias; xk1 += tmp[i + 4] * tmp_1; xk1 += tmp[i + 8] * tmp_2; xk1 += tmp[i + 12] * RLinv_m; /* Product: '/Product2' */ VFControl_B.Product2_o[i] = xk1; /* Sum: '/Ad*x(k-1) + Bd*( u(k-1) + u(k))' */ xk1 += VFControl_B.Product1_d[i]; VFControl_B.xk[i] = xk1; /* Switch: '/IC' */ VFControl_B.IC[i] = xk1; } /* End of Product: '/Product2' */ } else { /* Switch: '/IC' */ VFControl_B.IC[0] = VFControl_B.xk1[0]; VFControl_B.IC[1] = VFControl_B.xk1[1]; VFControl_B.IC[2] = VFControl_B.xk1[2]; VFControl_B.IC[3] = VFControl_B.xk1[3]; } /* End of Switch: '/IC' */ /* Sum: '/Sum2' */ xk1 = 0.0 - VFControl_B.MultiportSwitch_p[0]; xk1 -= VFControl_B.MultiportSwitch_p[1]; /* Sum: '/Sum2' */ VFControl_B.Sum2_l = xk1; /* Gain: '/unit conversion' */ VFControl_B.unitconversion[2] = VFControl_cal->unitconversion_Gain[2] * VFControl_B.Sum2_l; /* Sum: '/Sum3' */ xk1 = 0.0 - VFControl_B.MultiportSwitch1[0]; /* Gain: '/unit conversion' */ VFControl_B.unitconversion[0] = VFControl_cal->unitconversion_Gain[0] * VFControl_B.MultiportSwitch_p[0]; VFControl_B.unitconversion[3] = VFControl_B.Product3[2] * VFControl_cal->unitconversion_Gain[3]; VFControl_B.unitconversion[5] = VFControl_B.xk1[2] * VFControl_cal->unitconversion_Gain[5]; VFControl_B.unitconversion[7] = VFControl_B.MultiportSwitch_p2[0] * VFControl_cal->unitconversion_Gain[7]; VFControl_B.unitconversion[9] = VFControl_B.MultiportSwitch1[0] * VFControl_cal->unitconversion_Gain[9]; VFControl_B.unitconversion[12] = VFControl_B.Product3[0] * VFControl_cal->unitconversion_Gain[12]; VFControl_B.unitconversion[14] = VFControl_B.xk1[0] * VFControl_cal->unitconversion_Gain[14]; VFControl_B.unitconversion[16] = VFControl_B.MultiportSwitch1_f[0] * VFControl_cal->unitconversion_Gain[16]; /* Sum: '/Sum3' */ xk1 -= VFControl_B.MultiportSwitch1[1]; /* Gain: '/unit conversion' */ VFControl_B.unitconversion[1] = VFControl_cal->unitconversion_Gain[1] * VFControl_B.MultiportSwitch_p[1]; VFControl_B.unitconversion[4] = VFControl_B.Product3[3] * VFControl_cal->unitconversion_Gain[4]; VFControl_B.unitconversion[6] = VFControl_B.xk1[3] * VFControl_cal->unitconversion_Gain[6]; VFControl_B.unitconversion[8] = VFControl_B.MultiportSwitch_p2[1] * VFControl_cal->unitconversion_Gain[8]; VFControl_B.unitconversion[10] = VFControl_B.MultiportSwitch1[1] * VFControl_cal->unitconversion_Gain[10]; VFControl_B.unitconversion[13] = VFControl_B.Product3[1] * VFControl_cal->unitconversion_Gain[13]; VFControl_B.unitconversion[15] = VFControl_B.xk1[1] * VFControl_cal->unitconversion_Gain[15]; VFControl_B.unitconversion[17] = VFControl_B.MultiportSwitch1_f[1] * VFControl_cal->unitconversion_Gain[17]; /* Sum: '/Sum3' */ VFControl_B.Sum3 = xk1; /* Gain: '/unit conversion' */ VFControl_B.unitconversion[11] = VFControl_cal->unitconversion_Gain[11] * VFControl_B.Sum3; VFControl_B.unitconversion[18] = VFControl_cal->unitconversion_Gain[18] * VFControl_B.Switch2; /* Gain: '/1\p' */ VFControl_B.up = VFControl_cal->up_Gain * VFControl_B.Rotoranglethetam; /* Gain: '/1\p1' */ VFControl_B.wTethr[0] = VFControl_cal->up1_Gain[0] * VFControl_B.Sum1; VFControl_B.wTethr[1] = VFControl_cal->up1_Gain[1] * VFControl_B.Sum2_k; VFControl_B.wTethr[2] = VFControl_cal->up1_Gain[2] * VFControl_B.up; /* Gain: '/Unit conversion' */ VFControl_B.Unitconversion = VFControl_cal->Unitconversion_Gain * 0.0; /* Gain: '/F' */ VFControl_B.F = VFControl_cal->F_Gain * VFControl_B.Sum1; /* Sum: '/Sum' */ VFControl_B.Sum = (VFControl_B.Sum2_k - VFControl_B.Unitconversion) - VFControl_B.F; /* Gain: '/1_2H' */ VFControl_B.u_2H = VFControl_cal->u_2H_Gain * VFControl_B.Sum; /* DiscreteIntegrator: '/Rotor speed(wm)' */ if (VFControl_DW.Rotorspeedwm_SYSTEM_ENABLE != 0) { /* DiscreteIntegrator: '/Rotor speed(wm)' */ VFControl_B.Rotorspeedwm = VFControl_DW.Rotorspeedwm_DSTATE; } else { /* DiscreteIntegrator: '/Rotor speed(wm)' */ VFControl_B.Rotorspeedwm = VFControl_cal->Rotorspeedwm_gainval * VFControl_B.u_2H + VFControl_DW.Rotorspeedwm_DSTATE; } /* End of DiscreteIntegrator: '/Rotor speed(wm)' */ /* Gain: '/web_psb' */ VFControl_B.web_psb = VFControl_cal->web_psb_Gain_n * VFControl_B.Sum1; /* DigitalClock: '/Digital Clock' */ VFControl_B.DigitalClock_k = VFControl_M->Timing.t[1]; /* Lookup: '/Look-Up Table' */ VFControl_B.LookUpTable = rt_Lookup(&VFControl_cal->LookUpTable_XData[0], 8, VFControl_B.DigitalClock_k, &VFControl_cal->LookUpTable_YData[0]); /* RelationalOperator: '/Relational Operator3' incorporates: * Constant: '/Constant6' * Constant: '/valp_nom1' */ VFControl_B.RelationalOperator3 = (VFControl_cal->valp_nom1_Value == VFControl_cal->Constant6_Value_k); /* RelationalOperator: '/Relational Operator' incorporates: * Constant: '/Constant' * Constant: '/valp_nom3' */ VFControl_B.Amplitude = (VFControl_cal->valp_nom3_Value == VFControl_cal->Constant_Value_nw); /* Logic: '/Logical Operator1' */ VFControl_B.LogicalOperator1 = (VFControl_B.RelationalOperator3 && VFControl_B.Amplitude); /* Step: '/Step1' */ Bias = VFControl_M->Timing.t[1]; if (Bias < VFControl_cal->Variationvaluesteprampmod_Toff_) { /* Step: '/Step1' */ VFControl_B.Toff = VFControl_cal->Step1_Y0; } else { /* Step: '/Step1' */ VFControl_B.Toff = VFControl_cal->Step1_YFinal; } /* End of Step: '/Step1' */ /* DataTypeConversion: '/Data Type Conversion2' */ VFControl_B.DataTypeConversion2 = (VFControl_B.Toff != 0.0); /* Logic: '/Logical Operator1' */ VFControl_B.LogicalOperator1_l = !VFControl_B.DataTypeConversion2; /* RelationalOperator: '/Relational Operator1' incorporates: * Constant: '/valp_nom5' * Constant: '/Constant3' */ VFControl_B.RelationalOperator1 = (VFControl_cal->valp_nom5_Value == VFControl_cal->Constant3_Value_ey); /* DataTypeConversion: '/Data Type Conversion1' */ VFControl_B.DataTypeConversion1_f = VFControl_B.RelationalOperator1; /* Logic: '/Logical Operator' */ VFControl_B.LogicalOperator = (VFControl_B.LogicalOperator1_l && VFControl_B.DataTypeConversion1_f); /* Step: '/Step' */ Bias = VFControl_M->Timing.t[1]; if (Bias < VFControl_cal->Variationvaluesteprampmod_Ton_V) { /* Step: '/Step' */ VFControl_B.Ton = VFControl_cal->Step_Y0; } else { /* Step: '/Step' */ VFControl_B.Ton = VFControl_cal->Step_YFinal; } /* End of Step: '/Step' */ /* DiscreteIntegrator: '/Discrete-Time Integrator1' */ VFControl_B.DiscreteTimeIntegrator1 = VFControl_DW.DiscreteTimeIntegrator1_DSTATE; /* UnitDelay: '/Unit Delay1' */ VFControl_B.UnitDelay1 = VFControl_DW.UnitDelay1_DSTATE; /* Switch: '/Switch2' */ if (VFControl_B.Toff >= VFControl_cal->Switch2_Threshold_a) { /* MultiPortSwitch: '/Multiport Switch1' incorporates: * Constant: '/valp_nom5' */ switch (static_cast(VFControl_cal->valp_nom5_Value)) { case 1: /* Product: '/Product2' incorporates: * Constant: '/valp_nom6' */ VFControl_B.Step = VFControl_cal->Variationvaluesteprampmod_Var_n * VFControl_B.Ton; /* MultiPortSwitch: '/Multiport Switch1' */ VFControl_B.MultiportSwitch1_b = VFControl_B.Step; break; case 2: /* MultiPortSwitch: '/Multiport Switch1' */ VFControl_B.MultiportSwitch1_b = VFControl_B.DiscreteTimeIntegrator1; break; case 3: /* Gain: '/Gain1' incorporates: * Constant: '/valp_nom9' */ VFControl_B.Gain1_f = VFControl_cal->Gain1_Gain_n * VFControl_cal->Variationvaluesteprampmod_Varia; /* Product: '/Product1' */ VFControl_B.Product1_f = VFControl_B.DiscreteTimeIntegrator1 * VFControl_B.Gain1_f; /* Trigonometry: '/Trigonometric Function1' */ VFControl_B.TrigonometricFunction1_l = std::sin(VFControl_B.Product1_f); /* Product: '/Product' incorporates: * Constant: '/valp_nom8' */ VFControl_B.Mod = VFControl_cal->Variationvaluesteprampmod_Var_l * VFControl_B.TrigonometricFunction1_l; /* MultiPortSwitch: '/Multiport Switch1' */ VFControl_B.MultiportSwitch1_b = VFControl_B.Mod; break; default: /* MultiPortSwitch: '/Multiport Switch1' incorporates: * Constant: '/Constant5' */ VFControl_B.MultiportSwitch1_b = VFControl_cal->Constant5_Value_c; break; } /* End of MultiPortSwitch: '/Multiport Switch1' */ /* Switch: '/Switch2' */ VFControl_B.Switch2_d = VFControl_B.MultiportSwitch1_b; } else { /* Switch: '/Switch2' */ VFControl_B.Switch2_d = VFControl_B.UnitDelay1; } /* End of Switch: '/Switch2' */ /* Switch: '/Switch3' */ if (VFControl_B.LogicalOperator) { /* Switch: '/Switch3' incorporates: * Constant: '/Constant1' */ VFControl_B.Switch3 = VFControl_cal->Constant1_Value_a; } else { /* Switch: '/Switch3' */ VFControl_B.Switch3 = VFControl_B.Switch2_d; } /* End of Switch: '/Switch3' */ /* Switch: '/Switch2' */ if (VFControl_B.Amplitude) { /* Switch: '/Switch2' */ VFControl_B.Switch2_a = VFControl_B.Switch3; } else { /* Switch: '/Switch2' incorporates: * Constant: '/Constant1' */ VFControl_B.Switch2_a = VFControl_cal->Constant1_Value_j; } /* End of Switch: '/Switch2' */ /* Sum: '/Sum3' incorporates: * Constant: '/valp_nom2' */ VFControl_B.Sum3_e = VFControl_B.Switch2_a + VFControl_cal->valp_nom2_Value; /* Switch: '/Switch1' */ if (VFControl_B.LogicalOperator1) { /* Switch: '/Switch1' */ VFControl_B.Switch1 = VFControl_B.LookUpTable; } else { /* Switch: '/Switch1' */ VFControl_B.Switch1 = VFControl_B.Sum3_e; } /* End of Switch: '/Switch1' */ /* Switch: '/Switch5' */ VFControl_B.Switch5[0] = VFControl_B.Switch1; /* Switch: '/Switch5' incorporates: * Constant: '/SinglePhase' */ if (VFControl_cal->SinglePhase_Value >= VFControl_cal->Switch5_Threshold) { /* Switch: '/Switch5' */ VFControl_B.Switch5[1] = VFControl_B.Sum3_e; VFControl_B.Switch5[2] = VFControl_B.Sum3_e; } else { /* Switch: '/Switch5' */ VFControl_B.Switch5[1] = VFControl_B.Switch1; VFControl_B.Switch5[2] = VFControl_B.Switch1; } /* DigitalClock: '/t' */ VFControl_B.t = VFControl_M->Timing.t[1]; /* Gain: '/Gain' incorporates: * Constant: '/valp_nom1' */ VFControl_B.Gain_p = VFControl_cal->Gain_Gain_k * VFControl_cal->valp_nom1_Value_g; /* Product: '/Product' */ VFControl_B.Product = VFControl_B.t * VFControl_B.Gain_p; /* DiscreteIntegrator: '/Discrete-Time Integrator' */ VFControl_B.DiscreteTimeIntegrator = VFControl_DW.DiscreteTimeIntegrator_DSTATE; /* Sum: '/Sum' */ VFControl_B.Sum_n = VFControl_B.Product + VFControl_B.DiscreteTimeIntegrator; /* RelationalOperator: '/Relational Operator3' incorporates: * Constant: '/Constant6' * Constant: '/valp_nom1' */ VFControl_B.RelationalOperator3_f = (VFControl_cal->valp_nom1_Value_c == VFControl_cal->Constant6_Value_h); /* RelationalOperator: '/Relational Operator1' incorporates: * Constant: '/Constant2' * Constant: '/valp_nom3' */ VFControl_B.Phase = (VFControl_cal->valp_nom3_Value == VFControl_cal->Constant2_Value_b); /* Logic: '/Logical Operator1' */ VFControl_B.LogicalOperator1_b = (VFControl_B.RelationalOperator3_f && VFControl_B.Phase); /* Gain: '/Gain3' incorporates: * Constant: '/valp_nom' */ VFControl_B.Gain3 = VFControl_cal->Gain3_Gain_e * VFControl_cal->valp_nom_Value; /* Switch: '/Switch3' */ if (VFControl_B.Phase) { /* Gain: '/Gain4' */ VFControl_B.Gain4 = VFControl_cal->Gain4_Gain * VFControl_B.Switch3; /* Switch: '/Switch3' */ VFControl_B.Switch3_o = VFControl_B.Gain4; } else { /* Switch: '/Switch3' incorporates: * Constant: '/Constant4' */ VFControl_B.Switch3_o = VFControl_cal->Constant4_Value_l; } /* End of Switch: '/Switch3' */ /* Sum: '/Sum2' incorporates: * Constant: '/P1' */ VFControl_B.Sum2_j[0] = (VFControl_B.Gain3 + VFControl_cal->P1_Value_e[0]) + VFControl_B.Switch3_o; VFControl_B.Sum2_j[1] = (VFControl_B.Gain3 + VFControl_cal->P1_Value_e[1]) + VFControl_B.Switch3_o; VFControl_B.Sum2_j[2] = (VFControl_B.Gain3 + VFControl_cal->P1_Value_e[2]) + VFControl_B.Switch3_o; /* Switch: '/Switch1' */ if (VFControl_B.LogicalOperator1_b) { /* Gain: '/Gain3' */ VFControl_B.Gain3_n = VFControl_cal->Gain3_Gain_c * VFControl_B.LookUpTable; /* Sum: '/Sum2' incorporates: * Constant: '/P1' */ xk1 = VFControl_B.Gain3_n + VFControl_cal->P1_Value[0]; VFControl_B.Sum2_lw[0] = xk1; /* Switch: '/Switch1' */ VFControl_B.Switch1_a[0] = xk1; /* Sum: '/Sum2' incorporates: * Constant: '/P1' */ xk1 = VFControl_B.Gain3_n + VFControl_cal->P1_Value[1]; VFControl_B.Sum2_lw[1] = xk1; /* Switch: '/Switch1' */ VFControl_B.Switch1_a[1] = xk1; /* Sum: '/Sum2' incorporates: * Constant: '/P1' */ xk1 = VFControl_B.Gain3_n + VFControl_cal->P1_Value[2]; VFControl_B.Sum2_lw[2] = xk1; /* Switch: '/Switch1' */ VFControl_B.Switch1_a[2] = xk1; } else { /* Switch: '/Switch1' */ VFControl_B.Switch1_a[0] = VFControl_B.Sum2_j[0]; VFControl_B.Switch1_a[1] = VFControl_B.Sum2_j[1]; VFControl_B.Switch1_a[2] = VFControl_B.Sum2_j[2]; } /* End of Switch: '/Switch1' */ /* Switch: '/Switch5' incorporates: * Constant: '/SinglePhase' */ if (VFControl_cal->SinglePhase_Value_i >= VFControl_cal->Switch5_Threshold_m) { /* Switch: '/Switch5' */ VFControl_B.Switch5_b[0] = VFControl_B.Switch1_a[0]; VFControl_B.Switch5_b[1] = VFControl_B.Sum2_j[1]; VFControl_B.Switch5_b[2] = VFControl_B.Sum2_j[2]; } else { /* Switch: '/Switch5' */ VFControl_B.Switch5_b[0] = VFControl_B.Switch1_a[0]; VFControl_B.Switch5_b[1] = VFControl_B.Switch1_a[1]; VFControl_B.Switch5_b[2] = VFControl_B.Switch1_a[2]; } /* End of Switch: '/Switch5' */ /* Sum: '/Sum7' */ VFControl_B.Sum7[0] = VFControl_B.Sum_n + VFControl_B.Switch5_b[0]; /* Trigonometry: '/Trigonometric Function1' */ xk1 = std::sin(VFControl_B.Sum7[0]); VFControl_B.TrigonometricFunction1[0] = xk1; /* Product: '/Product2' */ VFControl_B.Product2[0] = VFControl_B.Switch5[0] * xk1; /* Sum: '/Sum7' */ VFControl_B.Sum7[1] = VFControl_B.Sum_n + VFControl_B.Switch5_b[1]; /* Trigonometry: '/Trigonometric Function1' */ xk1 = std::sin(VFControl_B.Sum7[1]); VFControl_B.TrigonometricFunction1[1] = xk1; /* Product: '/Product2' */ VFControl_B.Product2[1] = VFControl_B.Switch5[1] * xk1; /* Sum: '/Sum7' */ VFControl_B.Sum7[2] = VFControl_B.Sum_n + VFControl_B.Switch5_b[2]; /* Trigonometry: '/Trigonometric Function1' */ xk1 = std::sin(VFControl_B.Sum7[2]); VFControl_B.TrigonometricFunction1[2] = xk1; /* Product: '/Product2' */ VFControl_B.Product2[2] = VFControl_B.Switch5[2] * xk1; /* Step: '/Step' */ Bias = VFControl_M->Timing.t[1]; if (Bias < VFControl_cal->Step_Time) { /* Step: '/Step' */ VFControl_B.Ton_e = VFControl_cal->Step_Y0_k; } else { /* Step: '/Step' */ VFControl_B.Ton_e = VFControl_cal->Step_YFinal_d; } /* End of Step: '/Step' */ /* Step: '/Step1' */ Bias = VFControl_M->Timing.t[1]; if (Bias < VFControl_cal->Step1_Time) { /* Step: '/Step1' */ VFControl_B.Toff_e = VFControl_cal->Step1_Y0_i; } else { /* Step: '/Step1' */ VFControl_B.Toff_e = VFControl_cal->Step1_YFinal_k; } /* End of Step: '/Step1' */ /* Sum: '/Sum4' */ VFControl_B.Sum4 = VFControl_B.Ton_e + VFControl_B.Toff_e; /* DataTypeConversion: '/Data Type Conversion1' */ VFControl_B.DataTypeConversion1_j = (VFControl_B.Sum4 != 0.0); /* DataTypeConversion: '/Data Type Conversion2' incorporates: * Constant: '/valp_nom7' */ VFControl_B.DataTypeConversion2_m = (VFControl_cal->valp_nom7_Value != 0.0); /* Logic: '/Logical Operator' */ VFControl_B.LogicalOperator_l = (VFControl_B.DataTypeConversion1_j && VFControl_B.DataTypeConversion2_m); /* DataTypeConversion: '/Data Type Conversion' */ VFControl_B.DataTypeConversion = VFControl_B.LogicalOperator_l; /* Gain: '/Gain1' */ VFControl_B.Gain1 = VFControl_cal->HarmonicAgeneration_n_Harmo * VFControl_B.Sum_n; /* Gain: '/Gain3' incorporates: * Constant: '/Phase_Harmo' */ VFControl_B.Gain3_f = VFControl_cal->Gain3_Gain_l * VFControl_cal->HarmonicAgeneration_Phase_Harmo; /* Sum: '/Sum1' incorporates: * Constant: '/Phase_Harmo2' * Constant: '/valp_nom2' */ VFControl_B.Sum1_m = VFControl_cal->HarmonicAgeneration_Seq_Harmo + VFControl_cal->valp_nom2_Value_i; /* MultiPortSwitch: '/Multiport Switch' */ switch (static_cast(VFControl_B.Sum1_m)) { case 1: /* MultiPortSwitch: '/Multiport Switch' incorporates: * Constant: '/Zero-sequence' */ VFControl_B.MultiportSwitch_h[0] = VFControl_cal->Zerosequence_Value[0]; VFControl_B.MultiportSwitch_h[1] = VFControl_cal->Zerosequence_Value[1]; VFControl_B.MultiportSwitch_h[2] = VFControl_cal->Zerosequence_Value[2]; break; case 2: /* MultiPortSwitch: '/Multiport Switch' incorporates: * Constant: '/Positive-sequence' */ VFControl_B.MultiportSwitch_h[0] = VFControl_cal->Positivesequence_Value[0]; VFControl_B.MultiportSwitch_h[1] = VFControl_cal->Positivesequence_Value[1]; VFControl_B.MultiportSwitch_h[2] = VFControl_cal->Positivesequence_Value[2]; break; default: /* MultiPortSwitch: '/Multiport Switch' incorporates: * Constant: '/Negative-sequence' */ VFControl_B.MultiportSwitch_h[0] = VFControl_cal->Negativesequence_Value[0]; VFControl_B.MultiportSwitch_h[1] = VFControl_cal->Negativesequence_Value[1]; VFControl_B.MultiportSwitch_h[2] = VFControl_cal->Negativesequence_Value[2]; break; } /* End of MultiPortSwitch: '/Multiport Switch' */ /* Sum: '/Sum' */ xk1 = VFControl_B.Gain1 + VFControl_B.Gain3_f; /* Sum: '/Sum' */ VFControl_B.Sum_j[0] = xk1 + VFControl_B.MultiportSwitch_h[0]; /* Trigonometry: '/Trigonometric Function1' */ Bias = std::sin(VFControl_B.Sum_j[0]); VFControl_B.TrigonometricFunction1_d[0] = Bias; /* Product: '/Product1' incorporates: * Constant: '/Phase_Harmo1' */ tmp_1 = VFControl_B.DataTypeConversion * VFControl_cal->HarmonicAgeneration_Mag_Harmo; /* Product: '/Product1' */ VFControl_B.Product1[0] = tmp_1 * Bias; /* Sum: '/Sum' */ VFControl_B.Sum_j[1] = xk1 + VFControl_B.MultiportSwitch_h[1]; /* Trigonometry: '/Trigonometric Function1' */ Bias = std::sin(VFControl_B.Sum_j[1]); VFControl_B.TrigonometricFunction1_d[1] = Bias; /* Product: '/Product1' */ VFControl_B.Product1[1] = tmp_1 * Bias; /* Sum: '/Sum' */ VFControl_B.Sum_j[2] = xk1 + VFControl_B.MultiportSwitch_h[2]; /* Trigonometry: '/Trigonometric Function1' */ Bias = std::sin(VFControl_B.Sum_j[2]); VFControl_B.TrigonometricFunction1_d[2] = Bias; /* Product: '/Product1' */ VFControl_B.Product1[2] = tmp_1 * Bias; /* Gain: '/Gain1' */ VFControl_B.Gain1_m = VFControl_cal->HarmonicBgeneration_n_Harmo * VFControl_B.Sum_n; /* Gain: '/Gain3' incorporates: * Constant: '/Phase_Harmo' */ VFControl_B.Gain3_a = VFControl_cal->Gain3_Gain_j * VFControl_cal->HarmonicBgeneration_Phase_Harmo; /* Sum: '/Sum1' incorporates: * Constant: '/Phase_Harmo2' * Constant: '/valp_nom2' */ VFControl_B.Sum1_m3 = VFControl_cal->HarmonicBgeneration_Seq_Harmo + VFControl_cal->valp_nom2_Value_c; /* MultiPortSwitch: '/Multiport Switch' */ switch (static_cast(VFControl_B.Sum1_m3)) { case 1: /* MultiPortSwitch: '/Multiport Switch' incorporates: * Constant: '/Zero-sequence' */ VFControl_B.MultiportSwitch_n[0] = VFControl_cal->Zerosequence_Value_h[0]; VFControl_B.MultiportSwitch_n[1] = VFControl_cal->Zerosequence_Value_h[1]; VFControl_B.MultiportSwitch_n[2] = VFControl_cal->Zerosequence_Value_h[2]; break; case 2: /* MultiPortSwitch: '/Multiport Switch' incorporates: * Constant: '/Positive-sequence' */ VFControl_B.MultiportSwitch_n[0] = VFControl_cal->Positivesequence_Value_o[0]; VFControl_B.MultiportSwitch_n[1] = VFControl_cal->Positivesequence_Value_o[1]; VFControl_B.MultiportSwitch_n[2] = VFControl_cal->Positivesequence_Value_o[2]; break; default: /* MultiPortSwitch: '/Multiport Switch' incorporates: * Constant: '/Negative-sequence' */ VFControl_B.MultiportSwitch_n[0] = VFControl_cal->Negativesequence_Value_k[0]; VFControl_B.MultiportSwitch_n[1] = VFControl_cal->Negativesequence_Value_k[1]; VFControl_B.MultiportSwitch_n[2] = VFControl_cal->Negativesequence_Value_k[2]; break; } /* End of MultiPortSwitch: '/Multiport Switch' */ /* Sum: '/Sum' */ xk1 = VFControl_B.Gain1_m + VFControl_B.Gain3_a; /* Sum: '/Sum' */ VFControl_B.Sum_i[0] = xk1 + VFControl_B.MultiportSwitch_n[0]; /* Trigonometry: '/Trigonometric Function1' */ tmp_1 = std::sin(VFControl_B.Sum_i[0]); VFControl_B.TrigonometricFunction1_c[0] = tmp_1; /* Product: '/Product1' incorporates: * Constant: '/Phase_Harmo1' */ Bias = VFControl_B.DataTypeConversion * VFControl_cal->HarmonicBgeneration_Mag_Harmo; /* Product: '/Product1' */ tmp_1 *= Bias; VFControl_B.Product1_i[0] = tmp_1; /* Sum: '/Sum4' */ tmp_1 += VFControl_B.Product1[0]; VFControl_B.Sum4_o[0] = tmp_1; /* Sum: '/Sum8' */ VFControl_B.Sum8[0] = VFControl_B.Product2[0] + tmp_1; /* Sum: '/Sum' */ VFControl_B.Sum_i[1] = xk1 + VFControl_B.MultiportSwitch_n[1]; /* Trigonometry: '/Trigonometric Function1' */ tmp_1 = std::sin(VFControl_B.Sum_i[1]); VFControl_B.TrigonometricFunction1_c[1] = tmp_1; /* Product: '/Product1' */ tmp_1 *= Bias; VFControl_B.Product1_i[1] = tmp_1; /* Sum: '/Sum4' */ tmp_1 += VFControl_B.Product1[1]; VFControl_B.Sum4_o[1] = tmp_1; /* Sum: '/Sum8' */ VFControl_B.Sum8[1] = VFControl_B.Product2[1] + tmp_1; /* Sum: '/Sum' */ VFControl_B.Sum_i[2] = xk1 + VFControl_B.MultiportSwitch_n[2]; /* Trigonometry: '/Trigonometric Function1' */ tmp_1 = std::sin(VFControl_B.Sum_i[2]); VFControl_B.TrigonometricFunction1_c[2] = tmp_1; /* Product: '/Product1' */ tmp_1 *= Bias; VFControl_B.Product1_i[2] = tmp_1; /* Sum: '/Sum4' */ tmp_1 += VFControl_B.Product1[2]; VFControl_B.Sum4_o[2] = tmp_1; /* Sum: '/Sum8' */ VFControl_B.Sum8[2] = VFControl_B.Product2[2] + tmp_1; /* Clock: '/Clock' */ VFControl_B.Clock = VFControl_M->Timing.t[0]; /* Sum: '/Add1' incorporates: * Constant: '/Constant3' */ VFControl_B.Add1 = VFControl_B.Clock + VFControl_cal->Constant3_Value_m; /* Math: '/Math Function' incorporates: * Constant: '/Constant4' */ VFControl_B.MathFunction = rt_remd_snf(VFControl_B.Add1, VFControl_cal->Constant4_Value_p); /* Gain: '/1\ib1' */ VFControl_B.uib1 = VFControl_cal->uib1_Gain * VFControl_B.MathFunction; /* Lookup_n-D: '/1-D Lookup Table' incorporates: * Gain: '/1\ib1' */ VFControl_B.uDLookupTable = look1_pbinlxpw(VFControl_B.uib1, VFControl_cal->uDLookupTable_bp01Data_k, VFControl_cal->uDLookupTable_tableData_d, &VFControl_DW.m_bpIndex, 2U); /* Sum: '/Add3' incorporates: * Constant: '/Constant2' */ VFControl_B.Add3 = VFControl_B.uDLookupTable - VFControl_cal->Constant2_Value_a; /* ModelReference: '/Model' incorporates: * Constant: '/Constant' */ PWMGenerator(&VFControl_B.Sum8[0], &VFControl_B.Add3, &VFControl_cal->Constant_Value_c, &VFControl_B.Model_o1, &VFControl_B.Model_o2, &VFControl_B.Model_o3, &(VFControl_DW.Model_InstanceData.rtb)); /* DigitalClock: '/Digital Clock' */ VFControl_B.DigitalClock_m = VFControl_M->Timing.t[1]; /* Sum: '/Add1' incorporates: * Constant: '/Constant3' */ VFControl_B.Add1_e = VFControl_B.DigitalClock_m + VFControl_cal->Constant3_Value_ej; /* Math: '/Math Function' incorporates: * Constant: '/Constant1' */ VFControl_B.MathFunction_l = rt_remd_snf(VFControl_B.Add1_e, VFControl_cal->Constant1_Value_o); /* Gain: '/1\ib1' */ VFControl_B.uib1_h = VFControl_cal->uib1_Gain_i * VFControl_B.MathFunction_l; /* Lookup_n-D: '/1-D Lookup Table' incorporates: * Gain: '/1\ib1' */ VFControl_B.uDLookupTable_b = look1_pbinlxpw(VFControl_B.uib1_h, VFControl_cal->uDLookupTable_bp01Data_i, VFControl_cal->uDLookupTable_tableData_f, &VFControl_DW.m_bpIndex_e, 2U); /* Sum: '/Add3' incorporates: * Constant: '/Constant2' */ VFControl_B.Add3_h = VFControl_B.uDLookupTable_b - VFControl_cal->Constant2_Value_at; /* ModelReference: '/Model1' incorporates: * Constant: '/Constant1' */ PWMGenerator(&VFControl_B.Sum8[1], &VFControl_B.Add3_h, &VFControl_cal->Constant1_Value_ah, &VFControl_B.Model1_o1, &VFControl_B.Model1_o2, &VFControl_B.Model1_o3, &(VFControl_DW.Model1_InstanceData.rtb)); /* DigitalClock: '/Digital Clock' */ VFControl_B.DigitalClock_ms = VFControl_M->Timing.t[1]; /* Sum: '/Add1' incorporates: * Constant: '/Constant3' */ VFControl_B.Add1_l = VFControl_B.DigitalClock_ms + VFControl_cal->Constant3_Value_mm; /* Math: '/Math Function' incorporates: * Constant: '/Constant1' */ VFControl_B.MathFunction_o = rt_remd_snf(VFControl_B.Add1_l, VFControl_cal->Constant1_Value_p); /* Gain: '/1\ib1' */ VFControl_B.uib1_e = VFControl_cal->uib1_Gain_c * VFControl_B.MathFunction_o; /* Lookup_n-D: '/1-D Lookup Table' incorporates: * Gain: '/1\ib1' */ VFControl_B.uDLookupTable_bk = look1_pbinlxpw(VFControl_B.uib1_e, VFControl_cal->uDLookupTable_bp01Data_m, VFControl_cal->uDLookupTable_tableData_h, &VFControl_DW.m_bpIndex_p, 2U); /* Sum: '/Add3' incorporates: * Constant: '/Constant2' */ VFControl_B.Add3_n = VFControl_B.uDLookupTable_bk - VFControl_cal->Constant2_Value_k; /* ModelReference: '/Model2' incorporates: * Constant: '/Constant2' */ PWMGenerator(&VFControl_B.Sum8[2], &VFControl_B.Add3_n, &VFControl_cal->Constant2_Value_a1, &VFControl_B.Model2_o1, &VFControl_B.Model2_o2, &VFControl_B.Model2_o3, &(VFControl_DW.Model2_InstanceData.rtb)); /* TransportDelay: '/Transport Delay' */ { real_T **uBuffer = (real_T**) &VFControl_DW.TransportDelay_PWORK.TUbufferPtrs[0]; real_T simTime = VFControl_M->Timing.t[0]; real_T tMinusDelay = simTime - VFControl_cal->TransportDelay_Delay; VFControl_B.TransportDelay = rt_TDelayInterpolate( tMinusDelay, 0.0, *uBuffer, VFControl_DW.TransportDelay_IWORK.CircularBufSize, &VFControl_DW.TransportDelay_IWORK.Last, VFControl_DW.TransportDelay_IWORK.Tail, VFControl_DW.TransportDelay_IWORK.Head, (VFControl_cal->TransportDelay_InitOutput), 1, 0); } /* TransportDelay: '/Transport Delay' */ { real_T **uBuffer = (real_T**) &VFControl_DW.TransportDelay_PWORK_m.TUbufferPtrs[0]; real_T simTime = VFControl_M->Timing.t[0]; real_T tMinusDelay = simTime - VFControl_cal->TransportDelay_Delay_l; VFControl_B.TransportDelay_i = rt_TDelayInterpolate( tMinusDelay, 0.0, *uBuffer, VFControl_DW.TransportDelay_IWORK_g.CircularBufSize, &VFControl_DW.TransportDelay_IWORK_g.Last, VFControl_DW.TransportDelay_IWORK_g.Tail, VFControl_DW.TransportDelay_IWORK_g.Head, (VFControl_cal->TransportDelay_InitOutput_l), 1, 0); } /* TransportDelay: '/Transport Delay' */ { real_T **uBuffer = (real_T**) &VFControl_DW.TransportDelay_PWORK_f.TUbufferPtrs[0]; real_T simTime = VFControl_M->Timing.t[0]; real_T tMinusDelay = simTime - VFControl_cal->TransportDelay_Delay_c; VFControl_B.TransportDelay_n = rt_TDelayInterpolate( tMinusDelay, 0.0, *uBuffer, VFControl_DW.TransportDelay_IWORK_m.CircularBufSize, &VFControl_DW.TransportDelay_IWORK_m.Last, VFControl_DW.TransportDelay_IWORK_m.Tail, VFControl_DW.TransportDelay_IWORK_m.Head, (VFControl_cal->TransportDelay_InitOutput_le), 1, 0); } /* S-Function (sg_fpga_do_sf_a2): '/Digital output1' */ /* Level2 S-Function Block: '/Digital output1' (sg_fpga_do_sf_a2) */ { SimStruct *rts = VFControl_M->childSfunctions[0]; sfcnOutputs(rts,0); } /* S-Function (sg_fpga_do_sf_a2): '/Digital output2' */ /* Level2 S-Function Block: '/Digital output2' (sg_fpga_do_sf_a2) */ { SimStruct *rts = VFControl_M->childSfunctions[1]; sfcnOutputs(rts,0); } /* Switch: '/Switch' */ if (VFControl_B.StateSpace_o2[0] >= VFControl_cal->Switch_Threshold_e) { /* Gain: '/1//Rsw' */ VFControl_B.uRsw_k = VFControl_cal->uRsw_Gain * VFControl_B.StateSpace_o1[0]; /* Switch: '/Switch' */ VFControl_B.Switch = VFControl_B.uRsw_k; } else { /* Switch: '/Switch' incorporates: * Constant: '/0 4' */ VFControl_B.Switch = VFControl_cal->u4_Value_l; } /* End of Switch: '/Switch' */ /* Saturate: '/Saturation' */ if (VFControl_B.Model_o1 > VFControl_cal->Saturation_UpperSat) { xk1 = VFControl_cal->Saturation_UpperSat; } else if (VFControl_B.Model_o1 < VFControl_cal->Saturation_LowerSat) { xk1 = VFControl_cal->Saturation_LowerSat; } else { xk1 = VFControl_B.Model_o1; } /* Saturate: '/Saturation' */ VFControl_B.Saturation[0] = xk1; /* Saturate: '/Saturation' */ if (VFControl_B.TransportDelay > VFControl_cal->Saturation_UpperSat) { xk1 = VFControl_cal->Saturation_UpperSat; } else if (VFControl_B.TransportDelay < VFControl_cal->Saturation_LowerSat) { xk1 = VFControl_cal->Saturation_LowerSat; } else { xk1 = VFControl_B.TransportDelay; } /* Saturate: '/Saturation' */ VFControl_B.Saturation[1] = xk1; /* Saturate: '/Saturation' */ if (VFControl_B.Model1_o1 > VFControl_cal->Saturation_UpperSat) { xk1 = VFControl_cal->Saturation_UpperSat; } else if (VFControl_B.Model1_o1 < VFControl_cal->Saturation_LowerSat) { xk1 = VFControl_cal->Saturation_LowerSat; } else { xk1 = VFControl_B.Model1_o1; } /* Saturate: '/Saturation' */ VFControl_B.Saturation[2] = xk1; /* Saturate: '/Saturation' */ if (VFControl_B.TransportDelay_i > VFControl_cal->Saturation_UpperSat) { xk1 = VFControl_cal->Saturation_UpperSat; } else if (VFControl_B.TransportDelay_i < VFControl_cal->Saturation_LowerSat) { xk1 = VFControl_cal->Saturation_LowerSat; } else { xk1 = VFControl_B.TransportDelay_i; } /* Saturate: '/Saturation' */ VFControl_B.Saturation[3] = xk1; /* Saturate: '/Saturation' */ if (VFControl_B.Model2_o1 > VFControl_cal->Saturation_UpperSat) { xk1 = VFControl_cal->Saturation_UpperSat; } else if (VFControl_B.Model2_o1 < VFControl_cal->Saturation_LowerSat) { xk1 = VFControl_cal->Saturation_LowerSat; } else { xk1 = VFControl_B.Model2_o1; } /* Saturate: '/Saturation' */ VFControl_B.Saturation[4] = xk1; /* Saturate: '/Saturation' */ if (VFControl_B.TransportDelay_n > VFControl_cal->Saturation_UpperSat) { xk1 = VFControl_cal->Saturation_UpperSat; } else if (VFControl_B.TransportDelay_n < VFControl_cal->Saturation_LowerSat) { xk1 = VFControl_cal->Saturation_LowerSat; } else { xk1 = VFControl_B.TransportDelay_n; } /* Saturate: '/Saturation' */ VFControl_B.Saturation[5] = xk1; /* RelationalOperator: '/Compare' incorporates: * Constant: '/Constant6' * Constant: '/Constant' */ VFControl_B.Compare = (VFControl_cal->Constant6_Value_e <= VFControl_cal->CompareToConstant_const); /* DataTypeConversion: '/Data Type Conversion1' */ VFControl_B.DataTypeConversion1 = VFControl_B.Compare; for (i = 0; i < 6; i++) { /* DataTypeConversion: '/Data Type Conversion' */ xk1 = VFControl_B.Saturation[i]; VFControl_B.DataTypeConversion_p[i] = xk1; /* Product: '/Product4' */ VFControl_B.Product4[i] = xk1 * VFControl_B.DataTypeConversion1; } /* DataTypeConversion: '/Data Type Conversion' */ VFControl_B.DataTypeConversion_f = VFControl_B.Product4[0]; /* Switch: '/Switch' */ if (VFControl_B.StateSpace_o2[1] >= VFControl_cal->Switch_Threshold_p) { /* Gain: '/1//Rsw' */ VFControl_B.uRsw_c = VFControl_cal->uRsw_Gain_e * VFControl_B.StateSpace_o1 [1]; /* Switch: '/Switch' */ VFControl_B.Switch_e = VFControl_B.uRsw_c; } else { /* Switch: '/Switch' incorporates: * Constant: '/0 4' */ VFControl_B.Switch_e = VFControl_cal->u4_Value_j; } /* End of Switch: '/Switch' */ /* DataTypeConversion: '/Data Type Conversion' */ VFControl_B.DataTypeConversion_l = VFControl_B.Product4[1]; /* Switch: '/Switch' */ if (VFControl_B.StateSpace_o2[2] >= VFControl_cal->Switch_Threshold_i) { /* Gain: '/1//Rsw' */ VFControl_B.uRsw_g = VFControl_cal->uRsw_Gain_l * VFControl_B.StateSpace_o1 [2]; /* Switch: '/Switch' */ VFControl_B.Switch_k = VFControl_B.uRsw_g; } else { /* Switch: '/Switch' incorporates: * Constant: '/0 4' */ VFControl_B.Switch_k = VFControl_cal->u4_Value_c; } /* End of Switch: '/Switch' */ /* DataTypeConversion: '/Data Type Conversion' */ VFControl_B.DataTypeConversion_h = VFControl_B.Product4[2]; /* Switch: '/Switch' */ if (VFControl_B.StateSpace_o2[3] >= VFControl_cal->Switch_Threshold_o) { /* Gain: '/1//Rsw' */ VFControl_B.uRsw_i = VFControl_cal->uRsw_Gain_k * VFControl_B.StateSpace_o1 [3]; /* Switch: '/Switch' */ VFControl_B.Switch_i = VFControl_B.uRsw_i; } else { /* Switch: '/Switch' incorporates: * Constant: '/0 4' */ VFControl_B.Switch_i = VFControl_cal->u4_Value_m; } /* End of Switch: '/Switch' */ /* DataTypeConversion: '/Data Type Conversion' */ VFControl_B.DataTypeConversion_k = VFControl_B.Product4[3]; /* Switch: '/Switch' */ if (VFControl_B.StateSpace_o2[4] >= VFControl_cal->Switch_Threshold_a) { /* Gain: '/1//Rsw' */ VFControl_B.uRsw_n = VFControl_cal->uRsw_Gain_m * VFControl_B.StateSpace_o1 [4]; /* Switch: '/Switch' */ VFControl_B.Switch_a = VFControl_B.uRsw_n; } else { /* Switch: '/Switch' incorporates: * Constant: '/0 4' */ VFControl_B.Switch_a = VFControl_cal->u4_Value_lk; } /* End of Switch: '/Switch' */ /* DataTypeConversion: '/Data Type Conversion' */ VFControl_B.DataTypeConversion_i = VFControl_B.Product4[4]; /* Switch: '/Switch' */ if (VFControl_B.StateSpace_o2[5] >= VFControl_cal->Switch_Threshold_n) { /* Gain: '/1//Rsw' */ VFControl_B.uRsw = VFControl_cal->uRsw_Gain_k4 * VFControl_B.StateSpace_o1[5]; /* Switch: '/Switch' */ VFControl_B.Switch_a4 = VFControl_B.uRsw; } else { /* Switch: '/Switch' incorporates: * Constant: '/0 4' */ VFControl_B.Switch_a4 = VFControl_cal->u4_Value_o; } /* End of Switch: '/Switch' */ /* DataTypeConversion: '/Data Type Conversion' */ VFControl_B.DataTypeConversion_c = VFControl_B.Product4[5]; /* Product: '/Product' incorporates: * Constant: '/Constant' */ VFControl_B.Product_n = VFControl_B.Model_o1 * VFControl_cal->Constant_Value_a; /* Product: '/Product' incorporates: * Constant: '/Constant' */ VFControl_B.Product_b = VFControl_B.Model1_o1 * VFControl_cal->Constant_Value_g; /* Product: '/Product' incorporates: * Constant: '/Constant' */ VFControl_B.Product_l = VFControl_B.Model2_o1 * VFControl_cal->Constant_Value_n5; /* RelationalOperator: '/Relational Operator2' incorporates: * Constant: '/Constant3' * Constant: '/valp_nom3' */ VFControl_B.Frequency = (VFControl_cal->valp_nom3_Value == VFControl_cal->Constant3_Value_n); /* Switch: '/Switch4' */ if (VFControl_B.Frequency) { /* Switch: '/Switch4' */ VFControl_B.Switch4 = VFControl_B.Switch3; } else { /* Switch: '/Switch4' incorporates: * Constant: '/Constant5' */ VFControl_B.Switch4 = VFControl_cal->Constant5_Value_ct; } /* End of Switch: '/Switch4' */ /* Gain: '/Gain2' */ VFControl_B.Gain2 = VFControl_cal->Gain2_Gain_h * VFControl_B.Switch4; /* Sum: '/Sum1' incorporates: * Constant: '/valp_nom1' */ VFControl_B.Sum1_o = VFControl_cal->valp_nom1_Value_g + VFControl_B.Switch4; /* Gain: '/Gain3' */ VFControl_B.Gain3_m[0] = VFControl_cal->Gain3_Gain_i * VFControl_B.Switch5_b[0]; VFControl_B.Gain3_m[1] = VFControl_cal->Gain3_Gain_i * VFControl_B.Switch5_b[1]; VFControl_B.Gain3_m[2] = VFControl_cal->Gain3_Gain_i * VFControl_B.Switch5_b[2]; /* Math: '/Math Function' incorporates: * Constant: '/Constant7' */ VFControl_B.wtrad = rt_modd_snf(VFControl_B.Sum7[0], VFControl_cal->Constant7_Value); /* Switch: '/Switch' */ if (VFControl_B.Ton >= VFControl_cal->Switch_Threshold_d) { /* RelationalOperator: '/Relational Operator' incorporates: * Constant: '/valp_nom5' * Constant: '/Constant' */ VFControl_B.RelationalOperator = (VFControl_cal->valp_nom5_Value == VFControl_cal->Constant_Value_p); /* Switch: '/Switch1' */ if (VFControl_B.RelationalOperator) { /* Switch: '/Switch1' incorporates: * Constant: '/valp_nom7' */ VFControl_B.Switch1_j = VFControl_cal->Variationvaluesteprampmod_Var_p; } else { /* Switch: '/Switch1' incorporates: * Constant: '/Constant2' */ VFControl_B.Switch1_j = VFControl_cal->Constant2_Value_i; } /* End of Switch: '/Switch1' */ /* Switch: '/Switch' */ VFControl_B.Switch_c = VFControl_B.Switch1_j; } else { /* Switch: '/Switch' incorporates: * Constant: '/Constant4' */ VFControl_B.Switch_c = VFControl_cal->Constant4_Value_f; } /* End of Switch: '/Switch' */ /* Gain: '/do not delete this gain' */ VFControl_B.donotdeletethisgain = VFControl_cal->donotdeletethisgain_Gain * VFControl_B.StateSpace_o1[8]; /* Gain: '/do not delete this gain' */ VFControl_B.donotdeletethisgain_k = VFControl_cal->donotdeletethisgain_Gain_d * VFControl_B.StateSpace_o1[9]; /* Gain: '/do not delete this gain' */ VFControl_B.donotdeletethisgain_o = VFControl_cal->donotdeletethisgain_Gain_h * VFControl_B.StateSpace_o1[10]; /* Gain: '/Kv1' */ VFControl_B.Kv1[0] = VFControl_cal->Kv1_Gain * VFControl_B.donotdeletethisgain; VFControl_B.Kv1[1] = VFControl_cal->Kv1_Gain * VFControl_B.donotdeletethisgain_k; VFControl_B.Kv1[2] = VFControl_cal->Kv1_Gain * VFControl_B.donotdeletethisgain_o; /* Gain: '/do not delete this gain' */ VFControl_B.donotdeletethisgain_kv = VFControl_cal->donotdeletethisgain_Gain_j * VFControl_B.StateSpace_o1[11]; /* Gain: '/do not delete this gain' */ VFControl_B.donotdeletethisgain_b = VFControl_cal->donotdeletethisgain_Gain_n * VFControl_B.StateSpace_o1[12]; /* Gain: '/do not delete this gain' */ VFControl_B.donotdeletethisgain_h = VFControl_cal->donotdeletethisgain_Gain_p * VFControl_B.StateSpace_o1[13]; /* Gain: '/Kv' */ VFControl_B.Kv[0] = VFControl_cal->Kv_Gain * VFControl_B.donotdeletethisgain_kv; VFControl_B.Kv[1] = VFControl_cal->Kv_Gain * VFControl_B.donotdeletethisgain_b; VFControl_B.Kv[2] = VFControl_cal->Kv_Gain * VFControl_B.donotdeletethisgain_h; /* user code (Output function Trailer for TID0) */ { if (0) { io3xx_sgdma_feedSequential(1); } } /* Update for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE[0] = VFControl_B.IC[0]; /* Update for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE_l[0] = VFControl_B.xk1[0]; /* Update for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE[1] = VFControl_B.IC[1]; /* Update for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE_l[1] = VFControl_B.xk1[1]; /* Update for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE[2] = VFControl_B.IC[2]; /* Update for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE_l[2] = VFControl_B.xk1[2]; /* Update for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE[3] = VFControl_B.IC[3]; /* Update for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE_l[3] = VFControl_B.xk1[3]; /* Update for DiscreteIntegrator: '/Rotor angle thetam' */ VFControl_DW.Rotoranglethetam_DSTATE += VFControl_cal->Rotoranglethetam_gainval * VFControl_B.web_psb; /* Update for UnitDelay: '/wm_delay' */ VFControl_DW.wm_delay_DSTATE = VFControl_B.Rotorspeedwm; /* Update for UnitDelay: '/wm_predict' */ VFControl_DW.wm_predict_DSTATE = VFControl_B.wm_delay; /* Update for S-Function (sfun_spssw_discc): '/State-Space' incorporates: * Constant: '/DC' * Constant: '/SwitchCurrents' */ { int_T *gState = (int_T*)VFControl_DW.StateSpace_PWORK.G_STATE; /* Store switch gates values for next step */ *(gState++) = (int_T) VFControl_B.DataTypeConversion_f; *(gState++) = (int_T) VFControl_B.DataTypeConversion_l; *(gState++) = (int_T) VFControl_B.DataTypeConversion_h; *(gState++) = (int_T) VFControl_B.DataTypeConversion_k; *(gState++) = (int_T) VFControl_B.DataTypeConversion_i; *(gState++) = (int_T) VFControl_B.DataTypeConversion_c; } /* Update for UnitDelay: '/voltages' */ VFControl_DW.voltages_DSTATE[0] = VFControl_B.MultiportSwitch1_f[0]; VFControl_DW.voltages_DSTATE[2] = VFControl_B.MultiportSwitch_p2[0]; VFControl_DW.voltages_DSTATE[1] = VFControl_B.MultiportSwitch1_f[1]; VFControl_DW.voltages_DSTATE[3] = VFControl_B.MultiportSwitch_p2[1]; /* Update for DiscreteIntegrator: '/Rotor speed(wm)' */ VFControl_DW.Rotorspeedwm_SYSTEM_ENABLE = 0U; VFControl_DW.Rotorspeedwm_DSTATE = VFControl_cal->Rotorspeedwm_gainval * VFControl_B.u_2H + VFControl_B.Rotorspeedwm; /* Update for DiscreteIntegrator: '/Discrete-Time Integrator1' */ VFControl_DW.DiscreteTimeIntegrator1_DSTATE += VFControl_cal->DiscreteTimeIntegrator1_gainval * VFControl_B.Switch_c; /* Update for UnitDelay: '/Unit Delay1' */ VFControl_DW.UnitDelay1_DSTATE = VFControl_B.Switch2_d; /* Update for DiscreteIntegrator: '/Discrete-Time Integrator' */ VFControl_DW.DiscreteTimeIntegrator_DSTATE += VFControl_cal->DiscreteTimeIntegrator_gainval * VFControl_B.Gain2; /* Update for TransportDelay: '/Transport Delay' */ { real_T **uBuffer = (real_T**) &VFControl_DW.TransportDelay_PWORK.TUbufferPtrs[0]; real_T simTime = VFControl_M->Timing.t[0]; VFControl_DW.TransportDelay_IWORK.Head = ((VFControl_DW.TransportDelay_IWORK.Head < (VFControl_DW.TransportDelay_IWORK.CircularBufSize-1)) ? (VFControl_DW.TransportDelay_IWORK.Head+1) : 0); if (VFControl_DW.TransportDelay_IWORK.Head == VFControl_DW.TransportDelay_IWORK.Tail) { VFControl_DW.TransportDelay_IWORK.Tail = ((VFControl_DW.TransportDelay_IWORK.Tail < (VFControl_DW.TransportDelay_IWORK.CircularBufSize-1)) ? (VFControl_DW.TransportDelay_IWORK.Tail+1) : 0); } (*uBuffer + VFControl_DW.TransportDelay_IWORK.CircularBufSize) [VFControl_DW.TransportDelay_IWORK.Head] = simTime; (*uBuffer)[VFControl_DW.TransportDelay_IWORK.Head] = VFControl_B.Product_n; } /* Update for TransportDelay: '/Transport Delay' */ { real_T **uBuffer = (real_T**) &VFControl_DW.TransportDelay_PWORK_m.TUbufferPtrs[0]; real_T simTime = VFControl_M->Timing.t[0]; VFControl_DW.TransportDelay_IWORK_g.Head = ((VFControl_DW.TransportDelay_IWORK_g.Head < (VFControl_DW.TransportDelay_IWORK_g.CircularBufSize-1)) ? (VFControl_DW.TransportDelay_IWORK_g.Head+1) : 0); if (VFControl_DW.TransportDelay_IWORK_g.Head == VFControl_DW.TransportDelay_IWORK_g.Tail) { VFControl_DW.TransportDelay_IWORK_g.Tail = ((VFControl_DW.TransportDelay_IWORK_g.Tail < (VFControl_DW.TransportDelay_IWORK_g.CircularBufSize-1)) ? (VFControl_DW.TransportDelay_IWORK_g.Tail+1) : 0); } (*uBuffer + VFControl_DW.TransportDelay_IWORK_g.CircularBufSize) [VFControl_DW.TransportDelay_IWORK_g.Head] = simTime; (*uBuffer)[VFControl_DW.TransportDelay_IWORK_g.Head] = VFControl_B.Product_b; } /* Update for TransportDelay: '/Transport Delay' */ { real_T **uBuffer = (real_T**) &VFControl_DW.TransportDelay_PWORK_f.TUbufferPtrs[0]; real_T simTime = VFControl_M->Timing.t[0]; VFControl_DW.TransportDelay_IWORK_m.Head = ((VFControl_DW.TransportDelay_IWORK_m.Head < (VFControl_DW.TransportDelay_IWORK_m.CircularBufSize-1)) ? (VFControl_DW.TransportDelay_IWORK_m.Head+1) : 0); if (VFControl_DW.TransportDelay_IWORK_m.Head == VFControl_DW.TransportDelay_IWORK_m.Tail) { VFControl_DW.TransportDelay_IWORK_m.Tail = ((VFControl_DW.TransportDelay_IWORK_m.Tail < (VFControl_DW.TransportDelay_IWORK_m.CircularBufSize-1)) ? (VFControl_DW.TransportDelay_IWORK_m.Tail+1) : 0); } (*uBuffer + VFControl_DW.TransportDelay_IWORK_m.CircularBufSize) [VFControl_DW.TransportDelay_IWORK_m.Head] = simTime; (*uBuffer)[VFControl_DW.TransportDelay_IWORK_m.Head] = VFControl_B.Product_l; } /* Update absolute time */ /* The "clockTick0" counts the number of times the code of this task has * been executed. The absolute time is the multiplication of "clockTick0" * and "Timing.stepSize0". Size of "clockTick0" ensures timer will not * overflow during the application lifespan selected. * Timer of this task consists of two 32 bit unsigned integers. * The two integers represent the low bits Timing.clockTick0 and the high bits * Timing.clockTickH0. When the low bit overflows to 0, the high bits increment. */ if (!(++VFControl_M->Timing.clockTick0)) { ++VFControl_M->Timing.clockTickH0; } VFControl_M->Timing.t[0] = VFControl_M->Timing.clockTick0 * VFControl_M->Timing.stepSize0 + VFControl_M->Timing.clockTickH0 * VFControl_M->Timing.stepSize0 * 4294967296.0; /* Update absolute time */ /* The "clockTick1" counts the number of times the code of this task has * been executed. The absolute time is the multiplication of "clockTick1" * and "Timing.stepSize1". Size of "clockTick1" ensures timer will not * overflow during the application lifespan selected. * Timer of this task consists of two 32 bit unsigned integers. * The two integers represent the low bits Timing.clockTick1 and the high bits * Timing.clockTickH1. When the low bit overflows to 0, the high bits increment. */ if (!(++VFControl_M->Timing.clockTick1)) { ++VFControl_M->Timing.clockTickH1; } VFControl_M->Timing.t[1] = VFControl_M->Timing.clockTick1 * VFControl_M->Timing.stepSize1 + VFControl_M->Timing.clockTickH1 * VFControl_M->Timing.stepSize1 * 4294967296.0; } /* Model step function for TID2 */ void VFControl_step2(void) /* Sample time: [0.0005s, 0.0s] */ { /* UnitDelay: '/Unit Delay' */ VFControl_B.UnitDelay = VFControl_DW.UnitDelay_DSTATE; /* Update for UnitDelay: '/Unit Delay' */ VFControl_DW.UnitDelay_DSTATE = VFControl_B.UnitDelay; /* Update absolute time */ /* The "clockTick2" counts the number of times the code of this task has * been executed. The resolution of this integer timer is 0.0005, which is the step size * of the task. Size of "clockTick2" ensures timer will not overflow during the * application lifespan selected. * Timer of this task consists of two 32 bit unsigned integers. * The two integers represent the low bits Timing.clockTick2 and the high bits * Timing.clockTickH2. When the low bit overflows to 0, the high bits increment. */ VFControl_M->Timing.clockTick2++; if (!VFControl_M->Timing.clockTick2) { VFControl_M->Timing.clockTickH2++; } } /* Model initialize function */ void VFControl_initialize(void) { /* Registration code */ /* initialize non-finites */ rt_InitInfAndNaN(sizeof(real_T)); /* Set task counter limit used by the static main program */ (VFControl_M)->Timing.TaskCounters.cLimit[0] = 1; (VFControl_M)->Timing.TaskCounters.cLimit[1] = 1; (VFControl_M)->Timing.TaskCounters.cLimit[2] = 5; { /* Setup solver object */ rtsiSetSimTimeStepPtr(&VFControl_M->solverInfo, &VFControl_M->Timing.simTimeStep); rtsiSetTPtr(&VFControl_M->solverInfo, &rtmGetTPtr(VFControl_M)); rtsiSetStepSizePtr(&VFControl_M->solverInfo, &VFControl_M->Timing.stepSize0); rtsiSetErrorStatusPtr(&VFControl_M->solverInfo, (&rtmGetErrorStatus (VFControl_M))); rtsiSetRTModelPtr(&VFControl_M->solverInfo, VFControl_M); } rtsiSetSimTimeStep(&VFControl_M->solverInfo, MAJOR_TIME_STEP); rtsiSetIsMinorTimeStepWithModeChange(&VFControl_M->solverInfo, false); rtsiSetIsContModeFrozen(&VFControl_M->solverInfo, false); rtsiSetSolverName(&VFControl_M->solverInfo,"FixedStepDiscrete"); VFControl_M->solverInfoPtr = (&VFControl_M->solverInfo); /* Initialize timing info */ { int_T *mdlTsMap = VFControl_M->Timing.sampleTimeTaskIDArray; mdlTsMap[0] = 0; mdlTsMap[1] = 1; mdlTsMap[2] = 2; /* polyspace +2 MISRA2012:D4.1 [Justified:Low] "VFControl_M points to static memory which is guaranteed to be non-NULL" */ VFControl_M->Timing.sampleTimeTaskIDPtr = (&mdlTsMap[0]); VFControl_M->Timing.sampleTimes = (&VFControl_M->Timing.sampleTimesArray[0]); VFControl_M->Timing.offsetTimes = (&VFControl_M->Timing.offsetTimesArray[0]); /* task periods */ VFControl_M->Timing.sampleTimes[0] = (0.0); VFControl_M->Timing.sampleTimes[1] = (0.0001); VFControl_M->Timing.sampleTimes[2] = (0.0005); /* task offsets */ VFControl_M->Timing.offsetTimes[0] = (0.0); VFControl_M->Timing.offsetTimes[1] = (0.0); VFControl_M->Timing.offsetTimes[2] = (0.0); } rtmSetTPtr(VFControl_M, &VFControl_M->Timing.tArray[0]); { int_T *mdlSampleHits = VFControl_M->Timing.sampleHitArray; int_T *mdlPerTaskSampleHits = VFControl_M->Timing.perTaskSampleHitsArray; VFControl_M->Timing.perTaskSampleHits = (&mdlPerTaskSampleHits[0]); mdlSampleHits[0] = 1; VFControl_M->Timing.sampleHits = (&mdlSampleHits[0]); } rtmSetTFinal(VFControl_M, -1); VFControl_M->Timing.stepSize0 = 0.0001; VFControl_M->Timing.stepSize1 = 0.0001; VFControl_M->solverInfoPtr = (&VFControl_M->solverInfo); VFControl_M->Timing.stepSize = (0.0001); rtsiSetFixedStepSize(&VFControl_M->solverInfo, 0.0001); rtsiSetSolverMode(&VFControl_M->solverInfo, SOLVER_MODE_MULTITASKING); /* block I/O */ (void) std::memset((static_cast(&VFControl_B)), 0, sizeof(B_VFControl_T)); /* states (dwork) */ (void) std::memset(static_cast(&VFControl_DW), 0, sizeof(DW_VFControl_T)); /* child S-Function registration */ { RTWSfcnInfo *sfcnInfo = &VFControl_M->NonInlinedSFcns.sfcnInfo; VFControl_M->sfcnInfo = (sfcnInfo); rtssSetErrorStatusPtr(sfcnInfo, (&rtmGetErrorStatus(VFControl_M))); VFControl_M->Sizes.numSampTimes = (3); rtssSetNumRootSampTimesPtr(sfcnInfo, &VFControl_M->Sizes.numSampTimes); VFControl_M->NonInlinedSFcns.taskTimePtrs[0] = (&rtmGetTPtr(VFControl_M)[0]); VFControl_M->NonInlinedSFcns.taskTimePtrs[1] = (&rtmGetTPtr(VFControl_M)[1]); VFControl_M->NonInlinedSFcns.taskTimePtrs[2] = (&rtmGetTPtr(VFControl_M)[2]); rtssSetTPtrPtr(sfcnInfo,VFControl_M->NonInlinedSFcns.taskTimePtrs); rtssSetTStartPtr(sfcnInfo, &rtmGetTStart(VFControl_M)); rtssSetTFinalPtr(sfcnInfo, &rtmGetTFinal(VFControl_M)); rtssSetTimeOfLastOutputPtr(sfcnInfo, &rtmGetTimeOfLastOutput(VFControl_M)); rtssSetStepSizePtr(sfcnInfo, &VFControl_M->Timing.stepSize); rtssSetStopRequestedPtr(sfcnInfo, &rtmGetStopRequested(VFControl_M)); rtssSetDerivCacheNeedsResetPtr(sfcnInfo, &VFControl_M->derivCacheNeedsReset); rtssSetZCCacheNeedsResetPtr(sfcnInfo, &VFControl_M->zCCacheNeedsReset); rtssSetContTimeOutputInconsistentWithStateAtMajorStepPtr(sfcnInfo, &VFControl_M->CTOutputIncnstWithState); rtssSetSampleHitsPtr(sfcnInfo, &VFControl_M->Timing.sampleHits); rtssSetPerTaskSampleHitsPtr(sfcnInfo, &VFControl_M->Timing.perTaskSampleHits); rtssSetSimModePtr(sfcnInfo, &VFControl_M->simMode); rtssSetSolverInfoPtr(sfcnInfo, &VFControl_M->solverInfoPtr); } VFControl_M->Sizes.numSFcns = (2); /* register each child */ { (void) std::memset(static_cast (&VFControl_M->NonInlinedSFcns.childSFunctions[0]), 0, 2*sizeof(SimStruct)); VFControl_M->childSfunctions = (&VFControl_M->NonInlinedSFcns.childSFunctionPtrs[0]); VFControl_M->childSfunctions[0] = (&VFControl_M->NonInlinedSFcns.childSFunctions[0]); VFControl_M->childSfunctions[1] = (&VFControl_M->NonInlinedSFcns.childSFunctions[1]); /* Level2 S-Function Block: VFControl//Digital output1 (sg_fpga_do_sf_a2) */ { SimStruct *rts = VFControl_M->childSfunctions[0]; /* timing info */ time_T *sfcnPeriod = VFControl_M->NonInlinedSFcns.Sfcn0.sfcnPeriod; time_T *sfcnOffset = VFControl_M->NonInlinedSFcns.Sfcn0.sfcnOffset; int_T *sfcnTsMap = VFControl_M->NonInlinedSFcns.Sfcn0.sfcnTsMap; (void) std::memset(static_cast(sfcnPeriod), 0, sizeof(time_T)*1); (void) std::memset(static_cast(sfcnOffset), 0, sizeof(time_T)*1); ssSetSampleTimePtr(rts, &sfcnPeriod[0]); ssSetOffsetTimePtr(rts, &sfcnOffset[0]); ssSetSampleTimeTaskIDPtr(rts, sfcnTsMap); { ssSetBlkInfo2Ptr(rts, &VFControl_M->NonInlinedSFcns.blkInfo2[0]); } _ssSetBlkInfo2PortInfo2Ptr(rts, &VFControl_M->NonInlinedSFcns.inputOutputPortInfo2[0]); /* Set up the mdlInfo pointer */ ssSetRTWSfcnInfo(rts, VFControl_M->sfcnInfo); /* Allocate memory of model methods 2 */ { ssSetModelMethods2(rts, &VFControl_M->NonInlinedSFcns.methods2[0]); } /* Allocate memory of model methods 3 */ { ssSetModelMethods3(rts, &VFControl_M->NonInlinedSFcns.methods3[0]); } /* Allocate memory of model methods 4 */ { ssSetModelMethods4(rts, &VFControl_M->NonInlinedSFcns.methods4[0]); } /* Allocate memory for states auxilliary information */ { ssSetStatesInfo2(rts, &VFControl_M->NonInlinedSFcns.statesInfo2[0]); ssSetPeriodicStatesInfo(rts, &VFControl_M->NonInlinedSFcns.periodicStatesInfo[0]); } /* inputs */ { _ssSetNumInputPorts(rts, 3); ssSetPortInfoForInputs(rts, &VFControl_M->NonInlinedSFcns.Sfcn0.inputPortInfo[0]); ssSetPortInfoForInputs(rts, &VFControl_M->NonInlinedSFcns.Sfcn0.inputPortInfo[0]); _ssSetPortInfo2ForInputUnits(rts, &VFControl_M->NonInlinedSFcns.Sfcn0.inputPortUnits[0]); ssSetInputPortUnit(rts, 0, 0); ssSetInputPortUnit(rts, 1, 0); ssSetInputPortUnit(rts, 2, 0); _ssSetPortInfo2ForInputCoSimAttribute(rts, &VFControl_M->NonInlinedSFcns.Sfcn0.inputPortCoSimAttribute[0]); ssSetInputPortIsContinuousQuantity(rts, 0, 0); ssSetInputPortIsContinuousQuantity(rts, 1, 0); ssSetInputPortIsContinuousQuantity(rts, 2, 0); /* port 0 */ { ssSetInputPortRequiredContiguous(rts, 0, 1); ssSetInputPortSignal(rts, 0, &VFControl_B.TransportDelay); _ssSetInputPortNumDimensions(rts, 0, 1); ssSetInputPortWidthAsInt(rts, 0, 1); } /* port 1 */ { ssSetInputPortRequiredContiguous(rts, 1, 1); ssSetInputPortSignal(rts, 1, &VFControl_B.TransportDelay_i); _ssSetInputPortNumDimensions(rts, 1, 1); ssSetInputPortWidthAsInt(rts, 1, 1); } /* port 2 */ { ssSetInputPortRequiredContiguous(rts, 2, 1); ssSetInputPortSignal(rts, 2, &VFControl_B.TransportDelay_n); _ssSetInputPortNumDimensions(rts, 2, 1); ssSetInputPortWidthAsInt(rts, 2, 1); } } /* path info */ ssSetModelName(rts, "Digital output1"); ssSetPath(rts, "VFControl/Digital output1"); ssSetRTModel(rts,VFControl_M); ssSetParentSS(rts, (NULL)); ssSetRootSS(rts, rts); ssSetVersion(rts, SIMSTRUCT_VERSION_LEVEL2); /* parameters */ { mxArray **sfcnParams = (mxArray **) &VFControl_M->NonInlinedSFcns.Sfcn0.params; ssSetSFcnParamsCount(rts, 6); ssSetSFcnParamsPtr(rts, &sfcnParams[0]); ssSetSFcnParam(rts, 0, (mxArray*)VFControl_cal->Digitaloutput1_P1_Size); ssSetSFcnParam(rts, 1, (mxArray*)VFControl_cal->Digitaloutput1_P2_Size); ssSetSFcnParam(rts, 2, (mxArray*)VFControl_cal->Digitaloutput1_P3_Size); ssSetSFcnParam(rts, 3, (mxArray*)VFControl_cal->Digitaloutput1_P4_Size); ssSetSFcnParam(rts, 4, (mxArray*)VFControl_cal->Digitaloutput1_P5_Size); ssSetSFcnParam(rts, 5, (mxArray*)VFControl_cal->Digitaloutput1_P6_Size); } /* work vectors */ ssSetPWork(rts, (void **) &VFControl_DW.Digitaloutput1_PWORK[0]); { struct _ssDWorkRecord *dWorkRecord = (struct _ssDWorkRecord *) &VFControl_M->NonInlinedSFcns.Sfcn0.dWork; struct _ssDWorkAuxRecord *dWorkAuxRecord = (struct _ssDWorkAuxRecord *) &VFControl_M->NonInlinedSFcns.Sfcn0.dWorkAux; ssSetSFcnDWork(rts, dWorkRecord); ssSetSFcnDWorkAux(rts, dWorkAuxRecord); ssSetNumDWorkAsInt(rts, 1); /* PWORK */ ssSetDWorkWidthAsInt(rts, 0, 2); ssSetDWorkDataType(rts, 0,SS_POINTER); ssSetDWorkComplexSignal(rts, 0, 0); ssSetDWork(rts, 0, &VFControl_DW.Digitaloutput1_PWORK[0]); } /* registration */ sg_fpga_do_sf_a2(rts); sfcnInitializeSizes(rts); sfcnInitializeSampleTimes(rts); /* adjust sample time */ ssSetSampleTime(rts, 0, 0.0001); ssSetOffsetTime(rts, 0, 0.0); sfcnTsMap[0] = 1; /* set compiled values of dynamic vector attributes */ ssSetNumNonsampledZCsAsInt(rts, 0); /* Update connectivity flags for each port */ _ssSetInputPortConnected(rts, 0, 1); _ssSetInputPortConnected(rts, 1, 1); _ssSetInputPortConnected(rts, 2, 1); /* Update the BufferDstPort flags for each input port */ ssSetInputPortBufferDstPort(rts, 0, -1); ssSetInputPortBufferDstPort(rts, 1, -1); ssSetInputPortBufferDstPort(rts, 2, -1); } /* Level2 S-Function Block: VFControl//Digital output2 (sg_fpga_do_sf_a2) */ { SimStruct *rts = VFControl_M->childSfunctions[1]; /* timing info */ time_T *sfcnPeriod = VFControl_M->NonInlinedSFcns.Sfcn1.sfcnPeriod; time_T *sfcnOffset = VFControl_M->NonInlinedSFcns.Sfcn1.sfcnOffset; int_T *sfcnTsMap = VFControl_M->NonInlinedSFcns.Sfcn1.sfcnTsMap; (void) std::memset(static_cast(sfcnPeriod), 0, sizeof(time_T)*1); (void) std::memset(static_cast(sfcnOffset), 0, sizeof(time_T)*1); ssSetSampleTimePtr(rts, &sfcnPeriod[0]); ssSetOffsetTimePtr(rts, &sfcnOffset[0]); ssSetSampleTimeTaskIDPtr(rts, sfcnTsMap); { ssSetBlkInfo2Ptr(rts, &VFControl_M->NonInlinedSFcns.blkInfo2[1]); } _ssSetBlkInfo2PortInfo2Ptr(rts, &VFControl_M->NonInlinedSFcns.inputOutputPortInfo2[1]); /* Set up the mdlInfo pointer */ ssSetRTWSfcnInfo(rts, VFControl_M->sfcnInfo); /* Allocate memory of model methods 2 */ { ssSetModelMethods2(rts, &VFControl_M->NonInlinedSFcns.methods2[1]); } /* Allocate memory of model methods 3 */ { ssSetModelMethods3(rts, &VFControl_M->NonInlinedSFcns.methods3[1]); } /* Allocate memory of model methods 4 */ { ssSetModelMethods4(rts, &VFControl_M->NonInlinedSFcns.methods4[1]); } /* Allocate memory for states auxilliary information */ { ssSetStatesInfo2(rts, &VFControl_M->NonInlinedSFcns.statesInfo2[1]); ssSetPeriodicStatesInfo(rts, &VFControl_M->NonInlinedSFcns.periodicStatesInfo[1]); } /* inputs */ { _ssSetNumInputPorts(rts, 3); ssSetPortInfoForInputs(rts, &VFControl_M->NonInlinedSFcns.Sfcn1.inputPortInfo[0]); ssSetPortInfoForInputs(rts, &VFControl_M->NonInlinedSFcns.Sfcn1.inputPortInfo[0]); _ssSetPortInfo2ForInputUnits(rts, &VFControl_M->NonInlinedSFcns.Sfcn1.inputPortUnits[0]); ssSetInputPortUnit(rts, 0, 0); ssSetInputPortUnit(rts, 1, 0); ssSetInputPortUnit(rts, 2, 0); _ssSetPortInfo2ForInputCoSimAttribute(rts, &VFControl_M->NonInlinedSFcns.Sfcn1.inputPortCoSimAttribute[0]); ssSetInputPortIsContinuousQuantity(rts, 0, 0); ssSetInputPortIsContinuousQuantity(rts, 1, 0); ssSetInputPortIsContinuousQuantity(rts, 2, 0); /* port 0 */ { ssSetInputPortRequiredContiguous(rts, 0, 1); ssSetInputPortSignal(rts, 0, &VFControl_B.Model_o1); _ssSetInputPortNumDimensions(rts, 0, 1); ssSetInputPortWidthAsInt(rts, 0, 1); } /* port 1 */ { ssSetInputPortRequiredContiguous(rts, 1, 1); ssSetInputPortSignal(rts, 1, &VFControl_B.Model1_o1); _ssSetInputPortNumDimensions(rts, 1, 1); ssSetInputPortWidthAsInt(rts, 1, 1); } /* port 2 */ { ssSetInputPortRequiredContiguous(rts, 2, 1); ssSetInputPortSignal(rts, 2, &VFControl_B.Model2_o1); _ssSetInputPortNumDimensions(rts, 2, 1); ssSetInputPortWidthAsInt(rts, 2, 1); } } /* path info */ ssSetModelName(rts, "Digital output2"); ssSetPath(rts, "VFControl/Digital output2"); ssSetRTModel(rts,VFControl_M); ssSetParentSS(rts, (NULL)); ssSetRootSS(rts, rts); ssSetVersion(rts, SIMSTRUCT_VERSION_LEVEL2); /* parameters */ { mxArray **sfcnParams = (mxArray **) &VFControl_M->NonInlinedSFcns.Sfcn1.params; ssSetSFcnParamsCount(rts, 6); ssSetSFcnParamsPtr(rts, &sfcnParams[0]); ssSetSFcnParam(rts, 0, (mxArray*)VFControl_cal->Digitaloutput2_P1_Size); ssSetSFcnParam(rts, 1, (mxArray*)VFControl_cal->Digitaloutput2_P2_Size); ssSetSFcnParam(rts, 2, (mxArray*)VFControl_cal->Digitaloutput2_P3_Size); ssSetSFcnParam(rts, 3, (mxArray*)VFControl_cal->Digitaloutput2_P4_Size); ssSetSFcnParam(rts, 4, (mxArray*)VFControl_cal->Digitaloutput2_P5_Size); ssSetSFcnParam(rts, 5, (mxArray*)VFControl_cal->Digitaloutput2_P6_Size); } /* work vectors */ ssSetPWork(rts, (void **) &VFControl_DW.Digitaloutput2_PWORK[0]); { struct _ssDWorkRecord *dWorkRecord = (struct _ssDWorkRecord *) &VFControl_M->NonInlinedSFcns.Sfcn1.dWork; struct _ssDWorkAuxRecord *dWorkAuxRecord = (struct _ssDWorkAuxRecord *) &VFControl_M->NonInlinedSFcns.Sfcn1.dWorkAux; ssSetSFcnDWork(rts, dWorkRecord); ssSetSFcnDWorkAux(rts, dWorkAuxRecord); ssSetNumDWorkAsInt(rts, 1); /* PWORK */ ssSetDWorkWidthAsInt(rts, 0, 2); ssSetDWorkDataType(rts, 0,SS_POINTER); ssSetDWorkComplexSignal(rts, 0, 0); ssSetDWork(rts, 0, &VFControl_DW.Digitaloutput2_PWORK[0]); } /* registration */ sg_fpga_do_sf_a2(rts); sfcnInitializeSizes(rts); sfcnInitializeSampleTimes(rts); /* adjust sample time */ ssSetSampleTime(rts, 0, 0.0001); ssSetOffsetTime(rts, 0, 0.0); sfcnTsMap[0] = 1; /* set compiled values of dynamic vector attributes */ ssSetNumNonsampledZCsAsInt(rts, 0); /* Update connectivity flags for each port */ _ssSetInputPortConnected(rts, 0, 1); _ssSetInputPortConnected(rts, 1, 1); _ssSetInputPortConnected(rts, 2, 1); /* Update the BufferDstPort flags for each input port */ ssSetInputPortBufferDstPort(rts, 0, -1); ssSetInputPortBufferDstPort(rts, 1, -1); ssSetInputPortBufferDstPort(rts, 2, -1); } } /* Model Initialize function for ModelReference Block: '/Model' */ PWMGenerator_initialize(rtmGetErrorStatusPointer(VFControl_M), &(VFControl_DW.Model_InstanceData.rtm), &(VFControl_DW.Model_InstanceData.rtb)); /* Model Initialize function for ModelReference Block: '/Model1' */ PWMGenerator_initialize(rtmGetErrorStatusPointer(VFControl_M), &(VFControl_DW.Model1_InstanceData.rtm), &(VFControl_DW.Model1_InstanceData.rtb)); /* Model Initialize function for ModelReference Block: '/Model2' */ PWMGenerator_initialize(rtmGetErrorStatusPointer(VFControl_M), &(VFControl_DW.Model2_InstanceData.rtm), &(VFControl_DW.Model2_InstanceData.rtb)); /* Start for S-Function (sfun_spssw_discc): '/State-Space' incorporates: * Constant: '/DC' * Constant: '/SwitchCurrents' */ /* S-Function block: /State-Space */ { VFControl_DW.StateSpace_PWORK.DS = (real_T*)calloc(14 * 9, sizeof(real_T)); VFControl_DW.StateSpace_PWORK.DX_COL = (real_T*)calloc(14, sizeof(real_T)); VFControl_DW.StateSpace_PWORK.TMP2 = (real_T*)calloc(9, sizeof(real_T)); VFControl_DW.StateSpace_PWORK.SWITCH_STATUS = (int_T*)calloc(6, sizeof(int_T)); VFControl_DW.StateSpace_PWORK.SW_CHG = (int_T*)calloc(6, sizeof(int_T)); VFControl_DW.StateSpace_PWORK.G_STATE = (int_T*)calloc(6, sizeof(int_T)); VFControl_DW.StateSpace_PWORK.Y_SWITCH = (real_T*)calloc(6, sizeof(real_T)); VFControl_DW.StateSpace_PWORK.SWITCH_TYPES = (int_T*)calloc(6, sizeof(int_T)); VFControl_DW.StateSpace_PWORK.IDX_OUT_SW = (int_T*)calloc(6, sizeof(int_T)); VFControl_DW.StateSpace_PWORK.SWITCH_STATUS_INIT = (int_T*)calloc(6, sizeof (int_T)); VFControl_DW.StateSpace_PWORK.USWLAST = (real_T*)calloc(6, sizeof(real_T)); } /* Start for TransportDelay: '/Transport Delay' */ { real_T *pBuffer = &VFControl_DW.TransportDelay_RWORK.TUbufferArea[0]; VFControl_DW.TransportDelay_IWORK.Tail = 0; VFControl_DW.TransportDelay_IWORK.Head = 0; VFControl_DW.TransportDelay_IWORK.Last = 0; VFControl_DW.TransportDelay_IWORK.CircularBufSize = 1024; pBuffer[0] = (VFControl_cal->TransportDelay_InitOutput); pBuffer[1024] = VFControl_M->Timing.t[0]; VFControl_DW.TransportDelay_PWORK.TUbufferPtrs[0] = (void *) &pBuffer[0]; } /* Start for TransportDelay: '/Transport Delay' */ { real_T *pBuffer = &VFControl_DW.TransportDelay_RWORK_d.TUbufferArea[0]; VFControl_DW.TransportDelay_IWORK_g.Tail = 0; VFControl_DW.TransportDelay_IWORK_g.Head = 0; VFControl_DW.TransportDelay_IWORK_g.Last = 0; VFControl_DW.TransportDelay_IWORK_g.CircularBufSize = 1024; pBuffer[0] = (VFControl_cal->TransportDelay_InitOutput_l); pBuffer[1024] = VFControl_M->Timing.t[0]; VFControl_DW.TransportDelay_PWORK_m.TUbufferPtrs[0] = (void *) &pBuffer[0]; } /* Start for TransportDelay: '/Transport Delay' */ { real_T *pBuffer = &VFControl_DW.TransportDelay_RWORK_m.TUbufferArea[0]; VFControl_DW.TransportDelay_IWORK_m.Tail = 0; VFControl_DW.TransportDelay_IWORK_m.Head = 0; VFControl_DW.TransportDelay_IWORK_m.Last = 0; VFControl_DW.TransportDelay_IWORK_m.CircularBufSize = 1024; pBuffer[0] = (VFControl_cal->TransportDelay_InitOutput_le); pBuffer[1024] = VFControl_M->Timing.t[0]; VFControl_DW.TransportDelay_PWORK_f.TUbufferPtrs[0] = (void *) &pBuffer[0]; } /* Start for S-Function (sg_fpga_do_sf_a2): '/Digital output1' */ /* Level2 S-Function Block: '/Digital output1' (sg_fpga_do_sf_a2) */ { SimStruct *rts = VFControl_M->childSfunctions[0]; sfcnStart(rts); if (ssGetErrorStatus(rts) != (NULL)) return; } /* Start for S-Function (sg_fpga_do_sf_a2): '/Digital output2' */ /* Level2 S-Function Block: '/Digital output2' (sg_fpga_do_sf_a2) */ { SimStruct *rts = VFControl_M->childSfunctions[1]; sfcnStart(rts); if (ssGetErrorStatus(rts) != (NULL)) return; } { int32_T i; /* InitializeConditions for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE[0] = VFControl_cal->fluxes_InitialCondition[0]; /* InitializeConditions for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE_l[0] = VFControl_cal->fluxes_InitialCondition_a[0]; /* InitializeConditions for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE[1] = VFControl_cal->fluxes_InitialCondition[1]; /* InitializeConditions for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE_l[1] = VFControl_cal->fluxes_InitialCondition_a[1]; /* InitializeConditions for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE[2] = VFControl_cal->fluxes_InitialCondition[2]; /* InitializeConditions for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE_l[2] = VFControl_cal->fluxes_InitialCondition_a[2]; /* InitializeConditions for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE[3] = VFControl_cal->fluxes_InitialCondition[3]; /* InitializeConditions for UnitDelay: '/fluxes' */ VFControl_DW.fluxes_DSTATE_l[3] = VFControl_cal->fluxes_InitialCondition_a[3]; /* InitializeConditions for DiscreteIntegrator: '/Rotor angle thetam' */ VFControl_DW.Rotoranglethetam_DSTATE = VFControl_cal->Rotoranglethetam_IC; /* InitializeConditions for UnitDelay: '/wm_delay' */ VFControl_DW.wm_delay_DSTATE = VFControl_cal->wm_delay_InitialCondition; /* InitializeConditions for UnitDelay: '/wm_predict' */ VFControl_DW.wm_predict_DSTATE = VFControl_cal->wm_predict_InitialCondition; /* InitializeConditions for S-Function (sfun_spssw_discc): '/State-Space' incorporates: * Constant: '/DC' * Constant: '/SwitchCurrents' */ { int32_T i, j; real_T *Ds = (real_T*)VFControl_DW.StateSpace_PWORK.DS; /* Copy and transpose D */ for (i=0; i<14; i++) { for (j=0; j<9; j++) Ds[i*9 + j] = (VFControl_cal->StateSpace_DS_param[i + j*14]); } { /* Switches work vectors */ int_T *switch_status = (int_T*) VFControl_DW.StateSpace_PWORK.SWITCH_STATUS; int_T *gState = (int_T*)VFControl_DW.StateSpace_PWORK.G_STATE; real_T *yswitch = (real_T*)VFControl_DW.StateSpace_PWORK.Y_SWITCH; int_T *switchTypes = (int_T*)VFControl_DW.StateSpace_PWORK.SWITCH_TYPES; int_T *idxOutSw = (int_T*)VFControl_DW.StateSpace_PWORK.IDX_OUT_SW; int_T *switch_status_init = (int_T*) VFControl_DW.StateSpace_PWORK.SWITCH_STATUS_INIT; /* Initialize work vectors */ switch_status[0] = 0; switch_status_init[0] = 0; gState[0] = (int_T) 0.0; yswitch[0] = 1/0.001; switchTypes[0] = (int_T)7.0; idxOutSw[0] = ((int_T)0.0) - 1; switch_status[1] = 0; switch_status_init[1] = 0; gState[1] = (int_T) 0.0; yswitch[1] = 1/0.001; switchTypes[1] = (int_T)7.0; idxOutSw[1] = ((int_T)0.0) - 1; switch_status[2] = 0; switch_status_init[2] = 0; gState[2] = (int_T) 0.0; yswitch[2] = 1/0.001; switchTypes[2] = (int_T)7.0; idxOutSw[2] = ((int_T)0.0) - 1; switch_status[3] = 0; switch_status_init[3] = 0; gState[3] = (int_T) 0.0; yswitch[3] = 1/0.001; switchTypes[3] = (int_T)7.0; idxOutSw[3] = ((int_T)0.0) - 1; switch_status[4] = 0; switch_status_init[4] = 0; gState[4] = (int_T) 0.0; yswitch[4] = 1/0.001; switchTypes[4] = (int_T)7.0; idxOutSw[4] = ((int_T)0.0) - 1; switch_status[5] = 0; switch_status_init[5] = 0; gState[5] = (int_T) 0.0; yswitch[5] = 1/0.001; switchTypes[5] = (int_T)7.0; idxOutSw[5] = ((int_T)0.0) - 1; } } /* InitializeConditions for UnitDelay: '/voltages' */ VFControl_DW.voltages_DSTATE[0] = VFControl_cal->voltages_InitialCondition; VFControl_DW.voltages_DSTATE[1] = VFControl_cal->voltages_InitialCondition; VFControl_DW.voltages_DSTATE[2] = VFControl_cal->voltages_InitialCondition; VFControl_DW.voltages_DSTATE[3] = VFControl_cal->voltages_InitialCondition; /* InitializeConditions for DiscreteIntegrator: '/Rotor speed(wm)' */ VFControl_DW.Rotorspeedwm_DSTATE = VFControl_cal->Rotorspeedwm_IC; /* InitializeConditions for DiscreteIntegrator: '/Discrete-Time Integrator1' */ VFControl_DW.DiscreteTimeIntegrator1_DSTATE = VFControl_cal->DiscreteTimeIntegrator1_IC; /* InitializeConditions for UnitDelay: '/Unit Delay1' */ VFControl_DW.UnitDelay1_DSTATE = VFControl_cal->UnitDelay1_InitialCondition; /* InitializeConditions for DiscreteIntegrator: '/Discrete-Time Integrator' */ VFControl_DW.DiscreteTimeIntegrator_DSTATE = VFControl_cal->DiscreteTimeIntegrator_IC; /* InitializeConditions for UnitDelay: '/Unit Delay' */ VFControl_DW.UnitDelay_DSTATE = VFControl_cal->UnitDelay_InitialCondition; /* SystemInitialize for Enabled SubSystem: '/Saturation' */ /* InitializeConditions for UnitDelay: '/Delay' */ VFControl_DW.Delay_DSTATE = VFControl_cal->Delay_InitialCondition; /* SystemInitialize for Switch: '/Switch' incorporates: * Outport: '/Lm' */ VFControl_B.Switch_g = VFControl_cal->Lm_Y0; /* End of SystemInitialize for SubSystem: '/Saturation' */ /* SystemInitialize for Enabled SubSystem: '/Rotor reference frame' */ /* SystemInitialize for Fcn: '/vqr' incorporates: * Outport: '/vqr,vdr' */ VFControl_B.vqr_j = VFControl_cal->vqrvdr_Y0; /* SystemInitialize for Fcn: '/vdr' incorporates: * Outport: '/vqr,vdr' */ VFControl_B.vdr_l = VFControl_cal->vqrvdr_Y0; /* SystemInitialize for Fcn: '/vqs' incorporates: * Outport: '/vqs,vds' */ VFControl_B.vqs_l = VFControl_cal->vqsvds_Y0; /* SystemInitialize for Fcn: '/vds' incorporates: * Outport: '/vqs,vds' */ VFControl_B.vds_f = VFControl_cal->vqsvds_Y0; /* End of SystemInitialize for SubSystem: '/Rotor reference frame' */ /* SystemInitialize for Enabled SubSystem: '/Stationary reference frame' */ /* SystemInitialize for Fcn: '/vqr' incorporates: * Outport: '/vqr,vdr' */ VFControl_B.vqr_l = VFControl_cal->vqrvdr_Y0_a; /* SystemInitialize for Fcn: '/vdr' incorporates: * Outport: '/vqr,vdr' */ VFControl_B.vdr_p = VFControl_cal->vqrvdr_Y0_a; /* SystemInitialize for Fcn: '/vqs' incorporates: * Outport: '/vqs,vds' */ VFControl_B.vqs_i = VFControl_cal->vqsvds_Y0_m; /* SystemInitialize for Fcn: '/vds' incorporates: * Outport: '/vqs,vds' */ VFControl_B.vds_i = VFControl_cal->vqsvds_Y0_m; /* End of SystemInitialize for SubSystem: '/Stationary reference frame' */ /* SystemInitialize for Enabled SubSystem: '/Synchronous reference frame' */ /* SystemInitialize for Fcn: '/vqr' incorporates: * Outport: '/vqr,vdr' */ VFControl_B.vqr = VFControl_cal->vqrvdr_Y0_am; /* SystemInitialize for Fcn: '/vdr' incorporates: * Outport: '/vqr,vdr' */ VFControl_B.vdr = VFControl_cal->vqrvdr_Y0_am; /* SystemInitialize for Fcn: '/vqs' incorporates: * Outport: '/vqs,vds' */ VFControl_B.vqs = VFControl_cal->vqsvds_Y0_p; /* SystemInitialize for Fcn: '/vds' incorporates: * Outport: '/vqs,vds' */ VFControl_B.vds = VFControl_cal->vqsvds_Y0_p; /* End of SystemInitialize for SubSystem: '/Synchronous reference frame' */ /* SystemInitialize for Enabled SubSystem: '/Rotor reference frame' */ /* SystemInitialize for Fcn: '/ira' incorporates: * Outport: '/ira,irb' */ VFControl_B.ira_p = VFControl_cal->irairb_Y0; /* SystemInitialize for Fcn: '/irb' incorporates: * Outport: '/ira,irb' */ VFControl_B.irb_n = VFControl_cal->irairb_Y0; /* SystemInitialize for Fcn: '/isa' incorporates: * Outport: '/isa,isb' */ VFControl_B.isa_m = VFControl_cal->isaisb_Y0; /* SystemInitialize for Fcn: '/isb' incorporates: * Outport: '/isa,isb' */ VFControl_B.isb_p = VFControl_cal->isaisb_Y0; /* End of SystemInitialize for SubSystem: '/Rotor reference frame' */ /* SystemInitialize for Enabled SubSystem: '/Stationary reference frame' */ /* SystemInitialize for Fcn: '/ira' incorporates: * Outport: '/ira,irb' */ VFControl_B.ira_g = VFControl_cal->irairb_Y0_d; /* SystemInitialize for Fcn: '/irb' incorporates: * Outport: '/ira,irb' */ VFControl_B.irb_g = VFControl_cal->irairb_Y0_d; /* SystemInitialize for Fcn: '/isa' incorporates: * Outport: '/isa,isb' */ VFControl_B.isa_a = VFControl_cal->isaisb_Y0_k; /* SystemInitialize for Fcn: '/isb' incorporates: * Outport: '/isa,isb' */ VFControl_B.isb_f = VFControl_cal->isaisb_Y0_k; /* End of SystemInitialize for SubSystem: '/Stationary reference frame' */ /* SystemInitialize for Enabled SubSystem: '/Synchronous reference frame' */ /* SystemInitialize for Fcn: '/ira' incorporates: * Outport: '/ira,irb' */ VFControl_B.ira = VFControl_cal->irairb_Y0_h; /* SystemInitialize for Fcn: '/irb' incorporates: * Outport: '/ira,irb' */ VFControl_B.irb = VFControl_cal->irairb_Y0_h; /* SystemInitialize for Fcn: '/isa' incorporates: * Outport: '/isa,isb' */ VFControl_B.isa = VFControl_cal->isaisb_Y0_m; /* SystemInitialize for Fcn: '/isb' incorporates: * Outport: '/isa,isb' */ VFControl_B.isb = VFControl_cal->isaisb_Y0_m; /* End of SystemInitialize for SubSystem: '/Synchronous reference frame' */ /* SystemInitialize for Enabled SubSystem: '/sin(beta),cos(beta),sin(th),cos(th)' */ /* SystemInitialize for Trigonometry: '/Trigonometric Function1' incorporates: * Outport: '/sin(beta),cos(beta), sin(th),cos(th)' */ VFControl_B.TrigonometricFunction1_o1 = VFControl_cal->sinbetacosbetasinthcosth_Y0; /* SystemInitialize for Trigonometry: '/Trigonometric Function1' incorporates: * Outport: '/sin(beta),cos(beta), sin(th),cos(th)' */ VFControl_B.TrigonometricFunction1_o2 = VFControl_cal->sinbetacosbetasinthcosth_Y0; /* SystemInitialize for Trigonometry: '/Trigonometric Function' incorporates: * Outport: '/sin(beta),cos(beta), sin(th),cos(th)' */ VFControl_B.TrigonometricFunction_o1_dn = VFControl_cal->sinbetacosbetasinthcosth_Y0; /* SystemInitialize for Trigonometry: '/Trigonometric Function' incorporates: * Outport: '/sin(beta),cos(beta), sin(th),cos(th)' */ VFControl_B.TrigonometricFunction_o2_k = VFControl_cal->sinbetacosbetasinthcosth_Y0; /* End of SystemInitialize for SubSystem: '/sin(beta),cos(beta),sin(th),cos(th)' */ /* SystemInitialize for Enabled SubSystem: '/sin(thr),cos(thr)' */ /* SystemInitialize for Trigonometry: '/Trigonometric Function' incorporates: * Outport: '/sin(thr),cos(thr)' */ VFControl_B.TrigonometricFunction_o1_d = VFControl_cal->sinthrcosthr_Y0; /* SystemInitialize for Trigonometry: '/Trigonometric Function' incorporates: * Outport: '/sin(thr),cos(thr)' */ VFControl_B.TrigonometricFunction_o2_j = VFControl_cal->sinthrcosthr_Y0; /* SystemInitialize for Outport: '/sin(thr),cos(thr)' incorporates: * Constant: '/Constant' */ VFControl_B.Constant_e[0] = VFControl_cal->sinthrcosthr_Y0; VFControl_B.Constant_e[1] = VFControl_cal->sinthrcosthr_Y0; /* End of SystemInitialize for SubSystem: '/sin(thr),cos(thr)' */ /* SystemInitialize for Enabled SubSystem: '/sin(thr),cos(thr)1' */ /* SystemInitialize for Trigonometry: '/Trigonometric Function' incorporates: * Outport: '/sin(thr),cos(thr)' */ VFControl_B.TrigonometricFunction_o1 = VFControl_cal->sinthrcosthr_Y0_h; /* SystemInitialize for Trigonometry: '/Trigonometric Function' incorporates: * Outport: '/sin(thr),cos(thr)' */ VFControl_B.TrigonometricFunction_o2 = VFControl_cal->sinthrcosthr_Y0_h; /* SystemInitialize for Outport: '/sin(thr),cos(thr)' incorporates: * Constant: '/Constant' */ VFControl_B.Constant[0] = VFControl_cal->sinthrcosthr_Y0_h; VFControl_B.Constant[1] = VFControl_cal->sinthrcosthr_Y0_h; /* SystemInitialize for Enabled SubSystem: '/sin(thr),cos(thr)' */ /* SystemInitialize for Enabled SubSystem: '/sin(beta),cos(beta),sin(th),cos(th)' */ /* SystemInitialize for Enabled SubSystem: '/Saturation' */ for (i = 0; i < 16; i++) { /* SystemInitialize for Product: '/inversion' incorporates: * Outport: '/Linv' */ VFControl_B.Linv_h[i] = VFControl_cal->Linv_Y0; /* SystemInitialize for Product: '/Product1' incorporates: * Outport: '/R*Linv' */ VFControl_B.RLinv_m[i] = VFControl_cal->RLinv_Y0; /* SystemInitialize for Assignment: '/W(4,3)=wr-1' incorporates: * Outport: '/W' */ VFControl_B.W43wr1[i] = VFControl_cal->W_Y0; /* SystemInitialize for Assignment: '/W(2,1)=-wr' incorporates: * Outport: '/W' */ VFControl_B.W21wr[i] = VFControl_cal->W_Y0_m; /* SystemInitialize for Assignment: '/W(4,3)=wr' incorporates: * Outport: '/W' */ VFControl_B.W43wr[i] = VFControl_cal->W_Y0_o; } /* End of SystemInitialize for SubSystem: '/Saturation' */ /* End of SystemInitialize for SubSystem: '/sin(beta),cos(beta),sin(th),cos(th)' */ /* End of SystemInitialize for SubSystem: '/sin(thr),cos(thr)' */ /* End of SystemInitialize for SubSystem: '/sin(thr),cos(thr)1' */ } /* Enable for DiscreteIntegrator: '/Rotor speed(wm)' */ VFControl_DW.Rotorspeedwm_SYSTEM_ENABLE = 1U; } /* Model terminate function */ void VFControl_terminate(void) { /* Terminate for S-Function (sfun_spssw_discc): '/State-Space' incorporates: * Constant: '/DC' * Constant: '/SwitchCurrents' */ /* S-Function block: /State-Space */ { /* Free memory */ free(VFControl_DW.StateSpace_PWORK.DS); free(VFControl_DW.StateSpace_PWORK.DX_COL); free(VFControl_DW.StateSpace_PWORK.TMP2); /* * Circuit has switches*/ free(VFControl_DW.StateSpace_PWORK.G_STATE); free(VFControl_DW.StateSpace_PWORK.SWITCH_STATUS); free(VFControl_DW.StateSpace_PWORK.SW_CHG); free(VFControl_DW.StateSpace_PWORK.SWITCH_STATUS_INIT); } /* Terminate for S-Function (sg_fpga_do_sf_a2): '/Digital output1' */ /* Level2 S-Function Block: '/Digital output1' (sg_fpga_do_sf_a2) */ { SimStruct *rts = VFControl_M->childSfunctions[0]; sfcnTerminate(rts); } /* Terminate for S-Function (sg_fpga_do_sf_a2): '/Digital output2' */ /* Level2 S-Function Block: '/Digital output2' (sg_fpga_do_sf_a2) */ { SimStruct *rts = VFControl_M->childSfunctions[1]; sfcnTerminate(rts); } /* user code (Terminate function Trailer) */ { uintptr_t bar2Addr; volatile io3xx_pull *ptrIO31x_pull; volatile io3xx_2x *ptrio3xx_2x; uint16_t moduleArchitecture; sg_fpga_io3xxModuleIdT moduleId; static char msg[500]; // Get module IDs (PIC info) sg_fpga_IO3xxGetModuleId(39750, &moduleId); moduleArchitecture = moduleId.moduleArchitecture; SG_PRINTF(DEBUG, "moduleArchitecture %d\n",moduleArchitecture); if (moduleArchitecture == TEWS_TXMC) { // Get pointer to io31x_pull bar2Addr = (uintptr_t)io3xxGetAddressSgLib((int32_t)1, SG_FPGA_IO3XX_BAR2); if (bar2Addr == 0) { sprintf(msg, "%s", pSgErrorStr); rtmSetErrorStatus(VFControl_M, msg); SG_PRINTF(ERROR,msg); return; } ptrIO31x_pull = (io3xx_pull *)((uintptr_t)bar2Addr + IO3xx_PULL_BASE); // Disable pull resistors ptrIO31x_pull->enable = 0x0; // disable } // Pull down and disable DIOs if ((1 == 2) || (1 == 3)) { bar2Addr = (uintptr_t)io3xxGetAddressSgLib((int32_t)1, SG_FPGA_IO3XX_BAR2); if (bar2Addr == 0) { sprintf(msg, "%s", pSgErrorStr); rtmSetErrorStatus(VFControl_M, msg); SG_PRINTF(ERROR,msg); return; } ptrio3xx_2x = (io3xx_2x *)((uintptr_t)bar2Addr +IO3xx_2x_BASE); ptrio3xx_2x->pull = 0xffffffff; // pull down ptrio3xx_2x->dir = 0x0; // input ptrio3xx_2x->update = 0x1; sg_wait_s(SG_FPGA_WAIT_TIME_100us); ptrio3xx_2x->update = 0x0; sg_wait_s(SG_FPGA_WAIT_TIME_1ms); #if DEBUGGING // For debugging output port register of IO-Expander sg_wait_s(SG_FPGA_WAIT_TIME_100ms); SG_PRINTF(INFO, "last configuration from mdl start\n"); SG_PRINTF(INFO, "rxData of Expander1: 0x%X\n", ptrio3xx_2x->rxDataExpander1); SG_PRINTF(INFO, "rxData of Expander2: 0x%X\n", ptrio3xx_2x->rxDataExpander2); SG_PRINTF(INFO, "rxData of Expander3: 0x%X\n", ptrio3xx_2x->rxDataExpander3); SG_PRINTF(INFO, "rxData of Expander4: 0x%X\n", ptrio3xx_2x->rxDataExpander4); #endif } else if (1 == 4) { IO3xx_24_terminate(1); } freeFPGAModuleSgLib((uint32_t)1); } }