Problem with code reusabilty of inlined S-Function // multiple referencing

조회 수: 17 (최근 30일)
Eike
Eike 2011년 3월 1일
Hello,
I'm trying to use model referencing in my project. Therefore, I need model references to models containing S-Functions. The S-Function is inlined using a tlc file and I have used
ssSetOptions(S,(SS_OPTION_USE_TLC_WITH_ACCELERATOR | SS_OPTION_WORKS_WITH_CODE_REUSE));
in the mdlInitializeSizes routine of the corresponding c file to make it reusable.
However, when trying to build the model, I keep getting the following error report:
'Configuration Parameters > Model Referencing > Total number of instances allowed per top model' is set to 'Multiple' for model 'Submodel'. S-Function block 'Submodel/Init_PWM/fcn_VentOn_uP1/fpga_interface' of this model does not support code reuse. This is not allowed in a model configured to be referenced multiple times.
To enable code reuse, the block must have a TLC implementation and the S-function's mdlInitializeSizes function must set the options 'SS_OPTION_USE_TLC_WITH_ACCELERATOR' and 'SS_OPTION_WORKS_WITH_CODE_REUSE'.
To configure the model to be referenced only once, change the configuration parameter 'Total number of instances allowed per top model' to 'One'.
Any suggestions about my point of failure?
A question closely related to the one above is: When will the mdlInitializeSizes c-routine be executed? Shouldn't it normally be ignored due to the existing tlc file?

답변 (4개)

Kaustubha Govind
Kaustubha Govind 2011년 3월 1일
Do you ensure that your S-function also meets all the other requirements for code reuse?
mdlInitializeSizes is run when the S-function's parent model is compiled by the Simulink Engine - in other words, right before code generation. The TLC file is used to generate code for the S-function. So, the S-function MEX file is ignored when the top-level model is calling into the referenced model's generated code.
  댓글 수: 2
Eike
Eike 2011년 3월 2일
Ok, I'll move through the list part by part:
- The function is inlined.
- I don't use any static variables.
- I don't think I'm using any work vectors.
- I don't think my S-Function is a sink, since my S-Function has got Outputs?
- I don't use Run-Time parameters
- "The S-function must not be a device driver." I'm not sure with this one. What's the definition of a device driver in this case? In fact, my S-Function works as a FPGA read/write interface using routines like fpga_update from extern c files. But does that make it a device driver?
And what should prevent a device driver from being reused?
Kaustubha Govind
Kaustubha Govind 2011년 3월 3일
In my book, a device driver is any software that somehow accesses a hardware resource. It would not be suitable for re-use because it could result in multiple instances trying to access the same hardware resource (a bad idea in most situations, unless the resource can manage competing requests).
Could you try creating multiple instances of your S-function is a single model and try generating code from it? (Don't use model reference). Are you able to build code successfully? Is the S-function code generated as a reusable function?

댓글을 달려면 로그인하십시오.


Eike
Eike 2011년 3월 3일
mmh?
Commenting seems to be not the best idea since noone notices... :-)
  댓글 수: 1
Kaustubha Govind
Kaustubha Govind 2011년 3월 3일
FYI: I had seen your comment yesterday, but didn't have time to address it. :)

댓글을 달려면 로그인하십시오.


Eike
Eike 2011년 3월 3일
Building with multiple instances of the S-Function in one model works, we do that extensively. However, I just checked the code generation report and indeed all of my S-Functions are marked as not reusable due to the following reason:
The following block contains an S-Function that does not conform to Code Reuse restrictions. The S-Function block (a) should have a TLC implementation and (b) should set the option 'SS_OPTION_WORKS_WITH_CODE_REUSE'. [testmodel2/out_OutSignalCondition_lib/Init_PWM/fcn_PWMPEEPmax_uP2/fpga_interface]
Which is quite ironic since I (a) have a TLC implementation and (b) set the options SS_OPTION_WORKS_WITH_CODE_REUSE and SS_OPTION_USE_TLC_WITH_ACCELERATOR.
Maybe you're right and the real problem is that I'm accessing hardware. But then I'd kind of expect Matlab to tell me...
  댓글 수: 1
Eike
Eike 2011년 3월 3일
Btw. I'm also pretty sure that my TLC file is used correctly since the block is marked as inlined.

댓글을 달려면 로그인하십시오.


Eike
Eike 2011년 3월 4일
Okay, that was a really stupid problem. -.-
I just built the model in its original project path (before, I did in my own development folder with copies of all relevant libraries) and it works. I have no clue about the exact problem before, but since it works now I don't care too much.
Nevertheless thank you very much for your effort! :-)
  댓글 수: 2
Eike
Eike 2011년 3월 4일
Although I still find Matlab's error message in this case to be kind of misleading...
Kaustubha Govind
Kaustubha Govind 2011년 3월 4일
I'm glad you fixed the issue, but I agree that error reporting should be improved. I could create an internal change request to improve this error, but I will need an example model and S-function to reproduce the issue. Please let me know if it is possible for you to pare down your model to its bare minimum so we can use it for testing.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by