LoadObsTheta.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /*
  2. * File: LoadObsTheta.c
  3. *
  4. * Code generated for Simulink model 'LoadObsTheta'.
  5. *
  6. * Model version : 8.72
  7. * Simulink Coder version : 9.6 (R2021b) 14-May-2021
  8. * C/C++ source code generated on : Sat Nov 5 15:46:39 2022
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: ARM Compatible->ARM Cortex-M
  12. * Code generation objectives: Unspecified
  13. * Validation result: Not run
  14. */
  15. #include "LoadObsTheta.h"
  16. #ifndef UCHAR_MAX
  17. #include <limits.h>
  18. #endif
  19. #if ( UCHAR_MAX != (0xFFU) ) || ( SCHAR_MAX != (0x7F) )
  20. #error Code was generated for compiler with different sized uchar/char. \
  21. Consider adjusting Test hardware word size settings on the \
  22. Hardware Implementation pane to match your compiler word sizes as \
  23. defined in limits.h of the compiler. Alternatively, you can \
  24. select the Test hardware is the same as production hardware option and \
  25. select the Enable portable word sizes option on the Code Generation > \
  26. Verification pane for ERT based targets, which will disable the \
  27. preprocessor word size checks.
  28. #endif
  29. #if ( USHRT_MAX != (0xFFFFU) ) || ( SHRT_MAX != (0x7FFF) )
  30. #error Code was generated for compiler with different sized ushort/short. \
  31. Consider adjusting Test hardware word size settings on the \
  32. Hardware Implementation pane to match your compiler word sizes as \
  33. defined in limits.h of the compiler. Alternatively, you can \
  34. select the Test hardware is the same as production hardware option and \
  35. select the Enable portable word sizes option on the Code Generation > \
  36. Verification pane for ERT based targets, which will disable the \
  37. preprocessor word size checks.
  38. #endif
  39. #if ( UINT_MAX != (0xFFFFFFFFU) ) || ( INT_MAX != (0x7FFFFFFF) )
  40. #error Code was generated for compiler with different sized uint/int. \
  41. Consider adjusting Test hardware word size settings on the \
  42. Hardware Implementation pane to match your compiler word sizes as \
  43. defined in limits.h of the compiler. Alternatively, you can \
  44. select the Test hardware is the same as production hardware option and \
  45. select the Enable portable word sizes option on the Code Generation > \
  46. Verification pane for ERT based targets, which will disable the \
  47. preprocessor word size checks.
  48. #endif
  49. #if ( ULONG_MAX != (0xFFFFFFFFU) ) || ( LONG_MAX != (0x7FFFFFFF) )
  50. #error Code was generated for compiler with different sized ulong/long. \
  51. Consider adjusting Test hardware word size settings on the \
  52. Hardware Implementation pane to match your compiler word sizes as \
  53. defined in limits.h of the compiler. Alternatively, you can \
  54. select the Test hardware is the same as production hardware option and \
  55. select the Enable portable word sizes option on the Code Generation > \
  56. Verification pane for ERT based targets, which will disable the \
  57. preprocessor word size checks.
  58. #endif
  59. /* Skipping ulong_long/long_long check: insufficient preprocessor integer range. */
  60. /* Exported data definition */
  61. /* Definition for custom storage class: Struct */
  62. LoadObsTheta_stCoef_type LoadObsTheta_stCoef;
  63. LoadObsTheta_stCoefIn_type LoadObsTheta_stCoefIn;
  64. /* Block states (default storage) */
  65. DW_LoadObsTheta_T LoadObsTheta_DW;
  66. /* External inputs (root inport signals with default storage) */
  67. ExtU_LoadObsTheta_T LoadObsTheta_U;
  68. /* External outputs (root outports fed by signals with default storage) */
  69. ExtY_LoadObsTheta_T LoadObsTheta_Y;
  70. void LoadObsTheta_voCoef(void)
  71. {
  72. uint16_T rtb_Divide2;
  73. /* Outputs for Atomic SubSystem: '<Root>/Initialize Function2' */
  74. /* Product: '<S2>/Divide' incorporates:
  75. * DataStoreWrite: '<S2>/Data Store Write'
  76. * Inport: '<Root>/uwFbHz'
  77. * Inport: '<Root>/uwWtcHz'
  78. */
  79. LoadObsTheta_stCoef.uwK1Pu = (uint16_T)(LoadObsTheta_stCoefIn.uwFbHz == 0U ?
  80. MAX_uint32_T : ((uint32_T)LoadObsTheta_stCoefIn.uwWtcHz << 15) /
  81. LoadObsTheta_stCoefIn.uwFbHz);
  82. /* Product: '<S2>/Divide2' incorporates:
  83. * Gain: '<S2>/Gain'
  84. * Inport: '<Root>/uwJb'
  85. * Inport: '<Root>/uwMtJm'
  86. */
  87. rtb_Divide2 = (uint16_T)(LoadObsTheta_stCoefIn.uwJb == 0U ? MAX_uint32_T :
  88. 1000U * LoadObsTheta_stCoefIn.uwMtJm / LoadObsTheta_stCoefIn.uwJb);
  89. /* Product: '<S2>/Product6' incorporates:
  90. * DataStoreWrite: '<S2>/Data Store Write'
  91. * DataStoreWrite: '<S2>/Data Store Write1'
  92. * Product: '<S2>/Divide'
  93. * Product: '<S2>/Product'
  94. */
  95. LoadObsTheta_stCoef.uwK2Pu = (uint16_T)(((uint64_T)(((uint32_T)
  96. LoadObsTheta_stCoef.uwK1Pu * LoadObsTheta_stCoef.uwK1Pu) >> 1) *
  97. rtb_Divide2) >> 19);
  98. /* Product: '<S2>/Divide6' incorporates:
  99. * DataStoreRead: '<S2>/Data Store Read'
  100. * DataStoreWrite: '<S2>/Data Store Write'
  101. * DataStoreWrite: '<S2>/Data Store Write2'
  102. * Inport: '<Root>/uwMCoef'
  103. * Product: '<S2>/Divide'
  104. * Product: '<S2>/Product1'
  105. * Product: '<S2>/Product2'
  106. * Product: '<S2>/Product4'
  107. * Product: '<S2>/Product5'
  108. */
  109. LoadObsTheta_stCoef.uwK3Pu = (uint16_T)(LoadObsTheta_stCoefIn.uwMCoef == 0U ?
  110. MAX_uint32_T : (uint32_T)(uint16_T)(((uint64_T)(uint32_T)(((uint64_T)
  111. (uint32_T)(((uint64_T)(((uint32_T)LoadObsTheta_stCoef.uwK1Pu *
  112. LoadObsTheta_stCoef.uwK1Pu) >> 1) * LoadObsTheta_stCoef.uwK1Pu) >> 14) *
  113. rtb_Divide2) >> 6) * LoadObsTheta_stCoef.uwTctrPu) >> 21) /
  114. LoadObsTheta_stCoefIn.uwMCoef);
  115. /* Product: '<S2>/Divide3' incorporates:
  116. * DataStoreWrite: '<S2>/Data Store Write3'
  117. * Inport: '<Root>/uwFTbcHz'
  118. * Inport: '<Root>/uwFbHz'
  119. */
  120. LoadObsTheta_stCoef.uwCurTs = (uint16_T)(LoadObsTheta_stCoefIn.uwFTbcHz ==
  121. 0U ? MAX_uint32_T : ((uint32_T)LoadObsTheta_stCoefIn.uwFbHz << 10) /
  122. LoadObsTheta_stCoefIn.uwFTbcHz);
  123. /* Product: '<S2>/Divide4' incorporates:
  124. * DataStoreWrite: '<S2>/Data Store Write5'
  125. */
  126. LoadObsTheta_stCoef.uwJmPuInv = (uint16_T)(rtb_Divide2 == 0U ? MAX_uint32_T :
  127. 16384U / rtb_Divide2);
  128. /* Product: '<S2>/Product3' incorporates:
  129. * DataStoreWrite: '<S2>/Data Store Write3'
  130. * DataStoreWrite: '<S2>/Data Store Write7'
  131. * Product: '<S2>/Divide3'
  132. */
  133. LoadObsTheta_stCoef.uwTctrPu = (uint16_T)((LoadObsTheta_stCoef.uwCurTs *
  134. 3217U) >> 7);
  135. /* Product: '<S2>/Divide1' incorporates:
  136. * DataStoreWrite: '<S2>/Data Store Write4'
  137. * Inport: '<Root>/uwFluxWb'
  138. * Inport: '<Root>/uwFluxbWb'
  139. */
  140. LoadObsTheta_stCoef.uwFluxPu = (uint16_T)(LoadObsTheta_stCoefIn.uwFluxbWb ==
  141. 0U ? MAX_uint32_T : ((uint32_T)LoadObsTheta_stCoefIn.uwFluxWb << 12) /
  142. LoadObsTheta_stCoefIn.uwFluxbWb);
  143. /* Product: '<S2>/Divide5' incorporates:
  144. * DataStoreWrite: '<S2>/Data Store Write4'
  145. * DataStoreWrite: '<S2>/Data Store Write6'
  146. * Product: '<S2>/Divide1'
  147. */
  148. LoadObsTheta_stCoef.uwFluxPuInv = (uint16_T)(LoadObsTheta_stCoef.uwFluxPu ==
  149. 0U ? MAX_uint32_T : 16777216U / LoadObsTheta_stCoef.uwFluxPu);
  150. /* End of Outputs for SubSystem: '<Root>/Initialize Function2' */
  151. }
  152. void LoadObsTheta_voInit(void)
  153. {
  154. /* Outputs for Atomic SubSystem: '<Root>/Initialize Function1' */
  155. /* Outport: '<Root>/swSpdFbkPu' incorporates:
  156. * Constant: '<S1>/Constant'
  157. */
  158. LoadObsTheta_Y.swSpdFbkPu = 0;
  159. /* Outport: '<Root>/uwThetaObsPu' incorporates:
  160. * Constant: '<S1>/Constant1'
  161. */
  162. LoadObsTheta_Y.uwThetaObsPu = 0U;
  163. /* Outport: '<Root>/swTLPu' incorporates:
  164. * Constant: '<S1>/Constant2'
  165. */
  166. LoadObsTheta_Y.swTLPu = 0;
  167. /* Outport: '<Root>/swIqCompPu' incorporates:
  168. * Constant: '<S1>/Constant3'
  169. */
  170. LoadObsTheta_Y.swIqCompPu = 0;
  171. /* End of Outputs for SubSystem: '<Root>/Initialize Function1' */
  172. }
  173. /* Model step function */
  174. void LoadObsTheta_step(void)
  175. {
  176. int32_T rtb_Sum11;
  177. int16_T rtb_Sum5;
  178. /* Sum: '<S3>/Sum5' incorporates:
  179. * Inport: '<Root>/ThetamPu'
  180. * UnitDelay: '<S3>/Unit Delay4'
  181. */
  182. rtb_Sum5 = (int16_T)(((LoadObsTheta_U.ThetamPu << 13) -
  183. (LoadObsTheta_DW.UnitDelay4_DSTATE >> 1)) >> 13);
  184. /* Switch: '<S3>/Switch2' incorporates:
  185. * Constant: '<S3>/Constant2'
  186. * RelationalOperator: '<S6>/Compare'
  187. * RelationalOperator: '<S7>/Compare'
  188. * Sum: '<S3>/Sum1'
  189. * Sum: '<S3>/Sum5'
  190. * Switch: '<S3>/Switch3'
  191. */
  192. if (rtb_Sum5 >= 16384)
  193. {
  194. rtb_Sum5 = (int16_T)(rtb_Sum5 - 32767);
  195. }
  196. else if (rtb_Sum5 < -16384)
  197. {
  198. /* Switch: '<S3>/Switch2' incorporates:
  199. * Constant: '<S3>/Constant4'
  200. * Sum: '<S3>/Sum4'
  201. * Switch: '<S3>/Switch3'
  202. */
  203. rtb_Sum5 = (int16_T)(rtb_Sum5 + 32767);
  204. }
  205. /* End of Switch: '<S3>/Switch2' */
  206. /* Sum: '<S3>/Sum6' incorporates:
  207. * DataStoreRead: '<S3>/Data Store Read3'
  208. * Product: '<S3>/Product2'
  209. * Switch: '<S3>/Switch2'
  210. * UnitDelay: '<S3>/Unit Delay1'
  211. */
  212. LoadObsTheta_DW.UnitDelay1_DSTATE += LoadObsTheta_stCoef.uwK3Pu * rtb_Sum5;
  213. /* Sum: '<S3>/Sum11' incorporates:
  214. * DataStoreRead: '<S3>/Data Store Read'
  215. * DataStoreRead: '<S3>/Data Store Read1'
  216. * Inport: '<Root>/IqFbkPu'
  217. * Product: '<S3>/Product1'
  218. * Product: '<S3>/Product7'
  219. * Sum: '<S3>/Sum6'
  220. * Sum: '<S3>/Sum9'
  221. * Switch: '<S3>/Switch2'
  222. * UnitDelay: '<S3>/Unit Delay1'
  223. */
  224. rtb_Sum11 = (((int16_T)((LoadObsTheta_U.IqFbkPu *
  225. LoadObsTheta_stCoef.uwFluxPu) >> 14) << 13) +
  226. LoadObsTheta_stCoef.uwK2Pu * rtb_Sum5) +
  227. (LoadObsTheta_DW.UnitDelay1_DSTATE >> 5);
  228. /* Sum: '<S3>/Sum10' incorporates:
  229. * DataStoreRead: '<S3>/Data Store Read4'
  230. * DataStoreRead: '<S3>/Data Store Read6'
  231. * Product: '<S3>/Product4'
  232. * Product: '<S3>/Product5'
  233. * Sum: '<S3>/Sum11'
  234. * UnitDelay: '<S3>/Unit Delay2'
  235. */
  236. LoadObsTheta_DW.UnitDelay2_DSTATE += (int32_T)(((int64_T)
  237. LoadObsTheta_stCoef.uwJmPuInv * rtb_Sum11 * LoadObsTheta_stCoef.uwTctrPu)
  238. >> 22);
  239. /* Saturate: '<S3>/Saturation' incorporates:
  240. * Sum: '<S3>/Sum10'
  241. * UnitDelay: '<S3>/Unit Delay2'
  242. */
  243. if (LoadObsTheta_DW.UnitDelay2_DSTATE > 536870912)
  244. {
  245. /* Outport: '<Root>/swSpdFbkPu' incorporates:
  246. * DataTypeConversion: '<S3>/Data Type Conversion2'
  247. */
  248. LoadObsTheta_Y.swSpdFbkPu = MIN_int16_T;
  249. }
  250. else if (LoadObsTheta_DW.UnitDelay2_DSTATE < -536870912)
  251. {
  252. /* Outport: '<Root>/swSpdFbkPu' incorporates:
  253. * DataTypeConversion: '<S3>/Data Type Conversion2'
  254. */
  255. LoadObsTheta_Y.swSpdFbkPu = MIN_int16_T;
  256. }
  257. else
  258. {
  259. /* Outport: '<Root>/swSpdFbkPu' incorporates:
  260. * DataTypeConversion: '<S3>/Data Type Conversion2'
  261. */
  262. LoadObsTheta_Y.swSpdFbkPu = (int16_T)(LoadObsTheta_DW.UnitDelay2_DSTATE >>
  263. 14);
  264. }
  265. /* End of Saturate: '<S3>/Saturation' */
  266. /* Sum: '<S3>/Sum8' incorporates:
  267. * DataStoreRead: '<S3>/Data Store Read5'
  268. * DataStoreRead: '<S3>/Data Store Read8'
  269. * Product: '<S3>/Product3'
  270. * Product: '<S3>/Product6'
  271. * Sum: '<S3>/Sum10'
  272. * Sum: '<S3>/Sum7'
  273. * Switch: '<S3>/Switch2'
  274. * UnitDelay: '<S3>/Unit Delay2'
  275. * UnitDelay: '<S3>/Unit Delay3'
  276. */
  277. LoadObsTheta_DW.UnitDelay3_DSTATE += (int32_T)(((int64_T)
  278. (((LoadObsTheta_stCoef.uwK1Pu * rtb_Sum5) >> 1) +
  279. LoadObsTheta_DW.UnitDelay2_DSTATE) * LoadObsTheta_stCoef.uwCurTs) >> 10);
  280. /* Switch: '<S3>/Switch' incorporates:
  281. * Constant: '<S3>/Constant1'
  282. * RelationalOperator: '<S4>/Compare'
  283. * RelationalOperator: '<S5>/Compare'
  284. * Sum: '<S3>/Sum2'
  285. * Sum: '<S3>/Sum8'
  286. * Switch: '<S3>/Switch1'
  287. */
  288. if (LoadObsTheta_DW.UnitDelay3_DSTATE >= 536870912)
  289. {
  290. LoadObsTheta_DW.UnitDelay3_DSTATE -= 536870912;
  291. }
  292. else if (LoadObsTheta_DW.UnitDelay3_DSTATE < 0)
  293. {
  294. /* Switch: '<S3>/Switch' incorporates:
  295. * Constant: '<S3>/Constant3'
  296. * Sum: '<S3>/Sum3'
  297. * Switch: '<S3>/Switch1'
  298. * UnitDelay: '<S3>/Unit Delay3'
  299. */
  300. LoadObsTheta_DW.UnitDelay3_DSTATE += 536870912;
  301. }
  302. /* End of Switch: '<S3>/Switch' */
  303. /* Outport: '<Root>/uwThetaObsPu' incorporates:
  304. * DataTypeConversion: '<S3>/Data Type Conversion1'
  305. * Switch: '<S3>/Switch'
  306. * UnitDelay: '<S3>/Unit Delay3'
  307. */
  308. LoadObsTheta_Y.uwThetaObsPu = (uint16_T)(LoadObsTheta_DW.UnitDelay3_DSTATE >>
  309. 14);
  310. /* Outport: '<Root>/swTLPu' incorporates:
  311. * DataTypeConversion: '<S3>/Data Type Conversion3'
  312. * Sum: '<S3>/Sum6'
  313. * UnitDelay: '<S3>/Unit Delay1'
  314. */
  315. LoadObsTheta_Y.swTLPu = (int16_T)(LoadObsTheta_DW.UnitDelay1_DSTATE >> 18);
  316. /* Outport: '<Root>/swIqCompPu' incorporates:
  317. * DataStoreRead: '<S3>/Data Store Read2'
  318. * Product: '<S3>/Product8'
  319. * Sum: '<S3>/Sum11'
  320. */
  321. LoadObsTheta_Y.swIqCompPu = (int16_T)(((int64_T)
  322. LoadObsTheta_stCoef.uwFluxPuInv * rtb_Sum11) >> 23);
  323. /* Update for UnitDelay: '<S3>/Unit Delay4' incorporates:
  324. * Switch: '<S3>/Switch'
  325. * UnitDelay: '<S3>/Unit Delay3'
  326. */
  327. LoadObsTheta_DW.UnitDelay4_DSTATE = LoadObsTheta_DW.UnitDelay3_DSTATE;
  328. }
  329. /* Model initialize function */
  330. void LoadObsTheta_initialize(void)
  331. {
  332. /* (no initialization code required) */
  333. }
  334. /* Model terminate function */
  335. void LoadObsTheta_terminate(void)
  336. {
  337. /* (no terminate code required) */
  338. }
  339. /*
  340. * File trailer for generated code.
  341. *
  342. * [EOF]
  343. */