diff --git a/controllers/SFB__get_snc_crc32__SFB.mat b/controllers/SFB__get_snc_crc32__SFB.mat new file mode 100644 index 0000000..8eef420 Binary files /dev/null and b/controllers/SFB__get_snc_crc32__SFB.mat differ diff --git a/controllers/get_snc_crc.slx b/controllers/get_snc_crc.slx index 884a890..79a339a 100644 Binary files a/controllers/get_snc_crc.slx and b/controllers/get_snc_crc.slx differ diff --git a/controllers/get_snc_crc32.c b/controllers/get_snc_crc32.c index 3f7dd58..331ed01 100644 --- a/controllers/get_snc_crc32.c +++ b/controllers/get_snc_crc32.c @@ -26,7 +26,7 @@ * | 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 @@ -111,12 +111,10 @@ /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ #include "simstruc.h" -extern void get_snc_crc32_Start_wrapper(void); extern void get_snc_crc32_Outputs_wrapper(const uint8_T *ucBuffer, const uint32_T *u1Count, uint32_T *u1CRC, const int_T u_0_width); -extern void get_snc_crc32_Terminate_wrapper(void); /*====================* * S-function methods * @@ -250,7 +248,6 @@ static void mdlSetDefaultPortDataTypes(SimStruct *S) */ static void mdlStart(SimStruct *S) { - get_snc_crc32_Start_wrapper(); } #endif /* MDL_START */ @@ -275,7 +272,6 @@ static void mdlOutputs(SimStruct *S, int_T tid) */ static void mdlTerminate(SimStruct *S) { - get_snc_crc32_Terminate_wrapper(); } #ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */ diff --git a/controllers/get_snc_crc32.mexw64 b/controllers/get_snc_crc32.mexw64 index 032ea05..9ccde3a 100644 Binary files a/controllers/get_snc_crc32.mexw64 and b/controllers/get_snc_crc32.mexw64 differ diff --git a/controllers/get_snc_crc32.tlc b/controllers/get_snc_crc32.tlc new file mode 100644 index 0000000..d412680 --- /dev/null +++ b/controllers/get_snc_crc32.tlc @@ -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 = "%.h" + %selectfile hFile + #ifndef _%_H_ + #define _%_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 % *ucBuffer, + const % *u1Count, + % *u1CRC, + const % u_0_width); + #undef SFB_EXTERN_C + #endif + %closefile hFile + + %assign cFileName = "get_snc_crc32_accel_wrapper" + %openfile cFile = "%.c" + %selectfile cFile + #include + #ifdef MATLAB_MEX_FILE + #include "tmwtypes.h" + #else + #include "rtwtypes.h" + #endif + #include "%.h" + + + extern void get_snc_crc32_Start_wrapper(void); + extern void get_snc_crc32_Outputs_wrapper(const % *ucBuffer, + const % *u1Count, + % *u1CRC, + const % u_0_width); + extern void get_snc_crc32_Terminate_wrapper(void); + void get_snc_crc32_Outputs_wrapper_accel(const % *ucBuffer, + const % *u1Count, + % *u1CRC, + const % u_0_width){ + get_snc_crc32_Outputs_wrapper(ucBuffer, + u1Count, + u1CRC, + u_0_width); + } + + %closefile cFile + + %.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 % *ucBuffer, + const % *u1Count, + % *u1CRC, + const % u_0_width); + + SFB_EXTERN_C void get_snc_crc32_Terminate_wrapper(void); + + #undef SFB_EXTERN_C + %closefile 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(%, %, %, %); + %else + get_snc_crc32_Outputs_wrapper(%, %, %, %); + %endif + + %% +%endfunction + + +%% [EOF] get_snc_crc32.tlc + diff --git a/controllers/get_snc_crc32_wrapper.c b/controllers/get_snc_crc32_wrapper.c new file mode 100644 index 0000000..0533e2b --- /dev/null +++ b/controllers/get_snc_crc32_wrapper.c @@ -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 +#include +#include +/* %%%-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 */ +} + + diff --git a/mainModels/sunny360vfe_ap.slx b/mainModels/sunny360vfe_ap.slx index d252aed..84ad58c 100644 Binary files a/mainModels/sunny360vfe_ap.slx and b/mainModels/sunny360vfe_ap.slx differ diff --git a/rtwmakecfg.m b/rtwmakecfg.m new file mode 100644 index 0000000..a0e1421 --- /dev/null +++ b/rtwmakecfg.m @@ -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 = {}; + +% + +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