#include "AdjustModulePsiS.h"
#include "PDSFC.h"

SFIO_BlockExecutionResult AdjustModulePsiS(const void *pInBuff, void *pOutBuff, void *pVariables, SFIO_BlockCommand eCmd)
{
    /* input signals */
    typedef struct
    {
        Frac16             Psi_sk1[2];
        Frac16             Psi_ref;
        Frac16             I;
    } InStruct;

    /* output signals */
    typedef struct
    {
        long			   t1,t2;
        Frac16             Psi_sk1[2];
    } OutStruct;

    /* Uncomment the following structure and place your block-related 
       persistent variables there. Don't forget to change SIZEOF_StateStruct 
       below from 0 to sizeof(StateStruct). */ 
    /*typedef struct
    {
        short    x;
    }StateStruct;
    */

    /* structure lengths and sizes */
    enum StructSizes
    {
        LENGTHOF_InStruct  = 8,        /* real communicated length of input data items */
        LENGTHOF_OutStruct = 12,        /* real communicated length of output data items */
        SIZEOF_StateStruct = 0         /* size to be allocated, use sizeof(StateStruct) */
    };

    /* local variables */
    SFIO_BlockExecutionResult eResult;
    SFIO_BlockRegistration    *pReg;
    InStruct    *pIn = (InStruct*) pInBuff;
    OutStruct   *pOut = (OutStruct*) pOutBuff;
    //StateStruct *pState = (StateStruct *)pVariables;

    /* default result code */
    eResult = SFIO_EXEC_OK;

    switch(eCmd)
    {
        /* provide block registration data */
        case SFIO_CMD_REGISTER:
            pReg = (SFIO_BlockRegistration*) pOutBuff;
            pReg->wInputsCount = LENGTHOF_InStruct;          /* input data length in bytes */
            pReg->wOutputsCount = LENGTHOF_OutStruct;        /* output data length in bytes */
            pReg->wVariablesCount = SIZEOF_StateStruct;      /* state variables data size */
            //strcpy(pReg->pDescriptor,"AdjustModulePsiS");        /* block descriptor, customize if neccessary */
            break;

        /* state variables initialization */
        case SFIO_CMD_INIT:
            //pState->x = 0;
            break;

        /* compute function */
        case SFIO_CMD_EXECUTE:
            /* this macro gives an opportunity to break into this application
               when the "break" button is pressed in the Matlab/Simulink window */
            SFIO_Breakpoint();

            /**** place your computational code here ****/
			
			Psi_Sn.alpha = pIn->Psi_sk1[0];
			Psi_Sn.beta = pIn->Psi_sk1[1];
			
			SFIO_TimerStart();
			adjust_module_Psi_S(&Psi_Sn, pIn->Psi_ref, pIn->I);		//call the C function 'adjust_module_Psi_S' with input parameters and save return value to the output parameter
			SFIO_TimerStop(&pOut->t1);
			
			SFIO_TimerStart();
			a_adjust_module_Psi_S(&Psi_Sn, pIn->Psi_ref, pIn->I);	//call the assembler function 'a_adjust_module_Psi_S' with input parameter and save return value to the output parameter
			SFIO_TimerStop(&pOut->t2);
			
			pOut->Psi_sk1[0] = Psi_Sn.alpha;
			pOut->Psi_sk1[1] = Psi_Sn.beta;
				
            /**** end of your code ****/

            break;

        /* unknown command requested */
        default:
            eResult = SFIO_EXEC_UNKNOWN_COMMAND;
    }

    return(eResult);
}