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 */
/* 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 */
static void mdlOutputs(SimStruct *S, int_T tid) { /* * detect which inputs are complex or not */ boolean_T u0IsComplex = ssGetInputPortComplexSignal(S, 0) == COMPLEX_YES; boolean_T u1IsComplex = ssGetInputPortComplexSignal(S, 1) == COMPLEX_YES; boolean_T yIsComplex = ssGetOutputPortComplexSignal(S, 0)== COMPLEX_YES; DTypeId dType = ssGetOutputPortDataType(S,0); InputPtrsType u0VPtr = ssGetInputPortSignalPtrs(S,0); InputPtrsType u1VPtr = ssGetInputPortSignalPtrs(S,1); int_T width = ssGetInputPortWidth(S,0); int_T i; switch (dType) { case (SS_DOUBLE): { real_T *y = (real_T *)ssGetOutputPortSignal(S,0); real_T yr = 0.0; /* real part of the result */ real_T yi = 0.0; /* imag part of the result */ InputRealPtrsType u0Ptr = (InputRealPtrsType)u0VPtr; InputRealPtrsType u1Ptr = (InputRealPtrsType)u1VPtr; if(!yIsComplex){ /* both inputs are real */ for (i = 0; i < width; i++) { yr += (**u0Ptr++) * (**u1Ptr++); } } else { /* At least one if the inputs is complex. */ for (i = 0; i < width; i++) { real_T u0r = u0Ptr[i][0]; real_T u0i = (u0IsComplex)? - u0Ptr[i][1] : 0.0; real_T u1r = u1Ptr[i][0]; real_T u1i = (u1IsComplex)? u1Ptr[i][1] : 0.0; yr += (u0r * u1r - u0i * u1i); yi += (u0r * u1i + u0i * u1r); } } /* Update output */ y[0] = yr; if (yIsComplex) { y[1] = yi; } } break; case (SS_SINGLE): { real32_T *y = (real32_T *)ssGetOutputPortSignal(S,0); real32_T yr = 0.0F; /* real part of the result */ real32_T yi = 0.0F; /* imag part of the result */ if(!yIsComplex){ /* both inputs are real */ for (i = 0; i < width; i++) { const real32_T *u0Ptr = u0VPtr[i]; const real32_T *u1Ptr = u1VPtr[i]; yr += (*u0Ptr) * (*u1Ptr); } } else { /* At least one if the inputs is complex. */ for (i = 0; i < width; i++) { const real32_T *u0Ptr = u0VPtr[i]; const real32_T *u1Ptr = u1VPtr[i]; real32_T u0r = u0Ptr[0]; real32_T u0i = (u0IsComplex)? - u0Ptr[1] : 0.0F; real32_T u1r = u1Ptr[0]; real32_T u1i = (u1IsComplex)? u1Ptr[1] : 0.0F; yr += (u0r * u1r - u0i * u1i); yi += (u0r * u1i + u0i * u1r); } } /* Update output */ y[0] = yr; if (yIsComplex) { y[1] = yi; } } break; } }
/* mdlOutputs() */ static void mdlOutputs(SimStruct *S, int_T tid) { CAN_FRAME ** frames = (CAN_FRAME **)ssGetInputPortSignalPtrs(S,0); uint8_T * data_output; uint32_T * id_output; uint32_T * length_output; int_T payload_len; // The number of output ports required int nOP = 0; // The current output port int cOP = 0; // Check that the payload is a valid size payload_len = frames[0]->LENGTH; if (payload_len < 0 || payload_len > MAX_PAYLOAD_LEN) { ssSetErrorStatus(S,"Invalid input frame payload length."); return; } if ( P_SHOW_DATA){ DTypeId dtypeID = ssGetOutputPortDataType(S,cOP); int_T outWidth = ssGetDataTypeSize(S, dtypeID) * ssGetOutputPortWidth(S,cOP); int_T idx_end = payload_len < outWidth ? payload_len : outWidth; int idx; data_output = (unsigned char * ) ssGetOutputPortSignal(S,cOP); if (P_ENDIAN == CPU_ENDIAN ){ memcpy(data_output,&(frames[0]->DATA[0]),idx_end); }else{ int idx; int dataTypeSize,portWidth,signals,offset; dataTypeSize = ssGetDataTypeSize(S,ssGetOutputPortDataType(S,cOP)); portWidth = ssGetOutputPortWidth(S,cOP); for ( signals = 0; signals < portWidth; signals ++ ){ offset = signals * dataTypeSize; for ( idx=0;idx< dataTypeSize;idx++ ){ ((uint8_T *)(data_output))[idx+offset]= frames[0]->DATA[offset+dataTypeSize-idx-1]; } } } /* Zero the remaining elements in the output if there are any */ for ( idx=idx_end; idx < outWidth; idx++ ){ ((uint8_T *)(data_output))[idx]=0; } cOP++; } if(P_SHOW_ID){ id_output = (uint32_T *)ssGetOutputPortSignal(S,cOP); *id_output = frames[0]->ID; cOP++; } if(P_SHOW_LENGTH){ length_output = (uint32_T *)ssGetOutputPortSignal(S,cOP); *length_output = frames[0]->LENGTH; cOP++; } }