添加spi rec接口,spi和存储模块通信使用
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
|
||||
#define S_FUNCTION_LEVEL 2
|
||||
#define S_FUNCTION_NAME hal_spi_rec_out
|
||||
|
||||
#include "simstruc.h"
|
||||
|
||||
#define IS_PARAM_UINT8(pVal) (mxIsNumeric(pVal) && !mxIsLogical(pVal) && \
|
||||
!mxIsEmpty(pVal) && !mxIsSparse(pVal) && !mxIsComplex(pVal) && mxIsUint8(pVal))
|
||||
|
||||
/*====================*
|
||||
* S-function methods *
|
||||
*====================*/
|
||||
|
||||
#define MDL_CHECK_PARAMETERS
|
||||
#if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE)
|
||||
/* Function: mdlCheckParameters =============================================
|
||||
* Abstract:
|
||||
* Verify parameter definitions and types.
|
||||
*/
|
||||
static void mdlCheckParameters(SimStruct *S)
|
||||
{
|
||||
int paramIndex = 0;
|
||||
bool invalidParam = false;
|
||||
/* All parameters must match the S-function Builder Dialog */
|
||||
|
||||
{
|
||||
const mxArray *pVal0 = ssGetSFcnParam(S, 0);
|
||||
if (!IS_PARAM_UINT8(pVal0))
|
||||
{
|
||||
invalidParam = true;
|
||||
paramIndex = 0;
|
||||
goto EXIT_POINT;
|
||||
}
|
||||
}
|
||||
|
||||
EXIT_POINT:
|
||||
if (invalidParam)
|
||||
{
|
||||
char parameterErrorMsg[1024];
|
||||
sprintf(parameterErrorMsg, "The data type and or complexity of parameter %d does not match the "
|
||||
"information specified in the S-function Builder dialog. "
|
||||
"For non-double parameters you will need to cast them using int8, int16, "
|
||||
"int32, uint8, uint16, uint32 or boolean.",
|
||||
paramIndex + 1);
|
||||
ssSetErrorStatus(S, parameterErrorMsg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif /* MDL_CHECK_PARAMETERS */
|
||||
|
||||
/* Function: mdlInitializeSizes ===============================================
|
||||
* Abstract:
|
||||
* Setup sizes of the various vectors.
|
||||
*/
|
||||
static void mdlInitializeSizes(SimStruct *S)
|
||||
{
|
||||
ssSetNumSFcnParams(S, 1);
|
||||
if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S))
|
||||
{
|
||||
mdlCheckParameters(S);
|
||||
if (ssGetErrorStatus(S) != NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return; /* Parameter mismatch will be reported by Simulink */
|
||||
}
|
||||
|
||||
ssSetArrayLayoutForCodeGen(S, SS_COLUMN_MAJOR);
|
||||
|
||||
ssSetNumContStates(S, 0);
|
||||
ssSetNumDiscStates(S, 0);
|
||||
|
||||
if (!ssSetNumInputPorts(S, 2)) return;
|
||||
/* Input Port 0 */
|
||||
ssSetInputPortWidth(S, 0, 1);
|
||||
ssSetInputPortDataType(S, 0, SS_UINT32);
|
||||
ssSetInputPortComplexSignal(S, 0, COMPLEX_NO);
|
||||
ssSetInputPortDirectFeedThrough(S, 0, 1);
|
||||
ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/
|
||||
/* Input Port 1 */
|
||||
ssSetInputPortWidth(S, 1, 1);
|
||||
ssSetInputPortDataType(S, 1, SS_UINT16);
|
||||
ssSetInputPortComplexSignal(S, 1, COMPLEX_NO);
|
||||
ssSetInputPortDirectFeedThrough(S, 1, 1);
|
||||
ssSetInputPortRequiredContiguous(S, 1, 1); /*direct input signal access*/
|
||||
|
||||
if (!ssSetNumOutputPorts(S, 1)) return;
|
||||
/* Output Port 0 */
|
||||
ssSetOutputPortWidth(S, 0, DYNAMICALLY_SIZED);
|
||||
ssSetOutputPortDataType(S, 0, SS_UINT8);
|
||||
ssSetOutputPortComplexSignal(S, 0, COMPLEX_NO);
|
||||
|
||||
ssSetNumSampleTimes(S, 1);
|
||||
ssSetNumRWork(S, 0);
|
||||
ssSetNumIWork(S, 0);
|
||||
ssSetNumPWork(S, 0);
|
||||
ssSetNumModes(S, 0);
|
||||
ssSetNumNonsampledZCs(S, 0);
|
||||
|
||||
ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
|
||||
|
||||
/* Take care when specifying exception free code - see sfuntmpl_doc.c */
|
||||
ssSetOptions(S, SS_OPTION_WORKS_WITH_CODE_REUSE);
|
||||
}
|
||||
|
||||
/* Function: mdlInitializeSampleTimes =========================================
|
||||
* Abstract:
|
||||
* Specifiy the sample time.
|
||||
*/
|
||||
static void mdlInitializeSampleTimes(SimStruct *S)
|
||||
{
|
||||
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
|
||||
ssSetOffsetTime(S, 0, 0.0);
|
||||
ssSetModelReferenceSampleTimeDefaultInheritance(S);
|
||||
}
|
||||
|
||||
#define MDL_SET_WORK_WIDTHS
|
||||
#if defined(MDL_SET_WORK_WIDTHS) && defined(MATLAB_MEX_FILE)
|
||||
static void mdlSetWorkWidths(SimStruct *S)
|
||||
{
|
||||
const char_T *rtParamNames[] = {"ID"};
|
||||
ssRegAllTunableParamsAsRunTimeParams(S, rtParamNames);
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef MDL_START /* Change to #undef to remove function */
|
||||
#if defined(MDL_START)
|
||||
/* Function: mdlStart =======================================================
|
||||
* Abstract:
|
||||
* This function is called once at start of model execution. If you
|
||||
* have states that should be initialized once, this is the place
|
||||
* to do it.
|
||||
*/
|
||||
static void mdlStart(SimStruct *S)
|
||||
{
|
||||
}
|
||||
#endif /* MDL_START */
|
||||
|
||||
/* Function: mdlOutputs =======================================================
|
||||
*
|
||||
*/
|
||||
static void mdlOutputs(SimStruct *S, int_T tid)
|
||||
{
|
||||
}
|
||||
|
||||
/* Function: mdlTerminate =====================================================
|
||||
* Abstract:
|
||||
* In this function, you should perform any actions that are necessary
|
||||
* at the termination of a simulation. For example, if memory was
|
||||
* allocated in mdlStart, this is the place to free it.
|
||||
*/
|
||||
static void mdlTerminate(SimStruct *S)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user