MATLAB: How to generate zero initialization code which does not use the memset standard library function Real-Time Workshop Embedded Coder 5.3 (R2009a)

Embedded Coderfunctioninitializationlibrarymemsettargettflzero

I woud like to generate zero initialization code which does not use memset standard library function in the Real-Time Workshop Embedded Coder.

Best Answer

Target Function Library feature can replace memset function with the user original function.
Below is an example with the 'memcopy' function obtained by opening the HELP documentation for the Real-Time Workshop Embedded Coder.
In the documentation in the Contents section -> Click on Real-Time Workshop Embedded Coder -> Target Function Libraries -> Creating Function Replacement Tables -> Example: Mapping the memcpy Function to a Target-Specific Implementation
Here, in the memset case, you should change 'key' parameter 'memcopy' in the setTflCFunctionEntryParameters API function.
Also, the in the 'Real-time Workshop' -> 'Custom Code' -> 'Include list of additional' :
Include directories : <Include the directory path which has the Header file, i.e., say my_string.h>
Source File : <Include the file path, i.e., say my_string.c>
1. Create and save the following memset_tfl.m on your MATLAB path
function hTable = memset_tfl
hTable = RTW.TflTable;
% void* memset( void*, int, size_t )
fcn_entry = RTW.TflCFunctionEntry;
setTflCFunctionEntryParameters(fcn_entry, ...
'Key', 'memset', ...
'Priority', 90, ...
'ImplementationName', 'my_memset', ...
'ImplementationHeaderFile', 'my_string.h', ...
'ImplementationSourceFile', 'my_string.c', ...
'SideEffects', true);
arg = getTflArgFromString(hTable, 'y1', 'void*');
arg.IOType = 'RTW_IO_OUTPUT';
addConceptualArg(fcn_entry, arg);
arg = getTflArgFromString(hTable, 'u1', 'void*');
addConceptualArg(fcn_entry, arg);
arg = getTflArgFromString(hTable, 'u2', 'integer');
addConceptualArg(fcn_entry, arg);
arg = getTflArgFromString(hTable, 'u3', 'size_t');
addConceptualArg(fcn_entry, arg);
copyConceptualArgsToImplementation(fcn_entry);
addEntry( hTable, fcn_entry );
%EOF
2. Next, create and save sl_customization.m (example is ANSI) on your MATLAB path
function sl_customization(cm)
% sl_customization function to register a target function library (TFL)
% Register the TFL defined in local function locTflRegFcn
cm.registerTargetInfo(@locTflRegFcn);
end % End of SL_CUSTOMIZATION
% Local function to define a TFL containing tfl_table_memcpy
function thisTfl = locTflRegFcn
% Instantiate a TFL registry entry
thisTfl = RTW.TflRegistry;
% Define the TFL properties
thisTfl.Name = 'Memset Function Example';
thisTfl.Description = 'Demonstration of memcpy function replacement';
thisTfl.TableList = {'memset_tfl'};
thisTfl.BaseTfl = 'C89/C90 (ANSI)';
thisTfl.TargetHWDeviceType = {'*'};
end % End of LOCTFLREGFCN
3. Execute sl_refresh_customizations in the MATLAB command window.
4. Open your model and Select ”Memset Function Example” for Target Function Library in the configuration paramters (Real-Time Workshop/interface)
5. Generate Code