How do I access current simulation-time value within external custom C-code that is called in Stateflow Chart

1 view (last 30 days)
I am developing an embedded application using Stateflow and RTW (Matlab 2010b). The target is a custom controller with high-level C API. The code generated from the Stateflow chart must be include specific function calls that match the TargetController API ("BoardAPI.h" and "BoardAPI.c") as it will be cross-compiled and linked against those source files. So I have created a matching simulation version we'll call SimAPI ("SimAPI.h" and "SimAPI.c")
I can successfully call the SimAPI versions of the functions in the Stateflow simulation and have RTW generate the correct function call syntax so model.c files compiles against BoardAPI files using the procedure described in the Stateflow Help files describing how to incorporate external code. I have no problems implementing simulation versions of functions in BoardAPI that are independent of time with this method.
I now need to add a simulation version of a timer function that matches the calling of syntax of the function defined in the external API, and this simulated version will obviously be dependent on simulation time. In BoardAPI I have:
#include <microboard.h>
typedef uint32_t bTimer_t;
bTimer_t ElaspedUpTime()
{
/* code for getting uptime from etpu register calls into microboard.h */
}
What I need to create in SimAPI.c/.h is:
#include "appropriateSimulinkHeaderFile.h"
typedef uint32_T bTimer_t;
bTimer_t ElaspedUptime()
{
/* function call that returns the current simulation time, i.e. 1.5sec => then convert to integer */
/* or function call that returns number of simulation ticks...call in "appropriateSimulinkHeaderFile.h" */
}
I have found the function boolean_T ssIsMajorTimeStep(SimStruct *S) but that only seems to be applicable in the context of writing an S-Function, which won't work well for my situation.
I am aware of the Absolute-time temporal logic operators within Stateflow Action language. But to get a seamless simulation -> codegen (syntax matched to BoardAPI) -> cross-compilation workflow makes using temporal logic operators difficult. Any suggestions or advice would be appreciated. Thanks
Is there any other way to access the simulation time with external C-code? Is this something that is easy to do if I upgrade to a new version Matlab/Simulink?

Answers (0)

Categories

Find more on Stateflow in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!