Exemple #1
0
static void mdlRTW(SimStruct *S){
   int_T type     = P_TYPE;
   int_T id       = P_ID;
   DTypeId  dataType = ssGetInputPortDataType(S,0);
   int_T length   =ssGetDataTypeSize(S,dataType) * ssGetInputPortWidth(S,0); 
   int32_T       endian     = P_ENDIAN;

   /* -- Write Invariant Parameter Settings -- */
   ssWriteRTWParamSettings(S,4,
         SSWRITE_VALUE_DTYPE_NUM, "TYPE",
         &type,
         DTINFO(SS_UINT32,0),

         SSWRITE_VALUE_DTYPE_NUM, "ID",
         &id,
         DTINFO(SS_UINT32,0),

         SSWRITE_VALUE_DTYPE_NUM, "LENGTH",
         &length,
         DTINFO(SS_UINT16,0),

         SSWRITE_VALUE_DTYPE_NUM, "Endian",
         &endian,
         DTINFO(SS_UINT32,0)
      );

   /* -- Write Invariant Signal Settings -- */
   if ( !mxIsFinite( ssGetSampleTime( S, 0 ) ) ) {
      CAN_FRAME * frame = (CAN_FRAME *) ssGetOutputPortSignal(S,0);
      CAN_write_rtw_frame(S,frame);
   }

}
/* Function: mdlOutputs =======================================================
 *
*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
  DTypeId         uType         = ssGetInputPortDataType(S,0);
  size_t          uTypeSize     = (size_t) ssGetDataTypeSize(S, uType);
  const char   *u  = (const char*) ssGetInputPortSignal(S,0);
  char         *y  = (char *)ssGetOutputPortRealSignal(S,0); 
  
  (void)memcpy(y,u,uTypeSize);  
}
Exemple #3
0
    static void mdlSetDefaultPortDataTypes(SimStruct *S) {
        if ( ssGetInputPortDataType(S,0) == DYNAMICALLY_TYPED ){
			if ( isAcceptableDataType(S,SS_UINT8,ssGetInputPortWidth(S,0))){
            	ssSetInputPortDataType(  S, 0, SS_UINT8 );
			}else{
				ssSetErrorStatus(S,"Invalid input signal width, data type or input port is not connected. See mask help for valid data types.");
			}
        }

	}
Exemple #4
0
/* Function: mdlOutputs =======================================================
 * Abstract:
 *    In this function, you compute the outputs of your S-function
 *    block. Generally outputs are placed in the output vector, ssGetY(S).
 */
static void mdlOutputs(SimStruct *S, int_T tid)
{
   CAN_FRAME * frame;
   const void * uFrame = ssGetInputPortSignal(S,0);
   int length,idx,signals,portWidth,dataTypeSize,offset ;
   InputInt32PtrsType uID;
   DTypeId dataType = ssGetInputPortDataType(S,0);
   length = ssGetDataTypeSize(S,dataType) * ssGetInputPortWidth(S,0);



   frame = (CAN_FRAME *) ssGetOutputPortSignal(S,0);
   frame->LENGTH = length;
   memset(frame->DATA,0,8);

   if (P_ID == -1 ){
      uID = (InputInt32PtrsType) ssGetInputPortSignalPtrs(S,1);
      frame->ID = *uID[0];
   }else{
      frame->ID = P_ID;
   }

   if (P_ENDIAN == CPU_ENDIAN){
      /* Target is same endianess as source */
      memcpy(frame->DATA,uFrame,length);
   }else{
      /* Target is alternate endianess as source.
       * Reverse the bytes in each signal but 
       * preserve the ordering of the signals. */
      dataTypeSize = ssGetDataTypeSize(S,ssGetInputPortDataType(S,0));
      portWidth = ssGetInputPortWidth(S,0);
      for (signals = 0 ; signals < portWidth ; signals++){
         offset = signals * dataTypeSize;
         for ( idx=0;idx < dataTypeSize;idx++ ){
            ((uint8_T *)(frame->DATA))[offset+idx]=(( uint8_T *)uFrame)[offset+dataTypeSize-idx-1];
         }
      }
   }
}
Exemple #5
0
    static void mdlSetDefaultPortDataTypes(SimStruct *S) {

        int_T canStDT = ssGetDataTypeId(S,SL_CAN_STANDARD_FRAME_DTYPE_NAME );
        int dataPort;
        if ( ssGetInputPortDataType(S,0) == DYNAMICALLY_TYPED ){
            ssSetInputPortDataType(  S, 0, canStDT );
        }

        if (P_SHOW_DATA ){
            dataPort = 0;
            if ( ssGetOutputPortDataType(S,dataPort)==DYNAMICALLY_TYPED){
                ssSetOutputPortDataType(S,dataPort,SS_UINT8);
            }
        }

    } /* mdlSetDefaultPortDataTypes */
