| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- /*
- * File: ert_main.c
- *
- * Code generated for Simulink model 'PMSM_Controller'.
- *
- * Model version : 1.885
- * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Sat Jan 8 15:44:11 2022
- *
- * Target selection: ert.tlc
- * Embedded hardware selection: ARM Compatible->ARM Cortex-M
- * Code generation objectives:
- * 1. Execution efficiency
- * 2. RAM efficiency
- * Validation result: Not run
- */
- #include <stddef.h>
- #include <stdio.h> /* This ert_main.c example uses printf/fflush */
- #include "PMSM_Controller.h" /* Model's header file */
- #include "rtwtypes.h"
- static RT_MODEL rtM_;
- static RT_MODEL *const rtMPtr = &rtM_; /* Real-time model */
- static DW rtDW; /* Observable states */
- /* '<Root>/Vdc' */
- static int16_T rtU_Vdc;
- /* '<Root>/Ts' */
- static uint16_T rtU_Ts;
- /* '<Root>/adc_a' */
- static int16_T rtU_adc_a;
- /* '<Root>/adc_b' */
- static int16_T rtU_adc_b;
- /* '<Root>/rotor_angle' */
- static real_T rtU_rotor_angle;
- /* '<Root>/rotor_speed' */
- static int16_T rtU_rotor_speed;
- /* '<Root>/input_target' */
- static int16_T rtU_input_target;
- /* '<Root>/hall_a' */
- static uint8_T rtU_hall_a;
- /* '<Root>/hall_b' */
- static uint8_T rtU_hall_b;
- /* '<Root>/hall_c' */
- static uint8_T rtU_hall_c;
- /* '<Root>/hw_count' */
- static uint32_T rtU_hw_count;
- /* '<Root>/b_motor_enable' */
- static boolean_T rtU_b_motor_enable;
- /* '<Root>/b_cruise_enable' */
- static boolean_T rtU_b_cruise_enable;
- /* '<Root>/n_ctrl_type' */
- static uint8_T rtU_n_ctrl_type;
- /* '<Root>/pwm_counts' */
- static uint16_T rtY_pwm_counts[8];
- /* '<Root>/sector' */
- static uint8_T rtY_sector;
- /*
- * Associating rt_OneStep with a real-time clock or interrupt service routine
- * is what makes the generated code "real-time". The function rt_OneStep is
- * always associated with the base rate of the model. Subrates are managed
- * by the base rate from inside the generated code. Enabling/disabling
- * interrupts and floating point context switches are target specific. This
- * example code indicates where these should take place relative to executing
- * the generated code step function. Overrun behavior should be tailored to
- * your application needs. This example simply sets an error status in the
- * real-time model and returns from rt_OneStep.
- */
- void rt_OneStep(RT_MODEL *const rtM);
- void rt_OneStep(RT_MODEL *const rtM)
- {
- static boolean_T OverrunFlag = false;
- /* Disable interrupts here */
- /* Check for overrun */
- if (OverrunFlag) {
- rtmSetErrorStatus(rtM, "Overrun");
- return;
- }
- OverrunFlag = true;
- /* Save FPU context here (if necessary) */
- /* Re-enable timer or interrupt here */
- /* Set model inputs here */
- /* Step the model for base rate */
- PMSM_Controller_step(rtM, rtU_Vdc, rtU_Ts, rtU_adc_a, rtU_adc_b,
- rtU_rotor_angle, rtU_rotor_speed, rtU_input_target,
- rtY_pwm_counts, &rtY_sector);
- /* Get model outputs here */
- /* Indicate task complete */
- OverrunFlag = false;
- /* Disable interrupts here */
- /* Restore FPU context here (if necessary) */
- /* Enable interrupts here */
- }
- /*
- * The example "main" function illustrates what is required by your
- * application code to initialize, execute, and terminate the generated code.
- * Attaching rt_OneStep to a real-time clock is target specific. This example
- * illustrates how you do this relative to initializing the model.
- */
- int_T main(int_T argc, const char *argv[])
- {
- RT_MODEL *const rtM = rtMPtr;
- /* Unused arguments */
- (void)(argc);
- (void)(argv);
- /* Pack model data into RTM */
- rtM->dwork = &rtDW;
- /* Initialize model */
- PMSM_Controller_initialize(rtM);
- /* Attach rt_OneStep to a timer or interrupt service routine with
- * period 6.2E-6 seconds (the model's base sample time) here. The
- * call syntax for rt_OneStep is
- *
- * rt_OneStep(rtM);
- */
- printf("Warning: The simulation will run forever. "
- "Generated ERT main won't simulate model step behavior. "
- "To change this behavior select the 'MAT-file logging' option.\n");
- fflush((NULL));
- while (rtmGetErrorStatus(rtM) == (NULL)) {
- /* Perform other application tasks here */
- }
- /* Disable rt_OneStep() here */
- return 0;
- }
- /*
- * File trailer for generated code.
- *
- * [EOF]
- */
|