Main Content

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

ssRegisterDataTypeFxpBinaryPoint

Register a fixed-point data type with binary-point-only scaling and return its data type ID

sfun_user_fxp_asr.c

Line 248

ssRegisterDataTypeFxpFSlopeFixExpBias

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

ssRegisterDataTypeFxpScaledDouble

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

ssRegisterDataTypeFxpSlopeBias

Register a data type with [Slope Bias] scaling and return its data type ID

sfun_user_fxp_dtprop.c

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:

  1. 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.

  2. 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

ssGetDataTypeFxpContainWordLen

Return the word length of the storage container of a registered data type

sfun_user_fxp_ContainWordLenProbe.c

Line 116

ssGetDataTypeStorageContainCat

Return the storage container category of a registered data type

sfun_user_fxp_asr.c

Line 290

ssGetDataTypeStorageContainerSize

Return the storage container size of a registered data type

sfun_user_fxp_StorageContainSizeProbe.c

Line 171

Signal Data Type Information Functions

Function

Description

Example of Use

ssGetDataTypeFxpIsSigned

Determine whether a fixed-point registered data type is signed or unsigned

sfun_user_fxp_asr.c

Line 250

ssGetDataTypeFxpWordLength

Return the word length of a fixed-point registered data type

sfun_user_fxp_asr.c

Line 251

ssGetDataTypeIsFixedPoint

Determine whether a registered data type is a fixed-point data type

sfun_user_fxp_const.c

Line 128

ssGetDataTypeIsFloatingPoint

Determine whether a registered data type is a floating-point data type

sfun_user_fxp_IsFloatingPointProbe.c

Line 108

ssGetDataTypeIsFxpFltApiCompat

Determine whether a registered data type is supported by the API for user-written fixed-point S-functions

sfun_user_fxp_asr.c

Line 183

ssGetDataTypeIsScalingPow2

Determine whether a registered data type has power-of-two scaling

sfun_user_fxp_asr.c

Line 202

ssGetDataTypeIsScalingTrivial

Determine whether the scaling of a registered data type is slope = 1, bias = 0

sfun_user_fxp_IsScalingTrivialProbe.c

Line 104

Signal Scaling Information Functions

Function

Description

Example of Use

ssGetDataTypeBias

Return the bias of a registered data type

sfun_user_fxp_dtprop.c

Line 243

ssGetDataTypeFixedExponent

Return the exponent of the slope of a registered data type

sfun_user_fxp_dtprop.c

Line 242

ssGetDataTypeFracSlope

Return the fractional slope of a registered data type

sfun_user_fxp_dtprop.c

Line 239

ssGetDataTypeFractionLength

Return the fraction length of a registered data type with power-of-two scaling

sfun_user_fxp_asr.c

Line 252

ssGetDataTypeTotalSlope

Return the total slope of the scaling of a registered data type

sfun_user_fxp_dtprop.c

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

ssFxpConvert

Convert a value from one data type to another data type.

Not Available

ssFxpConvertFromRealWorldValue

Convert a value of data type double to another data type.

Not Available

ssFxpConvertToRealWorldValue

Convert a value of any data type to a double.

Not Available