user_interface.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. /**
  2. ******************************************************************************
  3. * @file user_interface.c
  4. * @author Motor Control SDK Team, ST Microelectronics
  5. * @brief This file provides firmware functions that implement the following features
  6. * of the user interface component of the Motor Control SDK.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by ST under Ultimate Liberty license
  14. * SLA0044, the "License"; You may not use this file except in compliance with
  15. * the License. You may obtain a copy of the License at:
  16. * www.st.com/SLA0044
  17. *
  18. ******************************************************************************
  19. */
  20. /* Includes ------------------------------------------------------------------*/
  21. /* Pre-compiler coherency check */
  22. #include "mc_type.h"
  23. #include "mc_math.h"
  24. #include "mc_config.h"
  25. #include "user_interface.h"
  26. /** @addtogroup MCSDK
  27. * @{
  28. */
  29. /** @defgroup MCUI Motor Control User Interface
  30. * @brief User Interface Components of the Motor Control SDK
  31. *
  32. * These components aim at connecting the Application with the outside. There are two categories
  33. * of UI Componentes:
  34. *
  35. * - Some connect the application with the Motor Conrol Monitor tool via a UART link. The Motor
  36. * Control Monitor can control the motor(s) driven by the application and also read and write
  37. * internal variables of the Motor Control subsystem.
  38. * - Others UI components allow for using the DAC(s) peripherals in
  39. * order to output internal variables of the Motor Control subsystem for debug purposes.
  40. *
  41. * @{
  42. */
  43. /**
  44. * @brief Initialize the user interface component.
  45. *
  46. * Perform the link between the UI, MC interface and MC tuning components.
  47. * @param pHandle: Pointer on Handle structure of UI component.
  48. * @param bMCNum Number of MC instance present in the list.
  49. * @param pMCI Pointer on the list of MC interface component to inked with UI.
  50. * @param pMCT Pointer on the list of MC tuning component to inked with UI.
  51. * @param pUICfg Pointer on the user interface configuration list.
  52. * Each element of the list must be a bit field containing one (or more) of
  53. * the exported configuration option UI_CFGOPT_xxx (eventually OR-ed).
  54. * @retval none.
  55. */
  56. __weak void UI_Init(UI_Handle_t *pHandle, uint8_t bMCNum, MCI_Handle_t ** pMCI, MCT_Handle_t** pMCT, uint32_t* pUICfg)
  57. {
  58. pHandle->bDriveNum = bMCNum;
  59. pHandle->pMCI = pMCI;
  60. pHandle->pMCT = pMCT;
  61. pHandle->bSelectedDrive = 0u;
  62. pHandle->pUICfg = pUICfg;
  63. }
  64. /**
  65. * @brief Allow to select the MC on which UI operates.
  66. * @param pHandle: Pointer on Handle structure of UI component.
  67. * @param bSelectMC: The new selected MC, zero based, on which UI operates.
  68. * @retval Boolean set to true if the bSelectMC is valid oterwise return false.
  69. */
  70. __weak bool UI_SelectMC(UI_Handle_t *pHandle,uint8_t bSelectMC)
  71. {
  72. bool retVal = true;
  73. if (bSelectMC >= pHandle->bDriveNum)
  74. {
  75. retVal = false;
  76. }
  77. else
  78. {
  79. pHandle->bSelectedDrive = bSelectMC;
  80. }
  81. return retVal;
  82. }
  83. /**
  84. * @brief Allow to retrieve the MC on which UI currently operates.
  85. * @param pHandle: Pointer on Handle structure of UI component.
  86. * @retval Return the currently selected MC, zero based, on which UI operates.
  87. */
  88. __weak uint8_t UI_GetSelectedMC(UI_Handle_t *pHandle)
  89. {
  90. return (pHandle->bSelectedDrive);
  91. }
  92. /**
  93. * @brief Retrieve the configuration of the MC on which UI currently operates.
  94. * @param pHandle: Pointer on Handle structure of UI component.
  95. * @retval Return the currently configuration of selected MC on which UI operates.
  96. * It represents a bit field containing one (or more) of
  97. * the exported configuration option UI_CFGOPT_xxx (eventually OR-ed).
  98. */
  99. __weak uint32_t UI_GetSelectedMCConfig(UI_Handle_t *pHandle)
  100. {
  101. return pHandle->pUICfg[pHandle->bSelectedDrive];
  102. }
  103. /**
  104. * @brief Allow to execute a SetReg command coming from the user.
  105. * @param pHandle: Pointer on Handle structure of UI component.
  106. * @param bRegID: Code of register to update.
  107. * See MC_PROTOCOL_REG_xxx for code definition.
  108. * @param wValue: New value to set.
  109. * @retval Return the currently selected MC, zero based, on which UI operates.
  110. */
  111. __weak bool UI_SetReg(UI_Handle_t *pHandle, MC_Protocol_REG_t bRegID, int32_t wValue)
  112. {
  113. MCI_Handle_t * pMCI = pHandle->pMCI[pHandle->bSelectedDrive];
  114. MCT_Handle_t * pMCT = pHandle->pMCT[pHandle->bSelectedDrive];
  115. bool retVal = true;
  116. switch (bRegID)
  117. {
  118. case MC_PROTOCOL_REG_TARGET_MOTOR:
  119. {
  120. retVal = UI_SelectMC(pHandle,(uint8_t)wValue);
  121. }
  122. break;
  123. case MC_PROTOCOL_REG_RAMP_FINAL_SPEED:
  124. {
  125. MCI_ExecSpeedRamp(pMCI,(int16_t)((wValue*SPEED_UNIT)/_RPM),0);
  126. }
  127. break;
  128. case MC_PROTOCOL_REG_SPEED_KP:
  129. {
  130. PID_SetKP(pMCT->pPIDSpeed,(int16_t)wValue);
  131. }
  132. break;
  133. case MC_PROTOCOL_REG_SPEED_KI:
  134. {
  135. PID_SetKI(pMCT->pPIDSpeed,(int16_t)wValue);
  136. }
  137. break;
  138. case MC_PROTOCOL_REG_SPEED_KD:
  139. {
  140. PID_SetKD(pMCT->pPIDSpeed,(int16_t)wValue);
  141. }
  142. break;
  143. case MC_PROTOCOL_REG_CONTROL_MODE:
  144. {
  145. if ((STC_Modality_t)wValue == STC_TORQUE_MODE)
  146. {
  147. MCI_ExecTorqueRamp(pMCI, MCI_GetTeref(pMCI),0);
  148. }
  149. if ((STC_Modality_t)wValue == STC_SPEED_MODE)
  150. {
  151. MCI_ExecSpeedRamp(pMCI, MCI_GetMecSpeedRefUnit(pMCI),0);
  152. }
  153. }
  154. break;
  155. case MC_PROTOCOL_REG_TORQUE_REF:
  156. {
  157. qd_t currComp;
  158. currComp = MCI_GetIqdref(pMCI);
  159. currComp.q = (int16_t)wValue;
  160. MCI_SetCurrentReferences(pMCI,currComp);
  161. }
  162. break;
  163. case MC_PROTOCOL_REG_TORQUE_KP:
  164. {
  165. PID_SetKP(pMCT->pPIDIq,(int16_t)wValue);
  166. }
  167. break;
  168. case MC_PROTOCOL_REG_TORQUE_KI:
  169. {
  170. PID_SetKI(pMCT->pPIDIq,(int16_t)wValue);
  171. }
  172. break;
  173. case MC_PROTOCOL_REG_TORQUE_KD:
  174. {
  175. PID_SetKD(pMCT->pPIDIq,(int16_t)wValue);
  176. }
  177. break;
  178. case MC_PROTOCOL_REG_FLUX_REF:
  179. {
  180. qd_t currComp;
  181. currComp = MCI_GetIqdref(pMCI);
  182. currComp.d = (int16_t)wValue;
  183. MCI_SetCurrentReferences(pMCI,currComp);
  184. }
  185. break;
  186. case MC_PROTOCOL_REG_FLUX_KP:
  187. {
  188. PID_SetKP(pMCT->pPIDId,(int16_t)wValue);
  189. }
  190. break;
  191. case MC_PROTOCOL_REG_FLUX_KI:
  192. {
  193. PID_SetKI(pMCT->pPIDId,(int16_t)wValue);
  194. }
  195. break;
  196. case MC_PROTOCOL_REG_FLUX_KD:
  197. {
  198. PID_SetKD(pMCT->pPIDId,(int16_t)wValue);
  199. }
  200. break;
  201. case MC_PROTOCOL_REG_IQ_SPEEDMODE:
  202. {
  203. MCI_SetIdref(pMCI,(int16_t)wValue);
  204. }
  205. break;
  206. default:
  207. retVal = false;
  208. break;
  209. }
  210. return retVal;
  211. }
  212. /* Used to execute a GetReg command coming from the user. */
  213. __weak int32_t UI_GetReg(UI_Handle_t *pHandle, MC_Protocol_REG_t bRegID, bool * success)
  214. {
  215. MCT_Handle_t* pMCT = pHandle->pMCT[pHandle->bSelectedDrive];
  216. MCI_Handle_t * pMCI = pHandle->pMCI[pHandle->bSelectedDrive];
  217. int32_t bRetVal = 0;
  218. if ( success != (bool *) 0 )
  219. {
  220. *success = true;
  221. }
  222. switch (bRegID)
  223. {
  224. case MC_PROTOCOL_REG_TARGET_MOTOR:
  225. {
  226. bRetVal = (int32_t)UI_GetSelectedMC(pHandle);
  227. }
  228. break;
  229. case MC_PROTOCOL_REG_FLAGS:
  230. {
  231. bRetVal = (int32_t)STM_GetFaultState(pMCT->pStateMachine);
  232. }
  233. break;
  234. case MC_PROTOCOL_REG_STATUS:
  235. {
  236. bRetVal = (int32_t)STM_GetState(pMCT->pStateMachine);
  237. }
  238. break;
  239. case MC_PROTOCOL_REG_SPEED_REF:
  240. {
  241. bRetVal = (int32_t)((MCI_GetMecSpeedRefUnit(pMCI)*_RPM)/SPEED_UNIT);
  242. }
  243. break;
  244. case MC_PROTOCOL_REG_SPEED_KP:
  245. {
  246. bRetVal = (int32_t)PID_GetKP(pMCT->pPIDSpeed);
  247. }
  248. break;
  249. case MC_PROTOCOL_REG_SPEED_KI:
  250. {
  251. bRetVal = (int32_t)PID_GetKI(pMCT->pPIDSpeed);
  252. }
  253. break;
  254. case MC_PROTOCOL_REG_SPEED_KD:
  255. {
  256. bRetVal = (int32_t)PID_GetKD(pMCT->pPIDSpeed);
  257. }
  258. break;
  259. case MC_PROTOCOL_REG_BUS_VOLTAGE:
  260. {
  261. bRetVal = (int32_t)VBS_GetAvBusVoltage_V(pMCT->pBusVoltageSensor);
  262. }
  263. break;
  264. case MC_PROTOCOL_REG_HEATS_TEMP:
  265. {
  266. bRetVal = (int32_t)NTC_GetAvTemp_C(pMCT->pTemperatureSensor);
  267. }
  268. break;
  269. case MC_PROTOCOL_REG_SPEED_MEAS:
  270. {
  271. bRetVal = (int32_t)((MCI_GetAvrgMecSpeedUnit(pMCI) * _RPM)/SPEED_UNIT);
  272. }
  273. break;
  274. case MC_PROTOCOL_REG_UID:
  275. {
  276. bRetVal = (int32_t)(MC_UID);
  277. }
  278. break;
  279. case MC_PROTOCOL_REG_CTRBDID:
  280. {
  281. bRetVal = CTRBDID;
  282. }
  283. break;
  284. case MC_PROTOCOL_REG_PWBDID:
  285. {
  286. bRetVal = PWBDID;
  287. }
  288. break;
  289. case MC_PROTOCOL_REG_PWBDID2:
  290. {
  291. bRetVal = (uint32_t) 0;
  292. }
  293. break;
  294. case MC_PROTOCOL_REG_TORQUE_REF:
  295. {
  296. qd_t currComp;
  297. currComp = MCI_GetIqdref(pMCI);
  298. bRetVal = (int32_t)currComp.q;
  299. }
  300. break;
  301. case MC_PROTOCOL_REG_FLUX_REF:
  302. {
  303. qd_t currComp;
  304. currComp = MCI_GetIqdref(pMCI);
  305. bRetVal = (int32_t)currComp.d;
  306. }
  307. break;
  308. case MC_PROTOCOL_REG_CONTROL_MODE:
  309. {
  310. bRetVal = (int32_t)MCI_GetControlMode(pMCI);
  311. }
  312. break;
  313. case MC_PROTOCOL_REG_RAMP_FINAL_SPEED:
  314. {
  315. if (MCI_GetControlMode(pMCI) == STC_SPEED_MODE)
  316. {
  317. bRetVal = (int32_t)((MCI_GetLastRampFinalSpeed(pMCI) * _RPM)/SPEED_UNIT) ;
  318. }
  319. else
  320. {
  321. bRetVal = (int32_t)((MCI_GetMecSpeedRefUnit(pMCI) * _RPM)/SPEED_UNIT) ;
  322. }
  323. }
  324. break;
  325. case MC_PROTOCOL_REG_SPEED_KP_DIV:
  326. {
  327. bRetVal = (int32_t)PID_GetKPDivisor(pMCT->pPIDSpeed);
  328. }
  329. break;
  330. case MC_PROTOCOL_REG_SPEED_KI_DIV:
  331. {
  332. bRetVal = (int32_t)PID_GetKIDivisor(pMCT->pPIDSpeed);
  333. }
  334. break;
  335. case MC_PROTOCOL_REG_TORQUE_KP:
  336. {
  337. bRetVal = (int32_t)PID_GetKP(pMCT->pPIDIq);
  338. }
  339. break;
  340. case MC_PROTOCOL_REG_TORQUE_KI:
  341. {
  342. bRetVal = (int32_t)PID_GetKI(pMCT->pPIDIq);
  343. }
  344. break;
  345. case MC_PROTOCOL_REG_TORQUE_KD:
  346. {
  347. bRetVal = (int32_t)PID_GetKD(pMCT->pPIDIq);
  348. }
  349. break;
  350. case MC_PROTOCOL_REG_IQ_SPEEDMODE:
  351. {
  352. qd_t currComp;
  353. currComp = MCI_GetIqdref(pMCI);
  354. bRetVal = (int32_t)currComp.d;
  355. }
  356. break;
  357. case MC_PROTOCOL_REG_FLUX_KP:
  358. {
  359. bRetVal = (int32_t)PID_GetKP(pMCT->pPIDId);
  360. }
  361. break;
  362. case MC_PROTOCOL_REG_FLUX_KI:
  363. {
  364. bRetVal = (int32_t)PID_GetKI(pMCT->pPIDId);
  365. }
  366. break;
  367. case MC_PROTOCOL_REG_FLUX_KD:
  368. {
  369. bRetVal = (int32_t)PID_GetKD(pMCT->pPIDId);
  370. }
  371. break;
  372. case MC_PROTOCOL_REG_MOTOR_POWER:
  373. {
  374. bRetVal = MPM_GetAvrgElMotorPowerW(pMCT->pMPM);
  375. }
  376. break;
  377. case MC_PROTOCOL_REG_MEAS_EL_ANGLE:
  378. {
  379. uint32_t hUICfg = pHandle->pUICfg[pHandle->bSelectedDrive];
  380. SpeednPosFdbk_Handle_t* pSPD = MC_NULL;
  381. if ((MAIN_SCFG_VALUE(hUICfg) == UI_SCODE_ENC) ||
  382. (MAIN_SCFG_VALUE(hUICfg) == UI_SCODE_HALL))
  383. {
  384. pSPD = pMCT->pSpeedSensorMain;
  385. }
  386. if ((AUX_SCFG_VALUE(hUICfg) == UI_SCODE_ENC) ||
  387. (AUX_SCFG_VALUE(hUICfg) == UI_SCODE_HALL))
  388. {
  389. pSPD = pMCT->pSpeedSensorAux;
  390. }
  391. if (pSPD != MC_NULL)
  392. {
  393. bRetVal = SPD_GetElAngle(pSPD);
  394. }
  395. }
  396. break;
  397. case MC_PROTOCOL_REG_MEAS_ROT_SPEED:
  398. {
  399. uint32_t hUICfg = pHandle->pUICfg[pHandle->bSelectedDrive];
  400. SpeednPosFdbk_Handle_t* pSPD = MC_NULL;
  401. if ((MAIN_SCFG_VALUE(hUICfg) == UI_SCODE_ENC) ||
  402. (MAIN_SCFG_VALUE(hUICfg) == UI_SCODE_HALL))
  403. {
  404. pSPD = pMCT->pSpeedSensorMain;
  405. }
  406. if ((AUX_SCFG_VALUE(hUICfg) == UI_SCODE_ENC) ||
  407. (AUX_SCFG_VALUE(hUICfg) == UI_SCODE_HALL))
  408. {
  409. pSPD = pMCT->pSpeedSensorAux;
  410. }
  411. if (pSPD != MC_NULL)
  412. {
  413. bRetVal = SPD_GetS16Speed(pSPD);
  414. }
  415. }
  416. break;
  417. case MC_PROTOCOL_REG_MAX_APP_SPEED:
  418. {
  419. bRetVal = (STC_GetMaxAppPositiveMecSpeedUnit(pMCT->pSpeednTorqueCtrl) * _RPM)/SPEED_UNIT ;
  420. }
  421. break;
  422. case MC_PROTOCOL_REG_MIN_APP_SPEED:
  423. {
  424. bRetVal = (STC_GetMinAppNegativeMecSpeedUnit(pMCT->pSpeednTorqueCtrl) * _RPM)/SPEED_UNIT ;
  425. }
  426. break;
  427. case MC_PROTOCOL_REG_TORQUE_MEAS:
  428. case MC_PROTOCOL_REG_I_Q:
  429. {
  430. bRetVal = MCI_GetIqd(pMCI).q;
  431. }
  432. break;
  433. case MC_PROTOCOL_REG_FLUX_MEAS:
  434. case MC_PROTOCOL_REG_I_D:
  435. {
  436. bRetVal = MCI_GetIqd(pMCI).d;
  437. }
  438. break;
  439. case MC_PROTOCOL_REG_RUC_STAGE_NBR:
  440. {
  441. if (pMCT->pRevupCtrl)
  442. {
  443. bRetVal = (int32_t)RUC_GetNumberOfPhases(pMCT->pRevupCtrl);
  444. }
  445. else
  446. {
  447. bRetVal = (uint32_t) 0;
  448. }
  449. }
  450. break;
  451. case MC_PROTOCOL_REG_I_A:
  452. {
  453. bRetVal = MCI_GetIab(pMCI).a;
  454. }
  455. break;
  456. case MC_PROTOCOL_REG_I_B:
  457. {
  458. bRetVal = MCI_GetIab(pMCI).b;
  459. }
  460. break;
  461. case MC_PROTOCOL_REG_I_ALPHA:
  462. {
  463. bRetVal = MCI_GetIalphabeta(pMCI).alpha;
  464. }
  465. break;
  466. case MC_PROTOCOL_REG_I_BETA:
  467. {
  468. bRetVal = MCI_GetIalphabeta(pMCI).beta;
  469. }
  470. break;
  471. case MC_PROTOCOL_REG_I_Q_REF:
  472. {
  473. bRetVal = MCI_GetIqdref(pMCI).q;
  474. }
  475. break;
  476. case MC_PROTOCOL_REG_I_D_REF:
  477. {
  478. bRetVal = MCI_GetIqdref(pMCI).d;
  479. }
  480. break;
  481. case MC_PROTOCOL_REG_V_Q:
  482. {
  483. bRetVal = MCI_GetVqd(pMCI).q;
  484. }
  485. break;
  486. case MC_PROTOCOL_REG_V_D:
  487. {
  488. bRetVal = MCI_GetVqd(pMCI).d;
  489. }
  490. break;
  491. case MC_PROTOCOL_REG_V_ALPHA:
  492. {
  493. bRetVal = MCI_GetValphabeta(pMCI).alpha;
  494. }
  495. break;
  496. case MC_PROTOCOL_REG_V_BETA:
  497. {
  498. bRetVal = MCI_GetValphabeta(pMCI).beta;
  499. }
  500. break;
  501. default:
  502. {
  503. if ( success != (bool *) 0 )
  504. {
  505. *success = false;
  506. }
  507. }
  508. break;
  509. }
  510. return bRetVal;
  511. }
  512. /**
  513. * @brief Allow to execute a command coming from the user.
  514. * @param pHandle: Pointer on Handle structure of UI component.
  515. * @param bCmdID: Code of command to execute.
  516. * See MC_PROTOCOL_CMD_xxx for code definition.
  517. * @retval Return true if the command executed succesfully, otherwise false.
  518. */
  519. __weak bool UI_ExecCmd(UI_Handle_t *pHandle, uint8_t bCmdID)
  520. {
  521. bool retVal = true;
  522. MCI_Handle_t * pMCI = pHandle->pMCI[pHandle->bSelectedDrive];
  523. switch (bCmdID)
  524. {
  525. case MC_PROTOCOL_CMD_START_MOTOR:
  526. {
  527. /* Call MCI Start motor; */
  528. MCI_StartMotor(pMCI);
  529. }
  530. break;
  531. case MC_PROTOCOL_CMD_STOP_MOTOR:
  532. case MC_PROTOCOL_CMD_SC_STOP:
  533. {
  534. /* Call MCI Stop motor; */
  535. MCI_StopMotor(pMCI);
  536. }
  537. break;
  538. case MC_PROTOCOL_CMD_STOP_RAMP:
  539. {
  540. if (MCI_GetSTMState(pMCI) == RUN)
  541. {
  542. MCI_StopRamp(pMCI);
  543. }
  544. }
  545. break;
  546. case MC_PROTOCOL_CMD_PING:
  547. {
  548. /* Do nothing at the moment */
  549. }
  550. break;
  551. case MC_PROTOCOL_CMD_START_STOP:
  552. {
  553. /* Queries the STM and a command start or stop depending on the state. */
  554. if (MCI_GetSTMState(pMCI) == IDLE)
  555. {
  556. MCI_StartMotor(pMCI);
  557. }
  558. else
  559. {
  560. MCI_StopMotor(pMCI);
  561. }
  562. }
  563. break;
  564. case MC_PROTOCOL_CMD_RESET:
  565. {
  566. /* Do nothing at the moment */
  567. }
  568. break;
  569. case MC_PROTOCOL_CMD_FAULT_ACK:
  570. {
  571. MCI_FaultAcknowledged(pMCI);
  572. }
  573. break;
  574. case MC_PROTOCOL_CMD_ENCODER_ALIGN:
  575. {
  576. MCI_EncoderAlign(pMCI);
  577. }
  578. break;
  579. case MC_PROTOCOL_CMD_IQDREF_CLEAR:
  580. {
  581. MCI_Clear_Iqdref(pMCI);
  582. }
  583. break;
  584. default:
  585. {
  586. retVal = false;
  587. }
  588. break;
  589. }
  590. return retVal;
  591. }
  592. /**
  593. * @brief Allow to execute a speed ramp command coming from the user.
  594. * @param pHandle: Pointer on Handle structure of UI component.
  595. * @param wFinalMecSpeedUnit: Final speed value expressed in the unit defined by #SPEED_UNIT.
  596. * @param hDurationms: Duration of the ramp expressed in milliseconds.
  597. * It is possible to set 0 to perform an instantaneous change in the value.
  598. * @retval Return true if the command executed succesfully, otherwise false.
  599. */
  600. __weak bool UI_ExecSpeedRamp(UI_Handle_t *pHandle, int32_t wFinalMecSpeedUnit, uint16_t hDurationms)
  601. {
  602. MCI_Handle_t * pMCI = pHandle->pMCI[pHandle->bSelectedDrive];
  603. /* Call MCI Exec Ramp */
  604. MCI_ExecSpeedRamp(pMCI,(int16_t)((wFinalMecSpeedUnit*SPEED_UNIT)/_RPM),hDurationms);
  605. return true;
  606. }
  607. /**
  608. * @brief It is used to execute a torque ramp command coming from the user.
  609. * @param pHandle: Pointer on Handle structure of UI component.
  610. * @param hTargetFinal: final torque value. See MCI interface for more
  611. details.
  612. * @param hDurationms: the duration of the ramp expressed in milliseconds. It
  613. * is possible to set 0 to perform an instantaneous change in the value.
  614. * @retval Return true if the command executed succesfully, otherwise false.
  615. */
  616. __weak bool UI_ExecTorqueRamp(UI_Handle_t *pHandle, int16_t hTargetFinal, uint16_t hDurationms)
  617. {
  618. MCI_Handle_t * pMCI = pHandle->pMCI[pHandle->bSelectedDrive];
  619. /* Call MCI Exec Ramp */
  620. MCI_ExecTorqueRamp(pMCI,hTargetFinal,hDurationms);
  621. return true;
  622. }
  623. /**
  624. * @brief Executes a get Revup data command coming from the user
  625. *
  626. * @param pHandle Pointer on Handle structure of UI component.
  627. * @param bStage Rev up phase to be read (zero based).
  628. * @param pDurationms Pointer to an uint16_t variable used to retrieve
  629. * the duration of the Revup stage.
  630. * @param pFinalMecSpeedUnit Pointer to an int16_t variable used to
  631. * retrieve the mechanical speed at the end of that stage. Expressed in
  632. * the unit defined by #SPEED_UNIT.
  633. * @param pFinalTorque Pointer to an int16_t variable used to
  634. * retrieve the value of motor torque at the end of that stage.
  635. * This value represents actually the Iq current expressed in digit.
  636. *
  637. * @retval Returns true if the command executed successfully, false otherwise.
  638. */
  639. __weak bool UI_GetRevupData(UI_Handle_t *pHandle, uint8_t bStage, uint16_t* pDurationms,
  640. int16_t* pFinalMecSpeedUnit, int16_t* pFinalTorque )
  641. {
  642. bool hRetVal = true;
  643. RevUpCtrl_Handle_t *pRevupCtrl = pHandle->pMCT[pHandle->bSelectedDrive]->pRevupCtrl;
  644. if (pRevupCtrl)
  645. {
  646. *pDurationms = RUC_GetPhaseDurationms(pRevupCtrl, bStage);
  647. *pFinalMecSpeedUnit = RUC_GetPhaseFinalMecSpeedUnit(pRevupCtrl, bStage);
  648. *pFinalTorque = RUC_GetPhaseFinalTorque(pRevupCtrl, bStage);
  649. }
  650. else
  651. {
  652. hRetVal = false;
  653. }
  654. return hRetVal;
  655. }
  656. /**
  657. * @brief It is used to execute a set Revup data command coming from the user.
  658. * @param pHandle: Pointer on Handle structure of UI component.
  659. * @param bStage: is the rev up phase, zero based, to be modified.
  660. * @param hDurationms: is the new duration of the Revup stage.
  661. * @param hFinalMecSpeedUnit: is the new mechanical speed at the end of that
  662. * stage expressed in the unit defined by SPEED_UNIT.
  663. * @param hFinalTorque: is the new value of motor torque at the end of that
  664. * stage. This value represents actually the Iq current expressed in
  665. * digit.
  666. * @retval Return true if the command executed successfully, otherwise false.
  667. */
  668. __weak bool UI_SetRevupData(UI_Handle_t *pHandle, uint8_t bStage, uint16_t hDurationms,
  669. int16_t hFinalMecSpeedUnit, int16_t hFinalTorque )
  670. {
  671. RevUpCtrl_Handle_t *pRevupCtrl = pHandle->pMCT[pHandle->bSelectedDrive]->pRevupCtrl;
  672. RUC_SetPhaseDurationms(pRevupCtrl, bStage, hDurationms);
  673. RUC_SetPhaseFinalMecSpeedUnit(pRevupCtrl, bStage, hFinalMecSpeedUnit);
  674. RUC_SetPhaseFinalTorque(pRevupCtrl, bStage, hFinalTorque);
  675. return true;
  676. }
  677. /**
  678. * @brief Allow to execute a set current reference command coming from the user.
  679. * @param pHandle: Pointer on Handle structure of UI component.
  680. * @param hIqRef: Current Iq reference on qd reference frame.
  681. * This value is expressed in digit.
  682. * @note current convertion formula (from digit to Amps):
  683. * Current(Amps) = [Current(digit) * Vdd micro] / [65536 * Rshunt * Aop]
  684. * @param hIdRef: Current Id reference on qd reference frame.
  685. * This value is expressed in digit. See hIqRef param description.
  686. * @retval none.
  687. */
  688. __weak void UI_SetCurrentReferences(UI_Handle_t *pHandle, int16_t hIqRef, int16_t hIdRef)
  689. {
  690. MCI_Handle_t * pMCI = pHandle->pMCI[pHandle->bSelectedDrive];
  691. qd_t currComp;
  692. currComp.q = hIqRef;
  693. currComp.d = hIdRef;
  694. MCI_SetCurrentReferences(pMCI,currComp);
  695. }
  696. /**
  697. * @brief Allow to get information about MP registers available for each step.
  698. * PC send to the FW the list of steps to get the available registers.
  699. * The FW returs the list of available registers for that steps.
  700. * @param stepList: List of requested steps.
  701. * @param pMPInfo: The returned list of register.
  702. * It is populated by this function.
  703. * @retval true if MP is enabled, false otherwise.
  704. */
  705. __weak bool UI_GetMPInfo(pMPInfo_t stepList, pMPInfo_t pMPInfo)
  706. {
  707. return false;
  708. }
  709. /**
  710. * @}
  711. */
  712. /**
  713. * @}
  714. */
  715. /**
  716. * @}
  717. */
  718. /************************ (C) COPYRIGHT 2019 STMicroelectronics *****END OF FILE****/