/*
 *	参考 ert_main.c， 对Simulink生成的代码做一次封装
 */

#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"
#include "zero_crossing_types.h"

static RT_MODEL rtM_;
static RT_MODEL *const rtMPtr = &rtM_; /* Real-time model */
static DW rtDW;                        /* Observable states */
static PrevZCX rtPrevZCX;              /* Triggered events */
static ExtU rtU;                       /* External inputs */
static ExtY rtY;                       /* External outputs */



void PMSM_FOC_Init(void) {
	RT_MODEL *const rtM = rtMPtr;	
	/* Pack model data into RTM */
	rtM->dwork = &rtDW;
	rtM->prevZCSigState = &rtPrevZCX;
	rtM->inputs = &rtU;
	rtM->outputs = &rtY;


	/* Initialize model */
	PMSM_Controller_initialize(rtM);
}



ExtU *PMSM_FOC_GetInputs(void) {
	return rtMPtr->inputs;
}

ExtY *PMSM_FOC_GetOutputs(void) {
	return rtMPtr->outputs;
}

P *PMSM_FOC_GetParams(void) {
	return &rtP;
}

void PMSM_FOC_Step(void) {
	
	PMSM_Controller_step(rtMPtr);
}


