/* * File: Model_actuator.c * * Code generated for Simulink model 'Model_actuator'. * * Model version : 1.572 * Simulink Coder version : 24.1 (R2024a) 19-Nov-2023 * C/C++ source code generated on : Fri Jan 30 16:05:13 2026 * * Target selection: ert.tlc * Embedded hardware selection: ARM Compatible->ARM Cortex-M * Emulation hardware selection: * Differs from embedded hardware (MATLAB Host) * Code generation objectives: Unspecified * Validation result: Not run */ #include "Model_actuator.h" #include #include #include "Model_actuator_private.h" /* Block states (default storage) */ DW rtDW; /* Real-time model */ static RT_MODEL rtM_; RT_MODEL *const rtM = &rtM_; double look1_binlx(double u0, const double bp0[], const double table[], uint32_t maxIndex) { double frac; double yL_0d0; uint32_t iLeft; /* Column-major Lookup 1-D Search method: 'binary' Use previous index: 'off' Interpolation method: 'Linear point-slope' Extrapolation method: 'Linear' Use last breakpoint for index at or above upper limit: 'off' Remove protection against out-of-range input in generated code: 'off' */ /* Prelookup - Index and Fraction Index Search method: 'binary' Extrapolation method: 'Linear' Use previous index: 'off' Use last breakpoint for index at or above upper limit: 'off' Remove protection against out-of-range input in generated code: 'off' */ if (u0 <= bp0[0U]) { iLeft = 0U; frac = (u0 - bp0[0U]) / (bp0[1U] - bp0[0U]); } else if (u0 < bp0[maxIndex]) { uint32_t bpIdx; uint32_t iRght; /* Binary Search */ bpIdx = maxIndex >> 1U; iLeft = 0U; iRght = maxIndex; while (iRght - iLeft > 1U) { if (u0 < bp0[bpIdx]) { iRght = bpIdx; } else { iLeft = bpIdx; } bpIdx = (iRght + iLeft) >> 1U; } frac = (u0 - bp0[iLeft]) / (bp0[iLeft + 1U] - bp0[iLeft]); } else { iLeft = maxIndex - 1U; frac = (u0 - bp0[maxIndex - 1U]) / (bp0[maxIndex] - bp0[maxIndex - 1U]); } /* Column-major Interpolation 1-D Interpolation method: 'Linear point-slope' Use last breakpoint for index at or above upper limit: 'off' Overflow mode: 'wrapping' */ yL_0d0 = table[iLeft]; return (table[iLeft + 1U] - yL_0d0) * frac + yL_0d0; } /* Model step function */ void Model_actuator_step(void) { double IncarFL; double rtb_Divide1; uint32_t rtb_dt; bool IncarFLErr; bool rtb_FailCond; /* Product: '/Divide1' incorporates: * Constant: '/Constant' * Constant: '/Constant1' * DataStoreRead: '/Data Store Read1' * Product: '/Divide' */ rtb_Divide1 = (double)rtDW.controllerDataIncarInput.InIncarFL / 4095.0 * 5.0; /* Logic: '/Logical Operator' incorporates: * Constant: '/Constant' * RelationalOperator: '/Compare' */ rtb_FailCond = (rtb_Divide1 < 15.0); /* Switch: '/Switch' incorporates: * DataStoreRead: '/Data Store Read4' * DataStoreWrite: '/Data Store Write' * Logic: '/Logical Operator3' * Logic: '/Logical Operator4' * UnitDelay: '/Unit Delay' */ if (rtb_FailCond && (!rtDW.UnitDelay_DSTATE)) { rtDW.UnitDelay1_DSTATE = rtDW.t_now; } /* End of Switch: '/Switch' */ /* Sum: '/Subtract' incorporates: * DataStoreRead: '/Data Store Read4' * DataStoreWrite: '/Data Store Write' */ rtb_dt = rtDW.t_now - rtDW.UnitDelay1_DSTATE; /* Logic: '/Logical Operator1' incorporates: * Constant: '/Constant' * DataStoreWrite: '/Data Store Write1' * RelationalOperator: '/Compare' */ IncarFLErr = (rtb_FailCond && (rtb_dt >= 3000U)); /* Switch: '/Switch' incorporates: * Constant: '/Constant2' * DataStoreWrite: '/Data Store Write' * DataStoreWrite: '/Data Store Write1' * Lookup_n-D: '/1-D Lookup Table' * Product: '/Divide1' */ if (IncarFLErr) { IncarFL = 200.0; } else { IncarFL = look1_binlx(rtb_Divide1, rtConstP.uDLookupTable_bp01Data, rtConstP.uDLookupTable_tableData, 475U); } /* End of Switch: '/Switch' */ /* MATLAB Function: '/Normal Mode2' */ /* : y = dt ; */ /* : fprintf('int16 %d\n',int16(dt)); */ if (rtb_dt > 32767U) { rtb_dt = 32767U; } printf("int16 %d\n", (int16_t)rtb_dt); fflush(stdout); /* End of MATLAB Function: '/Normal Mode2' */ /* MATLAB Function: '/Normal Mode' incorporates: * DataStoreRead: '/Data Store Read1' */ /* : y = IncarFL; */ /* : fprintf('IncarFL %u \n',IncarFL); */ printf("IncarFL %u \n", rtDW.controllerDataIncarInput.InIncarFL); fflush(stdout); /* MATLAB Function: '/Normal Mode1' */ /* : y = IncarFL_VIN ; */ /* : fprintf('IncarFL_VIN %f\n',IncarFL_VIN); */ printf("IncarFL_VIN %f\n", rtb_Divide1); fflush(stdout); /* MATLAB Function: '/Normal Mode2' incorporates: * DataStoreWrite: '/Data Store Write1' */ /* : y = IncarFLErr ; */ /* : fprintf('IncarFLErr %d\n',int8(IncarFLErr)); */ printf("IncarFLErr %d\n", (int8_t)IncarFLErr); fflush(stdout); /* MATLAB Function: '/Normal Mode3' incorporates: * DataStoreWrite: '/Data Store Write' */ /* : y = IncarFLOut ; */ /* : fprintf('IncarFLOut %f\n',IncarFLOut); */ printf("IncarFLOut %f\n", IncarFL); fflush(stdout); /* Update for UnitDelay: '/Unit Delay' */ rtDW.UnitDelay_DSTATE = rtb_FailCond; } /* Model initialize function */ void Model_actuator_initialize(void) { /* (no initialization code required) */ } /* Model terminate function */ void Model_actuator_terminate(void) { /* (no terminate code required) */ } /* * File trailer for generated code. * * [EOF] */