How to properly generate s-functions for functions from a static library?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
i work with an Infineon TriCore and Embedded Coder. I want to include hardware access into my Simulink project (e.g. toggle a pin).
I have a static library (library.a) containing low level drivers (e.g. there are functions like toggle_pin(Port port, Pin pin)). The data Types "Port" and "Pin" are also somewhere defined in the static libary.
My approach was to include this static library into Configuration Parameters -> Simulation Target -> Custom Code -> Libraries. Then i want to create a c-function like e.g. sfun_toggle_pin(int port, int pin). Within this function a statemachine maps the integer arguments (port and pin) to the data types Port and Pin and calls my toggle_pin-function from the library. How can i create a s-function block that calls sfun_toggle_pin? Do i have to tell this s-function block about the static library? Or is it enough to tell it Simulink in the configuration parameters?
The main functionality will be implemented in Stateflow. Later, more complicated functions shall be implemented, like UART. For example, if we get into a certain state in stateflow a message shall be send via UART. It would be nice to just have a s-function Block with a mask where the UART parameters could be set. Is something like this generally possible with a defensible amount of work?
Thank you in advance!
0 commentaires
Réponses (1)
Mark McBroom
le 9 Juin 2018
Use the legacy_code tool in Simulink to create an S-Function that calls externally written C code. There are options in the legacy_code tool for specifying .c/.h/.lib files which contain the external C code. Note that you may want to have 2 implementations of your toggle_pin() function, one for simulating your model on the host computer, and a second for the target hardware. The host computer version might write the state of the pin to the display or a file, while the target version would access actual hardware registers.
Voir également
Catégories
En savoir plus sur Code Generation for Custom Blocks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!