#include "TestCurrent.h"
#include "PDSFC.h"

SFIO_BlockExecutionResult TestCurrent(const void *pInBuff, void *pOutBuff, void *pVariables, SFIO_BlockCommand eCmd)
{
    /* input signals */
    typedef struct
    {
        short             i_s[2];
        short             I_max;
    } InStruct;

    /* output signals */
    typedef struct
    {
        long			  t1,t2;	
        short             I;
    } 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  = 6,        /* real communicated length of input data items */
        LENGTHOF_OutStruct = 10,        /* 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,"TestCurrent");        /* 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 ****/
			
			i_S.alpha = pIn->i_s[0];
			i_S.beta = pIn->i_s[1];
			
			SFIO_TimerStart();
			pOut->I = test_current(&i_S, pIn->I_max);	//call the C function 'test_current' with input parameters and save return value to the output parameter 
			SFIO_TimerStop(&pOut->t1);
			
			SFIO_TimerStart();
			pOut->I = a_test_current(&i_S, pIn->I_max); //call the assembler function 'a_test_current' with input parameters and save return value to the output parameter
			SFIO_TimerStop(&pOut->t2);
			
            /**** end of your code ****/

            break;

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

    return(eResult);
}