How to use ssRegister​DataTypeIn​teger with Simulink Coder ?

7 views (last 30 days)
Hi everyone,
I'm struggling for a while now (about a month) to use the ssRegisterDataTypeInteger function in my app. I had to test it out of my application to find the issue. When i'm running my s-function using ssRegisterDataTypeInteger (libfixedpoint) through Simulink it works perfectly. Then I'm building with simulink (C Code -> Build), it's working almost like a charm (had some issues with linking libfixedpoint.lib but seems to be solved), and when i'm trying to run the resulting .exe it's failing when calling ssRegisterDataTypeInteger, any clue about what's going on here ?
I've also tried the proposition of Mikhail on the following thread and it has given me the same behaviour :
https://fr.mathworks.com/matlabcentral/answers/345944-how-to-create-64-bit-integer-data-type-in-simulink

Accepted Answer

Andy Bartlett
Andy Bartlett on 12 Jan 2021
Edited: Andy Bartlett on 12 Jan 2021
Hi
I've created an example for cases where the types can vary per instance of the s-function.
The core of the s-function is contained in a C code file and header.
This C file is shared between simulation and code generation.
This code recieves attributes of the input and output ports using a structure.
Based on the contents of these attribute structures the core code dispatches to the correct behavior for each instance.
The wrapper C code and TLC code for the s-function need to fill in the structures,
then call the core function.
How the attribute structures are filled in is distinct to C and TLC.
But the core all comes from the same C file and header.
The example shows one possible way to organize the port information and do the dispatching.
Using the same concept, use whatever specific way works best for your application.
This example if found at GitHub-DynamicTypeHandling.
Please review and run runMeFirst.m to exercise the example.
-Andy
  1 Comment
Brieuc DANIEL
Brieuc DANIEL on 14 Jan 2021
Many thanks ! I'm currently working on a small project merging your kind example and sfcndemo_sfun_multiport, which is a simplified version of my real project ! I'll keep you posted in the few days, if the problem is completely solved !

Sign in to comment.

More Answers (2)

Mikhail
Mikhail on 11 Jan 2021
Hi Brieuc,
As I mentioned in the thread you've linked to (https://www.mathworks.com/matlabcentral/answers/345944-how-to-create-64-bit-integer-data-type-in-simulink#comment_850989)
4) And the worst. The S-Function using 64 bits data types must be inlined (this is from my experience, please tell me I'm wrong) for target-based builds. I'm not against throwing in some TLC, but I would really prefer not to inline S-Function in some cases. This also makes this API less capable than true built-in data types, where I don't have to worry about it.
So this might be problem.
But I can't tell fo sure unless you provide some reproduction steps and specific error messages.
  1 Comment
Brieuc DANIEL
Brieuc DANIEL on 11 Jan 2021
Thanks for your answer,
It helps a lot, can i abuse your kindness and asks you a very simple example of inlining a sfunction for 64 bytes like a sfunction adding 1 to the input ?
Thanks again for you answer !

Sign in to comment.


Andy Bartlett
Andy Bartlett on 11 Jan 2021
Edited: Andy Bartlett on 11 Jan 2021
Hi
A low effort way to inline an s-function is to use "wrapping".
The general concept of "wrapping" an s-function is described here.
I've created an example that is more specific to use of integer types including int64.
The sfunction's c, h, and tlc files can be found on github.
Please review and run runMeFirst.m to exercise the example.
Please note, this example only covers cases where the inner function being wrapped has a statically typed interface. Such as the github example.
uint64_t func_core_hybrid_add(uint64_t const a, uint32_t const b);
In other words, no polymorphism via void pointers or such.
If you need an interface that handles port types that are different for different instances of the s-function, that can be wrapped too. But that needs a different wrapping technique.
-Andy
  8 Comments
Brieuc DANIEL
Brieuc DANIEL on 12 Jan 2021
Hi,
It's quite complex.
The sfunction is used in three mode:
  • One connecting through a domain
  • One publishing to a shared memory
  • One subscribing to a shared memory
We've got M input and N outputs (almost everytime M:M) and we can have every combinations of input ports. The number and datatypes of inputs are given though a simulink mask.
I don't know if i'm clear enough ! Feel free to ask complementary informations if needed !

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!