ert_main.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // File: ert_main.cpp
  3. //
  4. // Code generated for Simulink model 'PmsmSimUt'.
  5. //
  6. // Model version : 1.18
  7. // Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. // C/C++ source code generated on : Tue Aug 1 23:42:37 2023
  9. //
  10. // Target selection: ert.tlc
  11. // Embedded hardware selection: Intel->x86-64 (Windows64)
  12. // Code generation objectives: Unspecified
  13. // Validation result: Not run
  14. //
  15. #include <stddef.h>
  16. #include <stdio.h> // This ert_main.c example uses printf/fflush
  17. #include "PmsmSimUt.h" // Model's header file
  18. #include "rtwtypes.h"
  19. static PmsmSimUtModelClass PmsmSimUt_Obj;// Instance of model class
  20. //
  21. // Associating rt_OneStep with a real-time clock or interrupt service routine
  22. // is what makes the generated code "real-time". The function rt_OneStep is
  23. // always associated with the base rate of the model. Subrates are managed
  24. // by the base rate from inside the generated code. Enabling/disabling
  25. // interrupts and floating point context switches are target specific. This
  26. // example code indicates where these should take place relative to executing
  27. // the generated code step function. Overrun behavior should be tailored to
  28. // your application needs. This example simply sets an error status in the
  29. // real-time model and returns from rt_OneStep.
  30. //
  31. void rt_OneStep(void);
  32. void rt_OneStep(void)
  33. {
  34. static boolean_T OverrunFlag = false;
  35. // Disable interrupts here
  36. // Check for overrun
  37. if (OverrunFlag) {
  38. rtmSetErrorStatus(PmsmSimUt_Obj.getRTM(), "Overrun");
  39. return;
  40. }
  41. OverrunFlag = true;
  42. // Save FPU context here (if necessary)
  43. // Re-enable timer or interrupt here
  44. // Set model inputs here
  45. // Step the model
  46. PmsmSimUt_Obj.step();
  47. // Get model outputs here
  48. // Indicate task complete
  49. OverrunFlag = false;
  50. // Disable interrupts here
  51. // Restore FPU context here (if necessary)
  52. // Enable interrupts here
  53. }
  54. //
  55. // The example "main" function illustrates what is required by your
  56. // application code to initialize, execute, and terminate the generated code.
  57. // Attaching rt_OneStep to a real-time clock is target specific. This example
  58. // illustrates how you do this relative to initializing the model.
  59. //
  60. int_T main(int_T argc, const char *argv[])
  61. {
  62. // Unused arguments
  63. (void)(argc);
  64. (void)(argv);
  65. // Initialize model
  66. PmsmSimUt_Obj.initialize();
  67. // Attach rt_OneStep to a timer or interrupt service routine with
  68. // period 0.0001 seconds (the model's base sample time) here. The
  69. // call syntax for rt_OneStep is
  70. //
  71. // rt_OneStep();
  72. printf("Warning: The simulation will run forever. "
  73. "Generated ERT main won't simulate model step behavior. "
  74. "To change this behavior select the 'MAT-file logging' option.\n");
  75. fflush((NULL));
  76. while (rtmGetErrorStatus(PmsmSimUt_Obj.getRTM()) == (NULL)) {
  77. // Perform other application tasks here
  78. }
  79. // Disable rt_OneStep() here
  80. // Terminate model
  81. PmsmSimUt_Obj.terminate();
  82. return 0;
  83. }
  84. //
  85. // File trailer for generated code.
  86. //
  87. // [EOF]
  88. //