Insert Custom Code into Built Code (Simulink Embedded Coder)

I have created an application for a TI F28035 microcontroller in Simulink using the TI C2000 hardware add-on. Everything works just fine. However, I was wondering if there was a way to insert custom lines of c code into the auto-generated code. I'm not talking about S functions or ceval calls or using the custom code portion of the Model Parameters. I'm talking about a simple block that lets you enter some simple lines of c code that when built will just plop those lines of code into the built code. Does anything like that exist?

回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2018 年 1 月 30 日

0 投票

In your version of Simulink, check Simulink Coder, Custom Code, Model Source block. It allows to add source code at either Top or Bottom of the model source code.

3 件のコメント

Adam Truelove
Adam Truelove 2018 年 1 月 30 日
It doesn't do me any good to just add code at the top or bottom of the source code. I need it to be called by an external trigger. Ideally I would have a "custom code" block (that doesn't seem to exist currently) that I would place in a triggered subsystem.
Fangjun Jiang
Fangjun Jiang 2018 年 1 月 30 日
In that case, use a Stateflow chart inside a triggered subsystem. You can pretty much write any manual code inside the Stateflow chart.
Adam Truelove
Adam Truelove 2018 年 1 月 30 日
編集済み: Adam Truelove 2018 年 1 月 30 日
I'm not exactly sure what you mean.
The custom code I need inserted into the generated code looks like this. I tried just copying this into a stateflow state, but I get all sorts of errors obviously.
Uint16 *p_id = (Uint16 *)0x0006CD;
*p_id = 0x00FF;
Uint32 *p_data = (Uint32 *)0x0006CE;
*p_data = 0xFFFFFFFF;
void (*foo)(void) = (void (*)(void))0x4E9867;
foo();

サインインしてコメントする。

Mark McBroom
Mark McBroom 2018 年 3 月 10 日

0 投票

Only way I know of is to create in-lined s-function. For Simulation, s-function would have no inputs, no outputs and therefore do nothing. For code generation, the TLC code for the s-function could emit the above code.

カテゴリ

ヘルプ センター および File ExchangeSimulink Functions についてさらに検索

質問済み:

2018 年 1 月 29 日

回答済み:

2018 年 3 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by