Trouble inlining C-Mex S-Functions
Show older comments
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 Comments
Kaustubha Govind
on 19 Feb 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).
Martin Dendaluce
on 13 Mar 2013
Accepted Answer
More Answers (0)
Categories
Find more on Texas Instruments C2000 Processors in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!