How are subsystem inports and outports handled during SimWB compliant code generation from the MLToolkit?
Question
How are subsystem inports and outports handled during SimWB compliant code generation from the MLToolkit?
Answer
Inports and Outports are different from other Sources and Sinks in Simulink because they behave differently inside and outside of Simulink subsystems. Subsystem inports and inports have to be connected to other blocks in the subsystem one level higher until we reach the root level (bdroot) of the model. At the root level, inports and outports are indicative of signals external to the Simulink model (i.e they come from the outside world). During SimWB compliant code generation the user can choose the following options:
- Map using block names
- Map "SW" prefixed blocks
If the user chooses the first option i.e. Map using block names, inports and outports are picked up only from the root level(bdroot) to be replaced by RTDB variables in the SimWB compliant generated code. All inports and outports within subsystems are ignored and will not be mapped to RTDB variables. If the user chooses the second option i.e. Map "SW" prefixed blocks, inports and outports with the SW prefix are picked up irrespective of which subsystem they are in within the model. For example, lets consider the model shown here.
The SW prefixed inport "SWin1" is picked and replaced by a RTDB variable during SimWB compliant code generation since we are telling RTW that the "SWin1" port data is essentially going to come from an external source. The RTW engine sees this during code generation and infers that the Sine Wave source block is no longer connected to the "SWin1" port for code generation purposes and so the Sine Wave block is optimized out of the generated code. During code generation, you will see a warning which is expected.
Warning: Unconnected output line found on 'testinports/Sine Wave' (output port: 1)
The following is a snippet of the generated code and we can see that the inport "SWin1" is now mapped to a RTDB variable "in1" which is a part of the the cvtTable structure. There is no mention of the "Sine Wave" block as it has been optimized out during the code generation process.
/* Model output function */ static void testinports_output(int_T tid) { /* local block i/o variables */ real_T rtb_SWin1; /* M-S-Function: '<S1>/SWin1' */ /* M-S-Function Block: <S1>/SWin1 */ rtb_SWin1 = cvtTable.in1 ; /* Gain: '<S1>/Gain' */ testinports_B.Gain = testinports_P.Gain_Gain * rtb_SWin1; /* M-S-Function: '<Root>/SWScope' */ /* M-S-Function Block: <Root>/SWScope */ cvtTable.Scope = testinports_B.Gain; /* tid is required for a uniform function interface. * Argument tid is not used in the function. */ UNUSED_PARAMETER(tid); }