Borrar filtros
Borrar filtros

How do I verify simulink coder output with an S-Function?

1 visualización (últimos 30 días)
Sean Donovan
Sean Donovan el 7 de Jun. de 2022
Respondida: Nithin Kumar el 1 de Sept. de 2023
I used Simulink Coder to create C-Code for my model. I would like to verify the code in my simulation, but when I create an S-Function around this new code, I am unable to connect the S-Function I/O to the C-code function (*_step()). How do I get data from the root ports into the C-code I/O data structures?

Respuestas (1)

Nithin Kumar
Nithin Kumar el 1 de Sept. de 2023
Hi Sean,
I understand that you are facing an issue while verifying the Simulink coder output with an S-function.
Kindly refer to the following steps to verify the generated C-code within the Simulink environment:
1. Create an S-Function: Create an S-function in Simulink to encapsulate the generated C-code. You can do this by using the S-Function Builder, writing custom S-function code, or using the Legacy Code Tool, depending on your preferences and the structure of your generated code.
2. Configure S-Function Parameters: Inside the S-function, configure parameters and input/output ports to match the requirements of your generated C-code. If you are unable to connect the S-function I/O to the C-code function, kindly check the following:
  • Port Mismatch: Verify that the number and data types of the input and output ports of your S-function match the requirements of your C-code function. If there is a mismatch, you will not be able to connect them.
  • Data type Compatibility: Ensure that the data types of the signals connected to the S-function's ports are compatible with the data types expected by your C-code function.
  • Configuration Parameters: Review the configuration parameters of both the S-function and your C-code function. Pay special attention to sample times, data types, and solver settings to ensure they are compatible.
3. Map Inputs and Outputs: Within the S-function block, map the input and output ports to the corresponding variables or data structures in your generated C-code. This ensures that data flows correctly between Simulink and your C-code.
4. Set Up Testing Harness: Create a Simulink testing harness or model that includes your S-function and any necessary input sources (e.g., test vectors) and output measurement blocks (e.g., scopes, displays).
5. Define Test Cases: Define test cases to cover various scenarios and conditions. Set up the input signals for these test cases within your testing harness.
6. Simulate and Compare Results: Run simulations of your testing harness and compare the results from Simulink with the expected results from your C-code. Ensure that the S-function correctly interfaces with the generated C-code.
7. Debug and Iterate: If you encounter any issues, use Simulink debugging tools to pinpoint problems. Modify the S-function or the generated C-code as needed, recompile if necessary, and iterate until you achieve matching results.
8. Coverage Analysis: Consider using coverage analysis tools for your generated C-code to ensure that your tests exercise all code paths.
To know more information about the usage of S-function in Simulink, kindly refer to the following documentation.
I hope this answer helps you.


Más información sobre Simulink Coder en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by