123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- /*
- * File: LoadObsTheta.c
- *
- * Code generated for Simulink model 'LoadObsTheta'.
- *
- * Model version : 8.72
- * Simulink Coder version : 9.6 (R2021b) 14-May-2021
- * C/C++ source code generated on : Sat Nov 5 15:46:39 2022
- *
- * Target selection: ert.tlc
- * Embedded hardware selection: ARM Compatible->ARM Cortex-M
- * Code generation objectives: Unspecified
- * Validation result: Not run
- */
- #include "LoadObsTheta.h"
- #ifndef UCHAR_MAX
- #include <limits.h>
- #endif
- #if ( UCHAR_MAX != (0xFFU) ) || ( SCHAR_MAX != (0x7F) )
- #error Code was generated for compiler with different sized uchar/char. \
- Consider adjusting Test hardware word size settings on the \
- Hardware Implementation pane to match your compiler word sizes as \
- defined in limits.h of the compiler. Alternatively, you can \
- select the Test hardware is the same as production hardware option and \
- select the Enable portable word sizes option on the Code Generation > \
- Verification pane for ERT based targets, which will disable the \
- preprocessor word size checks.
- #endif
- #if ( USHRT_MAX != (0xFFFFU) ) || ( SHRT_MAX != (0x7FFF) )
- #error Code was generated for compiler with different sized ushort/short. \
- Consider adjusting Test hardware word size settings on the \
- Hardware Implementation pane to match your compiler word sizes as \
- defined in limits.h of the compiler. Alternatively, you can \
- select the Test hardware is the same as production hardware option and \
- select the Enable portable word sizes option on the Code Generation > \
- Verification pane for ERT based targets, which will disable the \
- preprocessor word size checks.
- #endif
- #if ( UINT_MAX != (0xFFFFFFFFU) ) || ( INT_MAX != (0x7FFFFFFF) )
- #error Code was generated for compiler with different sized uint/int. \
- Consider adjusting Test hardware word size settings on the \
- Hardware Implementation pane to match your compiler word sizes as \
- defined in limits.h of the compiler. Alternatively, you can \
- select the Test hardware is the same as production hardware option and \
- select the Enable portable word sizes option on the Code Generation > \
- Verification pane for ERT based targets, which will disable the \
- preprocessor word size checks.
- #endif
- #if ( ULONG_MAX != (0xFFFFFFFFU) ) || ( LONG_MAX != (0x7FFFFFFF) )
- #error Code was generated for compiler with different sized ulong/long. \
- Consider adjusting Test hardware word size settings on the \
- Hardware Implementation pane to match your compiler word sizes as \
- defined in limits.h of the compiler. Alternatively, you can \
- select the Test hardware is the same as production hardware option and \
- select the Enable portable word sizes option on the Code Generation > \
- Verification pane for ERT based targets, which will disable the \
- preprocessor word size checks.
- #endif
- /* Skipping ulong_long/long_long check: insufficient preprocessor integer range. */
- /* Exported data definition */
- /* Definition for custom storage class: Struct */
- LoadObsTheta_stCoef_type LoadObsTheta_stCoef;
- LoadObsTheta_stCoefIn_type LoadObsTheta_stCoefIn;
- /* Block states (default storage) */
- DW_LoadObsTheta_T LoadObsTheta_DW;
- /* External inputs (root inport signals with default storage) */
- ExtU_LoadObsTheta_T LoadObsTheta_U;
- /* External outputs (root outports fed by signals with default storage) */
- ExtY_LoadObsTheta_T LoadObsTheta_Y;
- void LoadObsTheta_voCoef(void)
- {
- uint16_T rtb_Divide2;
- /* Outputs for Atomic SubSystem: '<Root>/Initialize Function2' */
- /* Product: '<S2>/Divide' incorporates:
- * DataStoreWrite: '<S2>/Data Store Write'
- * Inport: '<Root>/uwFbHz'
- * Inport: '<Root>/uwWtcHz'
- */
- LoadObsTheta_stCoef.uwK1Pu = (uint16_T)(LoadObsTheta_stCoefIn.uwFbHz == 0U ?
- MAX_uint32_T : ((uint32_T)LoadObsTheta_stCoefIn.uwWtcHz << 15) /
- LoadObsTheta_stCoefIn.uwFbHz);
- /* Product: '<S2>/Divide2' incorporates:
- * Gain: '<S2>/Gain'
- * Inport: '<Root>/uwJb'
- * Inport: '<Root>/uwMtJm'
- */
- rtb_Divide2 = (uint16_T)(LoadObsTheta_stCoefIn.uwJb == 0U ? MAX_uint32_T :
- 1000U * LoadObsTheta_stCoefIn.uwMtJm / LoadObsTheta_stCoefIn.uwJb);
- /* Product: '<S2>/Product6' incorporates:
- * DataStoreWrite: '<S2>/Data Store Write'
- * DataStoreWrite: '<S2>/Data Store Write1'
- * Product: '<S2>/Divide'
- * Product: '<S2>/Product'
- */
- LoadObsTheta_stCoef.uwK2Pu = (uint16_T)(((uint64_T)(((uint32_T)
- LoadObsTheta_stCoef.uwK1Pu * LoadObsTheta_stCoef.uwK1Pu) >> 1) *
- rtb_Divide2) >> 19);
- /* Product: '<S2>/Divide6' incorporates:
- * DataStoreRead: '<S2>/Data Store Read'
- * DataStoreWrite: '<S2>/Data Store Write'
- * DataStoreWrite: '<S2>/Data Store Write2'
- * Inport: '<Root>/uwMCoef'
- * Product: '<S2>/Divide'
- * Product: '<S2>/Product1'
- * Product: '<S2>/Product2'
- * Product: '<S2>/Product4'
- * Product: '<S2>/Product5'
- */
- LoadObsTheta_stCoef.uwK3Pu = (uint16_T)(LoadObsTheta_stCoefIn.uwMCoef == 0U ?
- MAX_uint32_T : (uint32_T)(uint16_T)(((uint64_T)(uint32_T)(((uint64_T)
- (uint32_T)(((uint64_T)(((uint32_T)LoadObsTheta_stCoef.uwK1Pu *
- LoadObsTheta_stCoef.uwK1Pu) >> 1) * LoadObsTheta_stCoef.uwK1Pu) >> 14) *
- rtb_Divide2) >> 6) * LoadObsTheta_stCoef.uwTctrPu) >> 21) /
- LoadObsTheta_stCoefIn.uwMCoef);
- /* Product: '<S2>/Divide3' incorporates:
- * DataStoreWrite: '<S2>/Data Store Write3'
- * Inport: '<Root>/uwFTbcHz'
- * Inport: '<Root>/uwFbHz'
- */
- LoadObsTheta_stCoef.uwCurTs = (uint16_T)(LoadObsTheta_stCoefIn.uwFTbcHz ==
- 0U ? MAX_uint32_T : ((uint32_T)LoadObsTheta_stCoefIn.uwFbHz << 10) /
- LoadObsTheta_stCoefIn.uwFTbcHz);
- /* Product: '<S2>/Divide4' incorporates:
- * DataStoreWrite: '<S2>/Data Store Write5'
- */
- LoadObsTheta_stCoef.uwJmPuInv = (uint16_T)(rtb_Divide2 == 0U ? MAX_uint32_T :
- 16384U / rtb_Divide2);
- /* Product: '<S2>/Product3' incorporates:
- * DataStoreWrite: '<S2>/Data Store Write3'
- * DataStoreWrite: '<S2>/Data Store Write7'
- * Product: '<S2>/Divide3'
- */
- LoadObsTheta_stCoef.uwTctrPu = (uint16_T)((LoadObsTheta_stCoef.uwCurTs *
- 3217U) >> 7);
- /* Product: '<S2>/Divide1' incorporates:
- * DataStoreWrite: '<S2>/Data Store Write4'
- * Inport: '<Root>/uwFluxWb'
- * Inport: '<Root>/uwFluxbWb'
- */
- LoadObsTheta_stCoef.uwFluxPu = (uint16_T)(LoadObsTheta_stCoefIn.uwFluxbWb ==
- 0U ? MAX_uint32_T : ((uint32_T)LoadObsTheta_stCoefIn.uwFluxWb << 12) /
- LoadObsTheta_stCoefIn.uwFluxbWb);
- /* Product: '<S2>/Divide5' incorporates:
- * DataStoreWrite: '<S2>/Data Store Write4'
- * DataStoreWrite: '<S2>/Data Store Write6'
- * Product: '<S2>/Divide1'
- */
- LoadObsTheta_stCoef.uwFluxPuInv = (uint16_T)(LoadObsTheta_stCoef.uwFluxPu ==
- 0U ? MAX_uint32_T : 16777216U / LoadObsTheta_stCoef.uwFluxPu);
- /* End of Outputs for SubSystem: '<Root>/Initialize Function2' */
- }
- void LoadObsTheta_voInit(void)
- {
- /* Outputs for Atomic SubSystem: '<Root>/Initialize Function1' */
- /* Outport: '<Root>/swSpdFbkPu' incorporates:
- * Constant: '<S1>/Constant'
- */
- LoadObsTheta_Y.swSpdFbkPu = 0;
- /* Outport: '<Root>/uwThetaObsPu' incorporates:
- * Constant: '<S1>/Constant1'
- */
- LoadObsTheta_Y.uwThetaObsPu = 0U;
- /* Outport: '<Root>/swTLPu' incorporates:
- * Constant: '<S1>/Constant2'
- */
- LoadObsTheta_Y.swTLPu = 0;
- /* Outport: '<Root>/swIqCompPu' incorporates:
- * Constant: '<S1>/Constant3'
- */
- LoadObsTheta_Y.swIqCompPu = 0;
- /* End of Outputs for SubSystem: '<Root>/Initialize Function1' */
- }
- /* Model step function */
- void LoadObsTheta_step(void)
- {
- int32_T rtb_Sum11;
- int16_T rtb_Sum5;
- /* Sum: '<S3>/Sum5' incorporates:
- * Inport: '<Root>/ThetamPu'
- * UnitDelay: '<S3>/Unit Delay4'
- */
- rtb_Sum5 = (int16_T)(((LoadObsTheta_U.ThetamPu << 13) -
- (LoadObsTheta_DW.UnitDelay4_DSTATE >> 1)) >> 13);
- /* Switch: '<S3>/Switch2' incorporates:
- * Constant: '<S3>/Constant2'
- * RelationalOperator: '<S6>/Compare'
- * RelationalOperator: '<S7>/Compare'
- * Sum: '<S3>/Sum1'
- * Sum: '<S3>/Sum5'
- * Switch: '<S3>/Switch3'
- */
- if (rtb_Sum5 >= 16384)
- {
- rtb_Sum5 = (int16_T)(rtb_Sum5 - 32767);
- }
- else if (rtb_Sum5 < -16384)
- {
- /* Switch: '<S3>/Switch2' incorporates:
- * Constant: '<S3>/Constant4'
- * Sum: '<S3>/Sum4'
- * Switch: '<S3>/Switch3'
- */
- rtb_Sum5 = (int16_T)(rtb_Sum5 + 32767);
- }
- /* End of Switch: '<S3>/Switch2' */
- /* Sum: '<S3>/Sum6' incorporates:
- * DataStoreRead: '<S3>/Data Store Read3'
- * Product: '<S3>/Product2'
- * Switch: '<S3>/Switch2'
- * UnitDelay: '<S3>/Unit Delay1'
- */
- LoadObsTheta_DW.UnitDelay1_DSTATE += LoadObsTheta_stCoef.uwK3Pu * rtb_Sum5;
- /* Sum: '<S3>/Sum11' incorporates:
- * DataStoreRead: '<S3>/Data Store Read'
- * DataStoreRead: '<S3>/Data Store Read1'
- * Inport: '<Root>/IqFbkPu'
- * Product: '<S3>/Product1'
- * Product: '<S3>/Product7'
- * Sum: '<S3>/Sum6'
- * Sum: '<S3>/Sum9'
- * Switch: '<S3>/Switch2'
- * UnitDelay: '<S3>/Unit Delay1'
- */
- rtb_Sum11 = (((int16_T)((LoadObsTheta_U.IqFbkPu *
- LoadObsTheta_stCoef.uwFluxPu) >> 14) << 13) +
- LoadObsTheta_stCoef.uwK2Pu * rtb_Sum5) +
- (LoadObsTheta_DW.UnitDelay1_DSTATE >> 5);
- /* Sum: '<S3>/Sum10' incorporates:
- * DataStoreRead: '<S3>/Data Store Read4'
- * DataStoreRead: '<S3>/Data Store Read6'
- * Product: '<S3>/Product4'
- * Product: '<S3>/Product5'
- * Sum: '<S3>/Sum11'
- * UnitDelay: '<S3>/Unit Delay2'
- */
- LoadObsTheta_DW.UnitDelay2_DSTATE += (int32_T)(((int64_T)
- LoadObsTheta_stCoef.uwJmPuInv * rtb_Sum11 * LoadObsTheta_stCoef.uwTctrPu)
- >> 22);
- /* Saturate: '<S3>/Saturation' incorporates:
- * Sum: '<S3>/Sum10'
- * UnitDelay: '<S3>/Unit Delay2'
- */
- if (LoadObsTheta_DW.UnitDelay2_DSTATE > 536870912)
- {
- /* Outport: '<Root>/swSpdFbkPu' incorporates:
- * DataTypeConversion: '<S3>/Data Type Conversion2'
- */
- LoadObsTheta_Y.swSpdFbkPu = MIN_int16_T;
- }
- else if (LoadObsTheta_DW.UnitDelay2_DSTATE < -536870912)
- {
- /* Outport: '<Root>/swSpdFbkPu' incorporates:
- * DataTypeConversion: '<S3>/Data Type Conversion2'
- */
- LoadObsTheta_Y.swSpdFbkPu = MIN_int16_T;
- }
- else
- {
- /* Outport: '<Root>/swSpdFbkPu' incorporates:
- * DataTypeConversion: '<S3>/Data Type Conversion2'
- */
- LoadObsTheta_Y.swSpdFbkPu = (int16_T)(LoadObsTheta_DW.UnitDelay2_DSTATE >>
- 14);
- }
- /* End of Saturate: '<S3>/Saturation' */
- /* Sum: '<S3>/Sum8' incorporates:
- * DataStoreRead: '<S3>/Data Store Read5'
- * DataStoreRead: '<S3>/Data Store Read8'
- * Product: '<S3>/Product3'
- * Product: '<S3>/Product6'
- * Sum: '<S3>/Sum10'
- * Sum: '<S3>/Sum7'
- * Switch: '<S3>/Switch2'
- * UnitDelay: '<S3>/Unit Delay2'
- * UnitDelay: '<S3>/Unit Delay3'
- */
- LoadObsTheta_DW.UnitDelay3_DSTATE += (int32_T)(((int64_T)
- (((LoadObsTheta_stCoef.uwK1Pu * rtb_Sum5) >> 1) +
- LoadObsTheta_DW.UnitDelay2_DSTATE) * LoadObsTheta_stCoef.uwCurTs) >> 10);
- /* Switch: '<S3>/Switch' incorporates:
- * Constant: '<S3>/Constant1'
- * RelationalOperator: '<S4>/Compare'
- * RelationalOperator: '<S5>/Compare'
- * Sum: '<S3>/Sum2'
- * Sum: '<S3>/Sum8'
- * Switch: '<S3>/Switch1'
- */
- if (LoadObsTheta_DW.UnitDelay3_DSTATE >= 536870912)
- {
- LoadObsTheta_DW.UnitDelay3_DSTATE -= 536870912;
- }
- else if (LoadObsTheta_DW.UnitDelay3_DSTATE < 0)
- {
- /* Switch: '<S3>/Switch' incorporates:
- * Constant: '<S3>/Constant3'
- * Sum: '<S3>/Sum3'
- * Switch: '<S3>/Switch1'
- * UnitDelay: '<S3>/Unit Delay3'
- */
- LoadObsTheta_DW.UnitDelay3_DSTATE += 536870912;
- }
- /* End of Switch: '<S3>/Switch' */
- /* Outport: '<Root>/uwThetaObsPu' incorporates:
- * DataTypeConversion: '<S3>/Data Type Conversion1'
- * Switch: '<S3>/Switch'
- * UnitDelay: '<S3>/Unit Delay3'
- */
- LoadObsTheta_Y.uwThetaObsPu = (uint16_T)(LoadObsTheta_DW.UnitDelay3_DSTATE >>
- 14);
- /* Outport: '<Root>/swTLPu' incorporates:
- * DataTypeConversion: '<S3>/Data Type Conversion3'
- * Sum: '<S3>/Sum6'
- * UnitDelay: '<S3>/Unit Delay1'
- */
- LoadObsTheta_Y.swTLPu = (int16_T)(LoadObsTheta_DW.UnitDelay1_DSTATE >> 18);
- /* Outport: '<Root>/swIqCompPu' incorporates:
- * DataStoreRead: '<S3>/Data Store Read2'
- * Product: '<S3>/Product8'
- * Sum: '<S3>/Sum11'
- */
- LoadObsTheta_Y.swIqCompPu = (int16_T)(((int64_T)
- LoadObsTheta_stCoef.uwFluxPuInv * rtb_Sum11) >> 23);
- /* Update for UnitDelay: '<S3>/Unit Delay4' incorporates:
- * Switch: '<S3>/Switch'
- * UnitDelay: '<S3>/Unit Delay3'
- */
- LoadObsTheta_DW.UnitDelay4_DSTATE = LoadObsTheta_DW.UnitDelay3_DSTATE;
- }
- /* Model initialize function */
- void LoadObsTheta_initialize(void)
- {
- /* (no initialization code required) */
- }
- /* Model terminate function */
- void LoadObsTheta_terminate(void)
- {
- /* (no terminate code required) */
- }
- /*
- * File trailer for generated code.
- *
- * [EOF]
- */
|