Exemple #6
0
/* Function: mdlOutputs =======================================================
 * Abstract:
 *    In this function, you compute the outputs of your S-function
 *    block. Generally outputs are placed in the output vector, ssGetY(S).
 */
static void mdlOutputs(SimStruct *S, int_T tid)
{
    DTypeId dataTypeId = ssGetInputPortDataType(S,0);
    int IsFxpFltApiCompat = ssGetDataTypeIsFxpFltApiCompat(S,dataTypeId);     
    double *y  = ssGetOutputPortSignal(S,0);

    if (IsFxpFltApiCompat){
  
        y[0] = ssGetDataTypeTotalSlope(S,dataTypeId);
        y[1] = 1;
    }
    else
    {
        y[0] = 0;
        y[1] = 0;
    }
}
Exemple #7
0
/* Function: mdlOutputs =======================================================
 * Abstract:
 *    In this function, you compute the outputs of your S-function
 *    block. Generally outputs are placed in the output vector(s),
 *    ssGetOutputPortSignal.
 */
static void mdlOutputs(SimStruct *S, int_T tid)
{
      const void *pVoidIn = (const void *) ssGetInputPortSignal(S, 0);
      void *pVoidOut = ssGetOutputPortSignal(S,0);
      int regionIdx = 0;
      
      boolean_T inIsComplex = (ssGetInputPortComplexSignal(S,0) == COMPLEX_YES);
      int dataSize = ssGetDataTypeSize( S, ssGetInputPortDataType( S, 0 ) );

      int dataWidth = ssGetInputPortWidth(S,0);

      unsigned int idx = 0;
      
      char * pCharInBase = NULL;
      char * pCharOutBase = NULL;
      
      char * pCharIn = NULL;
      char * pCharOut =NULL;
      
      uint32_T regionValue = 0;
      fxpStorageContainerCategory inStorageContainerCategory;
      fxpStorageContainerCategory outStorageContainerCategory;

      DTypeId dTypeId;

      if ( inIsComplex )
      {
          dataWidth = 2 * dataWidth;
      }

      dTypeId = ssGetInputPortDataType(S,0);

      inStorageContainerCategory = ssGetDataTypeStorageContainCat(S,dTypeId);

      dTypeId = ssGetOutputPortDataType(S,0);

      outStorageContainerCategory = ssGetDataTypeStorageContainCat(S,dTypeId);

      if(inStorageContainerCategory != outStorageContainerCategory)
      {
          ssSetErrorStatus(S, "Input and output have different container categories");
          return;
      }
      if(inStorageContainerCategory == FXP_STORAGE_DOUBLE ||
         inStorageContainerCategory == FXP_STORAGE_SINGLE ||
         inStorageContainerCategory == FXP_STORAGE_SCALEDDOUBLE)
      {
          memcpy( pVoidOut, pVoidIn,  dataWidth * dataSize );
      }
      else  /*are fixed point*/
      {
          pCharInBase = (char *) pVoidIn;
          pCharOutBase = (char *) pVoidOut;

          for(idx = 0; idx < dataWidth; idx ++) 
          {
              pCharIn = &pCharInBase[ idx * dataSize ];
              pCharOut = &pCharOutBase[ idx * dataSize ];

              for (regionIdx = 0; regionIdx < FXP_NUM_CHUNKS; regionIdx++)
              {
                  regionValue = ssFxpGetU32BitRegion(S, 
                                                     pCharIn, 
                                                     dTypeId, 
                                                     regionIdx);
                  
                  ssFxpSetU32BitRegion(S,
                                       pCharOut, 
                                       dTypeId,
                                       regionValue,
                                       regionIdx);
              }
          } 
      }
      return;
} /* end mdlOutputs */