302 lines
8.6 KiB
C
302 lines
8.6 KiB
C
/*
|
|
* File: Model_actuator.c
|
|
*
|
|
* Code generated for Simulink model 'Model_actuator'.
|
|
*
|
|
* Model version : 1.586
|
|
* Simulink Coder version : 24.1 (R2024a) 19-Nov-2023
|
|
* C/C++ source code generated on : Wed Feb 11 11:06:39 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 <stdbool.h>
|
|
#include <stdint.h>
|
|
#include "Model_actuator_types.h"
|
|
#include "Model_actuator_private.h"
|
|
|
|
/* Exported block states */
|
|
CmdBusStatus Status_Sensor_Model; /* '<S1>/Data Store Memory' */
|
|
CmdBusError CCU_Errors_Model; /* '<S1>/Data Store Memory3' */
|
|
|
|
/* Block states (default storage) */
|
|
DW rtDW;
|
|
|
|
/* Real-time model */
|
|
static RT_MODEL rtM_;
|
|
RT_MODEL *const rtM = &rtM_;
|
|
uint16_t look1_iu16tdIu16_binlcs(uint16_t u0, const uint16_t bp0[], const double
|
|
table[], uint32_t maxIndex)
|
|
{
|
|
double frac;
|
|
double yL_0d0;
|
|
uint32_t bpIdx;
|
|
uint32_t iLeft;
|
|
uint16_t bpLeftVar;
|
|
uint16_t tmp;
|
|
|
|
/* Column-major Lookup 1-D
|
|
Search method: 'binary'
|
|
Use previous index: 'off'
|
|
Interpolation method: 'Linear point-slope'
|
|
Extrapolation method: 'Clip'
|
|
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: 'Clip'
|
|
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 = 0.0;
|
|
} else if (u0 < bp0[maxIndex]) {
|
|
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;
|
|
}
|
|
|
|
bpLeftVar = bp0[iLeft];
|
|
frac = (double)((uint32_t)u0 - bpLeftVar) / (double)((uint32_t)bp0[iLeft +
|
|
1U] - bpLeftVar);
|
|
} else {
|
|
iLeft = maxIndex - 1U;
|
|
frac = 1.0;
|
|
}
|
|
|
|
/* Column-major Interpolation 1-D
|
|
Interpolation method: 'Linear point-slope'
|
|
Use last breakpoint for index at or above upper limit: 'off'
|
|
Overflow mode: 'saturate'
|
|
*/
|
|
yL_0d0 = table[iLeft];
|
|
if (yL_0d0 < 65536.0) {
|
|
if (yL_0d0 >= 0.0) {
|
|
bpLeftVar = (uint16_t)yL_0d0;
|
|
} else {
|
|
bpLeftVar = 0U;
|
|
}
|
|
} else {
|
|
bpLeftVar = UINT16_MAX;
|
|
}
|
|
|
|
frac *= table[iLeft + 1U] - yL_0d0;
|
|
if (frac < 65536.0) {
|
|
if (frac >= 0.0) {
|
|
tmp = (uint16_t)frac;
|
|
} else {
|
|
tmp = 0U;
|
|
}
|
|
} else {
|
|
tmp = UINT16_MAX;
|
|
}
|
|
|
|
bpIdx = (uint32_t)bpLeftVar + tmp;
|
|
if (bpIdx > 65535U) {
|
|
bpIdx = 65535U;
|
|
}
|
|
|
|
return (uint16_t)bpIdx;
|
|
}
|
|
|
|
/* Model step function */
|
|
void Model_actuator_step(void)
|
|
{
|
|
double rtb_Divide1;
|
|
uint32_t rtb_dt;
|
|
uint16_t IncarFL;
|
|
bool rtb_FailCond;
|
|
bool rtb_LogicalOperator1;
|
|
|
|
/* Product: '<S1>/Divide1' incorporates:
|
|
* Constant: '<S1>/Constant'
|
|
* Constant: '<S1>/Constant1'
|
|
* DataStoreRead: '<S1>/Data Store Read1'
|
|
* Product: '<S1>/Divide'
|
|
*/
|
|
rtb_Divide1 = (double)rtDW.ADC_Data_Model.Sensor_Incar_Temp_FL / 4095.0 * 5.0;
|
|
|
|
/* Logic: '<S1>/Logical Operator' incorporates:
|
|
* Constant: '<S4>/Constant'
|
|
* Constant: '<S5>/Constant'
|
|
* RelationalOperator: '<S4>/Compare'
|
|
* RelationalOperator: '<S5>/Compare'
|
|
*/
|
|
rtb_FailCond = ((rtb_Divide1 < 0.15) || (rtb_Divide1 > 4.9));
|
|
|
|
/* Sum: '<S11>/Subtract' incorporates:
|
|
* DataStoreRead: '<S11>/Data Store Read4'
|
|
* UnitDelay: '<S11>/t_start_delay_private '
|
|
*/
|
|
rtb_dt = rtDW.t_now - rtDW.t_start_delay_private_DSTATE;
|
|
|
|
/* Logic: '<S1>/Logical Operator1' incorporates:
|
|
* Constant: '<S6>/Constant'
|
|
* RelationalOperator: '<S6>/Compare'
|
|
*/
|
|
rtb_LogicalOperator1 = (rtb_FailCond && (rtb_dt >= 3000U));
|
|
|
|
/* BusCreator: '<S2>/Bus Creator' incorporates:
|
|
* DataStoreWrite: '<S2>/Data Store Write'
|
|
* DataTypeConversion: '<S2>/Data Type Conversion'
|
|
*/
|
|
CCU_Errors_Model.CCU_IncarTempErrF_Stat = rtb_LogicalOperator1;
|
|
CCU_Errors_Model.CCU_IncarTempErrR_Stat = 0U;
|
|
CCU_Errors_Model.CCU_DuctTempSenErrF_Stat = 0U;
|
|
CCU_Errors_Model.CCU_DuctTempSenErrR_Stat = 0U;
|
|
CCU_Errors_Model.CCU_EvaTempSenErrF_Stat = 0U;
|
|
CCU_Errors_Model.CCU_EvaTempSenErrR_Stat = 0U;
|
|
CCU_Errors_Model.CCU_DeflectorSwErrF_Stat = 0U;
|
|
CCU_Errors_Model.CCU_DeflectorSwErrR_Stat = 0U;
|
|
CCU_Errors_Model.CCU_PressSenErr_Stat = 0U;
|
|
CCU_Errors_Model.CCU_AmbienTemptSenErr_Stat = 0U;
|
|
CCU_Errors_Model.CCU_SealingValveErr_Stat = 0U;
|
|
CCU_Errors_Model.CCU_ETXVerr_Stat = 0U;
|
|
CCU_Errors_Model.CCU_HVACfanOrTXVerrF_Stat = 0U;
|
|
CCU_Errors_Model.CCU_HVACfanOrTXVerrR_Stat = 0U;
|
|
CCU_Errors_Model.CCU_ActuatorErrF_Stat = 0U;
|
|
CCU_Errors_Model.CCU_ActuatorErrR_Stat = 0U;
|
|
CCU_Errors_Model.CCU_UltravioletErr_Stat = 0U;
|
|
CCU_Errors_Model.CCU_VinRecordErr_Stat = 0U;
|
|
CCU_Errors_Model.CCU_AirQualSenErr_Stat = 0U;
|
|
CCU_Errors_Model.CCU_CommErr_Stat = 0U;
|
|
CCU_Errors_Model.CCU_TWVerr_Stat = 0U;
|
|
CCU_Errors_Model.CCU_IonizationErr_Stat = 0U;
|
|
CCU_Errors_Model.CCU_AromaErr_Stat = 0U;
|
|
|
|
/* Switch: '<S1>/Switch' incorporates:
|
|
* Constant: '<S1>/Constant2'
|
|
* DataStoreRead: '<S1>/Data Store Read1'
|
|
* DataStoreWrite: '<S1>/Data Store Write'
|
|
* Lookup_n-D: '<S1>/1-D Lookup Table'
|
|
*/
|
|
if (rtb_LogicalOperator1) {
|
|
IncarFL = 200U;
|
|
} else {
|
|
IncarFL = look1_iu16tdIu16_binlcs(rtDW.ADC_Data_Model.Sensor_Incar_Temp_FL,
|
|
rtConstP.uDLookupTable_bp01Data, rtConstP.uDLookupTable_tableData, 1023U);
|
|
}
|
|
|
|
/* End of Switch: '<S1>/Switch' */
|
|
|
|
/* BusCreator: '<S3>/Bus Creator' incorporates:
|
|
* DataStoreWrite: '<S1>/Data Store Write'
|
|
* DataStoreWrite: '<S3>/Data Store Write'
|
|
*/
|
|
Status_Sensor_Model.Sensor_Ambient_Temp = 0U;
|
|
Status_Sensor_Model.Battery = 0U;
|
|
Status_Sensor_Model.AMB = 0U;
|
|
Status_Sensor_Model.Incar_FL = IncarFL;
|
|
Status_Sensor_Model.Incar_FR = 0U;
|
|
Status_Sensor_Model.Incar_RL = 0U;
|
|
Status_Sensor_Model.Incar_RR = 0U;
|
|
Status_Sensor_Model.Eva_F = 0U;
|
|
Status_Sensor_Model.Eva_R = 0U;
|
|
Status_Sensor_Model.Pressure = 0U;
|
|
Status_Sensor_Model.Duct_FL_Upper = 0U;
|
|
Status_Sensor_Model.Duct_FL_Lower = 0U;
|
|
Status_Sensor_Model.Duct_FR_Upper = 0U;
|
|
Status_Sensor_Model.Duct_FR_Lower = 0U;
|
|
Status_Sensor_Model.Duct_RL = 0U;
|
|
Status_Sensor_Model.Duct_RR = 0U;
|
|
Status_Sensor_Model.Duct_Side_FL = 0U;
|
|
Status_Sensor_Model.Duct_Side_FR = 0U;
|
|
Status_Sensor_Model.Duct_Side_RL = 0U;
|
|
Status_Sensor_Model.Duct_Side_RR = 0U;
|
|
Status_Sensor_Model.AQS = 0U;
|
|
|
|
/* MATLAB Function: '<S1>/Normal Mode' incorporates:
|
|
* DataStoreRead: '<S1>/Data Store Read1'
|
|
*/
|
|
/* : y = IncarFL; */
|
|
/* : fprintf('IncarFL %u \n',IncarFL); */
|
|
printf("IncarFL %u \n", rtDW.ADC_Data_Model.Sensor_Incar_Temp_FL);
|
|
fflush(stdout);
|
|
|
|
/* MATLAB Function: '<S1>/Normal Mode1' */
|
|
/* : y = IncarFL_VIN ; */
|
|
/* : fprintf('IncarFL_VIN %f\n',IncarFL_VIN); */
|
|
printf("IncarFL_VIN %f\n", rtb_Divide1);
|
|
fflush(stdout);
|
|
|
|
/* MATLAB Function: '<S1>/Normal Mode2' */
|
|
/* : y = IncarFLErr ; */
|
|
/* : fprintf('IncarFLErr %d\n',int8(IncarFLErr)); */
|
|
printf("IncarFLErr %d\n", (int8_t)rtb_LogicalOperator1);
|
|
fflush(stdout);
|
|
|
|
/* MATLAB Function: '<S1>/Normal Mode3' incorporates:
|
|
* DataStoreWrite: '<S1>/Data Store Write'
|
|
*/
|
|
/* : y = IncarFLOut ; */
|
|
/* : fprintf('IncarFLOut %u\n',IncarFLOut); */
|
|
printf("IncarFLOut %u\n", IncarFL);
|
|
fflush(stdout);
|
|
|
|
/* MATLAB Function: '<S11>/Normal Mode2' */
|
|
/* : y = dt ; */
|
|
/* : fprintf('dt %d\n',int16(dt)); */
|
|
if (rtb_dt > 32767U) {
|
|
rtb_dt = 32767U;
|
|
}
|
|
|
|
printf("dt %d\n", (int16_t)rtb_dt);
|
|
fflush(stdout);
|
|
|
|
/* End of MATLAB Function: '<S11>/Normal Mode2' */
|
|
|
|
/* Switch: '<S11>/Switch' incorporates:
|
|
* DataStoreRead: '<S11>/Data Store Read4'
|
|
* Logic: '<S11>/Logical Operator3'
|
|
* Logic: '<S11>/Logical Operator4'
|
|
* UnitDelay: '<S11>/Cond_prev_private '
|
|
* UnitDelay: '<S11>/t_start_delay_private '
|
|
*/
|
|
if (rtb_FailCond && (!rtDW.Cond_prev_private_DSTATE)) {
|
|
rtDW.t_start_delay_private_DSTATE = rtDW.t_now;
|
|
}
|
|
|
|
/* End of Switch: '<S11>/Switch' */
|
|
|
|
/* Update for UnitDelay: '<S11>/Cond_prev_private ' */
|
|
rtDW.Cond_prev_private_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]
|
|
*/
|