外部惯导解包校验S_Function添加,固件可以生成

This commit is contained in:
LZY\79495
2025-06-13 15:02:58 +08:00
parent fa1573951e
commit eeb9cb168e
8 changed files with 287 additions and 5 deletions
Binary file not shown.
Binary file not shown.
+1 -5
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: Tue Jun 03 11:04:51 2025 * Created: Fri Jun 13 14:30:40 2025
*/ */
#define S_FUNCTION_LEVEL 2 #define S_FUNCTION_LEVEL 2
@@ -111,12 +111,10 @@
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#include "simstruc.h" #include "simstruc.h"
extern void get_snc_crc32_Start_wrapper(void);
extern void get_snc_crc32_Outputs_wrapper(const uint8_T *ucBuffer, extern void get_snc_crc32_Outputs_wrapper(const uint8_T *ucBuffer,
const uint32_T *u1Count, const uint32_T *u1Count,
uint32_T *u1CRC, uint32_T *u1CRC,
const int_T u_0_width); const int_T u_0_width);
extern void get_snc_crc32_Terminate_wrapper(void);
/*====================* /*====================*
* S-function methods * * S-function methods *
@@ -250,7 +248,6 @@ static void mdlSetDefaultPortDataTypes(SimStruct *S)
*/ */
static void mdlStart(SimStruct *S) static void mdlStart(SimStruct *S)
{ {
get_snc_crc32_Start_wrapper();
} }
#endif /* MDL_START */ #endif /* MDL_START */
@@ -275,7 +272,6 @@ static void mdlOutputs(SimStruct *S, int_T tid)
*/ */
static void mdlTerminate(SimStruct *S) static void mdlTerminate(SimStruct *S)
{ {
get_snc_crc32_Terminate_wrapper();
} }
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */ #ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */
Binary file not shown.
+137
View File
@@ -0,0 +1,137 @@
%% File : get_snc_crc32.tlc
%% Created : Fri Jun 13 14:30:40 2025
%%
%% Description:
%% Simulink Coder wrapper functions interface generated for
%% S-function "get_snc_crc32.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 get_snc_crc32 "C"
%% Function: BlockTypeSetup ===================================================
%%
%% Purpose:
%% Set up external references for wrapper functions in the
%% generated code.
%%
%function BlockTypeSetup(block, system) Output
%assign uint32Type = LibGetDataTypeNameFromId(::CompiledModel.tSS_UINT32)
%assign uint8Type = LibGetDataTypeNameFromId(::CompiledModel.tSS_UINT8)
%assign intType = LibGetDataTypeNameFromId(::CompiledModel.tSS_INTEGER)
%if IsModelReferenceSimTarget() || CodeFormat == "S-Function" || ::isRAccel
%assign hFileName = "get_snc_crc32_accel_wrapper"
%assign hFileNameMacro = FEVAL("upper", hFileName)
%openfile hFile = "%<hFileName>.h"
%selectfile hFile
#ifndef _%<hFileNameMacro>_H_
#define _%<hFileNameMacro>_H_
#ifdef MATLAB_MEX_FILE
#include "tmwtypes.h"
#else
#include "rtwtypes.h"
#endif
#ifdef __cplusplus
#define SFB_EXTERN_C extern "C"
#else
#define SFB_EXTERN_C extern
#endif
SFB_EXTERN_C void get_snc_crc32_Outputs_wrapper_accel(const %<uint8Type> *ucBuffer,
const %<uint32Type> *u1Count,
%<uint32Type> *u1CRC,
const %<intType> u_0_width);
#undef SFB_EXTERN_C
#endif
%closefile hFile
%assign cFileName = "get_snc_crc32_accel_wrapper"
%openfile cFile = "%<cFileName>.c"
%selectfile cFile
#include <string.h>
#ifdef MATLAB_MEX_FILE
#include "tmwtypes.h"
#else
#include "rtwtypes.h"
#endif
#include "%<hFileName>.h"
extern void get_snc_crc32_Start_wrapper(void);
extern void get_snc_crc32_Outputs_wrapper(const %<uint8Type> *ucBuffer,
const %<uint32Type> *u1Count,
%<uint32Type> *u1CRC,
const %<intType> u_0_width);
extern void get_snc_crc32_Terminate_wrapper(void);
void get_snc_crc32_Outputs_wrapper_accel(const %<uint8Type> *ucBuffer,
const %<uint32Type> *u1Count,
%<uint32Type> *u1CRC,
const %<intType> u_0_width){
get_snc_crc32_Outputs_wrapper(ucBuffer,
u1Count,
u1CRC,
u_0_width);
}
%closefile cFile
%<LibAddToCommonIncludes("%<hFileName>.h")>
%else
%openfile externs
#ifdef __cplusplus
#define SFB_EXTERN_C extern "C"
#else
#define SFB_EXTERN_C extern
#endif
SFB_EXTERN_C void get_snc_crc32_Start_wrapper(void);
SFB_EXTERN_C void get_snc_crc32_Outputs_wrapper(const %<uint8Type> *ucBuffer,
const %<uint32Type> *u1Count,
%<uint32Type> *u1CRC,
const %<intType> u_0_width);
SFB_EXTERN_C void get_snc_crc32_Terminate_wrapper(void);
#undef SFB_EXTERN_C
%closefile externs
%<LibCacheExtern(externs)>
%endif
%%
%endfunction
%% Function: Outputs ==========================================================
%%
%% Purpose:
%% Code generation rules for mdlOutputs function.
%%
%function Outputs(block, system) Output
%%
%assign pu0 = LibBlockInputSignalAddr(0, "", "", 0)
%assign pu1 = LibBlockInputSignalAddr(1, "", "", 0)
%assign pu_0_width = LibBlockInputSignalWidth(0)
%assign py0 = LibBlockOutputSignalAddr(0, "", "", 0)
%if IsModelReferenceSimTarget() || CodeFormat == "S-Function" || ::isRAccel
get_snc_crc32_Outputs_wrapper_accel(%<pu0>, %<pu1>, %<py0>, %<pu_0_width>);
%else
get_snc_crc32_Outputs_wrapper(%<pu0>, %<pu1>, %<py0>, %<pu_0_width>);
%endif
%%
%endfunction
%% [EOF] get_snc_crc32.tlc
+83
View File
@@ -0,0 +1,83 @@
/*
* Include Files
*
*/
#if defined(MATLAB_MEX_FILE)
#include "tmwtypes.h"
#include "simstruc_types.h"
#else
#define SIMPLIFIED_RTWTYPES_COMPATIBILITY
#include "rtwtypes.h"
#undef SIMPLIFIED_RTWTYPES_COMPATIBILITY
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#include <math.h>
#include <stdint.h>
#include <stddef.h>
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define u_1_width 1
#define y_width 1
/*
* Create external references here.
*
*/
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
/* extern double func(double a); */
uint32_t CRC32Value(int i)
{
int j;
uint32_t u1CRC;
u1CRC=i;
for(j=8 ;j>0 ;j-- )
{
if(u1CRC& 1)
u1CRC =(u1CRC >> 1)^0xEDB88320L;
else
u1CRC >>= 1;
}
return u1CRC;
}
uint32_t CalculateBlockCRC32(uint32_t u1Count,uint8_t *ucBuffer)
{
uint32_t u1Temp1;
uint32_t u1Temp2;
uint32_t u1CRC=0;
while(u1Count-- != 0)
{
u1Temp1 = u1CRC>>8 &0x00FFFFFFL;
u1Temp2 = CRC32Value(((int)u1CRC ^ *ucBuffer++) & 0xff);
u1CRC=u1Temp1 ^ u1Temp2;
}
return u1CRC;
}
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Output function
*
*/
void get_snc_crc32_Outputs_wrapper(const uint8_T *ucBuffer,
const uint32_T *u1Count,
uint32_T *u1CRC,
const int_T u_width)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
/* This sample sets the output equal to the input
y0[0] = u0[0];
For complex signals use: y0[0].re = u0[0].re;
y0[0].im = u0[0].im;
y1[0].re = u1[0].re;
y1[0].im = u1[0].im;
*/
u1CRC[0] = CalculateBlockCRC32(u1Count[0], ucBuffer);
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}
Binary file not shown.
+66
View File
@@ -0,0 +1,66 @@
function makeInfo=rtwmakecfg()
%RTWMAKECFG.m adds include and source directories to rtw make files.
% makeInfo=RTWMAKECFG returns a structured array containing
% following field:
% makeInfo.includePath - cell array containing additional include
% directories. Those directories will be
% expanded into include instructions of Simulink
% Coder generated make files.
%
% makeInfo.sourcePath - cell array containing additional source
% directories. Those directories will be
% expanded into rules of Simulink Coder generated
% make files.
makeInfo.includePath = {};
makeInfo.sourcePath = {};
makeInfo.linkLibsObjs = {};
%<Generated by S-Function Builder 3.0. DO NOT REMOVE>
sfBuilderBlocksByMaskType = find_system(bdroot,'FollowLinks','on','LookUnderMasks','on','MaskType','S-Function Builder');
sfBuilderBlocksByCallback = find_system(bdroot,'OpenFcn','sfunctionwizard(gcbh)');
sfBuilderBlocksDeployed = find_system(bdroot,'BlockType','S-Function','SFunctionDeploymentMode','on');
sfBuilderBlocks = {sfBuilderBlocksByMaskType{:} sfBuilderBlocksByCallback{:} sfBuilderBlocksDeployed{:}};
sfBuilderBlocks = unique(sfBuilderBlocks);
if isempty(sfBuilderBlocks)
return;
end
sfBuilderBlockNameMATFile = cell(1, length(sfBuilderBlocks));
for idx = 1:length(sfBuilderBlocks)
sfBuilderBlockNameMATFile{idx} = get_param(sfBuilderBlocks{idx},'FunctionName');
sfBuilderBlockNameMATFile{idx} = ['.' filesep 'SFB__' char(sfBuilderBlockNameMATFile{idx}) '__SFB.mat'];
end
sfBuilderBlockNameMATFile = unique(sfBuilderBlockNameMATFile);
for idx = 1:length(sfBuilderBlockNameMATFile)
if exist(sfBuilderBlockNameMATFile{idx}, 'file')
loadedData = load(sfBuilderBlockNameMATFile{idx});
if isfield(loadedData,'SFBInfoStruct')
makeInfo = UpdateMakeInfo(makeInfo,loadedData.SFBInfoStruct);
clear loadedData;
end
end
end
function updatedMakeInfo = UpdateMakeInfo(makeInfo,SFBInfoStruct)
updatedMakeInfo = {};
if isfield(makeInfo,'includePath')
if isfield(SFBInfoStruct,'includePath')
updatedMakeInfo.includePath = {makeInfo.includePath{:} SFBInfoStruct.includePath{:}};
else
updatedMakeInfo.includePath = {makeInfo.includePath{:}};
end
end
if isfield(makeInfo,'sourcePath')
if isfield(SFBInfoStruct,'sourcePath')
updatedMakeInfo.sourcePath = {makeInfo.sourcePath{:} SFBInfoStruct.sourcePath{:}};
else
updatedMakeInfo.sourcePath = {makeInfo.sourcePath{:}};
end
end
if isfield(makeInfo,'linkLibsObjs')
if isfield(SFBInfoStruct,'additionalLibraries')
updatedMakeInfo.linkLibsObjs = {makeInfo.linkLibsObjs{:} SFBInfoStruct.additionalLibraries{:}};
else
updatedMakeInfo.linkLibsObjs = {makeInfo.linkLibsObjs{:}};
end
end