/* * $Revision $ * $RCSfile: vxinterrupt1.c,v $ * * Abstract: * VxWorks Asynchronous Interrupt Block. * * Copyright 2003-2004 The MathWorks, Inc. */ #define S_FUNCTION_NAME vxinterrupt1 #define S_FUNCTION_LEVEL 2 #include "simstruc.h" #define ISR_NUMBERS (ssGetSFcnParam(S,0)) #define ISR_OFFSETS (ssGetSFcnParam(S,1)) #define ISR_PRIORITIES (ssGetSFcnParam(S,2)) #define ISR_PREEMPTION (ssGetSFcnParam(S,3)) #define SHOW_INPUTPORT (ssGetSFcnParam(S,4)) #define MANAGE_OWN_TIMER (ssGetSFcnParam(S,5)) #define TICK_RES (ssGetSFcnParam(S,6)) #define TICK_LENGTH (ssGetSFcnParam(S,7)) #ifndef MATLAB_MEX_FILE /* Since we have a target file for this S-function, declare an error here * so that, if for some reason this file is being used (instead of the * target file) for code generation, we can trap this problem at compile * time. */ # error This_file_can_be_used_only_during_simulation_inside_Simulink #endif /*====================* * S-function methods * *====================*/ #define MDL_CHECK_PARAMETERS static void mdlCheckParameters(SimStruct *S) { int_T i,j[8],k; int_T numISRs = (int_T) (mxGetNumberOfElements(ISR_NUMBERS)); int_T numOffsets = (int_T) (mxGetNumberOfElements(ISR_OFFSETS)); int_T numPriorities = (int_T) (mxGetNumberOfElements(ISR_PRIORITIES)); int_T numPreempts = (int_T) (mxGetNumberOfElements(ISR_PREEMPTION)); int_T numTickSize = (int_T) (mxGetNumberOfElements(TICK_RES)); /* Check ISR_NUMBERS */ if (numISRs < 1) { ssSetErrorStatus(S,"Must specify at least 1 interrrupt."); return; } else if (!mxIsDouble(ISR_NUMBERS)) { ssSetErrorStatus(S,"Must specify interrupt number as type 'double'."); return; } for (i=0;i<8;i++) j[i] = false; for (i=0;i 7) || (intnum < 1)) { ssSetErrorStatus(S,"Interrupt numbers must be 1-7."); return; } if (j[intnum] == true) { ssSetErrorStatus(S,"Interrupt numbers must be unique."); return; } else { j[intnum] = true; } } /* Check ISR_OFFSETS */ if (!mxIsDouble(ISR_OFFSETS)) { ssSetErrorStatus(S,"Must specify vector offset number as type 'double'."); return; } else if (numOffsets != numISRs) { ssSetErrorStatus(S,"The number of interrupt vector offsets must match the" " number of interrupts."); return; } for (i=0;i 0; j--) { for(i = 0; i < numISRs; i++) { /*call ISRs based on 7 being highest priority*/ if (((int_T)(mxGetPr(ISR_NUMBERS)[i])) == j) { ssCallSystemWithTid(S,i,tid); } } } } else { InputPtrsType uPtrs = ssGetInputPortSignalPtrs(S,0); for(j=7; j > 0; j--) { for(i = 0; i < ssGetInputPortWidth(S,0); i++) { /*call ISRs based on 7 being highest priority*/ if (((int_T)(mxGetPr(ISR_NUMBERS)[i])) == j) { switch (ssGetInputPortDataType(S, 0)) { case SS_DOUBLE: { InputRealPtrsType pU = (InputRealPtrsType)uPtrs; if(*pU[i]) { ssCallSystemWithTid(S,i,tid); } break; } case SS_SINGLE: { InputReal32PtrsType pU = (InputReal32PtrsType)uPtrs; if(*pU[i]) { ssCallSystemWithTid(S,i,tid); } break; } case SS_INT8: { InputInt8PtrsType pU = (InputInt8PtrsType)uPtrs; if(*pU[i]) { ssCallSystemWithTid(S,i,tid); } break; } case SS_UINT8: { InputUInt8PtrsType pU = (InputUInt8PtrsType)uPtrs; if(*pU[i]) { ssCallSystemWithTid(S,i,tid); } break; } case SS_INT16: { InputInt16PtrsType pU = (InputInt16PtrsType)uPtrs; if(*pU[i]) { ssCallSystemWithTid(S,i,tid); } break; } case SS_UINT16: { InputUInt16PtrsType pU = (InputUInt16PtrsType)uPtrs; if(*pU[i]) { ssCallSystemWithTid(S,i,tid); } break; } case SS_INT32: { InputInt32PtrsType pU = (InputInt32PtrsType)uPtrs; if(*pU[i]) { ssCallSystemWithTid(S,i,tid); } break; } case SS_UINT32: { InputUInt32PtrsType pU = (InputUInt32PtrsType)uPtrs; if(*pU[i]) { ssCallSystemWithTid(S,i,tid); } break; } case SS_BOOLEAN: { InputBooleanPtrsType pU = (InputBooleanPtrsType)uPtrs; if(*pU[i]) { ssCallSystemWithTid(S,i,tid); } break; } } } } } } } static void mdlTerminate(SimStruct *S) {} #define MDL_SET_INPUT_PORT_DATA_TYPE static void mdlSetInputPortDataType(SimStruct *S, int port, DTypeId dataType) { switch(dataType) { /* Accept Simulink data types */ case SS_DOUBLE: case SS_SINGLE: case SS_INT8: case SS_UINT8: case SS_INT16: case SS_UINT16: case SS_INT32: case SS_UINT32: case SS_BOOLEAN: ssSetInputPortDataType(S, 0, dataType); break; default: /* Reject proposed data type */ ssSetErrorStatus(S,"Invalid input port data type"); break; } } /* mdlSetInputPortDataType */ #define MDL_SET_DEFAULT_PORT_DATA_TYPES static void mdlSetDefaultPortDataTypes(SimStruct *S) { /* Set input port data type to bool */ ssSetInputPortDataType( S, 0, SS_BOOLEAN); } /* mdlSetDefaultPortDataTypes */ #define MDL_RTW static void mdlRTW(SimStruct *S) { /* Write out parameters for this block.*/ if (!ssWriteRTWParamSettings(S, 3, SSWRITE_VALUE_VECT,"Numbers", (real_T *) mxGetPr(ISR_NUMBERS), mxGetNumberOfElements(ISR_NUMBERS), SSWRITE_VALUE_VECT,"Offsets", (real_T *) mxGetPr(ISR_OFFSETS), mxGetNumberOfElements(ISR_OFFSETS), SSWRITE_VALUE_VECT,"Preemption", (real_T *) mxGetPr(ISR_PREEMPTION), mxGetNumberOfElements(ISR_PREEMPTION) )) { return; /* An error occurred which will be reported by SL */ } } /*=============================* * Required S-function trailer * *=============================*/ #ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */ #include "simulink.c" /* MEX-file interface mechanism */ #else #include "cg_sfun.h" /* Code generation registration function */ #endif /* EOF: vxinterrupt1.c*/