451 lines
15 KiB
C
451 lines
15 KiB
C
/*
|
|
* File: hal_uart_init.c
|
|
*
|
|
*
|
|
* --- THIS FILE GENERATED BY S-FUNCTION BUILDER: 3.0 ---
|
|
*
|
|
* This file is an S-function produced by the S-Function
|
|
* Builder which only recognizes certain fields. Changes made
|
|
* outside these fields will be lost the next time the block is
|
|
* used to load, edit, and resave this file. This file will be overwritten
|
|
* by the S-function Builder block. If you want to edit this file by hand,
|
|
* you must change it only in the area defined as:
|
|
*
|
|
* %%%-SFUNWIZ_defines_Changes_BEGIN
|
|
* #define NAME 'replacement text'
|
|
* %%% SFUNWIZ_defines_Changes_END
|
|
*
|
|
* DO NOT change NAME--Change the 'replacement text' only.
|
|
*
|
|
* For better compatibility with the Simulink Coder, the
|
|
* "wrapper" S-function technique is used. This is discussed
|
|
* in the Simulink Coder's Manual in the Chapter titled,
|
|
* "Wrapper S-functions".
|
|
*
|
|
* -------------------------------------------------------------------------
|
|
* | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template |
|
|
* -------------------------------------------------------------------------
|
|
*
|
|
* Created: Thu Mar 19 17:53:53 2020
|
|
*/
|
|
|
|
#define S_FUNCTION_LEVEL 2
|
|
#define S_FUNCTION_NAME hal_uart_init
|
|
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
|
|
/* %%%-SFUNWIZ_defines_Changes_BEGIN --- EDIT HERE TO _END */
|
|
#define NUM_INPUTS 7
|
|
/* Input Port 0 */
|
|
#define IN_PORT_0_NAME baudrate
|
|
#define INPUT_0_WIDTH 1
|
|
#define INPUT_DIMS_0_COL 1
|
|
#define INPUT_0_DTYPE uint32_T
|
|
#define INPUT_0_COMPLEX COMPLEX_NO
|
|
#define IN_0_FRAME_BASED FRAME_NO
|
|
#define IN_0_BUS_BASED 0
|
|
#define IN_0_BUS_NAME
|
|
#define IN_0_DIMS 1-D
|
|
#define INPUT_0_FEEDTHROUGH 1
|
|
#define IN_0_ISSIGNED 0
|
|
#define IN_0_WORDLENGTH 8
|
|
#define IN_0_FIXPOINTSCALING 1
|
|
#define IN_0_FRACTIONLENGTH 9
|
|
#define IN_0_BIAS 0
|
|
#define IN_0_SLOPE 0.125
|
|
/* Input Port 1 */
|
|
#define IN_PORT_1_NAME wordlen
|
|
#define INPUT_1_WIDTH 1
|
|
#define INPUT_DIMS_1_COL 1
|
|
#define INPUT_1_DTYPE uint8_T
|
|
#define INPUT_1_COMPLEX COMPLEX_NO
|
|
#define IN_1_FRAME_BASED FRAME_NO
|
|
#define IN_1_BUS_BASED 0
|
|
#define IN_1_BUS_NAME
|
|
#define IN_1_DIMS 1-D
|
|
#define INPUT_1_FEEDTHROUGH 1
|
|
#define IN_1_ISSIGNED 0
|
|
#define IN_1_WORDLENGTH 8
|
|
#define IN_1_FIXPOINTSCALING 1
|
|
#define IN_1_FRACTIONLENGTH 9
|
|
#define IN_1_BIAS 0
|
|
#define IN_1_SLOPE 0.125
|
|
/* Input Port 2 */
|
|
#define IN_PORT_2_NAME stopbits
|
|
#define INPUT_2_WIDTH 1
|
|
#define INPUT_DIMS_2_COL 1
|
|
#define INPUT_2_DTYPE uint8_T
|
|
#define INPUT_2_COMPLEX COMPLEX_NO
|
|
#define IN_2_FRAME_BASED FRAME_NO
|
|
#define IN_2_BUS_BASED 0
|
|
#define IN_2_BUS_NAME
|
|
#define IN_2_DIMS 1-D
|
|
#define INPUT_2_FEEDTHROUGH 1
|
|
#define IN_2_ISSIGNED 0
|
|
#define IN_2_WORDLENGTH 8
|
|
#define IN_2_FIXPOINTSCALING 1
|
|
#define IN_2_FRACTIONLENGTH 9
|
|
#define IN_2_BIAS 0
|
|
#define IN_2_SLOPE 0.125
|
|
/* Input Port 3 */
|
|
#define IN_PORT_3_NAME parity
|
|
#define INPUT_3_WIDTH 1
|
|
#define INPUT_DIMS_3_COL 1
|
|
#define INPUT_3_DTYPE uint8_T
|
|
#define INPUT_3_COMPLEX COMPLEX_NO
|
|
#define IN_3_FRAME_BASED FRAME_NO
|
|
#define IN_3_BUS_BASED 0
|
|
#define IN_3_BUS_NAME
|
|
#define IN_3_DIMS 1-D
|
|
#define INPUT_3_FEEDTHROUGH 1
|
|
#define IN_3_ISSIGNED 0
|
|
#define IN_3_WORDLENGTH 8
|
|
#define IN_3_FIXPOINTSCALING 1
|
|
#define IN_3_FRACTIONLENGTH 9
|
|
#define IN_3_BIAS 0
|
|
#define IN_3_SLOPE 0.125
|
|
/* Input Port 4 */
|
|
#define IN_PORT_4_NAME buff_rx
|
|
#define INPUT_4_WIDTH 1
|
|
#define INPUT_DIMS_4_COL 1
|
|
#define INPUT_4_DTYPE uint16_T
|
|
#define INPUT_4_COMPLEX COMPLEX_NO
|
|
#define IN_4_FRAME_BASED FRAME_NO
|
|
#define IN_4_BUS_BASED 0
|
|
#define IN_4_BUS_NAME
|
|
#define IN_4_DIMS 1-D
|
|
#define INPUT_4_FEEDTHROUGH 1
|
|
#define IN_4_ISSIGNED 0
|
|
#define IN_4_WORDLENGTH 8
|
|
#define IN_4_FIXPOINTSCALING 1
|
|
#define IN_4_FRACTIONLENGTH 9
|
|
#define IN_4_BIAS 0
|
|
#define IN_4_SLOPE 0.125
|
|
/* Input Port 5 */
|
|
#define IN_PORT_5_NAME buff_tx
|
|
#define INPUT_5_WIDTH 1
|
|
#define INPUT_DIMS_5_COL 1
|
|
#define INPUT_5_DTYPE uint16_T
|
|
#define INPUT_5_COMPLEX COMPLEX_NO
|
|
#define IN_5_FRAME_BASED FRAME_NO
|
|
#define IN_5_BUS_BASED 0
|
|
#define IN_5_BUS_NAME
|
|
#define IN_5_DIMS 1-D
|
|
#define INPUT_5_FEEDTHROUGH 1
|
|
#define IN_5_ISSIGNED 0
|
|
#define IN_5_WORDLENGTH 8
|
|
#define IN_5_FIXPOINTSCALING 1
|
|
#define IN_5_FRACTIONLENGTH 9
|
|
#define IN_5_BIAS 0
|
|
#define IN_5_SLOPE 0.125
|
|
/* Input Port 6 */
|
|
#define IN_PORT_6_NAME opts
|
|
#define INPUT_6_WIDTH 1
|
|
#define INPUT_DIMS_6_COL 1
|
|
#define INPUT_6_DTYPE uint32_T
|
|
#define INPUT_6_COMPLEX COMPLEX_NO
|
|
#define IN_6_FRAME_BASED FRAME_NO
|
|
#define IN_6_BUS_BASED 0
|
|
#define IN_6_BUS_NAME
|
|
#define IN_6_DIMS 1-D
|
|
#define INPUT_6_FEEDTHROUGH 1
|
|
#define IN_6_ISSIGNED 0
|
|
#define IN_6_WORDLENGTH 8
|
|
#define IN_6_FIXPOINTSCALING 1
|
|
#define IN_6_FRACTIONLENGTH 9
|
|
#define IN_6_BIAS 0
|
|
#define IN_6_SLOPE 0.125
|
|
|
|
#define NUM_OUTPUTS 1
|
|
/* Output Port 0 */
|
|
#define OUT_PORT_0_NAME ErrCode
|
|
#define OUTPUT_0_WIDTH 1
|
|
#define OUTPUT_DIMS_0_COL 1
|
|
#define OUTPUT_0_DTYPE int32_T
|
|
#define OUTPUT_0_COMPLEX COMPLEX_NO
|
|
#define OUT_0_FRAME_BASED FRAME_NO
|
|
#define OUT_0_BUS_BASED 0
|
|
#define OUT_0_BUS_NAME
|
|
#define OUT_0_DIMS 1-D
|
|
#define OUT_0_ISSIGNED 1
|
|
#define OUT_0_WORDLENGTH 8
|
|
#define OUT_0_FIXPOINTSCALING 1
|
|
#define OUT_0_FRACTIONLENGTH 3
|
|
#define OUT_0_BIAS 0
|
|
#define OUT_0_SLOPE 0.125
|
|
|
|
#define NPARAMS 1
|
|
/* Parameter 0 */
|
|
#define PARAMETER_0_NAME uart_id
|
|
#define PARAMETER_0_DTYPE uint8_T
|
|
#define PARAMETER_0_COMPLEX COMPLEX_NO
|
|
|
|
#define SAMPLE_TIME_0 INHERITED_SAMPLE_TIME
|
|
#define NUM_DISC_STATES 0
|
|
#define DISC_STATES_IC [0]
|
|
#define NUM_CONT_STATES 0
|
|
#define CONT_STATES_IC [0]
|
|
|
|
#define SFUNWIZ_GENERATE_TLC 1
|
|
#define SOURCEFILES "__SFB__"
|
|
#define PANELINDEX 8
|
|
#define USE_SIMSTRUCT 0
|
|
#define SHOW_COMPILE_STEPS 0
|
|
#define CREATE_DEBUG_MEXFILE 0
|
|
#define SAVE_CODE_ONLY 0
|
|
#define SFUNWIZ_REVISION 3.0
|
|
/* %%%-SFUNWIZ_defines_Changes_END --- EDIT HERE TO _BEGIN */
|
|
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
|
|
#include "simstruc.h"
|
|
|
|
#define PARAM_DEF0(S) ssGetSFcnParam(S, 0)
|
|
|
|
#define IS_PARAM_UINT8(pVal) (mxIsNumeric(pVal) && !mxIsLogical(pVal) &&\
|
|
!mxIsEmpty(pVal) && !mxIsSparse(pVal) && !mxIsComplex(pVal) && mxIsUint8(pVal))
|
|
|
|
extern void hal_uart_init_Start_wrapper(const uint8_T *uart_id, const int_T p_width0);
|
|
extern void hal_uart_init_Outputs_wrapper(const uint32_T *baudrate,
|
|
const uint8_T *wordlen,
|
|
const uint8_T *stopbits,
|
|
const uint8_T *parity,
|
|
const uint16_T *buff_rx,
|
|
const uint16_T *buff_tx,
|
|
const uint32_T *opts,
|
|
int32_T *ErrCode,
|
|
const uint8_T *uart_id, const int_T p_width0);
|
|
/*====================*
|
|
* 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)
|
|
{
|
|
|
|
DECL_AND_INIT_DIMSINFO(inputDimsInfo);
|
|
DECL_AND_INIT_DIMSINFO(outputDimsInfo);
|
|
ssSetNumSFcnParams(S, NPARAMS); /* Number of expected parameters */
|
|
#if defined(MATLAB_MEX_FILE)
|
|
if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {
|
|
mdlCheckParameters(S);
|
|
if (ssGetErrorStatus(S) != NULL) {
|
|
return;
|
|
}
|
|
} else {
|
|
return; /* Parameter mismatch will be reported by Simulink */
|
|
}
|
|
#endif
|
|
|
|
ssSetArrayLayoutForCodeGen(S, SS_COLUMN_MAJOR);
|
|
|
|
ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
|
|
|
|
ssSetNumContStates(S, NUM_CONT_STATES);
|
|
ssSetNumDiscStates(S, NUM_DISC_STATES);
|
|
|
|
|
|
if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;
|
|
/* Input Port 0 */
|
|
ssSetInputPortWidth(S, 0, INPUT_0_WIDTH);
|
|
ssSetInputPortDataType(S, 0, SS_UINT32);
|
|
ssSetInputPortComplexSignal(S, 0, INPUT_0_COMPLEX);
|
|
ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH);
|
|
ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/
|
|
|
|
/* Input Port 1 */
|
|
ssSetInputPortWidth(S, 1, INPUT_1_WIDTH);
|
|
ssSetInputPortDataType(S, 1, SS_UINT8);
|
|
ssSetInputPortComplexSignal(S, 1, INPUT_1_COMPLEX);
|
|
ssSetInputPortDirectFeedThrough(S, 1, INPUT_1_FEEDTHROUGH);
|
|
ssSetInputPortRequiredContiguous(S, 1, 1); /*direct input signal access*/
|
|
|
|
/* Input Port 2 */
|
|
ssSetInputPortWidth(S, 2, INPUT_2_WIDTH);
|
|
ssSetInputPortDataType(S, 2, SS_UINT8);
|
|
ssSetInputPortComplexSignal(S, 2, INPUT_2_COMPLEX);
|
|
ssSetInputPortDirectFeedThrough(S, 2, INPUT_2_FEEDTHROUGH);
|
|
ssSetInputPortRequiredContiguous(S, 2, 1); /*direct input signal access*/
|
|
|
|
/* Input Port 3 */
|
|
ssSetInputPortWidth(S, 3, INPUT_3_WIDTH);
|
|
ssSetInputPortDataType(S, 3, SS_UINT8);
|
|
ssSetInputPortComplexSignal(S, 3, INPUT_3_COMPLEX);
|
|
ssSetInputPortDirectFeedThrough(S, 3, INPUT_3_FEEDTHROUGH);
|
|
ssSetInputPortRequiredContiguous(S, 3, 1); /*direct input signal access*/
|
|
|
|
/* Input Port 4 */
|
|
ssSetInputPortWidth(S, 4, INPUT_4_WIDTH);
|
|
ssSetInputPortDataType(S, 4, SS_UINT16);
|
|
ssSetInputPortComplexSignal(S, 4, INPUT_4_COMPLEX);
|
|
ssSetInputPortDirectFeedThrough(S, 4, INPUT_4_FEEDTHROUGH);
|
|
ssSetInputPortRequiredContiguous(S, 4, 1); /*direct input signal access*/
|
|
|
|
/* Input Port 5 */
|
|
ssSetInputPortWidth(S, 5, INPUT_5_WIDTH);
|
|
ssSetInputPortDataType(S, 5, SS_UINT16);
|
|
ssSetInputPortComplexSignal(S, 5, INPUT_5_COMPLEX);
|
|
ssSetInputPortDirectFeedThrough(S, 5, INPUT_5_FEEDTHROUGH);
|
|
ssSetInputPortRequiredContiguous(S, 5, 1); /*direct input signal access*/
|
|
|
|
/* Input Port 6 */
|
|
ssSetInputPortWidth(S, 6, INPUT_6_WIDTH);
|
|
ssSetInputPortDataType(S, 6, SS_UINT32);
|
|
ssSetInputPortComplexSignal(S, 6, INPUT_6_COMPLEX);
|
|
ssSetInputPortDirectFeedThrough(S, 6, INPUT_6_FEEDTHROUGH);
|
|
ssSetInputPortRequiredContiguous(S, 6, 1); /*direct input signal access*/
|
|
|
|
|
|
if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
|
|
ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH);
|
|
ssSetOutputPortDataType(S, 0, SS_INT32);
|
|
ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
|
|
ssSetNumPWork(S, 0);
|
|
|
|
ssSetNumSampleTimes(S, 1);
|
|
ssSetNumRWork(S, 0);
|
|
ssSetNumIWork(S, 0);
|
|
ssSetNumModes(S, 0);
|
|
ssSetNumNonsampledZCs(S, 0);
|
|
|
|
ssSetSimulinkVersionGeneratedIn(S, "9.2");
|
|
|
|
/* Take care when specifying exception free code - see sfuntmpl_doc.c */
|
|
ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE |
|
|
SS_OPTION_USE_TLC_WITH_ACCELERATOR |
|
|
SS_OPTION_WORKS_WITH_CODE_REUSE));
|
|
}
|
|
|
|
/* Function: mdlInitializeSampleTimes =========================================
|
|
* Abstract:
|
|
* Specifiy the sample time.
|
|
*/
|
|
static void mdlInitializeSampleTimes(SimStruct *S)
|
|
{
|
|
ssSetSampleTime(S, 0, SAMPLE_TIME_0);
|
|
ssSetModelReferenceSampleTimeDefaultInheritance(S);
|
|
ssSetOffsetTime(S, 0, 0.0);
|
|
}
|
|
|
|
#define MDL_SET_INPUT_PORT_DATA_TYPE
|
|
static void mdlSetInputPortDataType(SimStruct *S, int port, DTypeId dType)
|
|
{
|
|
ssSetInputPortDataType(S, 0, dType);
|
|
}
|
|
|
|
#define MDL_SET_OUTPUT_PORT_DATA_TYPE
|
|
static void mdlSetOutputPortDataType(SimStruct *S, int port, DTypeId dType)
|
|
{
|
|
ssSetOutputPortDataType(S, 0, dType);
|
|
}
|
|
|
|
#define MDL_SET_DEFAULT_PORT_DATA_TYPES
|
|
static void mdlSetDefaultPortDataTypes(SimStruct *S)
|
|
{
|
|
ssSetInputPortDataType(S, 0, SS_DOUBLE);
|
|
ssSetOutputPortDataType(S, 0, SS_DOUBLE);
|
|
}
|
|
|
|
#define MDL_SET_WORK_WIDTHS
|
|
#if defined(MDL_SET_WORK_WIDTHS) && defined(MATLAB_MEX_FILE)
|
|
|
|
static void mdlSetWorkWidths(SimStruct *S)
|
|
{
|
|
|
|
const char_T *rtParamNames[] = {"P1"};
|
|
ssRegAllTunableParamsAsRunTimeParams(S, rtParamNames);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#define 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)
|
|
{
|
|
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
|
|
const uint8_T *uart_id = (const uint8_T *) mxGetData(PARAM_DEF0(S));
|
|
|
|
hal_uart_init_Start_wrapper(uart_id, p_width0);
|
|
}
|
|
#endif /* MDL_START */
|
|
|
|
/* Function: mdlOutputs =======================================================
|
|
*
|
|
*/
|
|
static void mdlOutputs(SimStruct *S, int_T tid)
|
|
{
|
|
const uint32_T *baudrate = (uint32_T *) ssGetInputPortRealSignal(S, 0);
|
|
const uint8_T *wordlen = (uint8_T *) ssGetInputPortRealSignal(S, 1);
|
|
const uint8_T *stopbits = (uint8_T *) ssGetInputPortRealSignal(S, 2);
|
|
const uint8_T *parity = (uint8_T *) ssGetInputPortRealSignal(S, 3);
|
|
const uint16_T *buff_rx = (uint16_T *) ssGetInputPortRealSignal(S, 4);
|
|
const uint16_T *buff_tx = (uint16_T *) ssGetInputPortRealSignal(S, 5);
|
|
const uint32_T *opts = (uint32_T *) ssGetInputPortRealSignal(S, 6);
|
|
int32_T *ErrCode = (int32_T *) ssGetOutputPortRealSignal(S, 0);
|
|
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
|
|
const uint8_T *uart_id = (const uint8_T *) mxGetData(PARAM_DEF0(S));
|
|
|
|
hal_uart_init_Outputs_wrapper(baudrate, wordlen, stopbits, parity, buff_rx, buff_tx, opts, ErrCode, uart_id, p_width0);
|
|
|
|
}
|
|
|
|
/* 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
|
|
|
|
|
|
|