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