Hardware specific Functions + Code Replacement + Embedded Coder

1 vue (au cours des 30 derniers jours)
Tom Poltz
Tom Poltz le 13 Avr 2021
Commenté : Tom Poltz le 15 Avr 2021
Designing C code from an algorithm in Simulink that also calls hardware-specific functions shouldn't be difficult, right?
For example, the algorithm could call a (hardware) function "void switch_Light(uint8)".
Since neither Simulink nor the PC compiler ("Visual Studio" or similar) knows this function, you could define an auxiliary function (for simulation purposes) and get the correct hardware function call (for the external hardware compiler) substituted with a "Code Replacement Library".
Apparently, this option does not exist? The examples included in help demonstrate other scenarios.
Does anyone have experience with this and can sketch a simple, working example of the above function call?
  1 commentaire
Mark McBroom
Mark McBroom le 13 Avr 2021
Rather than use the Code Replacement Library, a simpler approach would be to have two versions of function switch_Light(). One version is for simulation and the other is hardware specific. Place these two functions in two different C files. Compile/link to one for simulation and the other for code generation. Use the C Caller block to call your C function. Use the Configuration Parameters "Simulation Target" pane to specify the C file for simulation, and the Code Generation -> Custom Code pane to specify the C file for code generation.
As an alternate to 2 seperate C files, you could use a single C file/function with #ifdef #else #endif macros to seperate the simulation version of your function from one or more hardware-specific implementations.
Mark.

Connectez-vous pour commenter.

Réponse acceptée

Mark McBroom
Mark McBroom le 13 Avr 2021
Rather than use the Code Replacement Library, a simpler approach would be to have two versions of function switch_Light(). One version is for simulation and the other is hardware specific. Place these two functions in two different C files. Compile/link to one for simulation and the other for code generation. Use the C Caller block to call your C function. Use the Configuration Parameters "Simulation Target" pane to specify the C file for simulation, and the Code Generation -> Custom Code pane to specify the C file for code generation.
As an alternate to 2 seperate C files, you could use a single C file/function with #ifdef #else #endif macros to seperate the simulation version of your function from one or more hardware-specific implementations.
  3 commentaires
Mark McBroom
Mark McBroom le 14 Avr 2021
Hi Tom,
The approach I described will not copy the code from Switch_Light() function into the code from the Simulink model... it will simply make a call to switch_Light() as you described. This example walks you through the steps.
Thanks.
mark.
Tom Poltz
Tom Poltz le 15 Avr 2021
Thank you! I think, I've got it now.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by