PMSM_Controller.c 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496
  1. /*
  2. * File: PMSM_Controller.c
  3. *
  4. * Code generated for Simulink model 'PMSM_Controller'.
  5. *
  6. * Model version : 1.1301
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C/C++ source code generated on : Mon Apr 18 19:32:18 2022
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: ARM Compatible->ARM Cortex-M
  12. * Code generation objectives:
  13. * 1. Execution efficiency
  14. * 2. RAM efficiency
  15. * Validation result: Not run
  16. */
  17. #include "PMSM_Controller.h"
  18. /* Named constants for Chart: '<S4>/Control_Mode_Manager' */
  19. #define IN_ACTIVE ((uint8_T)1U)
  20. #define IN_NO_ACTIVE_CHILD ((uint8_T)0U)
  21. #define IN_OPEN ((uint8_T)2U)
  22. #define IN_SPEED_MODE ((uint8_T)1U)
  23. #define IN_TORQUE_MODE ((uint8_T)2U)
  24. #define OPEN_MODE ((uint8_T)0U)
  25. #define SPD_MODE ((uint8_T)1U)
  26. #define TRQ_MODE ((uint8_T)2U)
  27. #ifndef UCHAR_MAX
  28. #include <limits.h>
  29. #endif
  30. #if ( UCHAR_MAX != (0xFFU) ) || ( SCHAR_MAX != (0x7F) )
  31. #error Code was generated for compiler with different sized uchar/char. \
  32. Consider adjusting Test hardware word size settings on the \
  33. Hardware Implementation pane to match your compiler word sizes as \
  34. defined in limits.h of the compiler. Alternatively, you can \
  35. select the Test hardware is the same as production hardware option and \
  36. select the Enable portable word sizes option on the Code Generation > \
  37. Verification pane for ERT based targets, which will disable the \
  38. preprocessor word size checks.
  39. #endif
  40. #if ( USHRT_MAX != (0xFFFFU) ) || ( SHRT_MAX != (0x7FFF) )
  41. #error Code was generated for compiler with different sized ushort/short. \
  42. Consider adjusting Test hardware word size settings on the \
  43. Hardware Implementation pane to match your compiler word sizes as \
  44. defined in limits.h of the compiler. Alternatively, you can \
  45. select the Test hardware is the same as production hardware option and \
  46. select the Enable portable word sizes option on the Code Generation > \
  47. Verification pane for ERT based targets, which will disable the \
  48. preprocessor word size checks.
  49. #endif
  50. #if ( UINT_MAX != (0xFFFFFFFFU) ) || ( INT_MAX != (0x7FFFFFFF) )
  51. #error Code was generated for compiler with different sized uint/int. \
  52. Consider adjusting Test hardware word size settings on the \
  53. Hardware Implementation pane to match your compiler word sizes as \
  54. defined in limits.h of the compiler. Alternatively, you can \
  55. select the Test hardware is the same as production hardware option and \
  56. select the Enable portable word sizes option on the Code Generation > \
  57. Verification pane for ERT based targets, which will disable the \
  58. preprocessor word size checks.
  59. #endif
  60. #if ( ULONG_MAX != (0xFFFFFFFFU) ) || ( LONG_MAX != (0x7FFFFFFF) )
  61. #error Code was generated for compiler with different sized ulong/long. \
  62. Consider adjusting Test hardware word size settings on the \
  63. Hardware Implementation pane to match your compiler word sizes as \
  64. defined in limits.h of the compiler. Alternatively, you can \
  65. select the Test hardware is the same as production hardware option and \
  66. select the Enable portable word sizes option on the Code Generation > \
  67. Verification pane for ERT based targets, which will disable the \
  68. preprocessor word size checks.
  69. #endif
  70. /* Skipping ulong_long/long_long check: insufficient preprocessor integer range. */
  71. extern int16_T rt_sqrt_Us16En12_Ys16E_cQn1iwAF(int16_T u);
  72. static uint16_T plook_u16s16_evencka(int16_T u, int16_T bp0, uint16_T bpSpace,
  73. uint32_T maxIndex);
  74. static void Counter_Init(DW_Counter *localDW, uint16_T rtp_z_cntInit);
  75. static uint16_T Counter(uint16_T rtu_inc, uint16_T rtu_max, boolean_T rtu_rst,
  76. DW_Counter *localDW);
  77. static boolean_T either_edge(boolean_T rtu_u, DW_either_edge *localDW);
  78. static void Debounce_Filter_Init(DW_Debounce_Filter *localDW);
  79. static void Debounce_Filter(boolean_T rtu_u, uint16_T rtu_tAcv, uint16_T
  80. rtu_tDeacv, boolean_T *rty_y, DW_Debounce_Filter *localDW);
  81. static void Low_Pass_Filter(const int16_T rtu_u[2], uint16_T rtu_coef, int16_T
  82. rty_y[2], DW_Low_Pass_Filter *localDW);
  83. static void PI_backCalc_fixdt_Init(DW_PI_backCalc_fixdt *localDW);
  84. static void PI_backCalc_fixdt(int16_T rtu_err, int16_T rtu_P, int16_T rtu_I,
  85. int16_T rtu_Kb, int16_T rtu_satMax, int16_T rtu_satMin, int16_T
  86. rtu_ext_limProt, uint8_T rtu_reset, int16_T *rty_pi_out, const
  87. ConstB_PI_backCalc_fixdt *localC, DW_PI_backCalc_fixdt *localDW,
  88. ZCE_PI_backCalc_fixdt *localZCE);
  89. static void pi_speed_Init(DW_pi_speed *localDW);
  90. static int16_T pi_speed(int16_T rtu_err, int16_T rtu_P, int16_T rtu_I, int16_T
  91. rtu_Kb, int16_T rtu_satMax, int16_T rtu_satMin, int16_T rtu_ext_limProt,
  92. int16_T rtu_init, uint8_T rtu_reset, DW_pi_speed *localDW, ZCE_pi_speed
  93. *localZCE);
  94. static uint16_T plook_u16s16_evencka(int16_T u, int16_T bp0, uint16_T bpSpace,
  95. uint32_T maxIndex)
  96. {
  97. uint16_T bpIndex;
  98. /* Prelookup - Index only
  99. Index Search method: 'even'
  100. Extrapolation method: 'Clip'
  101. Use previous index: 'off'
  102. Use last breakpoint for index at or above upper limit: 'on'
  103. Remove protection against out-of-range input in generated code: 'off'
  104. */
  105. if (u <= bp0) {
  106. bpIndex = 0U;
  107. } else {
  108. bpIndex = (uint16_T)((uint32_T)(uint16_T)(u - bp0) / bpSpace);
  109. if (bpIndex < maxIndex) {
  110. } else {
  111. bpIndex = (uint16_T)maxIndex;
  112. }
  113. }
  114. return bpIndex;
  115. }
  116. /*
  117. * System initialize for atomic system:
  118. * '<S40>/Counter'
  119. * '<S39>/Counter'
  120. */
  121. static void Counter_Init(DW_Counter *localDW, uint16_T rtp_z_cntInit)
  122. {
  123. /* InitializeConditions for UnitDelay: '<S45>/UnitDelay' */
  124. localDW->UnitDelay_DSTATE = rtp_z_cntInit;
  125. }
  126. /*
  127. * Output and update for atomic system:
  128. * '<S40>/Counter'
  129. * '<S39>/Counter'
  130. */
  131. static uint16_T Counter(uint16_T rtu_inc, uint16_T rtu_max, boolean_T rtu_rst,
  132. DW_Counter *localDW)
  133. {
  134. uint16_T rty_cnt_0;
  135. uint16_T rtu_rst_0;
  136. /* Switch: '<S45>/Switch1' incorporates:
  137. * Constant: '<S45>/Constant23'
  138. * UnitDelay: '<S45>/UnitDelay'
  139. */
  140. if (rtu_rst) {
  141. rtu_rst_0 = 0U;
  142. } else {
  143. rtu_rst_0 = localDW->UnitDelay_DSTATE;
  144. }
  145. /* End of Switch: '<S45>/Switch1' */
  146. /* Sum: '<S44>/Sum1' */
  147. rty_cnt_0 = (uint16_T)((uint32_T)rtu_inc + rtu_rst_0);
  148. /* MinMax: '<S44>/MinMax' */
  149. if (rty_cnt_0 < rtu_max) {
  150. /* Update for UnitDelay: '<S45>/UnitDelay' */
  151. localDW->UnitDelay_DSTATE = rty_cnt_0;
  152. } else {
  153. /* Update for UnitDelay: '<S45>/UnitDelay' */
  154. localDW->UnitDelay_DSTATE = rtu_max;
  155. }
  156. /* End of MinMax: '<S44>/MinMax' */
  157. return rty_cnt_0;
  158. }
  159. /*
  160. * Output and update for atomic system:
  161. * '<S36>/either_edge'
  162. * '<S35>/either_edge'
  163. */
  164. static boolean_T either_edge(boolean_T rtu_u, DW_either_edge *localDW)
  165. {
  166. boolean_T rty_y_0;
  167. /* RelationalOperator: '<S41>/Relational Operator' incorporates:
  168. * UnitDelay: '<S41>/UnitDelay'
  169. */
  170. rty_y_0 = (rtu_u != localDW->UnitDelay_DSTATE);
  171. /* Update for UnitDelay: '<S41>/UnitDelay' */
  172. localDW->UnitDelay_DSTATE = rtu_u;
  173. return rty_y_0;
  174. }
  175. /* System initialize for atomic system: '<S35>/Debounce_Filter' */
  176. static void Debounce_Filter_Init(DW_Debounce_Filter *localDW)
  177. {
  178. /* SystemInitialize for IfAction SubSystem: '<S36>/Qualification' */
  179. /* SystemInitialize for Atomic SubSystem: '<S40>/Counter' */
  180. Counter_Init(&localDW->Counter_f, 0);
  181. /* End of SystemInitialize for SubSystem: '<S40>/Counter' */
  182. /* End of SystemInitialize for SubSystem: '<S36>/Qualification' */
  183. /* SystemInitialize for IfAction SubSystem: '<S36>/Dequalification' */
  184. /* SystemInitialize for Atomic SubSystem: '<S39>/Counter' */
  185. Counter_Init(&localDW->Counter_d, 0);
  186. /* End of SystemInitialize for SubSystem: '<S39>/Counter' */
  187. /* End of SystemInitialize for SubSystem: '<S36>/Dequalification' */
  188. }
  189. /* Output and update for atomic system: '<S35>/Debounce_Filter' */
  190. static void Debounce_Filter(boolean_T rtu_u, uint16_T rtu_tAcv, uint16_T
  191. rtu_tDeacv, boolean_T *rty_y, DW_Debounce_Filter *localDW)
  192. {
  193. uint16_T rtb_Sum1_jb;
  194. boolean_T rtb_RelationalOperator_e;
  195. /* Outputs for Atomic SubSystem: '<S36>/either_edge' */
  196. rtb_RelationalOperator_e = either_edge(rtu_u, &localDW->either_edge_j);
  197. /* End of Outputs for SubSystem: '<S36>/either_edge' */
  198. /* If: '<S36>/If2' incorporates:
  199. * Constant: '<S39>/Constant6'
  200. * Constant: '<S40>/Constant6'
  201. * Inport: '<S38>/yPrev'
  202. * Logic: '<S36>/Logical Operator1'
  203. * Logic: '<S36>/Logical Operator2'
  204. * Logic: '<S36>/Logical Operator3'
  205. * Logic: '<S36>/Logical Operator4'
  206. * UnitDelay: '<S36>/UnitDelay'
  207. */
  208. if (rtu_u && (!localDW->UnitDelay_DSTATE)) {
  209. /* Outputs for IfAction SubSystem: '<S36>/Qualification' incorporates:
  210. * ActionPort: '<S40>/Action Port'
  211. */
  212. /* Outputs for Atomic SubSystem: '<S40>/Counter' */
  213. rtb_Sum1_jb = Counter(1, rtu_tAcv, rtb_RelationalOperator_e,
  214. &localDW->Counter_f);
  215. /* End of Outputs for SubSystem: '<S40>/Counter' */
  216. /* Switch: '<S40>/Switch2' incorporates:
  217. * Constant: '<S40>/Constant6'
  218. * RelationalOperator: '<S40>/Relational Operator2'
  219. */
  220. *rty_y = ((rtb_Sum1_jb > rtu_tAcv) || localDW->UnitDelay_DSTATE);
  221. /* End of Outputs for SubSystem: '<S36>/Qualification' */
  222. } else if ((!rtu_u) && localDW->UnitDelay_DSTATE) {
  223. /* Outputs for IfAction SubSystem: '<S36>/Dequalification' incorporates:
  224. * ActionPort: '<S39>/Action Port'
  225. */
  226. /* Outputs for Atomic SubSystem: '<S39>/Counter' */
  227. rtb_Sum1_jb = Counter(1, rtu_tDeacv, rtb_RelationalOperator_e,
  228. &localDW->Counter_d);
  229. /* End of Outputs for SubSystem: '<S39>/Counter' */
  230. /* Switch: '<S39>/Switch2' incorporates:
  231. * Constant: '<S39>/Constant6'
  232. * RelationalOperator: '<S39>/Relational Operator2'
  233. */
  234. *rty_y = ((rtb_Sum1_jb <= rtu_tDeacv) && localDW->UnitDelay_DSTATE);
  235. /* End of Outputs for SubSystem: '<S36>/Dequalification' */
  236. } else {
  237. /* Outputs for IfAction SubSystem: '<S36>/Default' incorporates:
  238. * ActionPort: '<S38>/Action Port'
  239. */
  240. *rty_y = localDW->UnitDelay_DSTATE;
  241. /* End of Outputs for SubSystem: '<S36>/Default' */
  242. }
  243. /* End of If: '<S36>/If2' */
  244. /* Update for UnitDelay: '<S36>/UnitDelay' */
  245. localDW->UnitDelay_DSTATE = *rty_y;
  246. }
  247. /* Output and update for atomic system: '<S46>/Low_Pass_Filter' */
  248. static void Low_Pass_Filter(const int16_T rtu_u[2], uint16_T rtu_coef, int16_T
  249. rty_y[2], DW_Low_Pass_Filter *localDW)
  250. {
  251. int32_T tmp;
  252. /* Sum: '<S56>/Sum2' incorporates:
  253. * UnitDelay: '<S56>/UnitDelay1'
  254. */
  255. tmp = rtu_u[0] - localDW->UnitDelay1_DSTATE[0];
  256. if (tmp > 32767) {
  257. tmp = 32767;
  258. } else {
  259. if (tmp < -32768) {
  260. tmp = -32768;
  261. }
  262. }
  263. /* Product: '<S56>/Divide3' incorporates:
  264. * Sum: '<S56>/Sum2'
  265. */
  266. rty_y[0] = (int16_T)((rtu_coef * tmp) >> 16);
  267. /* Sum: '<S56>/Sum3' incorporates:
  268. * UnitDelay: '<S56>/UnitDelay1'
  269. */
  270. rty_y[0] += localDW->UnitDelay1_DSTATE[0];
  271. /* Update for UnitDelay: '<S56>/UnitDelay1' incorporates:
  272. * Sum: '<S56>/Sum3'
  273. */
  274. localDW->UnitDelay1_DSTATE[0] = rty_y[0];
  275. /* Sum: '<S56>/Sum2' incorporates:
  276. * UnitDelay: '<S56>/UnitDelay1'
  277. */
  278. tmp = rtu_u[1] - localDW->UnitDelay1_DSTATE[1];
  279. if (tmp > 32767) {
  280. tmp = 32767;
  281. } else {
  282. if (tmp < -32768) {
  283. tmp = -32768;
  284. }
  285. }
  286. /* Product: '<S56>/Divide3' incorporates:
  287. * Sum: '<S56>/Sum2'
  288. */
  289. rty_y[1] = (int16_T)((rtu_coef * tmp) >> 16);
  290. /* Sum: '<S56>/Sum3' incorporates:
  291. * UnitDelay: '<S56>/UnitDelay1'
  292. */
  293. rty_y[1] += localDW->UnitDelay1_DSTATE[1];
  294. /* Update for UnitDelay: '<S56>/UnitDelay1' incorporates:
  295. * Sum: '<S56>/Sum3'
  296. */
  297. localDW->UnitDelay1_DSTATE[1] = rty_y[1];
  298. }
  299. /*
  300. * System initialize for atomic system:
  301. * '<S61>/PI_iq'
  302. * '<S60>/PI_id'
  303. */
  304. static void PI_backCalc_fixdt_Init(DW_PI_backCalc_fixdt *localDW)
  305. {
  306. /* InitializeConditions for Delay: '<S68>/Resettable Delay' */
  307. localDW->icLoad = 1U;
  308. }
  309. /*
  310. * Output and update for atomic system:
  311. * '<S61>/PI_iq'
  312. * '<S60>/PI_id'
  313. */
  314. static void PI_backCalc_fixdt(int16_T rtu_err, int16_T rtu_P, int16_T rtu_I,
  315. int16_T rtu_Kb, int16_T rtu_satMax, int16_T rtu_satMin, int16_T
  316. rtu_ext_limProt, uint8_T rtu_reset, int16_T *rty_pi_out, const
  317. ConstB_PI_backCalc_fixdt *localC, DW_PI_backCalc_fixdt *localDW,
  318. ZCE_PI_backCalc_fixdt *localZCE)
  319. {
  320. int64_T tmp;
  321. int32_T rtb_Divide4_h;
  322. int32_T rtb_Sum1_ae;
  323. /* Product: '<S66>/Divide4' */
  324. rtb_Divide4_h = (rtu_err * rtu_P) >> 6;
  325. /* Delay: '<S68>/Resettable Delay' incorporates:
  326. * DataTypeConversion: '<S68>/Data Type Conversion2'
  327. */
  328. if ((rtu_reset > 0) && (localZCE->ResettableDelay_Reset_ZCE_p != POS_ZCSIG)) {
  329. localDW->icLoad = 1U;
  330. }
  331. localZCE->ResettableDelay_Reset_ZCE_p = (ZCSigState)(rtu_reset > 0);
  332. if (localDW->icLoad != 0) {
  333. localDW->ResettableDelay_DSTATE = localC->DataTypeConversion2;
  334. }
  335. /* Product: '<S66>/Divide1' incorporates:
  336. * Product: '<S66>/Divide4'
  337. */
  338. tmp = ((int64_T)rtb_Divide4_h * rtu_I) >> 10;
  339. if (tmp > 2147483647LL) {
  340. tmp = 2147483647LL;
  341. } else {
  342. if (tmp < -2147483648LL) {
  343. tmp = -2147483648LL;
  344. }
  345. }
  346. /* Sum: '<S66>/Sum2' incorporates:
  347. * Product: '<S66>/Divide1'
  348. * UnitDelay: '<S66>/UnitDelay'
  349. */
  350. tmp = (((int64_T)rtu_ext_limProt << 3) + (int32_T)tmp) +
  351. localDW->UnitDelay_DSTATE;
  352. if (tmp > 2147483647LL) {
  353. tmp = 2147483647LL;
  354. } else {
  355. if (tmp < -2147483648LL) {
  356. tmp = -2147483648LL;
  357. }
  358. }
  359. /* Sum: '<S68>/Sum1' incorporates:
  360. * Delay: '<S68>/Resettable Delay'
  361. * Sum: '<S66>/Sum2'
  362. */
  363. rtb_Sum1_ae = ((int32_T)tmp >> 2) + localDW->ResettableDelay_DSTATE;
  364. /* Sum: '<S66>/Sum6' incorporates:
  365. * DataTypeConversion: '<S68>/Data Type Conversion1'
  366. * Product: '<S66>/Divide4'
  367. * Sum: '<S68>/Sum1'
  368. */
  369. tmp = ((int64_T)(rtb_Sum1_ae >> 2) << 4) + rtb_Divide4_h;
  370. if (tmp > 2147483647LL) {
  371. tmp = 2147483647LL;
  372. } else {
  373. if (tmp < -2147483648LL) {
  374. tmp = -2147483648LL;
  375. }
  376. }
  377. /* Switch: '<S69>/Switch2' incorporates:
  378. * RelationalOperator: '<S69>/LowerRelop1'
  379. * RelationalOperator: '<S69>/UpperRelop'
  380. * Sum: '<S66>/Sum6'
  381. * Switch: '<S69>/Switch'
  382. */
  383. if ((int32_T)tmp > (rtu_satMax << 4)) {
  384. *rty_pi_out = rtu_satMax;
  385. } else if ((int32_T)tmp < (rtu_satMin << 4)) {
  386. /* Switch: '<S69>/Switch' */
  387. *rty_pi_out = rtu_satMin;
  388. } else {
  389. *rty_pi_out = (int16_T)((int32_T)tmp >> 4);
  390. }
  391. /* End of Switch: '<S69>/Switch2' */
  392. /* Update for UnitDelay: '<S66>/UnitDelay' incorporates:
  393. * Product: '<S66>/Divide2'
  394. * Sum: '<S66>/Sum3'
  395. * Sum: '<S66>/Sum6'
  396. */
  397. localDW->UnitDelay_DSTATE = (int32_T)(((int64_T)((*rty_pi_out << 4) - (int32_T)
  398. tmp) * rtu_Kb) >> 10);
  399. /* Update for Delay: '<S68>/Resettable Delay' incorporates:
  400. * Sum: '<S68>/Sum1'
  401. */
  402. localDW->icLoad = 0U;
  403. localDW->ResettableDelay_DSTATE = rtb_Sum1_ae;
  404. }
  405. /* System initialize for atomic system: '<S90>/pi_speed' */
  406. static void pi_speed_Init(DW_pi_speed *localDW)
  407. {
  408. /* InitializeConditions for Delay: '<S94>/Resettable Delay' */
  409. localDW->icLoad = 1U;
  410. }
  411. /* Output and update for atomic system: '<S90>/pi_speed' */
  412. static int16_T pi_speed(int16_T rtu_err, int16_T rtu_P, int16_T rtu_I, int16_T
  413. rtu_Kb, int16_T rtu_satMax, int16_T rtu_satMin, int16_T rtu_ext_limProt,
  414. int16_T rtu_init, uint8_T rtu_reset, DW_pi_speed *localDW, ZCE_pi_speed
  415. *localZCE)
  416. {
  417. int16_T rty_pi_out_0;
  418. int64_T tmp;
  419. int32_T rtb_Divide4_g;
  420. int32_T rtb_Sum1_c;
  421. /* Product: '<S93>/Divide4' */
  422. rtb_Divide4_g = (rtu_err * rtu_P) >> 1;
  423. /* Delay: '<S94>/Resettable Delay' incorporates:
  424. * DataTypeConversion: '<S94>/Data Type Conversion2'
  425. */
  426. if ((rtu_reset > 0) && (localZCE->ResettableDelay_Reset_ZCE != POS_ZCSIG)) {
  427. localDW->icLoad = 1U;
  428. }
  429. localZCE->ResettableDelay_Reset_ZCE = (ZCSigState)(rtu_reset > 0);
  430. if (localDW->icLoad != 0) {
  431. localDW->ResettableDelay_DSTATE = rtu_init << 2;
  432. }
  433. /* Product: '<S93>/Divide1' incorporates:
  434. * Product: '<S93>/Divide4'
  435. */
  436. tmp = ((int64_T)rtb_Divide4_g * rtu_I) >> 10;
  437. if (tmp > 2147483647LL) {
  438. tmp = 2147483647LL;
  439. } else {
  440. if (tmp < -2147483648LL) {
  441. tmp = -2147483648LL;
  442. }
  443. }
  444. /* Sum: '<S93>/Sum2' incorporates:
  445. * Product: '<S93>/Divide1'
  446. * UnitDelay: '<S93>/UnitDelay'
  447. */
  448. tmp = (((int64_T)(int32_T)tmp + rtu_ext_limProt) + ((int64_T)
  449. localDW->UnitDelay_DSTATE << 2)) >> 2;
  450. if (tmp > 2147483647LL) {
  451. tmp = 2147483647LL;
  452. } else {
  453. if (tmp < -2147483648LL) {
  454. tmp = -2147483648LL;
  455. }
  456. }
  457. /* Sum: '<S94>/Sum1' incorporates:
  458. * Delay: '<S94>/Resettable Delay'
  459. * Sum: '<S93>/Sum2'
  460. */
  461. rtb_Sum1_c = (int32_T)tmp + localDW->ResettableDelay_DSTATE;
  462. /* Sum: '<S93>/Sum6' incorporates:
  463. * DataTypeConversion: '<S94>/Data Type Conversion1'
  464. * Product: '<S93>/Divide4'
  465. * Sum: '<S94>/Sum1'
  466. */
  467. tmp = ((int64_T)(rtb_Sum1_c >> 2) << 4) + rtb_Divide4_g;
  468. if (tmp > 2147483647LL) {
  469. tmp = 2147483647LL;
  470. } else {
  471. if (tmp < -2147483648LL) {
  472. tmp = -2147483648LL;
  473. }
  474. }
  475. /* Switch: '<S95>/Switch2' incorporates:
  476. * RelationalOperator: '<S95>/LowerRelop1'
  477. * RelationalOperator: '<S95>/UpperRelop'
  478. * Sum: '<S93>/Sum6'
  479. * Switch: '<S95>/Switch'
  480. */
  481. if ((int32_T)tmp > (rtu_satMax << 4)) {
  482. rty_pi_out_0 = rtu_satMax;
  483. } else if ((int32_T)tmp < (rtu_satMin << 4)) {
  484. /* Switch: '<S95>/Switch' */
  485. rty_pi_out_0 = rtu_satMin;
  486. } else {
  487. rty_pi_out_0 = (int16_T)((int32_T)tmp >> 4);
  488. }
  489. /* End of Switch: '<S95>/Switch2' */
  490. /* Update for UnitDelay: '<S93>/UnitDelay' incorporates:
  491. * Product: '<S93>/Divide2'
  492. * Sum: '<S93>/Sum3'
  493. * Sum: '<S93>/Sum6'
  494. */
  495. localDW->UnitDelay_DSTATE = (int32_T)(((int64_T)((rty_pi_out_0 << 4) -
  496. (int32_T)tmp) * rtu_Kb) >> 12);
  497. /* Update for Delay: '<S94>/Resettable Delay' incorporates:
  498. * Sum: '<S94>/Sum1'
  499. */
  500. localDW->icLoad = 0U;
  501. localDW->ResettableDelay_DSTATE = rtb_Sum1_c;
  502. return rty_pi_out_0;
  503. }
  504. int16_T rt_sqrt_Us16En12_Ys16E_cQn1iwAF(int16_T u)
  505. {
  506. int32_T iBit;
  507. int32_T tmp03_u;
  508. int16_T shiftMask;
  509. int16_T tmp01_y;
  510. int16_T y;
  511. /* Fixed-Point Sqrt Computation by the bisection method. */
  512. if (u > 0) {
  513. y = 0;
  514. shiftMask = 16384;
  515. tmp03_u = u << 12;
  516. for (iBit = 0; iBit < 15; iBit++) {
  517. tmp01_y = (int16_T)(y | shiftMask);
  518. if (tmp01_y * tmp01_y <= tmp03_u) {
  519. y = tmp01_y;
  520. }
  521. shiftMask = (int16_T)((uint32_T)shiftMask >> 1U);
  522. }
  523. } else {
  524. y = 0;
  525. }
  526. return y;
  527. }
  528. /* Model step function */
  529. void PMSM_Controller_step(RT_MODEL *const rtM)
  530. {
  531. DW *rtDW = rtM->dwork;
  532. PrevZCX *rtPrevZCX = rtM->prevZCSigState;
  533. ExtU *rtU = (ExtU *) rtM->inputs;
  534. ExtY *rtY = (ExtY *) rtM->outputs;
  535. int64_T tmp;
  536. int32_T rtb_Gain;
  537. int32_T tmp_0;
  538. int32_T tmp_1;
  539. int32_T tmp_2;
  540. uint32_T qY;
  541. uint32_T tmp_3;
  542. int16_T rtb_DataTypeConversion[2];
  543. int16_T rtb_TmpSignalConversionAtLow_Pa[2];
  544. int16_T rtb_Divide1_m;
  545. int16_T rtb_Sign;
  546. int16_T rtb_Switch2_l;
  547. int16_T rtb_Switch3_c;
  548. int16_T rtb_Switch_np;
  549. uint16_T rtb_Abs2;
  550. uint16_T rtb_LogicalOperator3;
  551. uint16_T rtb_Switch2;
  552. int8_T UnitDelay3;
  553. int8_T rtb_Sum2;
  554. int8_T rtb_Sum2_tmp;
  555. uint8_T rtb_Add_cr;
  556. uint8_T rtb_DataTypeConversion_m;
  557. uint8_T rtb_Sum;
  558. uint8_T rtb_UnitDelay_bc;
  559. uint8_T rtb_z_ctrlMod;
  560. boolean_T rtb_Equal_k;
  561. boolean_T rtb_LogicalOperator2;
  562. boolean_T rtb_LogicalOperator4;
  563. boolean_T rtb_LogicalOperator_p;
  564. boolean_T rtb_RelationalOperator4_f;
  565. boolean_T rtb_n_commDeacv;
  566. /* Outputs for Atomic SubSystem: '<Root>/PMSM_Controller' */
  567. /* Sum: '<S7>/Sum3' incorporates:
  568. * UnitDelay: '<S7>/UnitDelay1'
  569. */
  570. qY = rtDW->UnitDelay1_DSTATE + /*MW:OvSatOk*/ 1U;
  571. if (rtDW->UnitDelay1_DSTATE + 1U < 1U) {
  572. qY = MAX_uint32_T;
  573. }
  574. /* RelationalOperator: '<S2>/Equal' incorporates:
  575. * Constant: '<S2>/Constant1'
  576. * Math: '<S2>/Rem'
  577. * Sum: '<S7>/Sum3'
  578. */
  579. rtb_Equal_k = (qY % 20U == 0U);
  580. /* Logic: '<S9>/Edge_Detect' incorporates:
  581. * Delay: '<S9>/Delay'
  582. * Delay: '<S9>/Delay1'
  583. * Delay: '<S9>/Delay2'
  584. * Inport: '<Root>/hall_a'
  585. * Inport: '<Root>/hall_b'
  586. * Inport: '<Root>/hall_c'
  587. */
  588. rtb_LogicalOperator_p = (boolean_T)((rtU->hall_a != 0) ^ (rtDW->Delay_DSTATE
  589. != 0) ^ (rtU->hall_b != 0) ^ (rtDW->Delay1_DSTATE != 0) ^ (rtU->hall_c != 0))
  590. ^ (rtDW->Delay2_DSTATE != 0);
  591. /* Sum: '<S11>/Add' incorporates:
  592. * Gain: '<S11>/Gain'
  593. * Gain: '<S11>/Gain1'
  594. * Inport: '<Root>/hall_a'
  595. * Inport: '<Root>/hall_b'
  596. * Inport: '<Root>/hall_c'
  597. */
  598. rtb_Add_cr = (uint8_T)((uint32_T)(uint8_T)((uint32_T)(uint8_T)(rtU->hall_c <<
  599. 2) + (uint8_T)(rtU->hall_b << 1)) + rtU->hall_a);
  600. /* If: '<S3>/If2' incorporates:
  601. * If: '<S14>/If2'
  602. * Inport: '<S19>/z_counterRawPrev'
  603. * UnitDelay: '<S14>/UnitDelay3'
  604. */
  605. if (rtb_LogicalOperator_p) {
  606. /* Outputs for IfAction SubSystem: '<S3>/Direction_Detection' incorporates:
  607. * ActionPort: '<S8>/Action Port'
  608. */
  609. /* UnitDelay: '<S8>/UnitDelay3' */
  610. UnitDelay3 = rtDW->Switch2_i;
  611. /* End of Outputs for SubSystem: '<S3>/Direction_Detection' */
  612. /* Selector: '<S11>/Selector' incorporates:
  613. * Constant: '<S11>/vec_hallToPos'
  614. */
  615. rtb_Sum2_tmp = rtConstP.vec_hallToPos_Value[rtb_Add_cr];
  616. /* Outputs for IfAction SubSystem: '<S3>/Direction_Detection' incorporates:
  617. * ActionPort: '<S8>/Action Port'
  618. */
  619. /* Sum: '<S8>/Sum2' incorporates:
  620. * Constant: '<S11>/vec_hallToPos'
  621. * Selector: '<S11>/Selector'
  622. * UnitDelay: '<S8>/UnitDelay2'
  623. */
  624. rtb_Sum2 = (int8_T)(rtb_Sum2_tmp - rtDW->UnitDelay2_DSTATE_j);
  625. /* Switch: '<S8>/Switch2' incorporates:
  626. * Constant: '<S8>/Constant20'
  627. * Constant: '<S8>/Constant8'
  628. * Logic: '<S8>/Logical Operator3'
  629. * RelationalOperator: '<S8>/Relational Operator1'
  630. * RelationalOperator: '<S8>/Relational Operator6'
  631. */
  632. if ((rtb_Sum2 == 1) || (rtb_Sum2 == -5)) {
  633. /* Switch: '<S8>/Switch2' incorporates:
  634. * Constant: '<S8>/Constant24'
  635. */
  636. rtDW->Switch2_i = 1;
  637. } else {
  638. /* Switch: '<S8>/Switch2' incorporates:
  639. * Constant: '<S8>/Constant23'
  640. */
  641. rtDW->Switch2_i = -1;
  642. }
  643. /* End of Switch: '<S8>/Switch2' */
  644. /* Update for UnitDelay: '<S8>/UnitDelay2' */
  645. rtDW->UnitDelay2_DSTATE_j = rtb_Sum2_tmp;
  646. /* End of Outputs for SubSystem: '<S3>/Direction_Detection' */
  647. /* Outputs for IfAction SubSystem: '<S14>/Raw_Motor_Speed_Estimation' incorporates:
  648. * ActionPort: '<S19>/Action Port'
  649. */
  650. /* RelationalOperator: '<S19>/Relational Operator4' */
  651. rtb_RelationalOperator4_f = (rtDW->Switch2_i != UnitDelay3);
  652. rtDW->z_counterRawPrev = rtDW->UnitDelay3_DSTATE;
  653. /* Switch: '<S19>/Switch3' incorporates:
  654. * Constant: '<S19>/Constant4'
  655. * Inport: '<S19>/z_counterRawPrev'
  656. * Logic: '<S19>/Logical Operator1'
  657. * Switch: '<S19>/Switch2'
  658. * UnitDelay: '<S14>/UnitDelay3'
  659. * UnitDelay: '<S19>/UnitDelay1'
  660. */
  661. if (rtb_RelationalOperator4_f && rtDW->UnitDelay1_DSTATE_i) {
  662. rtb_Switch3_c = 0;
  663. } else {
  664. if (rtb_RelationalOperator4_f) {
  665. /* Switch: '<S19>/Switch2' incorporates:
  666. * UnitDelay: '<S14>/UnitDelay4'
  667. */
  668. rtb_Switch2 = (uint16_T)(rtDW->UnitDelay4_DSTATE << 1);
  669. } else {
  670. /* Product: '<S19>/Divide13' incorporates:
  671. * Sum: '<S19>/Sum13'
  672. * Switch: '<S19>/Switch2'
  673. * UnitDelay: '<S19>/UnitDelay2'
  674. * UnitDelay: '<S19>/UnitDelay3'
  675. * UnitDelay: '<S19>/UnitDelay5'
  676. */
  677. tmp_3 = 4000000U / (((rtDW->UnitDelay2_DSTATE +
  678. rtDW->UnitDelay3_DSTATE_l) +
  679. rtDW->UnitDelay5_DSTATE) + rtDW->z_counterRawPrev);
  680. if (tmp_3 > 65535U) {
  681. tmp_3 = 65535U;
  682. }
  683. /* Switch: '<S19>/Switch2' incorporates:
  684. * Product: '<S19>/Divide13'
  685. */
  686. rtb_Switch2 = (uint16_T)((uint16_T)tmp_3 << 1);
  687. }
  688. rtb_Switch3_c = (int16_T)rtb_Switch2;
  689. }
  690. /* End of Switch: '<S19>/Switch3' */
  691. /* Product: '<S19>/Divide11' incorporates:
  692. * Switch: '<S19>/Switch3'
  693. */
  694. rtDW->Divide11 = (int16_T)((rtb_Switch3_c * rtDW->Switch2_i) >> 1);
  695. /* Update for UnitDelay: '<S19>/UnitDelay1' */
  696. rtDW->UnitDelay1_DSTATE_i = rtb_RelationalOperator4_f;
  697. /* Update for UnitDelay: '<S19>/UnitDelay2' incorporates:
  698. * UnitDelay: '<S19>/UnitDelay3'
  699. */
  700. rtDW->UnitDelay2_DSTATE = rtDW->UnitDelay3_DSTATE_l;
  701. /* Update for UnitDelay: '<S19>/UnitDelay3' incorporates:
  702. * UnitDelay: '<S19>/UnitDelay5'
  703. */
  704. rtDW->UnitDelay3_DSTATE_l = rtDW->UnitDelay5_DSTATE;
  705. /* Update for UnitDelay: '<S19>/UnitDelay5' */
  706. rtDW->UnitDelay5_DSTATE = rtDW->z_counterRawPrev;
  707. /* End of Outputs for SubSystem: '<S14>/Raw_Motor_Speed_Estimation' */
  708. }
  709. /* End of If: '<S3>/If2' */
  710. /* Switch: '<S10>/Switch3' incorporates:
  711. * Constant: '<S10>/Constant16'
  712. * Constant: '<S10>/Constant2'
  713. * Constant: '<S11>/vec_hallToPos'
  714. * RelationalOperator: '<S10>/Relational Operator7'
  715. * Selector: '<S11>/Selector'
  716. * Sum: '<S10>/Sum1'
  717. */
  718. if (rtDW->Switch2_i == 1) {
  719. rtb_Sum2 = rtConstP.vec_hallToPos_Value[rtb_Add_cr];
  720. } else {
  721. rtb_Sum2 = (int8_T)(rtConstP.vec_hallToPos_Value[rtb_Add_cr] + 1);
  722. }
  723. /* End of Switch: '<S10>/Switch3' */
  724. /* MinMax: '<S10>/MinMax' incorporates:
  725. * Inport: '<Root>/hw_count'
  726. */
  727. if (rtU->hw_count < rtDW->z_counterRawPrev) {
  728. tmp_3 = rtU->hw_count;
  729. } else {
  730. tmp_3 = rtDW->z_counterRawPrev;
  731. }
  732. /* End of MinMax: '<S10>/MinMax' */
  733. /* Sum: '<S10>/Sum3' incorporates:
  734. * Product: '<S10>/Divide1'
  735. * Product: '<S10>/Divide3'
  736. */
  737. rtb_Switch3_c = (int16_T)(((int16_T)((int16_T)(((uint64_T)tmp_3 << 14) /
  738. rtDW->z_counterRawPrev) * rtDW->Switch2_i) + (rtb_Sum2 << 14)) >> 2);
  739. /* MinMax: '<S10>/MinMax1' incorporates:
  740. * Constant: '<S10>/Constant1'
  741. * Sum: '<S10>/Sum3'
  742. * Switch: '<S10>/Switch2'
  743. */
  744. if (rtb_Switch3_c <= 0) {
  745. rtb_Switch3_c = 0;
  746. }
  747. /* End of MinMax: '<S10>/MinMax1' */
  748. /* Sum: '<S15>/Add2' incorporates:
  749. * Constant: '<S15>/Constant2'
  750. * Product: '<S10>/Divide2'
  751. */
  752. rtb_Switch3_c = (int16_T)((((15 * rtb_Switch3_c) >> 4) + 3840) >> 2);
  753. /* DataTypeConversion: '<S15>/Data Type Conversion' incorporates:
  754. * Sum: '<S15>/Add2'
  755. */
  756. rtb_Divide1_m = (int16_T)(rtb_Switch3_c >> 4);
  757. /* If: '<S15>/If' incorporates:
  758. * Constant: '<S15>/Constant3'
  759. * Inport: '<S16>/In1'
  760. * Merge: '<S15>/Merge'
  761. * Sum: '<S15>/Add'
  762. * Sum: '<S15>/Add2'
  763. */
  764. if (rtb_Divide1_m >= 360) {
  765. /* Outputs for IfAction SubSystem: '<S15>/If Action Subsystem' incorporates:
  766. * ActionPort: '<S16>/Action Port'
  767. */
  768. rtb_Switch3_c = (int16_T)(rtb_Switch3_c - 5760);
  769. /* End of Outputs for SubSystem: '<S15>/If Action Subsystem' */
  770. }
  771. /* End of If: '<S15>/If' */
  772. /* If: '<S3>/If' incorporates:
  773. * Inport: '<Root>/foc_calibrate'
  774. */
  775. if ((rtU->foc_calibrate == 0) || (rtU->foc_calibrate == 2)) {
  776. /* Outputs for IfAction SubSystem: '<S3>/If Action Subsystem' incorporates:
  777. * ActionPort: '<S12>/Action Port'
  778. */
  779. /* Merge: '<S3>/Merge' incorporates:
  780. * Inport: '<S12>/In1'
  781. * Merge: '<S15>/Merge'
  782. */
  783. rtDW->Merge_i = rtb_Switch3_c;
  784. /* End of Outputs for SubSystem: '<S3>/If Action Subsystem' */
  785. } else {
  786. if (rtU->foc_calibrate == 1) {
  787. /* Outputs for IfAction SubSystem: '<S3>/If Action Subsystem1' incorporates:
  788. * ActionPort: '<S13>/Action Port'
  789. */
  790. /* Merge: '<S3>/Merge' incorporates:
  791. * Inport: '<Root>/open_theta'
  792. * Inport: '<S13>/In1'
  793. */
  794. rtDW->Merge_i = rtU->open_theta;
  795. /* End of Outputs for SubSystem: '<S3>/If Action Subsystem1' */
  796. }
  797. }
  798. /* End of If: '<S3>/If' */
  799. /* Switch: '<S14>/Switch2' incorporates:
  800. * Constant: '<S14>/Constant4'
  801. * Inport: '<Root>/hw_count'
  802. * Product: '<S19>/Divide11'
  803. * RelationalOperator: '<S14>/Relational Operator2'
  804. */
  805. if (rtU->hw_count >= 400000U) {
  806. rtb_Switch2_l = 0;
  807. } else {
  808. rtb_Switch2_l = rtDW->Divide11;
  809. }
  810. /* End of Switch: '<S14>/Switch2' */
  811. /* Abs: '<S14>/Abs5' incorporates:
  812. * Switch: '<S14>/Switch2'
  813. */
  814. if (rtb_Switch2_l < 0) {
  815. rtb_Switch2 = (uint16_T)-rtb_Switch2_l;
  816. } else {
  817. rtb_Switch2 = (uint16_T)rtb_Switch2_l;
  818. }
  819. /* End of Abs: '<S14>/Abs5' */
  820. /* If: '<S14>/If1' */
  821. if (rtb_LogicalOperator_p) {
  822. /* Outputs for IfAction SubSystem: '<S14>/Subsystem' incorporates:
  823. * ActionPort: '<S20>/Action Port'
  824. */
  825. /* Relay: '<S20>/n_commDeacv' incorporates:
  826. * Abs: '<S14>/Abs5'
  827. */
  828. rtDW->n_commDeacv_Mode = ((rtb_Switch2 >= 60) || ((rtb_Switch2 > 30) &&
  829. rtDW->n_commDeacv_Mode));
  830. /* RelationalOperator: '<S22>/Compare' incorporates:
  831. * Constant: '<S22>/Constant'
  832. * Relay: '<S20>/n_commDeacv'
  833. * Sum: '<S20>/Sum13'
  834. * UnitDelay: '<S20>/UnitDelay2'
  835. * UnitDelay: '<S20>/UnitDelay3'
  836. * UnitDelay: '<S20>/UnitDelay5'
  837. */
  838. rtDW->Compare = ((uint16_T)((uint32_T)(uint16_T)((uint32_T)(uint16_T)
  839. ((uint32_T)rtDW->UnitDelay2_DSTATE_f + rtDW->UnitDelay3_DSTATE_lh) +
  840. rtDW->UnitDelay5_DSTATE_f) + rtDW->n_commDeacv_Mode) >= 4);
  841. /* Update for UnitDelay: '<S20>/UnitDelay2' incorporates:
  842. * UnitDelay: '<S20>/UnitDelay3'
  843. */
  844. rtDW->UnitDelay2_DSTATE_f = rtDW->UnitDelay3_DSTATE_lh;
  845. /* Update for UnitDelay: '<S20>/UnitDelay3' incorporates:
  846. * UnitDelay: '<S20>/UnitDelay5'
  847. */
  848. rtDW->UnitDelay3_DSTATE_lh = rtDW->UnitDelay5_DSTATE_f;
  849. /* Update for UnitDelay: '<S20>/UnitDelay5' incorporates:
  850. * Logic: '<S20>/Logical Operator3'
  851. * Relay: '<S20>/n_commDeacv'
  852. */
  853. rtDW->UnitDelay5_DSTATE_f = rtDW->n_commDeacv_Mode;
  854. /* End of Outputs for SubSystem: '<S14>/Subsystem' */
  855. }
  856. /* End of If: '<S14>/If1' */
  857. /* Abs: '<S4>/Abs2' incorporates:
  858. * Switch: '<S14>/Switch2'
  859. */
  860. if (rtb_Switch2_l < 0) {
  861. rtb_Abs2 = (uint16_T)((uint32_T)-rtb_Switch2_l >> 1);
  862. } else {
  863. rtb_Abs2 = (uint16_T)((uint32_T)rtb_Switch2_l >> 1);
  864. }
  865. /* End of Abs: '<S4>/Abs2' */
  866. /* S-Function (sfix_bitop): '<S4>/Bitwise Operator2' incorporates:
  867. * Inport: '<Root>/foc_calibrate'
  868. */
  869. rtb_LogicalOperator3 = (uint16_T)(rtU->foc_calibrate & 1);
  870. /* UnitDelay: '<S35>/UnitDelay' */
  871. rtb_UnitDelay_bc = rtDW->UnitDelay_DSTATE_j;
  872. /* Outport: '<Root>/VqPrev' incorporates:
  873. * UnitDelay: '<S6>/UnitDelay2'
  874. */
  875. rtY->VqPrev = rtDW->UnitDelay2_DSTATE_p;
  876. /* Switch: '<S35>/Switch3' incorporates:
  877. * Abs: '<S14>/Abs5'
  878. * Abs: '<S35>/Abs4'
  879. * Constant: '<S35>/CTRL_COMM4'
  880. * Inport: '<Root>/b_motEna'
  881. * Logic: '<S35>/Logical Operator1'
  882. * RelationalOperator: '<S14>/Relational Operator9'
  883. * RelationalOperator: '<S35>/Relational Operator7'
  884. * S-Function (sfix_bitop): '<S35>/Bitwise Operator1'
  885. * UnitDelay: '<S6>/UnitDelay2'
  886. */
  887. if ((rtb_UnitDelay_bc & 4U) != 0U) {
  888. rtb_LogicalOperator_p = true;
  889. } else {
  890. if (rtDW->UnitDelay2_DSTATE_p < 0) {
  891. /* Abs: '<S35>/Abs4' incorporates:
  892. * UnitDelay: '<S6>/UnitDelay2'
  893. */
  894. rtb_Switch_np = (int16_T)-rtDW->UnitDelay2_DSTATE_p;
  895. } else {
  896. /* Abs: '<S35>/Abs4' incorporates:
  897. * UnitDelay: '<S6>/UnitDelay2'
  898. */
  899. rtb_Switch_np = rtDW->UnitDelay2_DSTATE_p;
  900. }
  901. rtb_LogicalOperator_p = (rtU->b_motEna && (rtb_Switch2 < 6) &&
  902. (rtb_Switch_np > 960));
  903. }
  904. /* End of Switch: '<S35>/Switch3' */
  905. /* Sum: '<S35>/Sum' incorporates:
  906. * Constant: '<S35>/CTRL_COMM'
  907. * Constant: '<S35>/CTRL_COMM1'
  908. * DataTypeConversion: '<S35>/Data Type Conversion3'
  909. * Gain: '<S35>/g_Hb'
  910. * Gain: '<S35>/g_Hb1'
  911. * RelationalOperator: '<S35>/Relational Operator1'
  912. * RelationalOperator: '<S35>/Relational Operator3'
  913. */
  914. rtb_Sum = (uint8_T)(((uint32_T)((rtb_Add_cr == 7) << 1) + (rtb_Add_cr == 0)) +
  915. (rtb_LogicalOperator_p << 2));
  916. /* Outputs for Atomic SubSystem: '<S35>/Debounce_Filter' */
  917. /* RelationalOperator: '<S35>/Relational Operator2' incorporates:
  918. * Constant: '<S35>/CTRL_COMM2'
  919. * Constant: '<S35>/t_errDequal'
  920. * Constant: '<S35>/t_errQual'
  921. */
  922. Debounce_Filter(rtb_Sum != 0, 1600, 12000, &rtb_RelationalOperator4_f,
  923. &rtDW->Debounce_Filter_i);
  924. /* End of Outputs for SubSystem: '<S35>/Debounce_Filter' */
  925. /* Logic: '<S24>/Logical Operator12' incorporates:
  926. * Inport: '<Root>/b_motEna'
  927. * Logic: '<S24>/Logical Operator7'
  928. */
  929. rtb_n_commDeacv = ((!rtb_RelationalOperator4_f) && rtU->b_motEna);
  930. /* Logic: '<S24>/Logical Operator4' incorporates:
  931. * Constant: '<S24>/constant8'
  932. * Inport: '<Root>/n_ctrlModReq'
  933. * Logic: '<S24>/Logical Operator11'
  934. * Logic: '<S24>/Logical Operator8'
  935. * RelationalOperator: '<S24>/Relational Operator10'
  936. */
  937. rtb_LogicalOperator4 = ((rtb_LogicalOperator3 != 0) || (!rtDW->Compare) ||
  938. (!rtb_n_commDeacv) || (rtU->n_ctrlModReq == 0));
  939. /* Relay: '<S24>/n_SpeedCtrl' */
  940. rtDW->n_SpeedCtrl_Mode = ((rtb_Abs2 >= 300) || ((rtb_Abs2 > 200) &&
  941. rtDW->n_SpeedCtrl_Mode));
  942. rtb_LogicalOperator_p = rtDW->n_SpeedCtrl_Mode;
  943. /* Logic: '<S24>/Logical Operator10' incorporates:
  944. * Inport: '<Root>/b_cruiseEna'
  945. */
  946. rtb_LogicalOperator_p = (rtb_LogicalOperator_p && rtU->b_cruiseEna);
  947. /* Logic: '<S24>/Logical Operator2' incorporates:
  948. * Constant: '<S24>/constant'
  949. * Inport: '<Root>/n_ctrlModReq'
  950. * Logic: '<S24>/Logical Operator5'
  951. * RelationalOperator: '<S24>/Relational Operator4'
  952. */
  953. rtb_LogicalOperator2 = ((rtU->n_ctrlModReq == 2) && (!rtb_LogicalOperator_p));
  954. /* Logic: '<S24>/Logical Operator1' incorporates:
  955. * Constant: '<S24>/constant1'
  956. * Inport: '<Root>/n_ctrlModReq'
  957. * RelationalOperator: '<S24>/Relational Operator1'
  958. */
  959. rtb_LogicalOperator_p = ((rtU->n_ctrlModReq == 1) || rtb_LogicalOperator_p);
  960. /* Chart: '<S4>/Control_Mode_Manager' incorporates:
  961. * Logic: '<S24>/Logical Operator3'
  962. * Logic: '<S24>/Logical Operator6'
  963. * Logic: '<S24>/Logical Operator9'
  964. */
  965. if (rtDW->is_active_c5_PMSM_Controller == 0U) {
  966. rtDW->is_active_c5_PMSM_Controller = 1U;
  967. rtDW->is_c5_PMSM_Controller = IN_OPEN;
  968. rtb_z_ctrlMod = OPEN_MODE;
  969. } else if (rtDW->is_c5_PMSM_Controller == 1) {
  970. if (rtb_LogicalOperator4) {
  971. rtDW->is_ACTIVE = IN_NO_ACTIVE_CHILD;
  972. rtDW->is_c5_PMSM_Controller = IN_OPEN;
  973. rtb_z_ctrlMod = OPEN_MODE;
  974. } else if (rtDW->is_ACTIVE == 1) {
  975. rtb_z_ctrlMod = SPD_MODE;
  976. if (!rtb_LogicalOperator_p) {
  977. if (rtb_LogicalOperator2) {
  978. rtDW->is_ACTIVE = IN_TORQUE_MODE;
  979. rtb_z_ctrlMod = TRQ_MODE;
  980. } else {
  981. rtDW->is_ACTIVE = IN_SPEED_MODE;
  982. }
  983. }
  984. } else {
  985. /* case IN_TORQUE_MODE: */
  986. rtb_z_ctrlMod = TRQ_MODE;
  987. if (!rtb_LogicalOperator2) {
  988. rtDW->is_ACTIVE = IN_SPEED_MODE;
  989. rtb_z_ctrlMod = SPD_MODE;
  990. }
  991. }
  992. } else {
  993. /* case IN_OPEN: */
  994. rtb_z_ctrlMod = OPEN_MODE;
  995. if ((!rtb_LogicalOperator4) && (rtb_LogicalOperator2 ||
  996. rtb_LogicalOperator_p)) {
  997. rtDW->is_c5_PMSM_Controller = IN_ACTIVE;
  998. if (rtb_LogicalOperator2) {
  999. rtDW->is_ACTIVE = IN_TORQUE_MODE;
  1000. rtb_z_ctrlMod = TRQ_MODE;
  1001. } else {
  1002. rtDW->is_ACTIVE = IN_SPEED_MODE;
  1003. rtb_z_ctrlMod = SPD_MODE;
  1004. }
  1005. }
  1006. }
  1007. /* End of Chart: '<S4>/Control_Mode_Manager' */
  1008. /* Switch: '<S25>/Switch' incorporates:
  1009. * Constant: '<S25>/Constant3'
  1010. * Inport: '<Root>/speed_target'
  1011. */
  1012. if (rtU->speed_target > 30) {
  1013. /* Switch: '<S25>/Switch1' incorporates:
  1014. * Constant: '<S25>/Constant1'
  1015. * DataTypeConversion: '<S25>/Data Type Conversion'
  1016. * Switch: '<S25>/Switch'
  1017. */
  1018. if (rtb_n_commDeacv) {
  1019. rtb_Switch_np = rtU->speed_target;
  1020. } else {
  1021. rtb_Switch_np = 0;
  1022. }
  1023. /* End of Switch: '<S25>/Switch1' */
  1024. } else {
  1025. rtb_Switch_np = 0;
  1026. }
  1027. /* End of Switch: '<S25>/Switch' */
  1028. /* Switch: '<S25>/Switch3' incorporates:
  1029. * Constant: '<S25>/Constant4'
  1030. * DataTypeConversion: '<S25>/Data Type Conversion2'
  1031. * Inport: '<Root>/vdq_open_target'
  1032. */
  1033. if (rtb_n_commDeacv) {
  1034. rtb_Divide1_m = rtU->vdq_open_target[1];
  1035. } else {
  1036. rtb_Divide1_m = 0;
  1037. }
  1038. /* End of Switch: '<S25>/Switch3' */
  1039. /* If: '<S26>/If' incorporates:
  1040. * DataTypeConversion: '<S26>/Data Type Conversion1'
  1041. * DataTypeConversion: '<S26>/Data Type Conversion2'
  1042. * Inport: '<Root>/current_target'
  1043. * Inport: '<S27>/vq_in'
  1044. * Inport: '<S30>/r_currTgt'
  1045. * Switch: '<S25>/Switch3'
  1046. */
  1047. if (rtb_LogicalOperator3 == 1) {
  1048. /* Switch: '<S25>/Switch2' incorporates:
  1049. * Constant: '<S25>/Constant2'
  1050. * DataTypeConversion: '<S25>/Data Type Conversion1'
  1051. * Inport: '<Root>/vdq_open_target'
  1052. * Inport: '<S27>/vd_in'
  1053. */
  1054. if (rtb_n_commDeacv) {
  1055. /* Outputs for IfAction SubSystem: '<S26>/If Action Subsystem' incorporates:
  1056. * ActionPort: '<S27>/Action Port'
  1057. */
  1058. rtDW->Merge[0] = rtU->vdq_open_target[0];
  1059. /* End of Outputs for SubSystem: '<S26>/If Action Subsystem' */
  1060. } else {
  1061. /* Outputs for IfAction SubSystem: '<S26>/If Action Subsystem' incorporates:
  1062. * ActionPort: '<S27>/Action Port'
  1063. */
  1064. rtDW->Merge[0] = 0;
  1065. /* End of Outputs for SubSystem: '<S26>/If Action Subsystem' */
  1066. }
  1067. /* End of Switch: '<S25>/Switch2' */
  1068. /* Outputs for IfAction SubSystem: '<S26>/If Action Subsystem' incorporates:
  1069. * ActionPort: '<S27>/Action Port'
  1070. */
  1071. rtDW->Merge[1] = rtb_Divide1_m;
  1072. /* End of Outputs for SubSystem: '<S26>/If Action Subsystem' */
  1073. } else if ((rtb_z_ctrlMod == 0) && rtb_Equal_k) {
  1074. /* Outputs for IfAction SubSystem: '<S26>/open_mode' incorporates:
  1075. * ActionPort: '<S29>/Action Port'
  1076. */
  1077. /* RelationalOperator: '<S29>/Equal1' incorporates:
  1078. * Switch: '<S25>/Switch3'
  1079. * UnitDelay: '<S29>/Unit Delay'
  1080. */
  1081. rtb_LogicalOperator_p = (rtDW->UnitDelay_DSTATE != rtb_Divide1_m);
  1082. /* If: '<S31>/If' */
  1083. if (rtb_LogicalOperator_p) {
  1084. /* Outputs for IfAction SubSystem: '<S31>/Subsystem' incorporates:
  1085. * ActionPort: '<S33>/Action Port'
  1086. */
  1087. /* Sum: '<S33>/Add' incorporates:
  1088. * Signum: '<S33>/Sign'
  1089. * Switch: '<S25>/Switch3'
  1090. * UnitDelay: '<S6>/UnitDelay2'
  1091. */
  1092. rtb_Sign = (int16_T)((rtb_Divide1_m - rtDW->UnitDelay2_DSTATE_p) >> 2);
  1093. /* Signum: '<S33>/Sign' */
  1094. if (rtb_Sign < 0) {
  1095. rtb_Sign = -1;
  1096. } else {
  1097. rtb_Sign = (int16_T)(rtb_Sign > 0);
  1098. }
  1099. /* End of Signum: '<S33>/Sign' */
  1100. /* Product: '<S33>/Divide' incorporates:
  1101. * Constant: '<S29>/Constant5'
  1102. */
  1103. rtDW->Divide = (int16_T)(rtb_Sign * 6);
  1104. /* Switch: '<S33>/Switch' incorporates:
  1105. * Switch: '<S33>/Switch1'
  1106. */
  1107. if (rtb_Sign > 0) {
  1108. /* Switch: '<S33>/Switch' incorporates:
  1109. * Switch: '<S25>/Switch3'
  1110. */
  1111. rtDW->Switch_i = rtb_Divide1_m;
  1112. /* Switch: '<S33>/Switch1' incorporates:
  1113. * UnitDelay: '<S6>/UnitDelay2'
  1114. */
  1115. rtDW->Switch1 = rtDW->UnitDelay2_DSTATE_p;
  1116. } else {
  1117. /* Switch: '<S33>/Switch' incorporates:
  1118. * UnitDelay: '<S6>/UnitDelay2'
  1119. */
  1120. rtDW->Switch_i = rtDW->UnitDelay2_DSTATE_p;
  1121. /* Switch: '<S33>/Switch1' incorporates:
  1122. * Switch: '<S25>/Switch3'
  1123. */
  1124. rtDW->Switch1 = rtb_Divide1_m;
  1125. }
  1126. /* End of Switch: '<S33>/Switch' */
  1127. /* End of Outputs for SubSystem: '<S31>/Subsystem' */
  1128. /* Switch: '<S34>/Switch1' incorporates:
  1129. * UnitDelay: '<S6>/UnitDelay2'
  1130. */
  1131. rtb_Sign = rtDW->UnitDelay2_DSTATE_p;
  1132. } else {
  1133. /* Switch: '<S34>/Switch1' incorporates:
  1134. * UnitDelay: '<S34>/UnitDelay'
  1135. */
  1136. rtb_Sign = rtDW->UnitDelay_DSTATE_f;
  1137. }
  1138. /* End of If: '<S31>/If' */
  1139. /* Sum: '<S31>/Add2' incorporates:
  1140. * Product: '<S33>/Divide'
  1141. */
  1142. tmp_2 = ((rtb_Sign << 1) + rtDW->Divide) >> 1;
  1143. if (tmp_2 > 32767) {
  1144. tmp_2 = 32767;
  1145. } else {
  1146. if (tmp_2 < -32768) {
  1147. tmp_2 = -32768;
  1148. }
  1149. }
  1150. /* Switch: '<S29>/Switch' incorporates:
  1151. * Switch: '<S25>/Switch'
  1152. */
  1153. if (rtb_Switch_np > 0) {
  1154. /* Switch: '<S32>/Switch2' incorporates:
  1155. * RelationalOperator: '<S32>/LowerRelop1'
  1156. * RelationalOperator: '<S32>/UpperRelop'
  1157. * Sum: '<S31>/Add2'
  1158. * Switch: '<S32>/Switch'
  1159. * Switch: '<S33>/Switch'
  1160. * Switch: '<S33>/Switch1'
  1161. */
  1162. if ((int16_T)tmp_2 > rtDW->Switch_i) {
  1163. /* Merge: '<S26>/Merge' incorporates:
  1164. * Switch: '<S29>/Switch'
  1165. */
  1166. rtDW->Merge[1] = rtDW->Switch_i;
  1167. } else if ((int16_T)tmp_2 < rtDW->Switch1) {
  1168. /* Merge: '<S26>/Merge' incorporates:
  1169. * Switch: '<S29>/Switch'
  1170. * Switch: '<S32>/Switch'
  1171. * Switch: '<S33>/Switch1'
  1172. */
  1173. rtDW->Merge[1] = rtDW->Switch1;
  1174. } else {
  1175. /* Merge: '<S26>/Merge' incorporates:
  1176. * Switch: '<S29>/Switch'
  1177. */
  1178. rtDW->Merge[1] = (int16_T)tmp_2;
  1179. }
  1180. /* End of Switch: '<S32>/Switch2' */
  1181. } else {
  1182. /* Merge: '<S26>/Merge' incorporates:
  1183. * Constant: '<S29>/Constant1'
  1184. */
  1185. rtDW->Merge[1] = 0;
  1186. }
  1187. /* End of Switch: '<S29>/Switch' */
  1188. /* Merge: '<S26>/Merge' incorporates:
  1189. * Constant: '<S29>/Constant3'
  1190. * SignalConversion generated from: '<S29>/open_voltage'
  1191. */
  1192. rtDW->Merge[0] = 0;
  1193. /* Update for UnitDelay: '<S29>/Unit Delay' incorporates:
  1194. * Switch: '<S25>/Switch3'
  1195. */
  1196. rtDW->UnitDelay_DSTATE = rtb_Divide1_m;
  1197. /* Switch: '<S34>/Switch2' */
  1198. if (rtb_LogicalOperator_p) {
  1199. /* Update for UnitDelay: '<S34>/UnitDelay' incorporates:
  1200. * UnitDelay: '<S6>/UnitDelay2'
  1201. */
  1202. rtDW->UnitDelay_DSTATE_f = rtDW->UnitDelay2_DSTATE_p;
  1203. } else {
  1204. /* Update for UnitDelay: '<S34>/UnitDelay' incorporates:
  1205. * Sum: '<S31>/Add2'
  1206. */
  1207. rtDW->UnitDelay_DSTATE_f = (int16_T)tmp_2;
  1208. }
  1209. /* End of Switch: '<S34>/Switch2' */
  1210. /* End of Outputs for SubSystem: '<S26>/open_mode' */
  1211. } else if (rtb_z_ctrlMod == 2) {
  1212. /* Outputs for IfAction SubSystem: '<S26>/torque_mode' incorporates:
  1213. * ActionPort: '<S30>/Action Port'
  1214. */
  1215. rtDW->r_currTgt = rtU->current_target;
  1216. /* Merge: '<S26>/Merge1' incorporates:
  1217. * Inport: '<Root>/current_target'
  1218. * Inport: '<S30>/r_currTgt'
  1219. * Inport: '<S30>/r_spdTgt'
  1220. * Switch: '<S25>/Switch'
  1221. */
  1222. rtDW->Merge1 = rtb_Switch_np;
  1223. /* End of Outputs for SubSystem: '<S26>/torque_mode' */
  1224. } else {
  1225. /* Outputs for IfAction SubSystem: '<S26>/If Action Subsystem1' incorporates:
  1226. * ActionPort: '<S28>/Action Port'
  1227. */
  1228. /* Merge: '<S26>/Merge1' incorporates:
  1229. * Inport: '<S28>/In1'
  1230. * Switch: '<S25>/Switch'
  1231. */
  1232. rtDW->Merge1 = rtb_Switch_np;
  1233. /* End of Outputs for SubSystem: '<S26>/If Action Subsystem1' */
  1234. }
  1235. /* End of If: '<S26>/If' */
  1236. /* Outputs for Atomic SubSystem: '<S35>/either_edge' */
  1237. rtb_LogicalOperator_p = either_edge(rtb_RelationalOperator4_f,
  1238. &rtDW->either_edge_f);
  1239. /* End of Outputs for SubSystem: '<S35>/either_edge' */
  1240. /* Switch: '<S35>/Switch1' */
  1241. if (rtb_LogicalOperator_p) {
  1242. rtb_UnitDelay_bc = rtb_Sum;
  1243. }
  1244. /* End of Switch: '<S35>/Switch1' */
  1245. /* Gain: '<S52>/Multiply' incorporates:
  1246. * DataTypeConversion: '<S56>/Data Type Conversion'
  1247. * Inport: '<Root>/adc_a'
  1248. * Inport: '<Root>/adc_b'
  1249. */
  1250. tmp_2 = (12351 * rtU->adc_a) >> 11;
  1251. if (tmp_2 > 32767) {
  1252. tmp_2 = 32767;
  1253. } else {
  1254. if (tmp_2 < -32768) {
  1255. tmp_2 = -32768;
  1256. }
  1257. }
  1258. rtb_DataTypeConversion[0] = (int16_T)tmp_2;
  1259. rtb_Gain = (12351 * rtU->adc_b) >> 11;
  1260. if (rtb_Gain > 32767) {
  1261. rtb_Gain = 32767;
  1262. } else {
  1263. if (rtb_Gain < -32768) {
  1264. rtb_Gain = -32768;
  1265. }
  1266. }
  1267. rtb_DataTypeConversion[1] = (int16_T)rtb_Gain;
  1268. /* Sum: '<S46>/Add' incorporates:
  1269. * Gain: '<S52>/Multiply'
  1270. */
  1271. tmp_0 = (int16_T)tmp_2 + (int16_T)rtb_Gain;
  1272. if (tmp_0 > 32767) {
  1273. tmp_0 = 32767;
  1274. } else {
  1275. if (tmp_0 < -32768) {
  1276. tmp_0 = -32768;
  1277. }
  1278. }
  1279. /* Sum: '<S46>/Add1' incorporates:
  1280. * Sum: '<S46>/Add'
  1281. */
  1282. tmp_1 = -tmp_0;
  1283. if (-tmp_0 > 32767) {
  1284. tmp_1 = 32767;
  1285. }
  1286. /* Sum: '<S55>/Add3' incorporates:
  1287. * Gain: '<S52>/Multiply'
  1288. * Sum: '<S46>/Add1'
  1289. */
  1290. tmp_0 = (int16_T)rtb_Gain + (int16_T)tmp_1;
  1291. if (tmp_0 > 32767) {
  1292. tmp_0 = 32767;
  1293. } else {
  1294. if (tmp_0 < -32768) {
  1295. tmp_0 = -32768;
  1296. }
  1297. }
  1298. /* Sum: '<S55>/Add' incorporates:
  1299. * Gain: '<S52>/Multiply'
  1300. * Sum: '<S55>/Add3'
  1301. */
  1302. tmp_2 = (((int16_T)tmp_2 << 1) - tmp_0) >> 1;
  1303. if (tmp_2 > 32767) {
  1304. tmp_2 = 32767;
  1305. } else {
  1306. if (tmp_2 < -32768) {
  1307. tmp_2 = -32768;
  1308. }
  1309. }
  1310. /* Gain: '<S55>/Gain1' incorporates:
  1311. * Product: '<S57>/Divide1'
  1312. * Sum: '<S55>/Add'
  1313. */
  1314. rtb_Divide1_m = (int16_T)((21845 * tmp_2) >> 15);
  1315. /* Gain: '<S55>/Gain2' incorporates:
  1316. * Gain: '<S52>/Multiply'
  1317. * Sum: '<S46>/Add1'
  1318. * Sum: '<S55>/Add2'
  1319. */
  1320. tmp_2 = ((((int16_T)rtb_Gain - (int16_T)tmp_1) >> 1) * 18919) >> 14;
  1321. if (tmp_2 > 32767) {
  1322. tmp_2 = 32767;
  1323. } else {
  1324. if (tmp_2 < -32768) {
  1325. tmp_2 = -32768;
  1326. }
  1327. }
  1328. /* PreLookup: '<S58>/a_elecAngle_XA' incorporates:
  1329. * Merge: '<S3>/Merge'
  1330. */
  1331. rtb_LogicalOperator3 = plook_u16s16_evencka(rtDW->Merge_i, 0, 4U, 1440U);
  1332. /* Sum: '<S57>/Sum1' incorporates:
  1333. * Gain: '<S55>/Gain2'
  1334. * Interpolation_n-D: '<S58>/r_cos_M1'
  1335. * Interpolation_n-D: '<S58>/r_sin_M1'
  1336. * Product: '<S57>/Divide1'
  1337. * Product: '<S57>/Divide2'
  1338. * Product: '<S57>/Divide3'
  1339. */
  1340. rtb_Gain = (int16_T)((rtb_Divide1_m * rtConstP.pooled12[rtb_LogicalOperator3])
  1341. >> 14) + (int16_T)(((int16_T)tmp_2 *
  1342. rtConstP.pooled11[rtb_LogicalOperator3]) >> 14);
  1343. if (rtb_Gain > 32767) {
  1344. rtb_Gain = 32767;
  1345. } else {
  1346. if (rtb_Gain < -32768) {
  1347. rtb_Gain = -32768;
  1348. }
  1349. }
  1350. /* SignalConversion generated from: '<S46>/Low_Pass_Filter' incorporates:
  1351. * Sum: '<S57>/Sum1'
  1352. */
  1353. rtb_TmpSignalConversionAtLow_Pa[0] = (int16_T)rtb_Gain;
  1354. /* Sum: '<S57>/Sum6' incorporates:
  1355. * Gain: '<S55>/Gain2'
  1356. * Interpolation_n-D: '<S58>/r_cos_M1'
  1357. * Interpolation_n-D: '<S58>/r_sin_M1'
  1358. * Product: '<S57>/Divide1'
  1359. * Product: '<S57>/Divide4'
  1360. */
  1361. tmp_2 = (int16_T)(((int16_T)tmp_2 * rtConstP.pooled12[rtb_LogicalOperator3]) >>
  1362. 14) - (int16_T)((rtb_Divide1_m *
  1363. rtConstP.pooled11[rtb_LogicalOperator3]) >> 14);
  1364. if (tmp_2 > 32767) {
  1365. tmp_2 = 32767;
  1366. } else {
  1367. if (tmp_2 < -32768) {
  1368. tmp_2 = -32768;
  1369. }
  1370. }
  1371. /* SignalConversion generated from: '<S46>/Low_Pass_Filter' incorporates:
  1372. * Sum: '<S57>/Sum6'
  1373. */
  1374. rtb_TmpSignalConversionAtLow_Pa[1] = (int16_T)tmp_2;
  1375. /* Outputs for Atomic SubSystem: '<S46>/Low_Pass_Filter' */
  1376. /* Constant: '<S46>/Constant' */
  1377. Low_Pass_Filter(rtb_TmpSignalConversionAtLow_Pa, 26214, rtb_DataTypeConversion,
  1378. &rtDW->Low_Pass_Filter_d);
  1379. /* End of Outputs for SubSystem: '<S46>/Low_Pass_Filter' */
  1380. /* Switch: '<S54>/Switch2' */
  1381. rtb_Sum = (uint8_T)(rtb_z_ctrlMod != 0);
  1382. /* DataTypeConversion: '<S48>/Data Type Conversion' incorporates:
  1383. * Logic: '<S48>/Logical Operator'
  1384. * RelationalOperator: '<S48>/Equal'
  1385. * UnitDelay: '<S48>/Unit Delay'
  1386. */
  1387. rtb_DataTypeConversion_m = (uint8_T)((rtb_Sum != 0) &&
  1388. (rtDW->UnitDelay_DSTATE_b != rtb_Sum));
  1389. /* If: '<S53>/If' incorporates:
  1390. * Logic: '<S54>/Logical Operator'
  1391. */
  1392. if ((rtb_Sum != 0) && rtb_Equal_k) {
  1393. /* Outputs for IfAction SubSystem: '<S53>/Subsystem' incorporates:
  1394. * ActionPort: '<S81>/Action Port'
  1395. */
  1396. /* If: '<S84>/If' incorporates:
  1397. * Constant: '<S47>/Constant1'
  1398. * Constant: '<S90>/Constant1'
  1399. * Constant: '<S90>/Constant11'
  1400. * Constant: '<S90>/Constant2'
  1401. * Constant: '<S90>/Constant4'
  1402. * DataTypeConversion: '<S81>/Data Type Conversion'
  1403. * Gain: '<S81>/Gain'
  1404. * RelationalOperator: '<S81>/Equal'
  1405. * Sum: '<S90>/Add2'
  1406. * Switch: '<S14>/Switch2'
  1407. * Switch: '<S95>/Switch2'
  1408. * UnitDelay: '<S81>/Unit Delay'
  1409. * UnitDelay: '<S81>/Unit Delay1'
  1410. */
  1411. if (rtb_z_ctrlMod == 1) {
  1412. /* Outputs for IfAction SubSystem: '<S84>/speed_mode' incorporates:
  1413. * ActionPort: '<S90>/Action Port'
  1414. */
  1415. /* Switch: '<S92>/Switch2' incorporates:
  1416. * Inport: '<Root>/speed_limit'
  1417. * Merge: '<S26>/Merge1'
  1418. * RelationalOperator: '<S92>/LowerRelop1'
  1419. * RelationalOperator: '<S92>/UpperRelop'
  1420. * Switch: '<S92>/Switch'
  1421. * Switch: '<S95>/Switch2'
  1422. */
  1423. if (rtDW->Merge1 > rtU->speed_limit) {
  1424. rtb_Divide1_m = rtU->speed_limit;
  1425. } else if (rtDW->Merge1 < 0) {
  1426. /* Switch: '<S92>/Switch' incorporates:
  1427. * Constant: '<S90>/Constant5'
  1428. * Switch: '<S95>/Switch2'
  1429. */
  1430. rtb_Divide1_m = 0;
  1431. } else {
  1432. rtb_Divide1_m = rtDW->Merge1;
  1433. }
  1434. /* End of Switch: '<S92>/Switch2' */
  1435. /* Outputs for Atomic SubSystem: '<S90>/pi_speed' */
  1436. rtb_Divide1_m = pi_speed((int16_T)(rtb_Divide1_m - rtb_Switch2_l), 3174,
  1437. 10, 51, 7680, -7680, 0, (int16_T)(-rtDW->UnitDelay1_DSTATE_g >> 1),
  1438. (uint8_T)(rtDW->UnitDelay_DSTATE_p != 1), &rtDW->pi_speed_d,
  1439. &rtPrevZCX->pi_speed_d);
  1440. /* End of Outputs for SubSystem: '<S90>/pi_speed' */
  1441. /* Merge: '<S84>/Merge' incorporates:
  1442. * Constant: '<S47>/Constant1'
  1443. * Constant: '<S90>/Constant1'
  1444. * Constant: '<S90>/Constant11'
  1445. * Constant: '<S90>/Constant2'
  1446. * Constant: '<S90>/Constant4'
  1447. * DataTypeConversion: '<S81>/Data Type Conversion'
  1448. * Gain: '<S81>/Gain'
  1449. * RelationalOperator: '<S81>/Equal'
  1450. * SignalConversion generated from: '<S90>/idq_target'
  1451. * Sum: '<S90>/Add2'
  1452. * Switch: '<S14>/Switch2'
  1453. * Switch: '<S95>/Switch2'
  1454. * UnitDelay: '<S81>/Unit Delay'
  1455. * UnitDelay: '<S81>/Unit Delay1'
  1456. */
  1457. rtDW->Merge_f = rtb_Divide1_m;
  1458. /* End of Outputs for SubSystem: '<S84>/speed_mode' */
  1459. } else {
  1460. if (rtb_z_ctrlMod == 2) {
  1461. /* Outputs for IfAction SubSystem: '<S84>/torque_mode' incorporates:
  1462. * ActionPort: '<S91>/Action Port'
  1463. */
  1464. /* Switch: '<S91>/Switch' incorporates:
  1465. * Inport: '<S30>/r_currTgt'
  1466. * Switch: '<S14>/Switch2'
  1467. * Switch: '<S91>/Switch1'
  1468. */
  1469. if (rtDW->r_currTgt >= 0) {
  1470. /* Product: '<S91>/Divide' incorporates:
  1471. * Merge: '<S26>/Merge1'
  1472. * Sum: '<S91>/Sum2'
  1473. * Switch: '<S14>/Switch2'
  1474. */
  1475. tmp_2 = (int16_T)(rtDW->Merge1 - rtb_Switch2_l) * 192;
  1476. if (tmp_2 > 32767) {
  1477. tmp_2 = 32767;
  1478. } else {
  1479. if (tmp_2 < -32768) {
  1480. tmp_2 = -32768;
  1481. }
  1482. }
  1483. rtb_Divide1_m = (int16_T)tmp_2;
  1484. /* End of Product: '<S91>/Divide' */
  1485. /* Product: '<S91>/Divide1' incorporates:
  1486. * Merge: '<S26>/Merge1'
  1487. * Sum: '<S91>/Sum3'
  1488. * Switch: '<S14>/Switch2'
  1489. */
  1490. tmp_2 = ((int16_T)(rtb_Switch2_l - rtDW->Merge1) * 51) >> 4;
  1491. if (tmp_2 > 32767) {
  1492. tmp_2 = 32767;
  1493. } else {
  1494. if (tmp_2 < -32768) {
  1495. tmp_2 = -32768;
  1496. }
  1497. }
  1498. /* MinMax: '<S91>/Max' incorporates:
  1499. * Product: '<S91>/Divide'
  1500. * Product: '<S91>/Divide1'
  1501. */
  1502. if (rtb_Divide1_m > (int16_T)tmp_2) {
  1503. rtb_Sign = rtb_Divide1_m;
  1504. } else {
  1505. rtb_Sign = (int16_T)tmp_2;
  1506. }
  1507. /* End of MinMax: '<S91>/Max' */
  1508. /* MinMax: '<S91>/Max3' incorporates:
  1509. * Constant: '<S47>/Constant1'
  1510. * MinMax: '<S91>/Max'
  1511. */
  1512. if (7680 < rtb_Sign) {
  1513. rtb_Sign = 7680;
  1514. }
  1515. /* End of MinMax: '<S91>/Max3' */
  1516. /* Switch: '<S96>/Switch2' incorporates:
  1517. * MinMax: '<S91>/Max1'
  1518. * MinMax: '<S91>/Max3'
  1519. * Product: '<S91>/Divide'
  1520. * Product: '<S91>/Divide1'
  1521. * RelationalOperator: '<S96>/LowerRelop1'
  1522. */
  1523. if (rtDW->r_currTgt > rtb_Sign) {
  1524. /* Merge: '<S84>/Merge' */
  1525. rtDW->Merge_f = rtb_Sign;
  1526. } else {
  1527. if (rtb_Divide1_m >= (int16_T)tmp_2) {
  1528. /* MinMax: '<S91>/Max1' incorporates:
  1529. * Product: '<S91>/Divide1'
  1530. */
  1531. rtb_Divide1_m = (int16_T)tmp_2;
  1532. }
  1533. /* MinMax: '<S91>/Max2' incorporates:
  1534. * Gain: '<S47>/Gain1'
  1535. * MinMax: '<S91>/Max1'
  1536. */
  1537. if (rtb_Divide1_m <= -7680) {
  1538. rtb_Divide1_m = -7680;
  1539. }
  1540. /* End of MinMax: '<S91>/Max2' */
  1541. /* Switch: '<S96>/Switch' incorporates:
  1542. * MinMax: '<S91>/Max2'
  1543. * RelationalOperator: '<S96>/UpperRelop'
  1544. */
  1545. if (rtDW->r_currTgt < rtb_Divide1_m) {
  1546. /* Merge: '<S84>/Merge' */
  1547. rtDW->Merge_f = rtb_Divide1_m;
  1548. } else {
  1549. /* Merge: '<S84>/Merge' */
  1550. rtDW->Merge_f = rtDW->r_currTgt;
  1551. }
  1552. /* End of Switch: '<S96>/Switch' */
  1553. }
  1554. /* End of Switch: '<S96>/Switch2' */
  1555. } else if (rtb_Switch2_l > 80) {
  1556. /* Switch: '<S91>/Switch1' incorporates:
  1557. * Merge: '<S84>/Merge'
  1558. */
  1559. rtDW->Merge_f = rtDW->r_currTgt;
  1560. } else {
  1561. /* Merge: '<S84>/Merge' incorporates:
  1562. * Constant: '<S91>/Constant5'
  1563. * Switch: '<S91>/Switch1'
  1564. */
  1565. rtDW->Merge_f = 0;
  1566. }
  1567. /* End of Switch: '<S91>/Switch' */
  1568. /* End of Outputs for SubSystem: '<S84>/torque_mode' */
  1569. }
  1570. }
  1571. /* End of If: '<S84>/If' */
  1572. /* If: '<S83>/If' incorporates:
  1573. * Inport: '<Root>/foc_calibrate'
  1574. * S-Function (sfix_bitop): '<S83>/Bitwise Operator1'
  1575. */
  1576. if ((rtU->foc_calibrate & 2U) == 0U) {
  1577. /* Outputs for IfAction SubSystem: '<S83>/MTPA_Calc' incorporates:
  1578. * ActionPort: '<S87>/Action Port'
  1579. */
  1580. /* Merge: '<S83>/Merge' incorporates:
  1581. * Constant: '<S87>/Constant3'
  1582. * Switch: '<S87>/Switch'
  1583. */
  1584. rtDW->Merge_c[0] = 0;
  1585. rtDW->Merge_c[1] = rtDW->Merge_f;
  1586. /* End of Outputs for SubSystem: '<S83>/MTPA_Calc' */
  1587. } else {
  1588. /* Outputs for IfAction SubSystem: '<S83>/MTPA_Cali' incorporates:
  1589. * ActionPort: '<S88>/Action Port'
  1590. */
  1591. /* PreLookup: '<S89>/a_elecAngle_XA' incorporates:
  1592. * Inport: '<Root>/open_theta'
  1593. */
  1594. rtb_Abs2 = plook_u16s16_evencka(rtU->open_theta, 0, 4U, 1440U);
  1595. /* Product: '<S88>/Divide' incorporates:
  1596. * Gain: '<S88>/Gain'
  1597. * Interpolation_n-D: '<S89>/r_sin_M1'
  1598. * Merge: '<S84>/Merge'
  1599. */
  1600. rtDW->Merge_c[0] = (int16_T)(((int64_T)(-32768 *
  1601. rtConstP.pooled11[rtb_Abs2]) * rtDW->Merge_f) >> 29);
  1602. /* Product: '<S88>/Divide1' incorporates:
  1603. * Interpolation_n-D: '<S89>/r_cos_M1'
  1604. * Merge: '<S84>/Merge'
  1605. */
  1606. rtDW->Merge_c[1] = (int16_T)((rtConstP.pooled12[rtb_Abs2] * rtDW->Merge_f)
  1607. >> 14);
  1608. /* End of Outputs for SubSystem: '<S83>/MTPA_Cali' */
  1609. }
  1610. /* End of If: '<S83>/If' */
  1611. /* Switch: '<S82>/Switch' incorporates:
  1612. * Merge: '<S83>/Merge'
  1613. */
  1614. rtDW->Switch[0] = rtDW->Merge_c[0];
  1615. rtDW->Switch[1] = rtDW->Merge_c[1];
  1616. /* Update for UnitDelay: '<S81>/Unit Delay' */
  1617. rtDW->UnitDelay_DSTATE_p = rtb_z_ctrlMod;
  1618. /* Update for UnitDelay: '<S81>/Unit Delay1' incorporates:
  1619. * Merge: '<S84>/Merge'
  1620. */
  1621. rtDW->UnitDelay1_DSTATE_g = rtDW->Merge_f;
  1622. /* End of Outputs for SubSystem: '<S53>/Subsystem' */
  1623. }
  1624. /* End of If: '<S53>/If' */
  1625. /* If: '<S48>/If' incorporates:
  1626. * Constant: '<S60>/Constant3'
  1627. * Constant: '<S60>/Constant4'
  1628. * Constant: '<S60>/Constant6'
  1629. * Constant: '<S60>/Constant9'
  1630. * Constant: '<S61>/Constant1'
  1631. * Constant: '<S61>/Constant7'
  1632. * Constant: '<S61>/Constant8'
  1633. * Constant: '<S61>/Constant9'
  1634. * Gain: '<S47>/Gain3'
  1635. * Gain: '<S47>/Gain5'
  1636. * If: '<S48>/If1'
  1637. * Inport: '<Root>/vbus_voltage'
  1638. * Sum: '<S60>/Add'
  1639. * Sum: '<S61>/Add1'
  1640. * Switch: '<S63>/Switch2'
  1641. * Switch: '<S67>/Switch2'
  1642. */
  1643. if (rtb_Sum == 1) {
  1644. /* Outputs for IfAction SubSystem: '<S48>/iq_ctrl' incorporates:
  1645. * ActionPort: '<S61>/Action Port'
  1646. */
  1647. /* Switch: '<S67>/Switch2' incorporates:
  1648. * Constant: '<S47>/Constant1'
  1649. * RelationalOperator: '<S67>/LowerRelop1'
  1650. * RelationalOperator: '<S67>/UpperRelop'
  1651. * Switch: '<S67>/Switch'
  1652. */
  1653. if (rtDW->Switch[1] > 7680) {
  1654. rtb_Divide1_m = 7680;
  1655. } else if (rtDW->Switch[1] < -7680) {
  1656. /* Switch: '<S67>/Switch' incorporates:
  1657. * Gain: '<S47>/Gain1'
  1658. * Switch: '<S67>/Switch2'
  1659. */
  1660. rtb_Divide1_m = -7680;
  1661. } else {
  1662. rtb_Divide1_m = rtDW->Switch[1];
  1663. }
  1664. /* End of Switch: '<S67>/Switch2' */
  1665. /* Outputs for Atomic SubSystem: '<S61>/PI_iq' */
  1666. PI_backCalc_fixdt((int16_T)(rtb_Divide1_m - rtb_DataTypeConversion[1]), 2048,
  1667. 26, 1024, rtU->vbus_voltage, (int16_T)-rtU->vbus_voltage,
  1668. 0, rtb_DataTypeConversion_m, &rtDW->Switch2_d,
  1669. &rtConstB.PI_iq, &rtDW->PI_iq, &rtPrevZCX->PI_iq);
  1670. /* End of Outputs for SubSystem: '<S61>/PI_iq' */
  1671. /* End of Outputs for SubSystem: '<S48>/iq_ctrl' */
  1672. /* Outputs for IfAction SubSystem: '<S48>/id_ctrl' incorporates:
  1673. * ActionPort: '<S60>/Action Port'
  1674. */
  1675. /* Switch: '<S63>/Switch2' incorporates:
  1676. * Constant: '<S47>/Constant1'
  1677. * Constant: '<S61>/Constant1'
  1678. * Constant: '<S61>/Constant7'
  1679. * Constant: '<S61>/Constant8'
  1680. * Constant: '<S61>/Constant9'
  1681. * Gain: '<S47>/Gain5'
  1682. * Inport: '<Root>/vbus_voltage'
  1683. * RelationalOperator: '<S63>/LowerRelop1'
  1684. * RelationalOperator: '<S63>/UpperRelop'
  1685. * Sum: '<S61>/Add1'
  1686. * Switch: '<S63>/Switch'
  1687. * Switch: '<S67>/Switch2'
  1688. */
  1689. if (rtDW->Switch[0] > 7680) {
  1690. rtb_Divide1_m = 7680;
  1691. } else if (rtDW->Switch[0] < -7680) {
  1692. /* Switch: '<S63>/Switch' incorporates:
  1693. * Gain: '<S47>/Gain4'
  1694. * Switch: '<S63>/Switch2'
  1695. */
  1696. rtb_Divide1_m = -7680;
  1697. } else {
  1698. rtb_Divide1_m = rtDW->Switch[0];
  1699. }
  1700. /* End of Switch: '<S63>/Switch2' */
  1701. /* Outputs for Atomic SubSystem: '<S60>/PI_id' */
  1702. PI_backCalc_fixdt((int16_T)(rtb_Divide1_m - rtb_DataTypeConversion[0]), 4096,
  1703. 51, 1024, rtU->vbus_voltage, (int16_T)-rtU->vbus_voltage,
  1704. 0, rtb_DataTypeConversion_m, &rtDW->Switch2,
  1705. &rtConstB.PI_id, &rtDW->PI_id, &rtPrevZCX->PI_id);
  1706. /* End of Outputs for SubSystem: '<S60>/PI_id' */
  1707. /* End of Outputs for SubSystem: '<S48>/id_ctrl' */
  1708. }
  1709. /* End of If: '<S48>/If' */
  1710. /* Switch: '<S6>/Switch' incorporates:
  1711. * Merge: '<S26>/Merge'
  1712. */
  1713. if (rtb_z_ctrlMod != 0) {
  1714. rtb_TmpSignalConversionAtLow_Pa[0] = rtDW->Switch2;
  1715. rtb_TmpSignalConversionAtLow_Pa[1] = rtDW->Switch2_d;
  1716. } else {
  1717. rtb_TmpSignalConversionAtLow_Pa[0] = rtDW->Merge[0];
  1718. rtb_TmpSignalConversionAtLow_Pa[1] = rtDW->Merge[1];
  1719. }
  1720. /* End of Switch: '<S6>/Switch' */
  1721. /* Gain: '<S51>/Gain' incorporates:
  1722. * Inport: '<Root>/vbus_voltage'
  1723. * Product: '<S49>/Divide1'
  1724. */
  1725. rtb_Divide1_m = (int16_T)((15565 * rtU->vbus_voltage) >> 14);
  1726. /* Product: '<S51>/Divide' incorporates:
  1727. * Math: '<S51>/Math Function'
  1728. * Math: '<S51>/Math Function1'
  1729. * Product: '<S49>/Divide1'
  1730. * Sum: '<S51>/Sum of Elements'
  1731. * Switch: '<S6>/Switch'
  1732. */
  1733. tmp = ((int64_T)(((rtb_TmpSignalConversionAtLow_Pa[0] *
  1734. rtb_TmpSignalConversionAtLow_Pa[0]) >> 6) +
  1735. ((rtb_TmpSignalConversionAtLow_Pa[1] *
  1736. rtb_TmpSignalConversionAtLow_Pa[1]) >> 6)) << 12) /
  1737. ((rtb_Divide1_m * rtb_Divide1_m) >> 6);
  1738. if (tmp > 32767LL) {
  1739. tmp = 32767LL;
  1740. } else {
  1741. if (tmp < -32768LL) {
  1742. tmp = -32768LL;
  1743. }
  1744. }
  1745. /* Sqrt: '<S51>/Sqrt' incorporates:
  1746. * Product: '<S51>/Divide'
  1747. */
  1748. rtb_Divide1_m = rt_sqrt_Us16En12_Ys16E_cQn1iwAF((int16_T)tmp);
  1749. /* Switch: '<S51>/Switch' incorporates:
  1750. * Product: '<S51>/Divide1'
  1751. * RelationalOperator: '<S79>/Compare'
  1752. * Sqrt: '<S51>/Sqrt'
  1753. * Switch: '<S6>/Switch'
  1754. */
  1755. if (rtb_Divide1_m > 4096) {
  1756. /* Product: '<S51>/Divide1' incorporates:
  1757. * Switch: '<S6>/Switch'
  1758. */
  1759. tmp_2 = (rtb_TmpSignalConversionAtLow_Pa[0] << 12) / rtb_Divide1_m;
  1760. rtb_TmpSignalConversionAtLow_Pa[0] = (int16_T)tmp_2;
  1761. /* Product: '<S51>/Divide1' incorporates:
  1762. * Switch: '<S51>/Switch'
  1763. * Switch: '<S6>/Switch'
  1764. */
  1765. tmp_2 = (rtb_TmpSignalConversionAtLow_Pa[1] << 12) / rtb_Divide1_m;
  1766. rtb_TmpSignalConversionAtLow_Pa[1] = (int16_T)tmp_2;
  1767. }
  1768. /* End of Switch: '<S51>/Switch' */
  1769. /* Sum: '<S49>/Sum1' incorporates:
  1770. * Interpolation_n-D: '<S58>/r_cos_M1'
  1771. * Interpolation_n-D: '<S58>/r_sin_M1'
  1772. * Product: '<S49>/Divide2'
  1773. * Product: '<S49>/Divide3'
  1774. */
  1775. tmp_2 = (int16_T)((rtb_TmpSignalConversionAtLow_Pa[0] *
  1776. rtConstP.pooled11[rtb_LogicalOperator3]) >> 14) + (int16_T)
  1777. ((rtb_TmpSignalConversionAtLow_Pa[1] *
  1778. rtConstP.pooled12[rtb_LogicalOperator3]) >> 14);
  1779. if (tmp_2 > 32767) {
  1780. tmp_2 = 32767;
  1781. } else {
  1782. if (tmp_2 < -32768) {
  1783. tmp_2 = -32768;
  1784. }
  1785. }
  1786. rtb_Divide1_m = (int16_T)tmp_2;
  1787. /* End of Sum: '<S49>/Sum1' */
  1788. /* Sum: '<S49>/Sum6' incorporates:
  1789. * Interpolation_n-D: '<S58>/r_cos_M1'
  1790. * Interpolation_n-D: '<S58>/r_sin_M1'
  1791. * Product: '<S49>/Divide1'
  1792. * Product: '<S49>/Divide4'
  1793. */
  1794. tmp_2 = (int16_T)((rtb_TmpSignalConversionAtLow_Pa[0] *
  1795. rtConstP.pooled12[rtb_LogicalOperator3]) >> 14) - (int16_T)
  1796. ((rtb_TmpSignalConversionAtLow_Pa[1] *
  1797. rtConstP.pooled11[rtb_LogicalOperator3]) >> 14);
  1798. if (tmp_2 > 32767) {
  1799. tmp_2 = 32767;
  1800. } else {
  1801. if (tmp_2 < -32768) {
  1802. tmp_2 = -32768;
  1803. }
  1804. }
  1805. /* Product: '<S70>/Divide7' incorporates:
  1806. * Constant: '<S70>/Constant3'
  1807. * Sum: '<S49>/Sum1'
  1808. */
  1809. rtb_Sign = (int16_T)((2365 * rtb_Divide1_m) >> 12);
  1810. /* MATLAB Function: '<S70>/sector_select' incorporates:
  1811. * Product: '<S70>/Divide7'
  1812. * Sum: '<S49>/Sum1'
  1813. * Sum: '<S49>/Sum6'
  1814. */
  1815. if (rtb_Divide1_m >= 0) {
  1816. if ((int16_T)tmp_2 >= 0) {
  1817. if (rtb_Sign > (int16_T)tmp_2) {
  1818. /* DataTypeConversion: '<S70>/Data Type Conversion' */
  1819. rtb_DataTypeConversion_m = 2U;
  1820. } else {
  1821. /* DataTypeConversion: '<S70>/Data Type Conversion' */
  1822. rtb_DataTypeConversion_m = 1U;
  1823. }
  1824. } else if (-rtb_Sign > (int16_T)tmp_2) {
  1825. /* DataTypeConversion: '<S70>/Data Type Conversion' */
  1826. rtb_DataTypeConversion_m = 3U;
  1827. } else {
  1828. /* DataTypeConversion: '<S70>/Data Type Conversion' */
  1829. rtb_DataTypeConversion_m = 2U;
  1830. }
  1831. } else if ((int16_T)tmp_2 >= 0) {
  1832. if (-rtb_Sign > (int16_T)tmp_2) {
  1833. /* DataTypeConversion: '<S70>/Data Type Conversion' */
  1834. rtb_DataTypeConversion_m = 5U;
  1835. } else {
  1836. /* DataTypeConversion: '<S70>/Data Type Conversion' */
  1837. rtb_DataTypeConversion_m = 6U;
  1838. }
  1839. } else if (rtb_Sign > (int16_T)tmp_2) {
  1840. /* DataTypeConversion: '<S70>/Data Type Conversion' */
  1841. rtb_DataTypeConversion_m = 4U;
  1842. } else {
  1843. /* DataTypeConversion: '<S70>/Data Type Conversion' */
  1844. rtb_DataTypeConversion_m = 5U;
  1845. }
  1846. /* End of MATLAB Function: '<S70>/sector_select' */
  1847. /* Gain: '<S70>/Gain' incorporates:
  1848. * Inport: '<Root>/vbus_voltage'
  1849. */
  1850. rtb_Gain = 18919 * rtU->vbus_voltage;
  1851. /* Product: '<S70>/Divide' incorporates:
  1852. * Gain: '<S70>/Gain'
  1853. * Sum: '<S49>/Sum6'
  1854. */
  1855. rtb_Switch_np = (int16_T)(((int64_T)(int16_T)tmp_2 << 26) / rtb_Gain);
  1856. /* Product: '<S70>/Divide1' incorporates:
  1857. * Gain: '<S70>/Gain'
  1858. * Sum: '<S49>/Sum1'
  1859. */
  1860. rtb_Divide1_m = (int16_T)(((int64_T)rtb_Divide1_m << 26) / rtb_Gain);
  1861. /* MultiPortSwitch: '<S71>/Multiport Switch' incorporates:
  1862. * DataTypeConversion: '<S70>/Data Type Conversion1'
  1863. */
  1864. switch (rtb_DataTypeConversion_m) {
  1865. case 1:
  1866. /* Product: '<S73>/Divide3' incorporates:
  1867. * Product: '<S70>/Divide1'
  1868. * Product: '<S73>/Divide2'
  1869. */
  1870. rtb_Sign = (int16_T)(((int16_T)((rtb_Divide1_m * 9459) >> 13) * 375) >> 9);
  1871. /* Product: '<S73>/Divide1' incorporates:
  1872. * Constant: '<S73>/Constant'
  1873. * Product: '<S70>/Divide'
  1874. * Product: '<S70>/Divide1'
  1875. * Product: '<S73>/Divide'
  1876. * Sum: '<S73>/Add'
  1877. */
  1878. rtb_Divide1_m = (int16_T)(((int16_T)(rtb_Switch_np - ((rtb_Divide1_m * 9459)
  1879. >> 14)) * 375) >> 9);
  1880. /* Product: '<S73>/Divide4' incorporates:
  1881. * Sum: '<S73>/Add1'
  1882. * Sum: '<S73>/Add2'
  1883. */
  1884. rtb_Switch_np = (int16_T)((int16_T)(3000 - (int16_T)(rtb_Divide1_m +
  1885. rtb_Sign)) >> 1);
  1886. /* Sum: '<S73>/Add3' */
  1887. rtb_Sign += rtb_Switch_np;
  1888. /* Outport: '<Root>/PWM' incorporates:
  1889. * Sum: '<S73>/Add4'
  1890. */
  1891. rtY->PWM[0] = (int16_T)(rtb_Sign + rtb_Divide1_m);
  1892. rtY->PWM[1] = rtb_Sign;
  1893. rtY->PWM[2] = rtb_Switch_np;
  1894. break;
  1895. case 2:
  1896. /* Product: '<S74>/Divide1' incorporates:
  1897. * Constant: '<S74>/Constant'
  1898. * Product: '<S70>/Divide'
  1899. * Product: '<S70>/Divide1'
  1900. * Product: '<S74>/Divide'
  1901. * Sum: '<S74>/Add'
  1902. */
  1903. rtb_Sign = (int16_T)(((int16_T)(((rtb_Divide1_m * 9459) >> 14) +
  1904. rtb_Switch_np) * 375) >> 9);
  1905. /* Product: '<S74>/Divide3' incorporates:
  1906. * Constant: '<S74>/Constant'
  1907. * Product: '<S70>/Divide'
  1908. * Product: '<S70>/Divide1'
  1909. * Product: '<S74>/Divide2'
  1910. * Sum: '<S74>/Add5'
  1911. */
  1912. rtb_Divide1_m = (int16_T)(((int16_T)(((rtb_Divide1_m * 9459) >> 14) -
  1913. rtb_Switch_np) * 375) >> 9);
  1914. /* Product: '<S74>/Divide4' incorporates:
  1915. * Sum: '<S74>/Add1'
  1916. * Sum: '<S74>/Add2'
  1917. */
  1918. rtb_Switch_np = (int16_T)((int16_T)(3000 - (int16_T)(rtb_Divide1_m +
  1919. rtb_Sign)) >> 1);
  1920. /* Sum: '<S74>/Add3' */
  1921. rtb_Sign += rtb_Switch_np;
  1922. /* Outport: '<Root>/PWM' incorporates:
  1923. * Sum: '<S74>/Add4'
  1924. */
  1925. rtY->PWM[0] = rtb_Sign;
  1926. rtY->PWM[1] = (int16_T)(rtb_Sign + rtb_Divide1_m);
  1927. rtY->PWM[2] = rtb_Switch_np;
  1928. break;
  1929. case 3:
  1930. /* Product: '<S75>/Divide1' incorporates:
  1931. * Constant: '<S75>/Constant'
  1932. * Product: '<S70>/Divide'
  1933. * Product: '<S70>/Divide1'
  1934. * Product: '<S75>/Divide'
  1935. * Sum: '<S75>/Add'
  1936. */
  1937. rtb_Switch_np = (int16_T)(((int16_T)(-rtb_Switch_np - ((rtb_Divide1_m * 9459)
  1938. >> 14)) * 375) >> 9);
  1939. /* Product: '<S75>/Divide3' incorporates:
  1940. * Product: '<S70>/Divide1'
  1941. * Product: '<S75>/Divide2'
  1942. */
  1943. rtb_Divide1_m = (int16_T)(((int16_T)((rtb_Divide1_m * 9459) >> 13) * 375) >>
  1944. 9);
  1945. /* Product: '<S75>/Divide4' incorporates:
  1946. * Sum: '<S75>/Add1'
  1947. * Sum: '<S75>/Add2'
  1948. */
  1949. rtb_Sign = (int16_T)((int16_T)(3000 - (int16_T)(rtb_Divide1_m +
  1950. rtb_Switch_np)) >> 1);
  1951. /* Sum: '<S75>/Add3' */
  1952. rtb_Switch_np += rtb_Sign;
  1953. /* Outport: '<Root>/PWM' incorporates:
  1954. * Sum: '<S75>/Add4'
  1955. */
  1956. rtY->PWM[0] = rtb_Sign;
  1957. rtY->PWM[1] = (int16_T)(rtb_Switch_np + rtb_Divide1_m);
  1958. rtY->PWM[2] = rtb_Switch_np;
  1959. break;
  1960. case 4:
  1961. /* Product: '<S76>/Divide1' incorporates:
  1962. * Constant: '<S76>/Constant'
  1963. * Product: '<S70>/Divide'
  1964. * Product: '<S70>/Divide1'
  1965. * Product: '<S76>/Divide'
  1966. * Sum: '<S76>/Add'
  1967. */
  1968. rtb_Switch_np = (int16_T)(((int16_T)(((rtb_Divide1_m * 9459) >> 14) -
  1969. rtb_Switch_np) * 375) >> 9);
  1970. /* Product: '<S76>/Divide3' incorporates:
  1971. * Product: '<S70>/Divide1'
  1972. * Product: '<S76>/Divide2'
  1973. * Sum: '<S76>/Add5'
  1974. */
  1975. rtb_Divide1_m = (int16_T)(((int16_T)(-((int16_T)((rtb_Divide1_m * 9459) >>
  1976. 13) << 2) >> 2) * 375) >> 9);
  1977. /* Product: '<S76>/Divide4' incorporates:
  1978. * Sum: '<S76>/Add1'
  1979. * Sum: '<S76>/Add2'
  1980. */
  1981. rtb_Sign = (int16_T)((int16_T)(3000 - (int16_T)(rtb_Divide1_m +
  1982. rtb_Switch_np)) >> 1);
  1983. /* Sum: '<S76>/Add3' */
  1984. rtb_Switch_np += rtb_Sign;
  1985. /* Outport: '<Root>/PWM' incorporates:
  1986. * Sum: '<S76>/Add4'
  1987. */
  1988. rtY->PWM[0] = rtb_Sign;
  1989. rtY->PWM[1] = rtb_Switch_np;
  1990. rtY->PWM[2] = (int16_T)(rtb_Switch_np + rtb_Divide1_m);
  1991. break;
  1992. case 5:
  1993. /* Product: '<S77>/Divide3' incorporates:
  1994. * Constant: '<S77>/Constant'
  1995. * Product: '<S70>/Divide'
  1996. * Product: '<S70>/Divide1'
  1997. * Product: '<S77>/Divide2'
  1998. * Sum: '<S77>/Add5'
  1999. */
  2000. rtb_Sign = (int16_T)(((int16_T)(rtb_Switch_np - ((rtb_Divide1_m * 9459) >>
  2001. 14)) * 375) >> 9);
  2002. /* Product: '<S77>/Divide1' incorporates:
  2003. * Constant: '<S77>/Constant'
  2004. * Product: '<S70>/Divide'
  2005. * Product: '<S70>/Divide1'
  2006. * Product: '<S77>/Divide'
  2007. * Sum: '<S77>/Add'
  2008. */
  2009. rtb_Divide1_m = (int16_T)(((int16_T)(-rtb_Switch_np - ((rtb_Divide1_m * 9459)
  2010. >> 14)) * 375) >> 9);
  2011. /* Product: '<S77>/Divide4' incorporates:
  2012. * Sum: '<S77>/Add1'
  2013. * Sum: '<S77>/Add2'
  2014. */
  2015. rtb_Switch_np = (int16_T)((int16_T)(3000 - (int16_T)(rtb_Divide1_m +
  2016. rtb_Sign)) >> 1);
  2017. /* Sum: '<S77>/Add3' */
  2018. rtb_Sign += rtb_Switch_np;
  2019. /* Outport: '<Root>/PWM' incorporates:
  2020. * Sum: '<S77>/Add4'
  2021. */
  2022. rtY->PWM[0] = rtb_Sign;
  2023. rtY->PWM[1] = rtb_Switch_np;
  2024. rtY->PWM[2] = (int16_T)(rtb_Sign + rtb_Divide1_m);
  2025. break;
  2026. default:
  2027. /* Product: '<S78>/Divide3' incorporates:
  2028. * Product: '<S70>/Divide1'
  2029. * Product: '<S78>/Divide2'
  2030. * Sum: '<S78>/Add5'
  2031. */
  2032. rtb_Sign = (int16_T)(((int16_T)(-((int16_T)((rtb_Divide1_m * 9459) >> 13) <<
  2033. 2) >> 2) * 375) >> 9);
  2034. /* Product: '<S78>/Divide1' incorporates:
  2035. * Constant: '<S78>/Constant'
  2036. * Product: '<S70>/Divide'
  2037. * Product: '<S70>/Divide1'
  2038. * Product: '<S78>/Divide'
  2039. * Sum: '<S78>/Add'
  2040. */
  2041. rtb_Divide1_m = (int16_T)(((int16_T)(((rtb_Divide1_m * 9459) >> 14) +
  2042. rtb_Switch_np) * 375) >> 9);
  2043. /* Product: '<S78>/Divide4' incorporates:
  2044. * Sum: '<S78>/Add1'
  2045. * Sum: '<S78>/Add2'
  2046. */
  2047. rtb_Switch_np = (int16_T)((int16_T)(3000 - (int16_T)(rtb_Divide1_m +
  2048. rtb_Sign)) >> 1);
  2049. /* Sum: '<S78>/Add3' */
  2050. rtb_Sign += rtb_Switch_np;
  2051. /* Outport: '<Root>/PWM' incorporates:
  2052. * Sum: '<S78>/Add4'
  2053. */
  2054. rtY->PWM[0] = (int16_T)(rtb_Sign + rtb_Divide1_m);
  2055. rtY->PWM[1] = rtb_Switch_np;
  2056. rtY->PWM[2] = rtb_Sign;
  2057. break;
  2058. }
  2059. /* End of MultiPortSwitch: '<S71>/Multiport Switch' */
  2060. /* Outport: '<Root>/VdPrev' incorporates:
  2061. * UnitDelay: '<S6>/UnitDelay1'
  2062. */
  2063. rtY->VdPrev = rtDW->UnitDelay1_DSTATE_f;
  2064. /* Update for UnitDelay: '<S7>/UnitDelay1' incorporates:
  2065. * Sum: '<S7>/Sum3'
  2066. */
  2067. rtDW->UnitDelay1_DSTATE = qY;
  2068. /* Update for Delay: '<S9>/Delay' incorporates:
  2069. * Inport: '<Root>/hall_a'
  2070. */
  2071. rtDW->Delay_DSTATE = rtU->hall_a;
  2072. /* Update for Delay: '<S9>/Delay1' incorporates:
  2073. * Inport: '<Root>/hall_b'
  2074. */
  2075. rtDW->Delay1_DSTATE = rtU->hall_b;
  2076. /* Update for Delay: '<S9>/Delay2' incorporates:
  2077. * Inport: '<Root>/hall_c'
  2078. */
  2079. rtDW->Delay2_DSTATE = rtU->hall_c;
  2080. /* Update for UnitDelay: '<S14>/UnitDelay3' incorporates:
  2081. * Inport: '<Root>/hw_count'
  2082. */
  2083. rtDW->UnitDelay3_DSTATE = rtU->hw_count;
  2084. /* Update for UnitDelay: '<S14>/UnitDelay4' incorporates:
  2085. * Abs: '<S14>/Abs5'
  2086. */
  2087. rtDW->UnitDelay4_DSTATE = rtb_Switch2;
  2088. /* Update for UnitDelay: '<S35>/UnitDelay' */
  2089. rtDW->UnitDelay_DSTATE_j = rtb_UnitDelay_bc;
  2090. /* Update for UnitDelay: '<S6>/UnitDelay2' */
  2091. rtDW->UnitDelay2_DSTATE_p = rtb_TmpSignalConversionAtLow_Pa[1];
  2092. /* Update for UnitDelay: '<S48>/Unit Delay' */
  2093. rtDW->UnitDelay_DSTATE_b = rtb_Sum;
  2094. /* Update for UnitDelay: '<S6>/UnitDelay1' */
  2095. rtDW->UnitDelay1_DSTATE_f = rtb_TmpSignalConversionAtLow_Pa[0];
  2096. /* End of Outputs for SubSystem: '<Root>/PMSM_Controller' */
  2097. /* Outport: '<Root>/sector' */
  2098. rtY->sector = rtb_DataTypeConversion_m;
  2099. /* Outport: '<Root>/n_MotError' */
  2100. rtY->n_MotError = rtb_UnitDelay_bc;
  2101. /* Outport: '<Root>/id' */
  2102. rtY->id = rtb_DataTypeConversion[0];
  2103. /* Outport: '<Root>/iq' */
  2104. rtY->iq = rtb_DataTypeConversion[1];
  2105. /* Outport: '<Root>/angle' incorporates:
  2106. * Merge: '<S3>/Merge'
  2107. */
  2108. rtY->angle = rtDW->Merge_i;
  2109. /* Outport: '<Root>/rpm' incorporates:
  2110. * Switch: '<S14>/Switch2'
  2111. */
  2112. rtY->rpm = rtb_Switch2_l;
  2113. /* Outport: '<Root>/hall_angle' incorporates:
  2114. * Merge: '<S15>/Merge'
  2115. */
  2116. rtY->hall_angle = rtb_Switch3_c;
  2117. /* Outport: '<Root>/hall_state' */
  2118. rtY->hall_state = rtb_Add_cr;
  2119. /* Outport: '<Root>/running_mode' */
  2120. rtY->running_mode = rtb_z_ctrlMod;
  2121. }
  2122. /* Model initialize function */
  2123. void PMSM_Controller_initialize(RT_MODEL *const rtM)
  2124. {
  2125. DW *rtDW = rtM->dwork;
  2126. PrevZCX *rtPrevZCX = rtM->prevZCSigState;
  2127. ExtY *rtY = (ExtY *) rtM->outputs;
  2128. rtPrevZCX->pi_speed_d.ResettableDelay_Reset_ZCE = POS_ZCSIG;
  2129. rtPrevZCX->PI_id.ResettableDelay_Reset_ZCE_p = POS_ZCSIG;
  2130. rtPrevZCX->PI_iq.ResettableDelay_Reset_ZCE_p = POS_ZCSIG;
  2131. /* SystemInitialize for Atomic SubSystem: '<Root>/PMSM_Controller' */
  2132. /* SystemInitialize for IfAction SubSystem: '<S14>/Raw_Motor_Speed_Estimation' */
  2133. /* InitializeConditions for UnitDelay: '<S19>/UnitDelay2' */
  2134. rtDW->UnitDelay2_DSTATE = 200000U;
  2135. /* SystemInitialize for Outport: '<S19>/z_counter' incorporates:
  2136. * Inport: '<S19>/z_counterRawPrev'
  2137. */
  2138. rtDW->z_counterRawPrev = 200000U;
  2139. /* End of SystemInitialize for SubSystem: '<S14>/Raw_Motor_Speed_Estimation' */
  2140. /* SystemInitialize for Atomic SubSystem: '<S35>/Debounce_Filter' */
  2141. Debounce_Filter_Init(&rtDW->Debounce_Filter_i);
  2142. /* End of SystemInitialize for SubSystem: '<S35>/Debounce_Filter' */
  2143. /* SystemInitialize for IfAction SubSystem: '<S53>/Subsystem' */
  2144. /* SystemInitialize for IfAction SubSystem: '<S84>/speed_mode' */
  2145. /* SystemInitialize for Atomic SubSystem: '<S90>/pi_speed' */
  2146. pi_speed_Init(&rtDW->pi_speed_d);
  2147. /* End of SystemInitialize for SubSystem: '<S90>/pi_speed' */
  2148. /* End of SystemInitialize for SubSystem: '<S84>/speed_mode' */
  2149. /* End of SystemInitialize for SubSystem: '<S53>/Subsystem' */
  2150. /* SystemInitialize for IfAction SubSystem: '<S48>/iq_ctrl' */
  2151. /* SystemInitialize for Atomic SubSystem: '<S61>/PI_iq' */
  2152. PI_backCalc_fixdt_Init(&rtDW->PI_iq);
  2153. /* End of SystemInitialize for SubSystem: '<S61>/PI_iq' */
  2154. /* End of SystemInitialize for SubSystem: '<S48>/iq_ctrl' */
  2155. /* SystemInitialize for IfAction SubSystem: '<S48>/id_ctrl' */
  2156. /* SystemInitialize for Atomic SubSystem: '<S60>/PI_id' */
  2157. PI_backCalc_fixdt_Init(&rtDW->PI_id);
  2158. /* End of SystemInitialize for SubSystem: '<S60>/PI_id' */
  2159. /* End of SystemInitialize for SubSystem: '<S48>/id_ctrl' */
  2160. /* End of SystemInitialize for SubSystem: '<Root>/PMSM_Controller' */
  2161. /* SystemInitialize for Outport: '<Root>/angle' incorporates:
  2162. * Merge: '<S3>/Merge'
  2163. */
  2164. rtY->angle = rtDW->Merge_i;
  2165. }
  2166. /*
  2167. * File trailer for generated code.
  2168. *
  2169. * [EOF]
  2170. */