Trouble inlining C-Mex S-Functions
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone!
After spending quite a long time fighting with this issue I think I’m at the point of having to ask for some help to clear up my confussion. I consulted the documentation, examples and discussions, and thought I understood, but my failure to get it working proves the contrary.
So: I want to inline a quite heavy iterative algorithm that was given to me in form of a C-Mex S-Function. I’m working with code generation for embedded microcontroller targets, compiling the code in the corresponding IDE (TI CCSv3.3 and CCSv5). Everything was working fine until I decided to implement this S-Function and to inline it, mainly to avoid the S-Function API and improve the efficiency on target.
Writing a wohle new TLC is not a reasonable option for me. So I thought I could use the Legacy Code Tool. Am I wrong here and is this just thought for “pure” C code? Maybe I still could use it later on for registry operations, but first I need to implement the algorithm.
All the legacy_code commands seemed to work (sfcn_cmex_generate, slblock_generate, sfcn_tlc_generate…) except the ‘compile’ which failed with docens of messages like: “sfun_orig.obj : error LNK2005: _ssSetStateAbsTol already defined in ex_sfun_out.obj”
I’m therefore assuming I must use a wrapper. I understand this requires writing a small TLC to embodie the calling function. This shouldn’t be a big deal, as the algorithm has 2 inputs, 1 output, 1 discrite inherited sample time and just needs a couple of values from the previous steps... but I still didn’t manage it. Using it as a common level-2 C-Mex S-Functions works fine.
I’m even starting to think of “extracting” the c routines of the s-function and create a regular .c to work with, but I’m not sure if it’s a good solution... and maybe it’s an unnecessary mess.
Hopefully someone will give me a clue… so that I know in which way to focus my efforts.. .
Regards, and thanks a lot in advance!
Martin
2 comentarios
Kaustubha Govind
el 19 de Feb. de 2013
Are you using functions like ssSetStateAbsTol in your C code? If yes, that may be the issue. The code that you give to the Legacy Code Tool is supposed to be something that can run independently (including on an embedded target).
Respuesta aceptada
Kaustubha Govind
el 13 de Mzo. de 2013
I think you might be using the Legacy Code Tool incorrectly - the code that you supply to the tool is supposed to be standalone C code (probably some legacy algorithms that you inherited which you want to run as part of a Simulink model), and the tool generates the "wrapper" S-function interface like mdlInitializeSizes, mdlOutputs, etc. along with TLC code which basically just asks Simulink Coder to generates calls into your standalone C code. I wonder if it might be easier if you manually create the TLC file, unless there is an easy way to separate out the algorithm part of your S-function into standalone C code, and then generate a new S-function and TLC using Legacy Code Tool or S-function Builder.
4 comentarios
Kaustubha Govind
el 15 de Mzo. de 2013
Martin: I don't know of a significant difference in the generated TLC for performance - I think you can use whatever you find more convenient.
Más respuestas (0)
Ver también
Categorías
Más información sobre Simulink Coder en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!