编写hal_api.h接口与相应bus定义

This commit is contained in:
Matthew GONG
2020-03-24 12:08:03 +08:00
parent 5b6cb9cbd8
commit 6f0d95bd4b
19 changed files with 455 additions and 112 deletions
+21
View File
@@ -0,0 +1,21 @@
clear all;
hal_api_busdef;
moveBase2DD('hal_api.sldd');
function moveBase2DD(dictionaryName)
% moveBase2DD move all data in base to sldd file
openDDs = Simulink.data.dictionary.getOpenDictionaryPaths(dictionaryName);
if ~isempty(openDDs)
Simulink.data.dictionary.closeAll(dictionaryName,'-discard');
end
if isfile(dictionaryName)
delete(dictionaryName);
end
dictionaryObj = Simulink.data.dictionary.create(dictionaryName);
importFromBaseWorkspace(dictionaryObj);
saveChanges(dictionaryObj);
close(dictionaryObj);
evalin('base', 'clear all;');
end
+233
View File
@@ -0,0 +1,233 @@
#ifndef _HAL_H_
#define _HAL_H_
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdint.h>
/**
* \struct _HAL_gyro_SI_t
* \brief Gyroscope data with SI unit (rad/s)
*
* seq - sample count
* v - latest gyro data
* vi - integrate gyro from last call for EKF(rad)
* dti - intergrate time from last call
* temperature - For Temperature Compensation
*/
typedef struct _HAL_gyro_SI_t
{
uint32_t seq;
union {
float v[3];
struct
{
float x;
float y;
float z;
};
};
union {
float vi[3];
struct
{
float xi;
float yi;
float zi;
};
};
float dti;
float temperature; ///< Unit is Celsius
} HAL_gyro_SI_t;
/**
* \struct _HAL_acc_SI_t
* \brief Accelerometer data with SI unit (m/s2)
*
* seq - sample count
* v - latest Accelerometer data
* vi - integrated speed from last call for EKF(m/s)
* dti - intergrate time from last call
* temperature - For Temperature Compensation
*/
typedef struct _HAL_acc_SI_t
{
uint32_t seq;
union {
float a[3];
struct
{
float x;
float y;
float z;
};
};
union {
float v[3];
struct
{
float xi;
float yi;
float zi;
};
};
float dti;
float temperature; ///< Unit is Celsius
} HAL_acc_SI_t;
/**
* \struct _HAL_magn_mg_t
* \brief Magnetic data with mG unit
*
* seq - sample count
* v - latest Magnetic data
*/
typedef struct _HAL_magn_mG_t
{
uint32_t seq;
union {
float v[3];
struct
{
float x;
float y;
float z;
};
};
} HAL_magn_mG_t;
/**
* \struct _HAL_pressurePS_SI_t
* \brief Pressure data of pressure sensor with SI unit
* seq - sample count
* pressure - latest Magnetic data
* temperature - For Temperature Compensation
*/
typedef struct _HAL_pressure_SI_t
{
uint32_t seq;
float pressure; ///< Unit is Pascal
float temperature; ///< Unit is Celsius
} HAL_pressure_SI_t;
typedef struct _HAL_sbus_in_t
{
uint16_t channels[18];
uint8_t seq;
uint8_t valid;
} HAL_sbus_in_t;
typedef struct _HAL_led_color_t
{
union {
uint8_t rgb[3];
struct
{
uint8_t r;
uint8_t g;
uint8_t b;
};
};
} HAL_led_color_t;
/**
* \struct _HAL_GPS_SI_t
* \brief GPS receiver with SI unit
*
* fixtype:
* 0 - No GPS connected
* 1 - No position information, GPS is connected
* 2 - 2D position
* 3 - 3D position
* 4 - DGPS/SBAS aided 3D position
* 5 - RTK float, 3D position
* 6 - RTK Fixed, 3D position
* 7 - Static fixed, typically used for base stations
* 8 - PPP, 3D position.
*
* att_fixtype:
* 0 - attitude invalid
* 1 - pitch/heading valid
*/
typedef struct _HAL_GPS_SI_t
{
double latitude; ///< Unit is degree
double longitude; ///< Unit is degree
float altitude; ///< aititude from MSL, Unit is meter
union {
float vNED[3]; ///< Unit is meter per second, in NED axes
struct
{
float vel_north;
float vel_east;
float vel_down;
};
};
float heading; ///< Unit is radian, valid when fixtype_att>1
float pitch; ///< Unit is radian, valid when fixtype_att>1
float h_acc; ///< Unit is meter, Position uncertainty
float v_acc; ///< Unit is meter, Altitude uncertainty
float vel_acc; ///< Unit is m/s, velocity uncertainty
float att_acc; ///< Unit is radian, attitude uncertainty when fixtype_att>1
uint32_t TOW; ///< Unit is millisecond, Time of Week
uint32_t seq; ///< update count
uint32_t seq_att; ///< attitude update count
uint16_t HDOP; ///< GPS HDOP horizontal dilution of position
uint16_t VDOP; ///< GPS VDOP vertical dilution of position
uint16_t WN; ///< Week Number of GPS
uint8_t fixtype; ///< GPS fixtype
uint8_t fixtype_att;
uint8_t satnum;
} HAL_GPS_SI_t;
/**
* \struct _HAL_INS_SI_t
* \brief INS device output with SI unit
*/
typedef struct _HAL_INS_SI_t
{
double latitude; ///< Unit is degree
double longitude; ///< Unit is degree
float altitude; ///< aititude from MSL, Unit is meter
union {
float vNED[3]; ///< Unit is meter per second, in NED axes
struct
{
float vel_north;
float vel_east;
float vel_down;
};
};
union {
float attitude[3]; ///<Unit is radian
struct
{
float roll; ///< Unit is radian
float pitch; ///< Unit is radian
float yaw; ///< Unit is radian
};
};
uint32_t seq; ///< update count
uint8_t status; ///< working status
///< bit0 - attitude valid
///< bit1 - speed valid
///< bit2 - position valid
///< bit7 - calibration
uint8_t integration_status; ///< integration method
///< 0 - pure Inertial mode
///< bit0(1) - GPS assist
///< bit1(2) - baro assist
///< bit2(4) - radar assist
uint8_t BIT; ///< health status 0-health; otherwise-unhealth.
} HAL_INS_SI_t;
#ifdef __cplusplus
}
#endif
#endif // _HAL_H_
BIN
View File
Binary file not shown.
+151
View File
@@ -0,0 +1,151 @@
function cellInfo = hal_api_busdef(varargin)
% HAL_API_BUSDEF2 returns a cell array containing bus object information
%
% Optional Input: 'false' will suppress a call to Simulink.Bus.cellToObject
% when the MATLAB file is executed.
% The order of bus element attributes is as follows:
% ElementName, Dimensions, DataType, SampleTime, Complexity, SamplingMode, DimensionsMode, Min, Max, DocUnits, Description
suppressObject = false;
if nargin == 1 && islogical(varargin{1}) && varargin{1} == false
suppressObject = true;
elseif nargin > 1
error('Invalid input argument(s) encountered');
end
cellInfo = { ...
{ ...
'HAL_GPS_SI_t', ...
'hal_api.h', ...
'', ...
'Imported', ...
'-1', {...
{'latitude', 1, 'double', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('deg'), sprintf('')}; ...
{'longitude', 1, 'double', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('deg'), sprintf('')}; ...
{'altitude', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m'), sprintf('MSL海拔高度')}; ...
{'vel_north', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s'), sprintf('')}; ...
{'vel_east', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s'), sprintf('')}; ...
{'vel_down', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s'), sprintf('')}; ...
{'heading', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('rad'), sprintf('线')}; ...
{'pitch', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('rad'), sprintf('线')}; ...
{'h_acc', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m'), sprintf('')}; ...
{'v_acc', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m'), sprintf('')}; ...
{'vel_acc', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s'), sprintf('GPS定速精度')}; ...
{'att_acc', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s'), sprintf('GPS双天线定向精度')}; ...
{'TOW', 1, 'uint32', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('ms'), sprintf('GPS周内秒')}; ...
{'seq', 1, 'uint32', -1, 'real', 'Sample', 'Fixed', [], [], '', sprintf('')}; ...
{'seq_att', 1, 'uint32', -1, 'real', 'Sample', 'Fixed', [], [], '', sprintf('线')}; ...
{'HDOP', 1, 'uint16', -1, 'real', 'Sample', 'Fixed', [], [], '', sprintf('GPS HDOP horizontal dilution of position')}; ...
{'VDOP', 1, 'uint16', -1, 'real', 'Sample', 'Fixed', [], [], '', sprintf('GPS VDOP vertical dilution of position')}; ...
{'WN', 1, 'uint16', -1, 'real', 'Sample', 'Fixed', [], [], '', sprintf('GPS周计数')}; ...
{'fixtype', 1, 'uint8', -1, 'real', 'Sample', 'Fixed', [], [], '', sprintf('GPS定位模式fixtype:\n 0 - No GPS connected\n 1 - No position information, GPS is connected\n 2 - 2D position\n 3 - 3D position\n 4 - DGPS/SBAS aided 3D position\n 5 - RTK float, 3D position\n 6 - RTK Fixed, 3D position\n 7 - Static fixed, typically used for base stations\n 8 - PPP, 3D position.')}; ...
{'fixtype_att', 1, 'uint8', -1, 'real', 'Sample', 'Fixed', [], [], '', sprintf('GPS定向模式att_fixtype:\n 0 - attitude invalid\n 1 - pitch/heading valid')}; ...
{'satnum', 1, 'uint8', -1, 'real', 'Sample', 'Fixed', [], [], '', sprintf('')}; ...
} ...
} ...
{ ...
'HAL_INS_SI_t', ...
'hal_api.h', ...
sprintf(''), ...
'Imported', ...
'-1', {...
{'latitude', 1, 'double', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('deg'), sprintf('')}; ...
{'longitude', 1, 'double', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('deg'), sprintf('')}; ...
{'altitude', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m'), sprintf('MSL海拔高度')}; ...
{'vel_north', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s'), sprintf('')}; ...
{'vel_east', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s'), sprintf('')}; ...
{'vel_down', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s'), sprintf('')}; ...
{'roll', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('rad'), sprintf('')}; ...
{'pitch', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('rad'), sprintf('')}; ...
{'yaw', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('rad'), sprintf('')}; ...
{'seq', 1, 'uint32', -1, 'real', 'Sample', 'Fixed', [], [], '', sprintf('')}; ...
{'status', 1, 'uint8', -1, 'real', 'Sample', 'Fixed', [], [], '', sprintf('\nbit0 - 姿\nbit1 - \nbit2 - \nbit7 - ')}; ...
{'integration_status', 1, 'uint8', -1, 'real', 'Sample', 'Fixed', [], [], '', sprintf('\nbit0 - GPS输入可用\nbit1 - \nbit2 - ')}; ...
{'BIT', 1, 'uint8', -1, 'real', 'Sample', 'Fixed', [], [], '', sprintf('\n0-\n其他-')}; ...
} ...
} ...
{ ...
'HAL_acc_SI_t', ...
'hal_api.h', ...
sprintf(''), ...
'Imported', ...
'-1', {...
{'seq', 1, 'uint32', -1, 'real', 'Sample', 'Fixed', [], [], '', ''}; ...
{'x', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s/s'), sprintf('x/y/z是当前的IMU的三轴加速度输出')}; ...
{'y', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s/s'), ''}; ...
{'z', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s/s'), ''}; ...
{'xi', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s'), sprintf('xi/yi/zi是从上次到本次IMU的加速度积分输出EKF输入')}; ...
{'yi', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s'), ''}; ...
{'zi', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('m/s'), ''}; ...
{'dti', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('s'), ''}; ...
{'temperature', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('degC'), sprintf('')}; ...
} ...
} ...
{ ...
'HAL_gyro_SI_t', ...
'hal_api.h', ...
sprintf(''), ...
'Imported', ...
'-1', {...
{'seq', 1, 'uint32', -1, 'real', 'Sample', 'Fixed', [], [], '', ''}; ...
{'x', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('rad/s'), sprintf('x/y/z是当前的IMU的三轴角速度输出')}; ...
{'y', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('rad/s'), ''}; ...
{'z', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('rad/s'), ''}; ...
{'xi', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('rad'), sprintf('xi/yi/zi是从上次到本次IMU的角速度积分输出EKF输入')}; ...
{'yi', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('rad'), ''}; ...
{'zi', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('rad'), ''}; ...
{'dti', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('s'), ''}; ...
{'temperature', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('degC'), sprintf('')}; ...
} ...
} ...
{ ...
'HAL_led_color_t', ...
'hal_api.h', ...
sprintf('LED信号灯'), ...
'Imported', ...
'-1', {...
{'r', 1, 'uint8', -1, 'real', 'Sample', 'Fixed', [], [], '', ''}; ...
{'g', 1, 'uint8', -1, 'real', 'Sample', 'Fixed', [], [], '', ''}; ...
{'b', 1, 'uint8', -1, 'real', 'Sample', 'Fixed', [], [], '', ''}; ...
} ...
} ...
{ ...
'HAL_magn_mG_t', ...
'hal_api.h', ...
sprintf(''), ...
'Imported', ...
'-1', {...
{'seq', 1, 'uint32', -1, 'real', 'Sample', 'Fixed', [], [], '', ''}; ...
{'x', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('mG'), sprintf('x/y/z是当前磁力计的三轴输出')}; ...
{'y', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('mG'), ''}; ...
{'z', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('mG'), ''}; ...
} ...
} ...
{ ...
'HAL_pressure_SI_t', ...
'hal_api.h', ...
sprintf(''), ...
'Imported', ...
'-1', {...
{'seq', 1, 'uint32', -1, 'real', 'Sample', 'Fixed', [], [], '', ''}; ...
{'pressure', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('Pa'), ''}; ...
{'temperature', 1, 'single', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('degC'), sprintf('')}; ...
} ...
} ...
{ ...
'HAL_sbus_in_t', ...
'hal_api.h', ...
sprintf('sbus接收机输入信号'), ...
'Imported', ...
'-1', {...
{'channels', 18, 'uint16', -1, 'real', 'Sample', 'Fixed', [], [], sprintf('us'), ''}; ...
{'seq', 1, 'uint8', -1, 'real', 'Sample', 'Fixed', [], [], '', ''}; ...
{'valid', 1, 'boolean', -1, 'real', 'Sample', 'Fixed', [], [], '', ''}; ...
} ...
} ...
}';
if ~suppressObject
% Create bus objects in the MATLAB base workspace
Simulink.Bus.cellToObject(cellInfo)
end
Binary file not shown.
Binary file not shown.
+16 -16
View File
@@ -26,7 +26,7 @@
* | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template | * | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template |
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
* *
* Created: Mon Mar 23 12:38:55 2020 * Created: Tue Mar 24 11:49:54 2020
*/ */
#define S_FUNCTION_LEVEL 2 #define S_FUNCTION_LEVEL 2
@@ -42,7 +42,7 @@
#define INPUT_0_COMPLEX COMPLEX_NO #define INPUT_0_COMPLEX COMPLEX_NO
#define IN_0_FRAME_BASED FRAME_NO #define IN_0_FRAME_BASED FRAME_NO
#define IN_0_BUS_BASED 1 #define IN_0_BUS_BASED 1
#define IN_0_BUS_NAME LedColorMsg #define IN_0_BUS_NAME HAL_led_color_t
#define IN_0_DIMS 1-D #define IN_0_DIMS 1-D
#define INPUT_0_FEEDTHROUGH 1 #define INPUT_0_FEEDTHROUGH 1
#define IN_0_ISSIGNED 0 #define IN_0_ISSIGNED 0
@@ -57,7 +57,7 @@
#define OUT_PORT_0_NAME ErrorCode #define OUT_PORT_0_NAME ErrorCode
#define OUTPUT_0_WIDTH 1 #define OUTPUT_0_WIDTH 1
#define OUTPUT_DIMS_0_COL 1 #define OUTPUT_DIMS_0_COL 1
#define OUTPUT_0_DTYPE real_T #define OUTPUT_0_DTYPE int32_T
#define OUTPUT_0_COMPLEX COMPLEX_NO #define OUTPUT_0_COMPLEX COMPLEX_NO
#define OUT_0_FRAME_BASED FRAME_NO #define OUT_0_FRAME_BASED FRAME_NO
#define OUT_0_BUS_BASED 0 #define OUT_0_BUS_BASED 0
@@ -93,7 +93,7 @@
/* %%%-SFUNWIZ_defines_Changes_END --- EDIT HERE TO _BEGIN */ /* %%%-SFUNWIZ_defines_Changes_END --- EDIT HERE TO _BEGIN */
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#include "simstruc.h" #include "simstruc.h"
#include "hal_led_set_bus.h" #include "hal_api.h"
/* /*
* Code Generation Environment flag (simulation or standalone target). * Code Generation Environment flag (simulation or standalone target).
*/ */
@@ -114,8 +114,8 @@ typedef struct {
!mxIsEmpty(pVal) && !mxIsSparse(pVal) && !mxIsComplex(pVal) && mxIsUint8(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_Start_wrapper(const uint8_T *id, const int_T p_width0);
extern void hal_led_set_Outputs_wrapper(const LedColorMsg *color, extern void hal_led_set_Outputs_wrapper(const HAL_led_color_t *color,
real_T *ErrorCode, int32_T *ErrorCode,
const uint8_T *id, const int_T p_width0); const uint8_T *id, const int_T p_width0);
/*====================* /*====================*
* S-function methods * * S-function methods *
@@ -185,13 +185,13 @@ static void mdlInitializeSizes(SimStruct *S)
if (!ssSetNumInputPorts(S, NUM_INPUTS)) return; if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;
/* Register LedColorMsg datatype for Input port 0 */ /* Register HAL_led_color_t datatype for Input port 0 */
#if defined(MATLAB_MEX_FILE) #if defined(MATLAB_MEX_FILE)
if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY)
{ {
DTypeId dataTypeIdReg; DTypeId dataTypeIdReg;
ssRegisterTypeFromNamedObject(S, "LedColorMsg", &dataTypeIdReg); ssRegisterTypeFromNamedObject(S, "HAL_led_color_t", &dataTypeIdReg);
if(dataTypeIdReg == INVALID_DTYPE_ID) return; if(dataTypeIdReg == INVALID_DTYPE_ID) return;
ssSetInputPortDataType(S, 0, dataTypeIdReg); ssSetInputPortDataType(S, 0, dataTypeIdReg);
} }
@@ -205,7 +205,7 @@ static void mdlInitializeSizes(SimStruct *S)
if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return; if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH); ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH);
ssSetOutputPortDataType(S, 0, SS_DOUBLE); ssSetOutputPortDataType(S, 0, SS_INT32);
ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX); ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
if (ssRTWGenIsCodeGen(S)) { if (ssRTWGenIsCodeGen(S)) {
@@ -232,7 +232,7 @@ static void mdlInitializeSizes(SimStruct *S)
#if defined(MATLAB_MEX_FILE) #if defined(MATLAB_MEX_FILE)
if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) { if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) {
DTypeId dataTypeIdReg; DTypeId dataTypeIdReg;
ssRegisterTypeFromNamedObject(S, "LedColorMsg", &dataTypeIdReg); ssRegisterTypeFromNamedObject(S, "HAL_led_color_t", &dataTypeIdReg);
if (dataTypeIdReg == INVALID_DTYPE_ID) return; if (dataTypeIdReg == INVALID_DTYPE_ID) return;
ssSetDWorkDataType(S, 0, dataTypeIdReg); ssSetDWorkDataType(S, 0, dataTypeIdReg);
} }
@@ -325,7 +325,7 @@ static void mdlStart(SimStruct *S)
/* Bus Information */ /* Bus Information */
slDataTypeAccess *dta = ssGetDataTypeAccess(S); slDataTypeAccess *dta = ssGetDataTypeAccess(S);
const char *bpath = ssGetPath(S); const char *bpath = ssGetPath(S);
DTypeId LedColorMsgId = ssGetDataTypeId(S, "LedColorMsg"); DTypeId HAL_led_color_tId = ssGetDataTypeId(S, "HAL_led_color_t");
busInfoStruct *busInfo = (busInfoStruct *)malloc(6*sizeof(busInfoStruct)); busInfoStruct *busInfo = (busInfoStruct *)malloc(6*sizeof(busInfoStruct));
if(busInfo==NULL) { if(busInfo==NULL) {
@@ -335,13 +335,13 @@ static void mdlStart(SimStruct *S)
/* Calculate offsets of all primitive elements of the bus */ /* Calculate offsets of all primitive elements of the bus */
busInfo[0].offset = dtaGetDataTypeElementOffset(dta, bpath, LedColorMsgId, 0); busInfo[0].offset = dtaGetDataTypeElementOffset(dta, bpath, HAL_led_color_tId, 0);
busInfo[0].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint8")); busInfo[0].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint8"));
busInfo[0].numElems = 1; busInfo[0].numElems = 1;
busInfo[1].offset = dtaGetDataTypeElementOffset(dta, bpath, LedColorMsgId, 1); busInfo[1].offset = dtaGetDataTypeElementOffset(dta, bpath, HAL_led_color_tId, 1);
busInfo[1].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint8")); busInfo[1].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint8"));
busInfo[1].numElems = 1; busInfo[1].numElems = 1;
busInfo[2].offset = dtaGetDataTypeElementOffset(dta, bpath, LedColorMsgId, 2); busInfo[2].offset = dtaGetDataTypeElementOffset(dta, bpath, HAL_led_color_tId, 2);
busInfo[2].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint8")); busInfo[2].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint8"));
busInfo[2].numElems = 1; busInfo[2].numElems = 1;
ssSetUserData(S, busInfo); ssSetUserData(S, busInfo);
@@ -358,14 +358,14 @@ static void mdlStart(SimStruct *S)
static void mdlOutputs(SimStruct *S, int_T tid) static void mdlOutputs(SimStruct *S, int_T tid)
{ {
const char *color = (char *) ssGetInputPortSignal(S, 0); const char *color = (char *) ssGetInputPortSignal(S, 0);
real_T *ErrorCode = (real_T *) ssGetOutputPortRealSignal(S, 0); int32_T *ErrorCode = (int32_T *) ssGetOutputPortRealSignal(S, 0);
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S)); const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
const uint8_T *id = (const uint8_T *) mxGetData(PARAM_DEF0(S)); const uint8_T *id = (const uint8_T *) mxGetData(PARAM_DEF0(S));
busInfoStruct* busInfo = (busInfoStruct *) ssGetUserData(S); busInfoStruct* busInfo = (busInfoStruct *) ssGetUserData(S);
/* Temporary bus copy declarations */ /* Temporary bus copy declarations */
LedColorMsg _colorBUS; HAL_led_color_t _colorBUS;
/* Copy input bus into temporary structure */ /* Copy input bus into temporary structure */
(void) memcpy(&_colorBUS.r, color + busInfo[0].offset, busInfo[0].elemSize * busInfo[0].numElems); (void) memcpy(&_colorBUS.r, color + busInfo[0].offset, busInfo[0].elemSize * busInfo[0].numElems);
Binary file not shown.
+8 -8
View File
@@ -1,5 +1,5 @@
%% File : hal_led_set.tlc %% File : hal_led_set.tlc
%% Created : Mon Mar 23 12:38:55 2020 %% Created : Tue Mar 24 11:49:54 2020
%% %%
%% Description: %% Description:
%% Simulink Coder wrapper functions interface generated for %% Simulink Coder wrapper functions interface generated for
@@ -37,7 +37,7 @@
#endif #endif
extern void hal_led_set_Start_wrapper_accel(const uint8_T *id, const int_T p_width0); 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, extern void hal_led_set_Outputs_wrapper_accel(const void *color, void *__colorBUS,
real_T *ErrorCode, int32_T *ErrorCode,
const uint8_T *id, const int_T p_width0); const uint8_T *id, const int_T p_width0);
#ifdef __cplusplus #ifdef __cplusplus
} }
@@ -50,18 +50,18 @@
%selectfile cFile %selectfile cFile
#include <string.h> #include <string.h>
#include "tmwtypes.h" #include "tmwtypes.h"
#include "hal_led_set_bus.h" #include "hal_api.h"
void hal_led_set_Start_wrapper_accel(const uint8_T *id, const int_T p_width0){ void hal_led_set_Start_wrapper_accel(const uint8_T *id, const int_T p_width0){
hal_led_set_Start_wrapper(id, p_width0); hal_led_set_Start_wrapper(id, p_width0);
} }
void hal_led_set_Outputs_wrapper_accel(const void *color, void *__colorBUS, void hal_led_set_Outputs_wrapper_accel(const void *color, void *__colorBUS,
real_T *ErrorCode, int32_T *ErrorCode,
const uint8_T *id, const int_T p_width0){ const uint8_T *id, const int_T p_width0){
%assign dTypeId = LibBlockInputSignalDataTypeId(0) %assign dTypeId = LibBlockInputSignalDataTypeId(0)
%<SLibAssignSLStructToUserStruct(dTypeId, "(*(LedColorMsg *) __colorBUS)", "(char *) color", 0)> %<SLibAssignSLStructToUserStruct(dTypeId, "(*(HAL_led_color_t *) __colorBUS)", "(char *) color", 0)>
hal_led_set_Outputs_wrapper((LedColorMsg *) __colorBUS, hal_led_set_Outputs_wrapper((HAL_led_color_t *) __colorBUS,
ErrorCode, ErrorCode,
id, p_width0); id, p_width0);
} }
@@ -80,8 +80,8 @@
extern void hal_led_set_Start_wrapper(const uint8_T *id, const int_T p_width0); 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, extern void hal_led_set_Outputs_wrapper(const HAL_led_color_t *color,
real_T *ErrorCode, int32_T *ErrorCode,
const uint8_T *id, const int_T p_width0); 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); extern void hal_led_set_Terminate_wrapper(const uint8_T *id, const int_T p_width0);
-26
View File
@@ -1,26 +0,0 @@
/* 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
+13 -13
View File
@@ -26,7 +26,7 @@
* | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template | * | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template |
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
* *
* Created: Mon Mar 23 12:38:40 2020 * Created: Tue Mar 24 11:50:58 2020
*/ */
#define S_FUNCTION_LEVEL 2 #define S_FUNCTION_LEVEL 2
@@ -44,7 +44,7 @@
#define OUTPUT_0_COMPLEX COMPLEX_NO #define OUTPUT_0_COMPLEX COMPLEX_NO
#define OUT_0_FRAME_BASED FRAME_NO #define OUT_0_FRAME_BASED FRAME_NO
#define OUT_0_BUS_BASED 1 #define OUT_0_BUS_BASED 1
#define OUT_0_BUS_NAME SbusInMsg #define OUT_0_BUS_NAME HAL_sbus_in_t
#define OUT_0_DIMS 1-D #define OUT_0_DIMS 1-D
#define OUT_0_ISSIGNED 1 #define OUT_0_ISSIGNED 1
#define OUT_0_WORDLENGTH 8 #define OUT_0_WORDLENGTH 8
@@ -92,7 +92,7 @@
/* %%%-SFUNWIZ_defines_Changes_END --- EDIT HERE TO _BEGIN */ /* %%%-SFUNWIZ_defines_Changes_END --- EDIT HERE TO _BEGIN */
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#include "simstruc.h" #include "simstruc.h"
#include "hal_sbus_in_bus.h" #include "hal_api.h"
/* /*
* Code Generation Environment flag (simulation or standalone target). * Code Generation Environment flag (simulation or standalone target).
*/ */
@@ -113,7 +113,7 @@ typedef struct {
!mxIsEmpty(pVal) && !mxIsSparse(pVal) && !mxIsComplex(pVal) && mxIsUint8(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_Start_wrapper(const uint8_T *id, const int_T p_width0);
extern void hal_sbus_in_Outputs_wrapper(SbusInMsg *sbus, extern void hal_sbus_in_Outputs_wrapper(HAL_sbus_in_t *sbus,
int32_T *ErrorCode, int32_T *ErrorCode,
const uint8_T *id, const int_T p_width0); const uint8_T *id, const int_T p_width0);
/*====================* /*====================*
@@ -186,19 +186,19 @@ static void mdlInitializeSizes(SimStruct *S)
if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return; if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
/* Output Port 0 */ /* Output Port 0 */
/* Register SbusInMsg datatype for Output port 0 */ /* Register HAL_sbus_in_t datatype for Output port 0 */
#if defined(MATLAB_MEX_FILE) #if defined(MATLAB_MEX_FILE)
if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY)
{ {
DTypeId dataTypeIdReg; DTypeId dataTypeIdReg;
ssRegisterTypeFromNamedObject(S, "SbusInMsg", &dataTypeIdReg); ssRegisterTypeFromNamedObject(S, "HAL_sbus_in_t", &dataTypeIdReg);
if(dataTypeIdReg == INVALID_DTYPE_ID) return; if(dataTypeIdReg == INVALID_DTYPE_ID) return;
ssSetOutputPortDataType(S, 0, dataTypeIdReg); ssSetOutputPortDataType(S, 0, dataTypeIdReg);
} }
#endif #endif
ssSetBusOutputObjectName(S, 0, (void *) "SbusInMsg"); ssSetBusOutputObjectName(S, 0, (void *) "HAL_sbus_in_t");
ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH); ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH);
ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX); ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
ssSetBusOutputAsStruct(S, 0,OUT_0_BUS_BASED); ssSetBusOutputAsStruct(S, 0,OUT_0_BUS_BASED);
@@ -232,7 +232,7 @@ static void mdlInitializeSizes(SimStruct *S)
#if defined(MATLAB_MEX_FILE) #if defined(MATLAB_MEX_FILE)
if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) { if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) {
DTypeId dataTypeIdReg; DTypeId dataTypeIdReg;
ssRegisterTypeFromNamedObject(S, "SbusInMsg", &dataTypeIdReg); ssRegisterTypeFromNamedObject(S, "HAL_sbus_in_t", &dataTypeIdReg);
if (dataTypeIdReg == INVALID_DTYPE_ID) return; if (dataTypeIdReg == INVALID_DTYPE_ID) return;
ssSetDWorkDataType(S, 0, dataTypeIdReg); ssSetDWorkDataType(S, 0, dataTypeIdReg);
} }
@@ -318,7 +318,7 @@ static void mdlStart(SimStruct *S)
/* Bus Information */ /* Bus Information */
slDataTypeAccess *dta = ssGetDataTypeAccess(S); slDataTypeAccess *dta = ssGetDataTypeAccess(S);
const char *bpath = ssGetPath(S); const char *bpath = ssGetPath(S);
DTypeId SbusInMsgId = ssGetDataTypeId(S, "SbusInMsg"); DTypeId HAL_sbus_in_tId = ssGetDataTypeId(S, "HAL_sbus_in_t");
busInfoStruct *busInfo = (busInfoStruct *)malloc(6*sizeof(busInfoStruct)); busInfoStruct *busInfo = (busInfoStruct *)malloc(6*sizeof(busInfoStruct));
if(busInfo==NULL) { if(busInfo==NULL) {
@@ -328,13 +328,13 @@ static void mdlStart(SimStruct *S)
/* Calculate offsets of all primitive elements of the bus */ /* Calculate offsets of all primitive elements of the bus */
busInfo[0].offset = dtaGetDataTypeElementOffset(dta, bpath, SbusInMsgId, 0); busInfo[0].offset = dtaGetDataTypeElementOffset(dta, bpath, HAL_sbus_in_tId, 0);
busInfo[0].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint16")); busInfo[0].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint16"));
busInfo[0].numElems = 18; busInfo[0].numElems = 18;
busInfo[1].offset = dtaGetDataTypeElementOffset(dta, bpath, SbusInMsgId, 1); busInfo[1].offset = dtaGetDataTypeElementOffset(dta, bpath, HAL_sbus_in_tId, 1);
busInfo[1].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint8")); busInfo[1].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "uint8"));
busInfo[1].numElems = 1; busInfo[1].numElems = 1;
busInfo[2].offset = dtaGetDataTypeElementOffset(dta, bpath, SbusInMsgId, 2); busInfo[2].offset = dtaGetDataTypeElementOffset(dta, bpath, HAL_sbus_in_tId, 2);
busInfo[2].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "boolean")); busInfo[2].elemSize = dtaGetDataTypeSize(dta, bpath, ssGetDataTypeId(S, "boolean"));
busInfo[2].numElems = 1; busInfo[2].numElems = 1;
ssSetUserData(S, busInfo); ssSetUserData(S, busInfo);
@@ -358,7 +358,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
busInfoStruct* busInfo = (busInfoStruct *) ssGetUserData(S); busInfoStruct* busInfo = (busInfoStruct *) ssGetUserData(S);
/* Temporary bus copy declarations */ /* Temporary bus copy declarations */
SbusInMsg _sbusBUS; HAL_sbus_in_t _sbusBUS;
/* Copy input bus into temporary structure */ /* Copy input bus into temporary structure */
Binary file not shown.
+5 -5
View File
@@ -1,5 +1,5 @@
%% File : hal_sbus_in.tlc %% File : hal_sbus_in.tlc
%% Created : Mon Mar 23 12:38:40 2020 %% Created : Tue Mar 24 11:50:58 2020
%% %%
%% Description: %% Description:
%% Simulink Coder wrapper functions interface generated for %% Simulink Coder wrapper functions interface generated for
@@ -50,7 +50,7 @@
%selectfile cFile %selectfile cFile
#include <string.h> #include <string.h>
#include "tmwtypes.h" #include "tmwtypes.h"
#include "hal_sbus_in_bus.h" #include "hal_api.h"
void hal_sbus_in_Start_wrapper_accel(const uint8_T *id, const int_T p_width0){ void hal_sbus_in_Start_wrapper_accel(const uint8_T *id, const int_T p_width0){
hal_sbus_in_Start_wrapper(id, p_width0); hal_sbus_in_Start_wrapper(id, p_width0);
@@ -58,12 +58,12 @@
void hal_sbus_in_Outputs_wrapper_accel(void *sbus, void *__sbusBUS, void hal_sbus_in_Outputs_wrapper_accel(void *sbus, void *__sbusBUS,
int32_T *ErrorCode, int32_T *ErrorCode,
const uint8_T *id, const int_T p_width0){ const uint8_T *id, const int_T p_width0){
hal_sbus_in_Outputs_wrapper((SbusInMsg *) __sbusBUS, hal_sbus_in_Outputs_wrapper((HAL_sbus_in_t *) __sbusBUS,
ErrorCode, ErrorCode,
id, p_width0); id, p_width0);
%assign dTypeId = LibBlockOutputSignalDataTypeId(0) %assign dTypeId = LibBlockOutputSignalDataTypeId(0)
%<SLibAssignUserStructToSLStruct(dTypeId, "(char *) sbus", "(*(SbusInMsg *) __sbusBUS)", 0)> %<SLibAssignUserStructToSLStruct(dTypeId, "(char *) sbus", "(*(HAL_sbus_in_t *) __sbusBUS)", 0)>
} }
%closefile cFile %closefile cFile
@@ -80,7 +80,7 @@
extern void hal_sbus_in_Start_wrapper(const uint8_T *id, const int_T p_width0); 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, extern void hal_sbus_in_Outputs_wrapper(HAL_sbus_in_t *sbus,
int32_T *ErrorCode, int32_T *ErrorCode,
const uint8_T *id, const int_T p_width0); const uint8_T *id, const int_T p_width0);
-26
View File
@@ -1,26 +0,0 @@
/* 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];
uint8_T seq;
boolean_T valid;
} SbusInMsg;
#endif
/* Read only - ENDS */
#endif
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+1 -1
Submodule param updated: a884588641...b4fdb74d94
+4 -15
View File
@@ -10,7 +10,8 @@
#include "rtwtypes.h" #include "rtwtypes.h"
#endif #endif
#include "hal_led_set_bus.h" #include "hal_api.h"
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */ /* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#ifdef HAL_IMPL #ifdef HAL_IMPL
@@ -29,8 +30,6 @@
#ifdef HAL_IMPL #ifdef HAL_IMPL
int is_led_g0_init = 0; 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) void led_set_init(uint8_t id)
{ {
@@ -39,16 +38,6 @@ void led_set_init(uint8_t id)
//TODO //TODO
is_led_g0_init = 1; 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 #endif
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ /* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
@@ -69,8 +58,8 @@ led_set_init(id[0]);
* Output function * Output function
* *
*/ */
void hal_led_set_Outputs_wrapper(const LedColorMsg *color, void hal_led_set_Outputs_wrapper(const HAL_led_color_t *color,
real_T *ErrorCode, int32_T *ErrorCode,
const uint8_T *id, const int_T p_width0) const uint8_T *id, const int_T p_width0)
{ {
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ /* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
+3 -2
View File
@@ -10,7 +10,8 @@
#include "rtwtypes.h" #include "rtwtypes.h"
#endif #endif
#include "hal_sbus_in_bus.h" #include "hal_api.h"
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */ /* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#ifdef HAL_IMPL #ifdef HAL_IMPL
@@ -56,7 +57,7 @@ sbus_input_init(id[0]);
* Output function * Output function
* *
*/ */
void hal_sbus_in_Outputs_wrapper(SbusInMsg *sbus, void hal_sbus_in_Outputs_wrapper(HAL_sbus_in_t *sbus,
int32_T *ErrorCode, int32_T *ErrorCode,
const uint8_T *id, const int_T p_width0) const uint8_T *id, const int_T p_width0)
{ {