MATLAB: Assembler commands in C-code for S-Functions

real time workshops-functionsti280x dsp

Hello! I have a question concerning assembler commands in custom C-code that I want to integrate in an simulink s-function block for code generation by Real Time Workshop afterwards. Speaking more detailed: I wanted to implement an own SCI-Protocol, specified by my University department, in a Simulink block, so I can easily use it in a model for transforming it into C-Code that will run on my TI 2808 DSP. For the SCI and GPIO initialization, I will need assembler commands like "EALLOW" etc. to be able to write certain registers. The problem is, that the lcc compiler does not accept the command "asm(…)", resulting in an error that the symbol asm is undefined. Does anyone have an answer that would solve my problem or lead me closer to the goal? Any help is appreciated! Thanks so far!

Best Answer

Where are you writing the asm(...) commands? Note that your MEX S-function is used for simulation on the host machine (where MATLAB is installed) - so these assembly commands are not appropriate for the host platform (and therefore LCC, Visual Studio or other PC compilers won't recognize them). Since these commands should only be used in the generated code, what you need to do is provide a TLC file for your S-function. See Inlining C MEX S-Functions for more information about this.
In other words, you can have two separate implementations of the block - the MEX S-function to run on the host machine, and the TLC file to represent the block in generated code. When you put your assembler commands in the TLC, they are produced in the code generated for your model, which must be compiled using Code Composer Studio (or the corresponding target compiler).