Hi Eamon,
Yes, this is possible without post-processing but there’s no single TLC function that will automatically instrument every generated function. There are, however some TLC functions that can partially help:
- “LibMdlStartCustomCode“and”LibMdlTerminateCustomCode” These target only the model’s top level initialization and termination functions, not every function generated by Embedded Coder.
- “LibSystemInitializeCustomCode”,”LibSystemOutputCustomCode”,”LibSystemUpdateCustomCode” These apply within each subsystem’s functions (initialize, output, update), but only where subsystems are defined. They do not cover other generated functions like utility or block-specific functions.
- “LibGetModelDotCFile”+LibSetSourceFileSection This lets you inject code into the “Functions” section of the model’s main.c file, but again, this is not true per-function instrumentation.
You can refer to the documentation for more detail:
If still you want to modify all functions, you will need to edit the TLC templates that define how functions are emitted. This is not recommended on the original files , instead make a copy of the TLC files, modify those, and point your build to the custom ert.tlc so your changes are isolated.
Some TLC files you might look at include:
codetemplatelib.tlc
commonbodlib.tlc
hookslib.tlc
blocklib.tlc
In this case,native TLC modification is more viable than MATLAB Script. Changes are applied before the C code is written to disk, so you avoid extra parsing, patching, or string matching afterward.
