ert_main.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * File: ert_main.c
  3. *
  4. * Code generated for Simulink model 'PMSM_Controller'.
  5. *
  6. * Model version : 1.1447
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C/C++ source code generated on : Mon May 23 16:15:38 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 <stddef.h>
  18. #include <stdio.h> /* This ert_main.c example uses printf/fflush */
  19. #include "PMSM_Controller.h" /* Model's header file */
  20. #include "rtwtypes.h"
  21. #include "zero_crossing_types.h"
  22. static RT_MODEL rtM_;
  23. static RT_MODEL *const rtMPtr = &rtM_; /* Real-time model */
  24. static DW rtDW; /* Observable states */
  25. static PrevZCX rtPrevZCX; /* Triggered events */
  26. static ExtU rtU; /* External inputs */
  27. static ExtY rtY; /* External outputs */
  28. /*
  29. * Associating rt_OneStep with a real-time clock or interrupt service routine
  30. * is what makes the generated code "real-time". The function rt_OneStep is
  31. * always associated with the base rate of the model. Subrates are managed
  32. * by the base rate from inside the generated code. Enabling/disabling
  33. * interrupts and floating point context switches are target specific. This
  34. * example code indicates where these should take place relative to executing
  35. * the generated code step function. Overrun behavior should be tailored to
  36. * your application needs. This example simply sets an error status in the
  37. * real-time model and returns from rt_OneStep.
  38. */
  39. void rt_OneStep(RT_MODEL *const rtM);
  40. void rt_OneStep(RT_MODEL *const rtM)
  41. {
  42. static boolean_T OverrunFlag = false;
  43. /* Disable interrupts here */
  44. /* Check for overrun */
  45. if (OverrunFlag) {
  46. rtmSetErrorStatus(rtM, "Overrun");
  47. return;
  48. }
  49. OverrunFlag = true;
  50. /* Save FPU context here (if necessary) */
  51. /* Re-enable timer or interrupt here */
  52. /* Set model inputs here */
  53. /* Step the model */
  54. PMSM_Controller_step(rtM);
  55. /* Get model outputs here */
  56. /* Indicate task complete */
  57. OverrunFlag = false;
  58. /* Disable interrupts here */
  59. /* Restore FPU context here (if necessary) */
  60. /* Enable interrupts here */
  61. }
  62. /*
  63. * The example "main" function illustrates what is required by your
  64. * application code to initialize, execute, and terminate the generated code.
  65. * Attaching rt_OneStep to a real-time clock is target specific. This example
  66. * illustrates how you do this relative to initializing the model.
  67. */
  68. int_T main(int_T argc, const char *argv[])
  69. {
  70. RT_MODEL *const rtM = rtMPtr;
  71. /* Unused arguments */
  72. (void)(argc);
  73. (void)(argv);
  74. /* Pack model data into RTM */
  75. rtM->dwork = &rtDW;
  76. rtM->prevZCSigState = &rtPrevZCX;
  77. rtM->inputs = &rtU;
  78. rtM->outputs = &rtY;
  79. /* Initialize model */
  80. PMSM_Controller_initialize(rtM);
  81. /* Attach rt_OneStep to a timer or interrupt service routine with
  82. * period 5.0E-5 seconds (the model's base sample time) here. The
  83. * call syntax for rt_OneStep is
  84. *
  85. * rt_OneStep(rtM);
  86. */
  87. printf("Warning: The simulation will run forever. "
  88. "Generated ERT main won't simulate model step behavior. "
  89. "To change this behavior select the 'MAT-file logging' option.\n");
  90. fflush((NULL));
  91. while (rtmGetErrorStatus(rtM) == (NULL)) {
  92. /* Perform other application tasks here */
  93. }
  94. /* Disable rt_OneStep() here */
  95. return 0;
  96. }
  97. /*
  98. * File trailer for generated code.
  99. *
  100. * [EOF]
  101. */