Data Type IDs
The Assignment of Data Type IDs
Each data type used in your S-function is assigned a data type ID. You should always use data type IDs to get and set information about data types in your S-function.
In general, the Simulink® software assigns data type IDs during model initialization on a “first come, first served” basis. For example, consider the generalized schema of a block diagram below.
The Simulink software assigns a data type ID for each output data type in the diagram in the order it is requested. For simplicity, assume that the order of request occurs from left to right. Therefore, the output of block A may be assigned data type ID 13, and the output of block B may be assigned data type ID 14. The output data type of block C is the same as that of block A, so the data type ID assigned to the output of block C is also 13. The output of block D is assigned data type ID 15.
Now if the blocks in the model are rearranged,
The Simulink software still assigns the data type IDs in the order in which they are used. Therefore each data type might end up with a different data type ID. The output of block A is still assigned data type ID 13. The output of block D is now next in line and is assigned data type ID 14. The output of block B is assigned data type ID 15. The output data type of block C is still the same as that of block A, so it is also assigned data type ID 13.
This table summarizes the two cases described above.
Block | Data Type ID in Model_1 | Data Type ID in Model_2 |
---|---|---|
A | 13 | 13 |
B | 14 | 15 |
C | 13 | 13 |
D | 15 | 14 |
This example illustrates that there is no strict relationship between the attributes of a data type and the value of its data type ID. In other words, the data type ID is not assigned based on the characteristics of the data type it is representing, but rather on when that data type is first needed.
Note
Because of the nature of the assignment of data type IDs, you should always use API functions to extract information from a data type ID about a data type in your S-function.
Registering Data Types
The functions in the following table are available in the API for user-written fixed-point S-functions for registering data types in simulation. Each of these functions will return a data type ID. To see an example of a function being used, go to the file and line indicated in the table.
Data Type Registration Functions
Function | Description | Example of Use |
---|---|---|
Register a fixed-point data type with binary-point-only scaling and return its data type ID | Line 248 | |
Register a fixed-point data type with [Slope Bias] scaling specified in terms of fractional slope, fixed exponent, and bias, and return its data type ID | Not Available | |
Register a scaled double data type with [Slope Bias] scaling specified in terms of fractional slope, fixed exponent, and bias, and return its data type ID | Not Available | |
Register a data type with [Slope Bias] scaling and return its data type ID | Line 324 |
Preassigned Data Type IDs
The Simulink software registers its built-in data types, and those data types always have preassigned data type IDs. The built-in data type IDs are given by the following tokens:
SS_DOUBLE
SS_SINGLE
SS_INT8
SS_UINT8
SS_INT16
SS_UINT16
SS_INT32
SS_UINT32
SS_BOOLEAN
You do not need to register these data types. If you attempt to register a built-in data type, the registration function simply returns the preassigned data type ID.
Setting and Getting Data Types
Data type IDs are used to specify the data types of input and output ports, run-time parameters, and DWork states. To set fixed-point data types for quantities in your S-function, the procedure is as follows:
Register a data type using one of the functions listed in the table Data Type Registration Functions. A data type ID is returned to you.
Alternately, you can use one of the preassigned data type IDs of the Simulink built-in data types.
Use the data type ID to set the data type for an input or output port, run-time parameter, or DWork state using one of the following functions:
To get the data type ID of an input or output port, run-time parameter, or DWork state, use one of the following functions:
Getting Information About Data Types
You can use data type IDs with functions to get information about the built-in and
registered data types in your S-function. The functions in the following tables are
available in the API for extracting information about registered data types. To see
an example of a function being used, go to the file and line indicated in the table.
Note that data type IDs can also be used with all the standard data type access
methods in simstruc.h
, such as ssGetDataTypeSize
.
Storage Container Information Functions
Function | Description | Example of Use |
---|---|---|
Return the word length of the storage container of a registered data type |
Line 116 | |
Return the storage container category of a registered data type | Line 290 | |
Return the storage container size of a registered data type |
Line 171 |
Signal Data Type Information Functions
Function | Description | Example of Use |
---|---|---|
Determine whether a fixed-point registered data type is signed or unsigned | Line 250 | |
Return the word length of a fixed-point registered data type | Line 251 | |
Determine whether a registered data type is a fixed-point data type | Line 128 | |
Determine whether a registered data type is a floating-point data type |
Line 108 | |
Determine whether a registered data type is supported by the API for user-written fixed-point S-functions | Line 183 | |
Determine whether a registered data type has power-of-two scaling | Line 202 | |
Determine whether the scaling of a registered data type is slope = 1, bias = 0 |
Line 104 |
Signal Scaling Information Functions
Function | Description | Example of Use |
---|---|---|
Return the bias of a registered data type | Line 243 | |
Return the exponent of the slope of a registered data type | Line 242 | |
Return the fractional slope of a registered data type | Line 239 | |
Return the fraction length of a registered data type with power-of-two scaling | Line 252 | |
Return the total slope of the scaling of a registered data type | Line 245 |
Converting Data Types
The functions in the following table allow you to convert values between registered data types in your fixed-point S-function.
Data Type Conversion Functions
Function | Description | Example of Use |
---|---|---|
Convert a value from one data type to another data type. | Not Available | |
Convert a value of data type | Not Available | |
Convert a value of any data type to a
| Not Available |