foc_wapper.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * 参考 ert_main.c, 对Simulink生成的代码做一次封装
  3. */
  4. #include <stddef.h>
  5. #include <stdio.h> /* This ert_main.c example uses printf/fflush */
  6. #include "PMSM_Controller.h" /* Model's header file */
  7. #include "rtwtypes.h"
  8. #include "zero_crossing_types.h"
  9. static RT_MODEL rtM_;
  10. static RT_MODEL *const rtMPtr = &rtM_; /* Real-time model */
  11. static DW rtDW; /* Observable states */
  12. static PrevZCX rtPrevZCX; /* Triggered events */
  13. static ExtU rtU; /* External inputs */
  14. static ExtY rtY; /* External outputs */
  15. void PMSM_FOC_Init(void) {
  16. RT_MODEL *const rtM = rtMPtr;
  17. /* Pack model data into RTM */
  18. rtM->dwork = &rtDW;
  19. rtM->prevZCSigState = &rtPrevZCX;
  20. rtM->inputs = &rtU;
  21. rtM->outputs = &rtY;
  22. /* Initialize model */
  23. PMSM_Controller_initialize(rtM);
  24. }
  25. ExtU *PMSM_FOC_GetInputs(void) {
  26. return rtMPtr->inputs;
  27. }
  28. ExtY *PMSM_FOC_GetOutputs(void) {
  29. return rtMPtr->outputs;
  30. }
  31. P *PMSM_FOC_GetParams(void) {
  32. return &rtP;
  33. }
  34. void PMSM_FOC_Step(void) {
  35. PMSM_Controller_step(rtMPtr);
  36. }