how to set simulink module priority ?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

how to set simulink module priority ?

跳至解决方案
8,359 次查看
642142357
Contributor III

use "Model-Based Design Toolbox for s32k144" to develop project,how to set simulink module priority ?

0 项奖励
回复
1 解答
8,003 次查看
constantinrazva
NXP Employee
NXP Employee

Hello 642142357@qq.com‌,

To set the priority for a block, you should right-click it, then go to Properties -> Priority.

pastedImage_1.png

Keep in mind that the lower the priority number you input, the higher the priority (low numbers will generate code first).

Hope this helps!

Razvan.

在原帖中查看解决方案

0 项奖励
回复
12 回复数
8,004 次查看
constantinrazva
NXP Employee
NXP Employee

Hello 642142357@qq.com‌,

To set the priority for a block, you should right-click it, then go to Properties -> Priority.

pastedImage_1.png

Keep in mind that the lower the priority number you input, the higher the priority (low numbers will generate code first).

Hope this helps!

Razvan.

0 项奖励
回复
8,003 次查看
642142357
Contributor III

the higher or low the priority only means that model generate code order????what refer to set the priority ??? what relation about priority and program execute order ???

0 项奖励
回复
8,003 次查看
constantinrazva
NXP Employee
NXP Employee

Hello 642142357@qq.com‌,

So there are 2 types of priorities we can think of when talking about our MBD toolboxes and Simulink. I'm going into details for both of them as I can not understand what you want to know.

  1. Simulink block priority - this priority is taken into consideration by Simulink for its execution order (note that Simulink execution order is not the same thing as the embedded application execution order). Simulink can execute more actions, like code generation or simulation. So if you're generating code (clicking on the Build button), Simulink will go through each of the blocks you have in the model, and generate code for each one. The order in which it will take the models is given by the Simulink execution order, and it can be influenced by the user, in the manner I mentioned above (right click -> properties -> priority). The rule is the following: Simulink starts with blocks that have the lowest number(value) and continues with those of higher number(value). Once all the blocks that have user-defined priorities are finished, Simulink will decide what the order will be for the ones that remain. The way code generation works in our toolboxes is that we have some tlc-files which control what code is generated for each block, and where the code is placed (in an ISR, in the step function of the model, in the initialization phase, etc). With this priority you can control the order in which blocks will generate code, while the destination is the same (e.g.: if more blocks want to generate code in the Init() function, you can control the order in which code is generated by editing the blocks' priority).
  2. ISR priority - this refers to the priority in which interrupts routines are being executed. This can be controlled by each ISR block - you can select the number from a drop-down list. This number controls the priority in the NVIC registers.

To answer your other question - as for the relationship between code generation order and execution order, they will be tightly coupled, while in the same place. So if we have 2 blocks that generate initialization code, they will be placed in the same Init() function. The order in which the code is generated will ultimately give you the order in which the blocks will be executed.

Please let me know if you have further issues, or give me an example of what you are trying to accomplish and I will make an example for you, highlighting the priority management.

Kind regards,

Razvan.

0 项奖励
回复
8,003 次查看
642142357
Contributor III

on the same simulink level model, how to decide the c code (generation by simulink models based on s32ktoolbox)execute order ???show picture below,thks.22.png

want to A generate c code executed prior to B  generate c code executed ,how to do ?

0 项奖励
回复
8,003 次查看
constantinrazva
NXP Employee
NXP Employee

Hello 642142357@qq.com‌,

Can you send me the model? I'm having a hard time trying to see the order Simulink has set up. You can strip out any proprietary code and just leave out the empty subsystems if you'd like.

Kind regards,

Razvan.

0 项奖励
回复
8,003 次查看
642142357
Contributor III

thks firstly,attached model.

0 项奖励
回复
8,003 次查看
constantinrazva
NXP Employee
NXP Employee

Hello 642142357@qq.com‌,

So if you want the whole subsystem A to be generated first, and then the whole subsystem B, you have to right click on subsystem A, go to Properties, then write a number in the Priority edit box (e.g.: 5). Then go to subsystem B, do the same (right click -> Properties), and enter a higher number (lower priority) than what you've inserted in subsystem A (e.g.: 10). Now, if you build the model, you'll see that code generated for subsystem A is before code generated for subsystem B. You can check Simulink's order by pressing CTRL+D on your keyboard, while in the model. This will force an update to the model, which, among other things, will update the priorities (you can see them in the corner of every block, denoted with 2 numbers - e.g.: 5:21).

pastedImage_1.png

pastedImage_2.png

Following the same approach, you can set priorities for each and every block in Simulink (be it from Standard Simulink block set, our toolbox or any other toolbox).

Hope this helps,

Razvan.

0 项奖励
回复
8,003 次查看
642142357
Contributor III

aim to how to decided by me c code (generated by A ) executed prior to c code(generated by B ), that is to say , c code execute order.not "  code generated by A or B order " you said.Or rather, you means,c code execute order = c code generated by simulink order ???

0 项奖励
回复
8,003 次查看
constantinrazva
NXP Employee
NXP Employee

Hello 642142357@qq.com‌,

As I stated before, there are more parts where code can be generated. This parts can be:

  • initialization code - executed only 1 time, before loop code
  • loop code - executed periodically
  • interrupt code - executed when triggered by specific events

If the code for block A and code B is generated for same part (e.g.: both blocks generate loop code), the order given in Simulink = order of execution (C code running on target).

I can't make a general rule that Simulink order = execution order on target. I will give you a simple example to make my point more clear: you have block A that generates initialization code; you also have block B that generates loop code. In this example, regardless of the priorities, the code executed on the target will always be in the following order: initialization code, then loop code.

But as a rule of thumb, you can expect that code executed on target should be (in most cases) = priority in Simulink.

Kind regards,

Razvan.

0 项奖励
回复
8,002 次查看
642142357
Contributor III

Helloconstantinrazvan.chivu

      could u give me a sample simulink project based on toolbox with s32k144 to describe that you said.not a sample of " block A that generates initialization code;  block B that generates loop code. ".thks.

Kind regards.

0 项奖励
回复
8,002 次查看
constantinrazva
NXP Employee
NXP Employee

Hello 642142357@qq.com‌,

Every peripheral configuration block generates code that goes into the initialization function. You can take as an example one of the following: SPI Config, CAN Config, ADC Config, etc.

Most peripheral action blocks generate code that goes into the loop code (step function). You can take as an example one of the following: SPI Transfer, CAN Send, etc.

Kind regards,

Razvan.

0 项奖励
回复
8,003 次查看
642142357
Contributor III

Priority low or higher only means that generate code order ???? how to decide the program execute  order ????

0 项奖励
回复