Beispiel #1
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
*    The sizes information is used by Simulink to determine the S-function
*    block's characteristics (number of inputs, outputs, states, etc.).
*/
static void mdlInitializeSizes(SimStruct *S)
{
   // loop counter
   int idx;

   ssSetNumSFcnParams(S, P_NPARMS);  /* Number of expected parameters */
   // No parameters will be tunable
   for(idx=0; idx<P_NPARMS; idx++){
      ssSetSFcnParamNotTunable(S,idx);
   }

   if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
      /* Return if number of expected != number of actual parameters */
      return;
   }

   // Setup all the CAN datatypes
   CAN_Common_MdlInitSizes(S);
   // Extended frame
   int_T canExDT = ssGetDataTypeId(S,SL_CAN_EXTENDED_FRAME_DTYPE_NAME );
   // Standard frame
   int_T canStDT = ssGetDataTypeId(S,SL_CAN_STANDARD_FRAME_DTYPE_NAME );

   // Setup input port
   ssSetNumInputPorts(S,1);
   ssSetInputPortWidth(S,0,1);
   ssSetInputPortDirectFeedThrough(S,0,true);
   ssSetInputPortDataType(S,0,DYNAMICALLY_TYPED);
   
   // Setup output ports
   ssSetNumOutputPorts(S,4);

   ssSetOutputPortWidth(S,0,1); /* ID */
   ssSetOutputPortDataType(S,0, SS_DOUBLE);
   
   
   ssSetOutputPortWidth(S,1,1); /* Length */
   ssSetOutputPortDataType(S,1, SS_DOUBLE);
 
   ssSetOutputPortWidth(S,2,1); /* Type */
   ssSetOutputPortDataType(S,2, SS_DOUBLE);

   ssSetOutputPortWidth(S,3,1); /* Data */
   ssSetOutputPortDataType(S,3, SS_DOUBLE);
   

   ssSetNumContStates(S, 0);
   ssSetNumDiscStates(S, 0);

   ssSetNumSampleTimes(S, 1);
   
   ssSetNumRWork(S, 0);
   ssSetNumIWork(S, 0);
   ssSetNumPWork(S, 0);
   ssSetNumModes(S, 0);
   ssSetNumNonsampledZCs(S, 0);

   /* use generated code in Accelerator Mode */   
   ssSetOptions(S, SS_OPTION_USE_TLC_WITH_ACCELERATOR);
}
Beispiel #2
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *    The sizes information is used by Simulink to determine the S-function
 *    block's characteristics (number of inputs, outputs, states, etc.).
 */
static void mdlInitializeSizes(SimStruct *S)
{
        int idx;

        int_T canExDT; // Extended extended frame
        int_T canStDT; // Standard frame

        /* See sfuntmpl_doc.c for more details on the macros below */

        ssSetNumSFcnParams(S, P_NPARMS);  /* Number of expected parameters */
        
        if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
                /* Return if number of expected != number of actual parameters */
                return;
        }
                
        // No parameters will be tunable
        for(idx=0; idx<P_NPARMS; idx++){
                ssSetSFcnParamNotTunable(S,idx);
        }

        // Setup all the CAN datatypes
        CAN_Common_MdlInitSizes(S);
        canExDT = ssGetDataTypeId(S,SL_CAN_EXTENDED_FRAME_DTYPE_NAME );
        canStDT = ssGetDataTypeId(S,SL_CAN_STANDARD_FRAME_DTYPE_NAME );

        // One vectorized output port may contain several CAN
        // messages, one frame per signal element
        ssSetNumOutputPorts(S,1);
        ssSetOutputPortWidth(S,0,1);
        if( P_TYPE == CAN_MESSAGE_STANDARD){
                ssSetOutputPortDataType(S,0,canStDT);
        }else if ( P_TYPE == CAN_MESSAGE_EXTENDED ){
                ssSetOutputPortDataType(S,0,canExDT);
        }

        // Multiple input ports. Each input port represents
        // a CAN data frame. These will be vectorized
        // uint8 inputs. The width corressponds to the
        // number of data bytes in the frame
        setInputPorts(S);

        ssSetNumContStates(S, 0);
        ssSetNumDiscStates(S, 0);


        ssSetNumSampleTimes(S, 1);
        ssSetNumRWork(S, 0);
        ssSetNumIWork(S, 0);
        ssSetNumPWork(S, 0);
        ssSetNumModes(S, 0);
        ssSetNumNonsampledZCs(S, 0);
         
        /* use generated code in Accelerator Mode */
        ssSetOptions(S, SS_OPTION_USE_TLC_WITH_ACCELERATOR);
}
Beispiel #3
0
    /* mdlInitializeSizes() */
    static void mdlInitializeSizes(SimStruct *S) {

        // A counting variable
        int idx;

        // The number of output ports required
        int nOP = 0;

        // The current output port
        int cOP = 0;


        /* Register the custom CAN data types */
        CAN_Common_MdlInitSizes(S);

        ssSetNumSFcnParams(S,NUM_PARAMS); /* Number of expected parameters */

#if defined (MATLAB_MEX_FILE)

        if(ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
            return; /* Simulink will report a mismatch error */
        }

#endif /* MATLAB_MEX_FILE */
                
        // No parameters will be tunable
        for(idx=0; idx<NUM_PARAMS; idx++){
            ssSetSFcnParamNotTunable(S,idx);
        }

        ssSetNumInputPorts               (S,1);
        ssSetInputPortWidth              (S,0,1);
        ssSetInputPortDirectFeedThrough  (S,0,1);
        ssSetInputPortDataType           (S,0,DYNAMICALLY_TYPED);

        nOP += P_SHOW_ID;       
        nOP += P_SHOW_LENGTH;
        nOP += P_SHOW_DATA;
        ssSetNumOutputPorts(S,nOP);

        // Set the current output port to zero
        cOP = 0; 

		  if(P_SHOW_DATA){
            ssSetOutputPortDataType(S,cOP,DYNAMICALLY_TYPED);
            ssSetOutputPortWidth(S,cOP++,DYNAMICALLY_SIZED);
        }
		  
        if(P_SHOW_ID){
            ssSetOutputPortDataType (S,cOP,SS_UINT32);
            ssSetOutputPortWidth(S,cOP++,1);
        }

        if(P_SHOW_LENGTH){
            ssSetOutputPortDataType (S,cOP,SS_UINT32);
            ssSetOutputPortWidth(S,cOP++,1);
        }

        

        ssSetNumSampleTimes              (S,1);
        /* use generated code in Accelerator Mode */         
        ssSetOptions                     (S,SS_OPTION_EXCEPTION_FREE_CODE | SS_OPTION_USE_TLC_WITH_ACCELERATOR);
    }