Sbus Input and LED set HAL API
This commit is contained in:
Binary file not shown.
Binary file not shown.
+447
@@ -0,0 +1,447 @@
|
|||||||
|
/*
|
||||||
|
* File: hal_led_set.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: Fri Mar 20 11:30:03 2020
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define S_FUNCTION_LEVEL 2
|
||||||
|
#define S_FUNCTION_NAME hal_led_set
|
||||||
|
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
|
||||||
|
/* %%%-SFUNWIZ_defines_Changes_BEGIN --- EDIT HERE TO _END */
|
||||||
|
#define NUM_INPUTS 1
|
||||||
|
/* Input Port 0 */
|
||||||
|
#define IN_PORT_0_NAME color
|
||||||
|
#define INPUT_0_WIDTH 1
|
||||||
|
#define INPUT_DIMS_0_COL 1
|
||||||
|
#define INPUT_0_DTYPE real_T
|
||||||
|
#define INPUT_0_COMPLEX COMPLEX_NO
|
||||||
|
#define IN_0_FRAME_BASED FRAME_NO
|
||||||
|
#define IN_0_BUS_BASED 1
|
||||||
|
#define IN_0_BUS_NAME LedColorMsg
|
||||||
|
#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
|
||||||
|
|
||||||
|
#define NUM_OUTPUTS 1
|
||||||
|
/* Output Port 0 */
|
||||||
|
#define OUT_PORT_0_NAME ErrorCode
|
||||||
|
#define OUTPUT_0_WIDTH 1
|
||||||
|
#define OUTPUT_DIMS_0_COL 1
|
||||||
|
#define OUTPUT_0_DTYPE real_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 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"
|
||||||
|
#include "hal_led_set_bus.h"
|
||||||
|
/*
|
||||||
|
* Code Generation Environment flag (simulation or standalone target).
|
||||||
|
*/
|
||||||
|
static int_T isSimulationTarget;
|
||||||
|
/* Utility function prototypes. */
|
||||||
|
static int_T GetRTWEnvironmentMode(SimStruct *S);
|
||||||
|
/* Macro used to check if Simulation mode is set to accelerator */
|
||||||
|
#define isBusDWorkPresent ( ( ( !ssRTWGenIsCodeGen(S) || isSimulationTarget ) && !ssIsExternalSim(S) ) || ssIsRapidAcceleratorActive(S) )
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int_T offset;
|
||||||
|
int_T elemSize;
|
||||||
|
int_T numElems;
|
||||||
|
} busInfoStruct;
|
||||||
|
#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_led_set_Start_wrapper(const uint8_T *id, const int_T p_width0);
|
||||||
|
extern void hal_led_set_Outputs_wrapper(const LedColorMsg *color,
|
||||||
|
real_T *ErrorCode,
|
||||||
|
const uint8_T *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;
|
||||||
|
|
||||||
|
/* Register LedColorMsg datatype for Input port 0 */
|
||||||
|
|
||||||
|
#if defined(MATLAB_MEX_FILE)
|
||||||
|
if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY)
|
||||||
|
{
|
||||||
|
DTypeId dataTypeIdReg;
|
||||||
|
ssRegisterTypeFromNamedObject(S, "LedColorMsg", &dataTypeIdReg);
|
||||||
|
if(dataTypeIdReg == INVALID_DTYPE_ID) return;
|
||||||
|
ssSetInputPortDataType(S, 0, dataTypeIdReg);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
ssSetInputPortWidth(S, 0, INPUT_0_WIDTH);
|
||||||
|
ssSetInputPortComplexSignal(S, 0, INPUT_0_COMPLEX);
|
||||||
|
ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH);
|
||||||
|
ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/
|
||||||
|
ssSetBusInputAsStruct(S, 0, IN_0_BUS_BASED);
|
||||||
|
ssSetInputPortBusMode(S, 0, SL_BUS_MODE);
|
||||||
|
|
||||||
|
if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
|
||||||
|
ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH);
|
||||||
|
ssSetOutputPortDataType(S, 0, SS_DOUBLE);
|
||||||
|
ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
|
||||||
|
|
||||||
|
if (ssRTWGenIsCodeGen(S)) {
|
||||||
|
isSimulationTarget = GetRTWEnvironmentMode(S);
|
||||||
|
if (isSimulationTarget == -1) {
|
||||||
|
ssSetErrorStatus(S, " Unable to determine a valid code generation environment mode");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isSimulationTarget |= ssRTWGenIsModelReferenceSimTarget(S);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the number of dworks */
|
||||||
|
if (!isBusDWorkPresent) {
|
||||||
|
if (!ssSetNumDWork(S, 0)) return;
|
||||||
|
} else {
|
||||||
|
if (!ssSetNumDWork(S, 1)) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isBusDWorkPresent) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Configure the dwork 0 (colorBUS)
|
||||||
|
*/
|
||||||
|
#if defined(MATLAB_MEX_FILE)
|
||||||
|
if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) {
|
||||||
|
DTypeId dataTypeIdReg;
|
||||||
|
ssRegisterTypeFromNamedObject(S, "LedColorMsg", &dataTypeIdReg);
|
||||||
|
if (dataTypeIdReg == INVALID_DTYPE_ID) return;
|
||||||
|
ssSetDWorkDataType(S, 0, dataTypeIdReg);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ssSetDWorkUsageType(S, 0, SS_DWORK_USED_AS_DWORK);
|
||||||
|
ssSetDWorkName(S, 0, "colorBUS");
|
||||||
|
ssSetDWorkWidth(S, 0, DYNAMICALLY_SIZED);
|
||||||
|
ssSetDWorkComplexSignal(S, 0, COMPLEX_NO);
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
/* Set the width of DWork(s) used for marshalling the IOs */
|
||||||
|
if (isBusDWorkPresent) {
|
||||||
|
|
||||||
|
/* Update dwork 0 */
|
||||||
|
ssSetDWorkWidth(S, 0, ssGetInputPortWidth(S, 0));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
/* Bus Information */
|
||||||
|
slDataTypeAccess *dta = ssGetDataTypeAccess(S);
|
||||||
|
const char *bpath = ssGetPath(S);
|
||||||
|
DTypeId LedColorMsgId = ssGetDataTypeId(S, "LedColorMsg");
|
||||||
|
|
||||||
|
busInfoStruct *busInfo = (busInfoStruct *)malloc(6*sizeof(busInfoStruct));
|
||||||
|
if(busInfo==NULL) {
|
||||||
|
ssSetErrorStatus(S, "Memory allocation failure");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate offsets of all primitive elements of the bus */
|
||||||
|
|
||||||
|
busInfo[0].offset = dtaGetDataTypeElementOffset(dta, bpath, LedColorMsgId, 0);
|
||||||
|
busInfo[0].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint8"));
|
||||||
|
busInfo[0].numElems = 1;
|
||||||
|
busInfo[1].offset = dtaGetDataTypeElementOffset(dta, bpath, LedColorMsgId, 1);
|
||||||
|
busInfo[1].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint8"));
|
||||||
|
busInfo[1].numElems = 1;
|
||||||
|
busInfo[2].offset = dtaGetDataTypeElementOffset(dta, bpath, LedColorMsgId, 2);
|
||||||
|
busInfo[2].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint8"));
|
||||||
|
busInfo[2].numElems = 1;
|
||||||
|
ssSetUserData(S, busInfo);
|
||||||
|
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
|
||||||
|
const uint8_T *id = (const uint8_T *) mxGetData(PARAM_DEF0(S));
|
||||||
|
|
||||||
|
hal_led_set_Start_wrapper(id, p_width0);
|
||||||
|
}
|
||||||
|
#endif /* MDL_START */
|
||||||
|
|
||||||
|
/* Function: mdlOutputs =======================================================
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void mdlOutputs(SimStruct *S, int_T tid)
|
||||||
|
{
|
||||||
|
const char *color = (char *) ssGetInputPortSignal(S, 0);
|
||||||
|
real_T *ErrorCode = (real_T *) ssGetOutputPortRealSignal(S, 0);
|
||||||
|
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
|
||||||
|
const uint8_T *id = (const uint8_T *) mxGetData(PARAM_DEF0(S));
|
||||||
|
|
||||||
|
busInfoStruct* busInfo = (busInfoStruct *) ssGetUserData(S);
|
||||||
|
|
||||||
|
/* Temporary bus copy declarations */
|
||||||
|
LedColorMsg _colorBUS;
|
||||||
|
|
||||||
|
/* Copy input bus into temporary structure */
|
||||||
|
(void) memcpy(&_colorBUS.r, color + busInfo[0].offset, busInfo[0].elemSize * busInfo[0].numElems);
|
||||||
|
(void) memcpy(&_colorBUS.g, color + busInfo[1].offset, busInfo[1].elemSize * busInfo[1].numElems);
|
||||||
|
(void) memcpy(&_colorBUS.b, color + busInfo[2].offset, busInfo[2].elemSize * busInfo[2].numElems);
|
||||||
|
|
||||||
|
hal_led_set_Outputs_wrapper(&_colorBUS, ErrorCode, id, p_width0);
|
||||||
|
|
||||||
|
/* Copy temporary structure into output bus */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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)
|
||||||
|
{
|
||||||
|
/* Free stored bus information */
|
||||||
|
busInfoStruct *busInfo = (busInfoStruct *) ssGetUserData(S);
|
||||||
|
if(busInfo != NULL) {
|
||||||
|
free(busInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int_T GetRTWEnvironmentMode(SimStruct *S)
|
||||||
|
{
|
||||||
|
int_T status = -1;
|
||||||
|
mxArray *plhs[1];
|
||||||
|
mxArray *prhs[1];
|
||||||
|
mxArray * err;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the name of the Simulink block diagram
|
||||||
|
*/
|
||||||
|
prhs[0] = mxCreateString(ssGetModelName(ssGetRootSS(S)));
|
||||||
|
plhs[0] = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Call "isSimulationTarget = rtwenvironmentmode(modelName)" in MATLAB
|
||||||
|
*/
|
||||||
|
err = mexCallMATLABWithTrap(1, plhs, 1, prhs, "rtwenvironmentmode");
|
||||||
|
mxDestroyArray(prhs[0]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the error status if an error occurred
|
||||||
|
*/
|
||||||
|
if (err) {
|
||||||
|
if (plhs[0]) {
|
||||||
|
mxDestroyArray(plhs[0]);
|
||||||
|
plhs[0] = NULL;
|
||||||
|
}
|
||||||
|
ssSetErrorStatus(S, "Unknown error during call to 'rtwenvironmentmode'.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the value returned by rtwenvironmentmode(modelName)
|
||||||
|
*/
|
||||||
|
if (plhs[0]) {
|
||||||
|
status = (int_T) (mxGetScalar(plhs[0]) != 0);
|
||||||
|
mxDestroyArray(plhs[0]);
|
||||||
|
plhs[0] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (status);
|
||||||
|
}
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Binary file not shown.
+142
@@ -0,0 +1,142 @@
|
|||||||
|
%% File : hal_led_set.tlc
|
||||||
|
%% Created : Fri Mar 20 11:30:03 2020
|
||||||
|
%%
|
||||||
|
%% Description:
|
||||||
|
%% Simulink Coder wrapper functions interface generated for
|
||||||
|
%% S-function "hal_led_set.c".
|
||||||
|
%%
|
||||||
|
%% File generated by S-function Builder Block
|
||||||
|
%%
|
||||||
|
%% For more information on using the Target Language with the
|
||||||
|
%% Simulink Coder, see the Target Language Compiler manual
|
||||||
|
%% (under Simulink Coder) in the "Inlining S-Functions"
|
||||||
|
%% chapter under the section and subsection:
|
||||||
|
%% "Writing Block Target Files to Inline S-Functions",
|
||||||
|
%% "Function-Based or Wrappered Code".
|
||||||
|
%%
|
||||||
|
%implements hal_led_set "C"
|
||||||
|
%% Function: BlockTypeSetup ===================================================
|
||||||
|
%%
|
||||||
|
%% Purpose:
|
||||||
|
%% Set up external references for wrapper functions in the
|
||||||
|
%% generated code.
|
||||||
|
%%
|
||||||
|
%function BlockTypeSetup(block, system) Output
|
||||||
|
|
||||||
|
%if IsModelReferenceSimTarget() || CodeFormat == "S-Function" || ::isRAccel
|
||||||
|
%assign hFileName = "hal_led_set_accel_wrapper"
|
||||||
|
%assign hFileNameMacro = FEVAL("upper", hFileName)
|
||||||
|
%openfile hFile = "%<hFileName>.h"
|
||||||
|
%selectfile hFile
|
||||||
|
#ifndef _%<hFileNameMacro>_H_
|
||||||
|
#define _%<hFileNameMacro>_H_
|
||||||
|
|
||||||
|
#include "tmwtypes.h"
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
extern void hal_led_set_Start_wrapper_accel(const uint8_T *id, const int_T p_width0);
|
||||||
|
extern void hal_led_set_Outputs_wrapper_accel(const void *color, void *__colorBUS,
|
||||||
|
real_T *ErrorCode,
|
||||||
|
const uint8_T *id, const int_T p_width0);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
%closefile hFile
|
||||||
|
|
||||||
|
%assign cFileName = "hal_led_set_accel_wrapper"
|
||||||
|
%openfile cFile = "%<cFileName>.c"
|
||||||
|
%selectfile cFile
|
||||||
|
#include <string.h>
|
||||||
|
#include "tmwtypes.h"
|
||||||
|
#include "hal_led_set_bus.h"
|
||||||
|
|
||||||
|
void hal_led_set_Start_wrapper_accel(const uint8_T *id, const int_T p_width0){
|
||||||
|
hal_led_set_Start_wrapper(id, p_width0);
|
||||||
|
}
|
||||||
|
void hal_led_set_Outputs_wrapper_accel(const void *color, void *__colorBUS,
|
||||||
|
real_T *ErrorCode,
|
||||||
|
const uint8_T *id, const int_T p_width0){
|
||||||
|
|
||||||
|
%assign dTypeId = LibBlockInputSignalDataTypeId(0)
|
||||||
|
%<SLibAssignSLStructToUserStruct(dTypeId, "(*(LedColorMsg *) __colorBUS)", "(char *) color", 0)>
|
||||||
|
hal_led_set_Outputs_wrapper((LedColorMsg *) __colorBUS,
|
||||||
|
ErrorCode,
|
||||||
|
id, p_width0);
|
||||||
|
}
|
||||||
|
|
||||||
|
%closefile cFile
|
||||||
|
|
||||||
|
%<LibAddToCommonIncludes("%<hFileName>.h")>
|
||||||
|
%<LibAddToModelSources("%<cFileName>")>
|
||||||
|
|
||||||
|
%else
|
||||||
|
%openfile externs
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern void hal_led_set_Start_wrapper(const uint8_T *id, const int_T p_width0);
|
||||||
|
|
||||||
|
extern void hal_led_set_Outputs_wrapper(const LedColorMsg *color,
|
||||||
|
real_T *ErrorCode,
|
||||||
|
const uint8_T *id, const int_T p_width0);
|
||||||
|
|
||||||
|
extern void hal_led_set_Terminate_wrapper(const uint8_T *id, const int_T p_width0);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
%closefile externs
|
||||||
|
%<LibCacheExtern(externs)>
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%%
|
||||||
|
%endfunction
|
||||||
|
|
||||||
|
|
||||||
|
%% Function: Start ============================================================
|
||||||
|
%%
|
||||||
|
%function Start(block, system) Output
|
||||||
|
/* %<Type> Block: %<Name> */
|
||||||
|
%assign nelements1 = LibBlockParameterSize(P1)
|
||||||
|
%assign param_width1 = nelements1[0] * nelements1[1]
|
||||||
|
%if (param_width1) > 1
|
||||||
|
%assign pp1 = LibBlockMatrixParameterBaseAddr(P1)
|
||||||
|
%else
|
||||||
|
%assign pp1 = LibBlockParameterAddr(P1, "", "", 0)
|
||||||
|
%endif
|
||||||
|
hal_led_set_Start_wrapper(%<pp1>, %<param_width1>);
|
||||||
|
%endfunction
|
||||||
|
%% Function: Outputs ==========================================================
|
||||||
|
%%
|
||||||
|
%% Purpose:
|
||||||
|
%% Code generation rules for mdlOutputs function.
|
||||||
|
%%
|
||||||
|
%function Outputs(block, system) Output
|
||||||
|
%%
|
||||||
|
%assign pu0 = LibBlockInputSignalAddr(0, "", "", 0)
|
||||||
|
%assign py0 = LibBlockOutputSignalAddr(0, "", "", 0)
|
||||||
|
%assign nelements1 = LibBlockParameterSize(P1)
|
||||||
|
%assign param_width1 = nelements1[0] * nelements1[1]
|
||||||
|
%if (param_width1) > 1
|
||||||
|
%assign pp1 = LibBlockMatrixParameterBaseAddr(P1)
|
||||||
|
%else
|
||||||
|
%assign pp1 = LibBlockParameterAddr(P1, "", "", 0)
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%if IsModelReferenceSimTarget() || CodeFormat == "S-Function" || ::isRAccel
|
||||||
|
%assign colorBUS_ptr = LibBlockDWorkAddr(colorBUS, "", "", 0)
|
||||||
|
hal_led_set_Outputs_wrapper_accel(%<pu0>, %<colorBUS_ptr>, %<py0>, %<pp1>, %<param_width1>);
|
||||||
|
%else
|
||||||
|
hal_led_set_Outputs_wrapper(%<pu0>, %<py0>, %<pp1>, %<param_width1>);
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%%
|
||||||
|
%endfunction
|
||||||
|
|
||||||
|
|
||||||
|
%% [EOF] hal_led_set.tlc
|
||||||
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/* Generated by S-function Builder */
|
||||||
|
#ifndef _HAL_LED_SET_BUS_H_
|
||||||
|
#define _HAL_LED_SET_BUS_H_
|
||||||
|
/* Read only - STARTS */
|
||||||
|
#ifdef MATLAB_MEX_FILE
|
||||||
|
#include "tmwtypes.h"
|
||||||
|
#else
|
||||||
|
#include "rtwtypes.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _DEFINED_TYPEDEF_FOR_LedColorMsg_
|
||||||
|
#define _DEFINED_TYPEDEF_FOR_LedColorMsg_
|
||||||
|
typedef struct {
|
||||||
|
uint8_T r;
|
||||||
|
uint8_T g;
|
||||||
|
uint8_T b;
|
||||||
|
} LedColorMsg;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Read only - ENDS */
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* Include Files
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#if defined(MATLAB_MEX_FILE)
|
||||||
|
#include "tmwtypes.h"
|
||||||
|
#include "simstruc_types.h"
|
||||||
|
#else
|
||||||
|
#include "rtwtypes.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "hal_led_set_bus.h"
|
||||||
|
|
||||||
|
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
|
||||||
|
#ifdef HAL_IMPL
|
||||||
|
//#include "param_mgr.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#endif
|
||||||
|
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
|
||||||
|
#define u_width 1
|
||||||
|
#define y_width 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create external references here.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
|
||||||
|
#ifdef HAL_IMPL
|
||||||
|
|
||||||
|
int is_led_g0_init = 0;
|
||||||
|
int is_led_g1_init = 0;
|
||||||
|
int is_led_g2_init = 0;
|
||||||
|
|
||||||
|
void led_set_init(uint8_t id)
|
||||||
|
{
|
||||||
|
if (id == 0u && !is_led_g0_init)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
is_led_g0_init = 1;
|
||||||
|
}
|
||||||
|
if (id == 1u && !is_led_g1_init)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
is_led_g1_init = 1;
|
||||||
|
}
|
||||||
|
if (id == 2u && !is_led_g2_init)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
is_led_g2_init = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start function
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void hal_led_set_Start_wrapper(const uint8_T *id, const int_T p_width0)
|
||||||
|
{
|
||||||
|
/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */
|
||||||
|
#ifdef HAL_IMPL
|
||||||
|
led_set_init(id[0]);
|
||||||
|
#endif
|
||||||
|
/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Output function
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void hal_led_set_Outputs_wrapper(const LedColorMsg *color,
|
||||||
|
real_T *ErrorCode,
|
||||||
|
const uint8_T *id, const int_T p_width0)
|
||||||
|
{
|
||||||
|
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
|
||||||
|
#ifdef HAL_IMPL
|
||||||
|
/*
|
||||||
|
* set LED group *id* with *color*
|
||||||
|
*
|
||||||
|
* ErrorCode - return zero on success, otherwise nonzero on failures.
|
||||||
|
*/
|
||||||
|
if (id[0] == 0u && is_led_g0_init)
|
||||||
|
{
|
||||||
|
// TODO set led color
|
||||||
|
ErrorCode[0] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ErrorCode[0] = -1;
|
||||||
|
#else
|
||||||
|
ErrorCode[0] = 0;
|
||||||
|
#endif
|
||||||
|
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+440
@@ -0,0 +1,440 @@
|
|||||||
|
/*
|
||||||
|
* File: hal_sbus_in.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: Fri Mar 20 11:07:31 2020
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define S_FUNCTION_LEVEL 2
|
||||||
|
#define S_FUNCTION_NAME hal_sbus_in
|
||||||
|
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
|
||||||
|
/* %%%-SFUNWIZ_defines_Changes_BEGIN --- EDIT HERE TO _END */
|
||||||
|
#define NUM_INPUTS 0
|
||||||
|
|
||||||
|
#define NUM_OUTPUTS 2
|
||||||
|
/* Output Port 0 */
|
||||||
|
#define OUT_PORT_0_NAME sbus
|
||||||
|
#define OUTPUT_0_WIDTH 1
|
||||||
|
#define OUTPUT_DIMS_0_COL 1
|
||||||
|
#define OUTPUT_0_DTYPE real_T
|
||||||
|
#define OUTPUT_0_COMPLEX COMPLEX_NO
|
||||||
|
#define OUT_0_FRAME_BASED FRAME_NO
|
||||||
|
#define OUT_0_BUS_BASED 1
|
||||||
|
#define OUT_0_BUS_NAME SbusInMsg
|
||||||
|
#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
|
||||||
|
/* Output Port 1 */
|
||||||
|
#define OUT_PORT_1_NAME ErrorCode
|
||||||
|
#define OUTPUT_1_WIDTH 1
|
||||||
|
#define OUTPUT_DIMS_1_COL 1
|
||||||
|
#define OUTPUT_1_DTYPE int32_T
|
||||||
|
#define OUTPUT_1_COMPLEX COMPLEX_NO
|
||||||
|
#define OUT_1_FRAME_BASED FRAME_NO
|
||||||
|
#define OUT_1_BUS_BASED 0
|
||||||
|
#define OUT_1_BUS_NAME
|
||||||
|
#define OUT_1_DIMS 1-D
|
||||||
|
#define OUT_1_ISSIGNED 1
|
||||||
|
#define OUT_1_WORDLENGTH 8
|
||||||
|
#define OUT_1_FIXPOINTSCALING 1
|
||||||
|
#define OUT_1_FRACTIONLENGTH 3
|
||||||
|
#define OUT_1_BIAS 0
|
||||||
|
#define OUT_1_SLOPE 0.125
|
||||||
|
|
||||||
|
#define NPARAMS 1
|
||||||
|
/* Parameter 0 */
|
||||||
|
#define PARAMETER_0_NAME 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"
|
||||||
|
#include "hal_sbus_in_bus.h"
|
||||||
|
/*
|
||||||
|
* Code Generation Environment flag (simulation or standalone target).
|
||||||
|
*/
|
||||||
|
static int_T isSimulationTarget;
|
||||||
|
/* Utility function prototypes. */
|
||||||
|
static int_T GetRTWEnvironmentMode(SimStruct *S);
|
||||||
|
/* Macro used to check if Simulation mode is set to accelerator */
|
||||||
|
#define isBusDWorkPresent ( ( ( !ssRTWGenIsCodeGen(S) || isSimulationTarget ) && !ssIsExternalSim(S) ) || ssIsRapidAcceleratorActive(S) )
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int_T offset;
|
||||||
|
int_T elemSize;
|
||||||
|
int_T numElems;
|
||||||
|
} busInfoStruct;
|
||||||
|
#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_sbus_in_Start_wrapper(const uint8_T *id, const int_T p_width0);
|
||||||
|
extern void hal_sbus_in_Outputs_wrapper(SbusInMsg *sbus,
|
||||||
|
int32_T *ErrorCode,
|
||||||
|
const uint8_T *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(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;
|
||||||
|
|
||||||
|
if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
|
||||||
|
/* Output Port 0 */
|
||||||
|
|
||||||
|
/* Register SbusInMsg datatype for Output port 0 */
|
||||||
|
|
||||||
|
#if defined(MATLAB_MEX_FILE)
|
||||||
|
if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY)
|
||||||
|
{
|
||||||
|
DTypeId dataTypeIdReg;
|
||||||
|
ssRegisterTypeFromNamedObject(S, "SbusInMsg", &dataTypeIdReg);
|
||||||
|
if(dataTypeIdReg == INVALID_DTYPE_ID) return;
|
||||||
|
ssSetOutputPortDataType(S, 0, dataTypeIdReg);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ssSetBusOutputObjectName(S, 0, (void *) "SbusInMsg");
|
||||||
|
ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH);
|
||||||
|
ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
|
||||||
|
ssSetBusOutputAsStruct(S, 0,OUT_0_BUS_BASED);
|
||||||
|
ssSetOutputPortBusMode(S, 0, SL_BUS_MODE);
|
||||||
|
/* Output Port 1 */
|
||||||
|
ssSetOutputPortWidth(S, 1, OUTPUT_1_WIDTH);
|
||||||
|
ssSetOutputPortDataType(S, 1, SS_INT32);
|
||||||
|
ssSetOutputPortComplexSignal(S, 1, OUTPUT_1_COMPLEX);
|
||||||
|
|
||||||
|
if (ssRTWGenIsCodeGen(S)) {
|
||||||
|
isSimulationTarget = GetRTWEnvironmentMode(S);
|
||||||
|
if (isSimulationTarget == -1) {
|
||||||
|
ssSetErrorStatus(S, " Unable to determine a valid code generation environment mode");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isSimulationTarget |= ssRTWGenIsModelReferenceSimTarget(S);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the number of dworks */
|
||||||
|
if (!isBusDWorkPresent) {
|
||||||
|
if (!ssSetNumDWork(S, 0)) return;
|
||||||
|
} else {
|
||||||
|
if (!ssSetNumDWork(S, 1)) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isBusDWorkPresent) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Configure the dwork 0 (sbusBUS)
|
||||||
|
*/
|
||||||
|
#if defined(MATLAB_MEX_FILE)
|
||||||
|
if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) {
|
||||||
|
DTypeId dataTypeIdReg;
|
||||||
|
ssRegisterTypeFromNamedObject(S, "SbusInMsg", &dataTypeIdReg);
|
||||||
|
if (dataTypeIdReg == INVALID_DTYPE_ID) return;
|
||||||
|
ssSetDWorkDataType(S, 0, dataTypeIdReg);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ssSetDWorkUsageType(S, 0, SS_DWORK_USED_AS_DWORK);
|
||||||
|
ssSetDWorkName(S, 0, "sbusBUS");
|
||||||
|
ssSetDWorkWidth(S, 0, DYNAMICALLY_SIZED);
|
||||||
|
ssSetDWorkComplexSignal(S, 0, COMPLEX_NO);
|
||||||
|
}
|
||||||
|
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_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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
/* Set the width of DWork(s) used for marshalling the IOs */
|
||||||
|
if (isBusDWorkPresent) {
|
||||||
|
|
||||||
|
/* Update dwork 0 */
|
||||||
|
ssSetDWorkWidth(S, 0, ssGetOutputPortWidth(S, 0));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
/* Bus Information */
|
||||||
|
slDataTypeAccess *dta = ssGetDataTypeAccess(S);
|
||||||
|
const char *bpath = ssGetPath(S);
|
||||||
|
DTypeId SbusInMsgId = ssGetDataTypeId(S, "SbusInMsg");
|
||||||
|
|
||||||
|
busInfoStruct *busInfo = (busInfoStruct *)malloc(6*sizeof(busInfoStruct));
|
||||||
|
if(busInfo==NULL) {
|
||||||
|
ssSetErrorStatus(S, "Memory allocation failure");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate offsets of all primitive elements of the bus */
|
||||||
|
|
||||||
|
busInfo[0].offset = dtaGetDataTypeElementOffset(dta, bpath, SbusInMsgId, 0);
|
||||||
|
busInfo[0].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint16"));
|
||||||
|
busInfo[0].numElems = 18;
|
||||||
|
busInfo[1].offset = dtaGetDataTypeElementOffset(dta, bpath, SbusInMsgId, 1);
|
||||||
|
busInfo[1].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "double"));
|
||||||
|
busInfo[1].numElems = 1;
|
||||||
|
busInfo[2].offset = dtaGetDataTypeElementOffset(dta, bpath, SbusInMsgId, 2);
|
||||||
|
busInfo[2].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint8"));
|
||||||
|
busInfo[2].numElems = 1;
|
||||||
|
ssSetUserData(S, busInfo);
|
||||||
|
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
|
||||||
|
const uint8_T *id = (const uint8_T *) mxGetData(PARAM_DEF0(S));
|
||||||
|
|
||||||
|
hal_sbus_in_Start_wrapper(id, p_width0);
|
||||||
|
}
|
||||||
|
#endif /* MDL_START */
|
||||||
|
|
||||||
|
/* Function: mdlOutputs =======================================================
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void mdlOutputs(SimStruct *S, int_T tid)
|
||||||
|
{
|
||||||
|
char *sbus = (char *) ssGetOutputPortSignal(S, 0);
|
||||||
|
int32_T *ErrorCode = (int32_T *) ssGetOutputPortRealSignal(S, 1);
|
||||||
|
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
|
||||||
|
const uint8_T *id = (const uint8_T *) mxGetData(PARAM_DEF0(S));
|
||||||
|
|
||||||
|
busInfoStruct* busInfo = (busInfoStruct *) ssGetUserData(S);
|
||||||
|
|
||||||
|
/* Temporary bus copy declarations */
|
||||||
|
SbusInMsg _sbusBUS;
|
||||||
|
|
||||||
|
/* Copy input bus into temporary structure */
|
||||||
|
|
||||||
|
hal_sbus_in_Outputs_wrapper(&_sbusBUS, ErrorCode, id, p_width0);
|
||||||
|
|
||||||
|
/* Copy temporary structure into output bus */
|
||||||
|
(void) memcpy(sbus + busInfo[0].offset, _sbusBUS.channels, busInfo[0].elemSize * busInfo[0].numElems);
|
||||||
|
(void) memcpy(sbus + busInfo[1].offset, &_sbusBUS.a1, busInfo[1].elemSize * busInfo[1].numElems);
|
||||||
|
(void) memcpy(sbus + busInfo[2].offset, &_sbusBUS.seq, busInfo[2].elemSize * busInfo[2].numElems);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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)
|
||||||
|
{
|
||||||
|
/* Free stored bus information */
|
||||||
|
busInfoStruct *busInfo = (busInfoStruct *) ssGetUserData(S);
|
||||||
|
if(busInfo != NULL) {
|
||||||
|
free(busInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int_T GetRTWEnvironmentMode(SimStruct *S)
|
||||||
|
{
|
||||||
|
int_T status = -1;
|
||||||
|
mxArray *plhs[1];
|
||||||
|
mxArray *prhs[1];
|
||||||
|
mxArray * err;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the name of the Simulink block diagram
|
||||||
|
*/
|
||||||
|
prhs[0] = mxCreateString(ssGetModelName(ssGetRootSS(S)));
|
||||||
|
plhs[0] = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Call "isSimulationTarget = rtwenvironmentmode(modelName)" in MATLAB
|
||||||
|
*/
|
||||||
|
err = mexCallMATLABWithTrap(1, plhs, 1, prhs, "rtwenvironmentmode");
|
||||||
|
mxDestroyArray(prhs[0]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the error status if an error occurred
|
||||||
|
*/
|
||||||
|
if (err) {
|
||||||
|
if (plhs[0]) {
|
||||||
|
mxDestroyArray(plhs[0]);
|
||||||
|
plhs[0] = NULL;
|
||||||
|
}
|
||||||
|
ssSetErrorStatus(S, "Unknown error during call to 'rtwenvironmentmode'.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the value returned by rtwenvironmentmode(modelName)
|
||||||
|
*/
|
||||||
|
if (plhs[0]) {
|
||||||
|
status = (int_T) (mxGetScalar(plhs[0]) != 0);
|
||||||
|
mxDestroyArray(plhs[0]);
|
||||||
|
plhs[0] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (status);
|
||||||
|
}
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Binary file not shown.
+142
@@ -0,0 +1,142 @@
|
|||||||
|
%% File : hal_sbus_in.tlc
|
||||||
|
%% Created : Fri Mar 20 11:07:31 2020
|
||||||
|
%%
|
||||||
|
%% Description:
|
||||||
|
%% Simulink Coder wrapper functions interface generated for
|
||||||
|
%% S-function "hal_sbus_in.c".
|
||||||
|
%%
|
||||||
|
%% File generated by S-function Builder Block
|
||||||
|
%%
|
||||||
|
%% For more information on using the Target Language with the
|
||||||
|
%% Simulink Coder, see the Target Language Compiler manual
|
||||||
|
%% (under Simulink Coder) in the "Inlining S-Functions"
|
||||||
|
%% chapter under the section and subsection:
|
||||||
|
%% "Writing Block Target Files to Inline S-Functions",
|
||||||
|
%% "Function-Based or Wrappered Code".
|
||||||
|
%%
|
||||||
|
%implements hal_sbus_in "C"
|
||||||
|
%% Function: BlockTypeSetup ===================================================
|
||||||
|
%%
|
||||||
|
%% Purpose:
|
||||||
|
%% Set up external references for wrapper functions in the
|
||||||
|
%% generated code.
|
||||||
|
%%
|
||||||
|
%function BlockTypeSetup(block, system) Output
|
||||||
|
|
||||||
|
%if IsModelReferenceSimTarget() || CodeFormat == "S-Function" || ::isRAccel
|
||||||
|
%assign hFileName = "hal_sbus_in_accel_wrapper"
|
||||||
|
%assign hFileNameMacro = FEVAL("upper", hFileName)
|
||||||
|
%openfile hFile = "%<hFileName>.h"
|
||||||
|
%selectfile hFile
|
||||||
|
#ifndef _%<hFileNameMacro>_H_
|
||||||
|
#define _%<hFileNameMacro>_H_
|
||||||
|
|
||||||
|
#include "tmwtypes.h"
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
extern void hal_sbus_in_Start_wrapper_accel(const uint8_T *id, const int_T p_width0);
|
||||||
|
extern void hal_sbus_in_Outputs_wrapper_accel(void *sbus, void *__sbusBUS,
|
||||||
|
int32_T *ErrorCode,
|
||||||
|
const uint8_T *id, const int_T p_width0);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
%closefile hFile
|
||||||
|
|
||||||
|
%assign cFileName = "hal_sbus_in_accel_wrapper"
|
||||||
|
%openfile cFile = "%<cFileName>.c"
|
||||||
|
%selectfile cFile
|
||||||
|
#include <string.h>
|
||||||
|
#include "tmwtypes.h"
|
||||||
|
#include "hal_sbus_in_bus.h"
|
||||||
|
|
||||||
|
void hal_sbus_in_Start_wrapper_accel(const uint8_T *id, const int_T p_width0){
|
||||||
|
hal_sbus_in_Start_wrapper(id, p_width0);
|
||||||
|
}
|
||||||
|
void hal_sbus_in_Outputs_wrapper_accel(void *sbus, void *__sbusBUS,
|
||||||
|
int32_T *ErrorCode,
|
||||||
|
const uint8_T *id, const int_T p_width0){
|
||||||
|
hal_sbus_in_Outputs_wrapper((SbusInMsg *) __sbusBUS,
|
||||||
|
ErrorCode,
|
||||||
|
id, p_width0);
|
||||||
|
|
||||||
|
%assign dTypeId = LibBlockOutputSignalDataTypeId(0)
|
||||||
|
%<SLibAssignUserStructToSLStruct(dTypeId, "(char *) sbus", "(*(SbusInMsg *) __sbusBUS)", 0)>
|
||||||
|
}
|
||||||
|
|
||||||
|
%closefile cFile
|
||||||
|
|
||||||
|
%<LibAddToCommonIncludes("%<hFileName>.h")>
|
||||||
|
%<LibAddToModelSources("%<cFileName>")>
|
||||||
|
|
||||||
|
%else
|
||||||
|
%openfile externs
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern void hal_sbus_in_Start_wrapper(const uint8_T *id, const int_T p_width0);
|
||||||
|
|
||||||
|
extern void hal_sbus_in_Outputs_wrapper(SbusInMsg *sbus,
|
||||||
|
int32_T *ErrorCode,
|
||||||
|
const uint8_T *id, const int_T p_width0);
|
||||||
|
|
||||||
|
extern void hal_sbus_in_Terminate_wrapper(const uint8_T *id, const int_T p_width0);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
%closefile externs
|
||||||
|
%<LibCacheExtern(externs)>
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%%
|
||||||
|
%endfunction
|
||||||
|
|
||||||
|
|
||||||
|
%% Function: Start ============================================================
|
||||||
|
%%
|
||||||
|
%function Start(block, system) Output
|
||||||
|
/* %<Type> Block: %<Name> */
|
||||||
|
%assign nelements1 = LibBlockParameterSize(P1)
|
||||||
|
%assign param_width1 = nelements1[0] * nelements1[1]
|
||||||
|
%if (param_width1) > 1
|
||||||
|
%assign pp1 = LibBlockMatrixParameterBaseAddr(P1)
|
||||||
|
%else
|
||||||
|
%assign pp1 = LibBlockParameterAddr(P1, "", "", 0)
|
||||||
|
%endif
|
||||||
|
hal_sbus_in_Start_wrapper(%<pp1>, %<param_width1>);
|
||||||
|
%endfunction
|
||||||
|
%% Function: Outputs ==========================================================
|
||||||
|
%%
|
||||||
|
%% Purpose:
|
||||||
|
%% Code generation rules for mdlOutputs function.
|
||||||
|
%%
|
||||||
|
%function Outputs(block, system) Output
|
||||||
|
%%
|
||||||
|
%assign py0 = LibBlockOutputSignalAddr(0, "", "", 0)
|
||||||
|
%assign py1 = LibBlockOutputSignalAddr(1, "", "", 0)
|
||||||
|
%assign nelements1 = LibBlockParameterSize(P1)
|
||||||
|
%assign param_width1 = nelements1[0] * nelements1[1]
|
||||||
|
%if (param_width1) > 1
|
||||||
|
%assign pp1 = LibBlockMatrixParameterBaseAddr(P1)
|
||||||
|
%else
|
||||||
|
%assign pp1 = LibBlockParameterAddr(P1, "", "", 0)
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%if IsModelReferenceSimTarget() || CodeFormat == "S-Function" || ::isRAccel
|
||||||
|
%assign sbusBUS_ptr = LibBlockDWorkAddr(sbusBUS, "", "", 0)
|
||||||
|
hal_sbus_in_Outputs_wrapper_accel(%<py0>, %<sbusBUS_ptr>, %<py1>, %<pp1>, %<param_width1>);
|
||||||
|
%else
|
||||||
|
hal_sbus_in_Outputs_wrapper(%<py0>, %<py1>, %<pp1>, %<param_width1>);
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%%
|
||||||
|
%endfunction
|
||||||
|
|
||||||
|
|
||||||
|
%% [EOF] hal_sbus_in.tlc
|
||||||
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/* Generated by S-function Builder */
|
||||||
|
#ifndef _HAL_SBUS_IN_BUS_H_
|
||||||
|
#define _HAL_SBUS_IN_BUS_H_
|
||||||
|
/* Read only - STARTS */
|
||||||
|
#ifdef MATLAB_MEX_FILE
|
||||||
|
#include "tmwtypes.h"
|
||||||
|
#else
|
||||||
|
#include "rtwtypes.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _DEFINED_TYPEDEF_FOR_SbusInMsg_
|
||||||
|
#define _DEFINED_TYPEDEF_FOR_SbusInMsg_
|
||||||
|
typedef struct {
|
||||||
|
uint16_T channels[18];
|
||||||
|
real_T a1;
|
||||||
|
uint8_T seq;
|
||||||
|
} SbusInMsg;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Read only - ENDS */
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* Include Files
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#if defined(MATLAB_MEX_FILE)
|
||||||
|
#include "tmwtypes.h"
|
||||||
|
#include "simstruc_types.h"
|
||||||
|
#else
|
||||||
|
#include "rtwtypes.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "hal_sbus_in_bus.h"
|
||||||
|
|
||||||
|
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
|
||||||
|
#ifdef HAL_IMPL
|
||||||
|
//#include "param_mgr.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#endif
|
||||||
|
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
|
||||||
|
#define y_width 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create external references here.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
|
||||||
|
#ifdef HAL_IMPL
|
||||||
|
|
||||||
|
int is_sbus0_in_init = 0;
|
||||||
|
|
||||||
|
void sbus_input_init(uint8_t id)
|
||||||
|
{
|
||||||
|
if (id == 0u && !is_sbus0_in_init)
|
||||||
|
{
|
||||||
|
//TODO config channels, update rate, etc. and bind properties
|
||||||
|
is_sbus0_in_init = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start function
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void hal_sbus_in_Start_wrapper(const uint8_T *id, const int_T p_width0)
|
||||||
|
{
|
||||||
|
/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */
|
||||||
|
#ifdef HAL_IMPL
|
||||||
|
sbus_input_init(id[0]);
|
||||||
|
#endif
|
||||||
|
/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Output function
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void hal_sbus_in_Outputs_wrapper(SbusInMsg *sbus,
|
||||||
|
int32_T *ErrorCode,
|
||||||
|
const uint8_T *id, const int_T p_width0)
|
||||||
|
{
|
||||||
|
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
|
||||||
|
#ifdef HAL_IMPL
|
||||||
|
/*
|
||||||
|
* input *AI* from ADC channels from *start_idx* to *start_idx*+y_width-1.
|
||||||
|
*
|
||||||
|
* ErrorCode - return zero on success, otherwise nonzero on failures.
|
||||||
|
*/
|
||||||
|
if (id[0] == 0u && is_sbus0_in_init)
|
||||||
|
{
|
||||||
|
// TODO set sbus outputs
|
||||||
|
ErrorCode[0] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ErrorCode[0] = -1;
|
||||||
|
#else
|
||||||
|
ErrorCode[0] = 0;
|
||||||
|
#endif
|
||||||
|
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user