Difference between revisions of "Matlab/Simulink files"

From OpenMBD
Jump to: navigation, search
(sfcn_signal_tower.m)
Line 13: Line 13:
 
<br>
 
<br>
 
The S-function requires two dialog parameters:
 
The S-function requires two dialog parameters:
*The selected hardware target, which in this example will always be the Olimexino STM32
+
*The selected hardware target, which in this example project will always be the Olimexino STM32
 
*The selected SPI channel.
 
*The selected SPI channel.
These are set by:<br>
+
This number of parameters is set by the following line of code:<br>
 
'''block.NumDialogPrms = 2;'''
 
'''block.NumDialogPrms = 2;'''
  
 
== sfcn_signal_tower_chk.m ==
 
== sfcn_signal_tower_chk.m ==
'''File location: ./blockset/toolbox/STM32/blocks/sfcn_signal_tower_chk.m'''<br>
+
'''File location: .\blockset\toolbox\STM32\blocks\sfcn_signal_tower_chk.m'''<br>
Each layer of the signal tower requires three input ports: one for each RGB color.<br>
+
The Olimexino STM32 features two SPI channels. This function checks if there more than two signal tower blocks in the model and will generate an error message.<br>
 +
 
 +
== sfcn_signal_tower_mcb.m ==
 +
'''File location: .\blockset\toolbox\STM32\blocks\sfcn_signal_tower_mcb.m'''<br>
 +
<br>
 +
 
 +
== sfcn_signal_tower.tlc ==
 +
'''File location: .\blockset\toolbox\STM32\blocks\tlc_csfcn_signal_tower.tlc'''<br>
 +
<br>

Revision as of 14:06, 28 February 2019

Creating a custom S-function block requires the addition of four files to the MatLAB/Simulink project.

  • sfcn_<name>.m: A function written in MatLAB code describing the S-function block's basic characteristics, such as the number of input ports and the umber of dialog parameters.
  • sfcn_<name>_chk.m: A function written in MatLAB code for checking prerequisites and/or dependencies of using the block, such as that only a single block might be present in the model.
  • sfcn_<name>_mcb.m: A function written in MatLAB code that is used for setting up the block's customized parameters. This arguments of the function are the actual parameters. The return value is an human readable information string.
  • sfcn_<name>.tlc: A function written in both MatLAB code and C-code, that can be seen as a transfer layer between the block's settings, input ports, output ports and the C-code.

sfcn_signal_tower.m

File location: ./blockset/toolbox/STM32/blocks/sfcn_signal_tower.m
Each layer of the signal tower requires three input ports: one for each RGB color.
As there are four layers, a total of twelve input ports are created in the setup function.
Notice that the DataTtypeID of each port is set to 3, which means that the ports requires data of type uint8_T.
The range of a uint8_T variable is 0-255.

The S-function requires two dialog parameters:

  • The selected hardware target, which in this example project will always be the Olimexino STM32
  • The selected SPI channel.

This number of parameters is set by the following line of code:
block.NumDialogPrms = 2;

sfcn_signal_tower_chk.m

File location: .\blockset\toolbox\STM32\blocks\sfcn_signal_tower_chk.m
The Olimexino STM32 features two SPI channels. This function checks if there more than two signal tower blocks in the model and will generate an error message.

sfcn_signal_tower_mcb.m

File location: .\blockset\toolbox\STM32\blocks\sfcn_signal_tower_mcb.m

sfcn_signal_tower.tlc

File location: .\blockset\toolbox\STM32\blocks\tlc_csfcn_signal_tower.tlc