MATLAB Answers

is it possible to inline C2000 (F28379D) legacy code for CLA usage

22 views (last 30 days)
Alexander Voit
Alexander Voit on 10 Apr 2018
Answered: Antonin on 18 Apr 2018
i have a really tricky question with the following Background:
- We build a Controlboard with a TI F28379D and use Simulink and Embedder Coder for Generating the Software
- The Board also contains some Hardware that is not supported by the DSP like Resolver Circuit, extenal ADC, external DAC and so on. For this Hardware we generated Drivers by including legacy code as S-Funktions. This is working well, we tested it with the CPU of the DSP.
- Now we want to let the Hardware Drivers run in the CLA of the DSP and this is where the Problems start. I already have M-Functions working inside the CLA, but as soon as i add a S-Funktion to the CLA everything inside the CLA stops working.
- As far as i figured out with Code Composer Studio this has to be related to the fact that all functions inside the CLA should be inlined that is working perfect for the M-Funktions. As soon as i change my function definition in the .c file of my own Funktion into "inline" i get a compilation error due to unresolved objects. If i compile it as non inline it is working but in the source code for the cla_Task.cla i see the Funktion call of my c-Funktion that can not work.
How can i inline legacy c-code for usage in the CLA of the DSP? Do you have any ideas for me?

Answers (5)

Antonin on 11 Apr 2018
Hi Alexander,
Use an S-function with TLC code. You can inline the logic of your C function in the TLC file. In this page , look at the "S-function builder" solution, that is the easiest way to get started.
More info on the S-function builder on this page.
I hope it helps,

Alexander Voit
Alexander Voit on 11 Apr 2018
i create my S-Function with the Legacy Code Tool because i also Need some initialization functions of some Registers of the DSP, all this is working well. The lecacy code is correctly compiled an working as long as the code execution is done by the CPU of the DSP.
The Problem i have that the S-Funtions don't work inside CLA Tasks and after the build Process if i open the Project for Debugging with the Texas Instruments Code Composer Studio i can see the function call of my code inside the CLA Task but it has to be inlined there.
If i define the Function in C as inline or static inline the compilation for this is not working. So the question is how tho make s-funktions working inside CLA Tasks of the DSP?
  1 Comment
Antonin on 11 Apr 2018
Hi Alexander,
I understand your problem, migration from the legacy code tool to the S-function builder shouldn't be hard, TLC will allow you to inline your code.
I hope it helps,

Sign in to comment.

Alexander Voit
Alexander Voit on 11 Apr 2018
Hello again,
so now i tried the same with the S-function builder and the Problem remains exactly the same, by the way, with the legacy code tool TLC is also available. To show you my Problem i created some small examples i attached to this post that have exactely the same behaviour like my target application.
In the Folder "S_fun_creation" you can find the Header and C-code of simply toggling a GPIO with some wait time inbetween as well as the make config file and the Register initializations.
The file "S_function_CPU_working.slx" Shows the generated s-function running in the CPU absolutely correctly.
The file "S_function_CLA_not_working.slx" Shows exactly the same S-Funktion in a CLA Task not running.
There are some comments in the Files, maybe you can take a look at it and compile it to see the Problem. My assumption is that the c-code has to be inlined to the cla function because in code Composer Studio i only see the function call. A breakpoint in CCS that is placed at the function is never reached by the CLA example.
The Configuration is made for the TI Delfino F28379D but it should be the same Problem for every TI DSP that has a CLA.
My Matlab Version and configuration is as following:
MATLAB Version 9.3 (R2017b)
Simulink Version 9.0 (R2017b)
Embedded Coder Version 6.13 (R2017b)
Fixed-Point Designer Version 6.0 (R2017b)
MATLAB Coder Version 3.4 (R2017b)
Simulink Coder Version 8.13 (R2017b)
  1 Comment
Arun Munuswamy Sambandham
Arun Munuswamy Sambandham on 13 Apr 2018
Hi Alexander, I looked at your files and found that you rely on SS_OPTION_SFUNCTION_INLINED_FOR_RTW for inlining. This S-function library indicates there is a tlc file associated with your S-fcn, thats all.
So, currently to make this work, inline the full algorithm inside the tlc.
Old tlc outputs: %function Outputs (block, system) Output IO_toggle(); %endfunction
new tlc output: %function Outputs (block, system) Output GpioDataRegs.GPBSET.bit.GPIO46 = 1 asm(" MNOP"); // RPT is not availble for CLA asm(" MNOP"); // use a loop to add more MNOP, GpioDataRegs.GPBCLEAR.bit.GPIO46 = 1 %endfunction

Sign in to comment.

Alexander Voit
Alexander Voit on 17 Apr 2018
thank you, i tried this and placed it in the tlc. The compilation is done and the Placement in the code is insiede the cla_Task.cla But this is all, the real Hardware is doing nothing, the I/O Pin remains as it is.
I wonder if the modeling of Simulink can access the Hardware of the DSP?
I created two other short examples you can find in the Attachement:
The "CLA_Toggle_Test_OK" is working, a toggle Signal is generated, transfered to the CLA, multiplied by one and afterwords transfered to the CPU. In the CPU this Signal is used to set the I/O port and this is perfectely done by the real Hardware.
In the "CLA_Toggle_Test_NOT_OK" the only difference is that an additional Digital Output Block of the Embedded Coder Support Package is placed inside the CLA Task. This leads to a compilation error.
Is there any further documentation by mathworks what is possible with the CLA and what not? The only Thing is the example for the blinking LED and there is not a lot of Information. Is there a newer Version with better Support and usage of the CLA?
Actually i think i can not use the CLA the way i want to to with Simulink.
BR Alex

Antonin on 18 Apr 2018

Hi Alexander,

You are close. By default GPIOs are controlled by the CPU and the CLA doesn't have access the registers. As of today, our GPIO block only works from the CPU. We are working on enhancing this for the future. In the meantime, just use a simple line of custom code to change the master that has access to the GPIO registers. Something like (for GPIO16):

GpioCtrlRegs.GPACSEL3.bit.GPIO16 = 1; // 0=CPU1, 1=CPU1.CLA1, 2=CPU2, 3=CPU2.CLA

To include custom code easily, I recommend the custom code blocks from Simulink Coder.

Section of the F28379D reference manual explains that part.

From your models, I see that you are using MATBA R2017b. I strongly recommend that you upgrade to MATLAB R2018a, which provides multiple enhancements to our CLA support.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!