#include "SectorSelector.h"
#include "DTC.h"
int mfr32Sqrt(int);
//short asmsectorselector(short[]);		//declaration a assembler function asmsectorselector

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

    /* output signals */
    typedef struct
    {
        long		t1,t2;
        short		s;
    } 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  = 4,        /* 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,"SectorSelector");        /* 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 ****/
			
			SFIO_TimerStart();
			//pOut->s = asmsectorselector(pIn->Psi_s); 	//call the assembler function 'asmsectorselector' with input parameter and save return value to the output parameter
			pOut->s = a_sectorselector(pIn->Psi_s);		//call the assembler function 'a_sectorselector' with input parameter and save return value to the output parameter
			SFIO_TimerStop(&pOut->t1);
			
			SFIO_TimerStart();
			pOut->s = c_sectorselector(pIn->Psi_s); 	//call the C function 'vyber_sektoru' 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);
}
