Hi
Mikhail's instructions on registering a 64 bit integer type are spot-on. Nice job!
Starting in R2017a, 64 bit integers in Simulink do NOT require a Fixed-Point Designer license or install.
In R2020a, there are a few new APIs in fixedpoint.h for integers.
ssRegisterDataTypeInteger /* A wee tiny bit simpler than what Mikhail showed.*/
ssGetDataTypeIsInteger
ssGetDataTypeIsSpecifiedInteger
The header listings are given below.
Note, this header is installed with Simulink even if Fixed-Point Designer is not installed.
Using these APIs with types equivalent to built-in types does not require a Fixed-Point Designer license (since R2017a).
The latter API can be used to dispatch code based on integer type.
For example,
if (ssGetDataTypeIsSpecifiedInteger(S,dataTypeID,0,8)) {
/* handle 8 bit unsigned integers */
...
}
else if (ssGetDataTypeIsSpecifiedInteger(S,dataTypeID,0,64)) {
/* handle 64 bit unsigned integers */
...
}
else if (ssGetDataTypeIsSpecifiedInteger(S,dataTypeID,0,64)) {
/* handle 64 bit Signed integers */
}
Regarding Simulink's set of statically define type SS_ enums like SS_UINT8.
For a variety of reasons, MathWorks is not currently planning to extend this set of statically defined enums to 64 bit integers, to half-precision floating-point, or to other future types. Please give the API above a try and let us know your feedback.
If using the new API's is not a satisfactory, we'd be happy to better understand your needs and the level of priority.
Regards
Andy Bartlett
-----------------------------------------------------------
Excerpts from fixedpoint.h header
-----------------------------------------------------------
/* Function: ssRegisterDataTypeInteger ===============================
*
* This function fully registers any integer data type with Simulink and
* returns a Data Type Id. Supported types are
* Unsigned with wordlength 1 up to 128
* Signed with wordlength 2 up to 128
*
* This function is available for any Simulink install, even if
* Fixed-Point Designer is not installed.
* If the registered wordlength of the integer is 8, 16, 32, or 64,
* then a Simulink license is sufficient.
* For any of the other 124 possible wordlengths,
* a Fixed-Point Designer license is required.
*
*
* Unlike the standard Simulink function, ssRegisterDataType, additional
* registration steps do not need to be taken
* and should not be taken. The returned Data Type Id can be used to specify
* the data types of input ports, output ports, RunTimeParameters, and DWork
* states. The Data Type Id can also be used with all the standard
* data type access methods in simstruc.h such as ssGetDataTypeSize.
*
* The input arguments are
* isSigned TRUE if signed, FALSE if unsigned
* wordLength total number of bits including any sign bit
* obeyDataTypeOverride if FALSE ignore system's setting for Data Type Override
* if TRUE obey Data Type Override setting, depending
* on Data Type Override, resulting data type could be
* True Double, True Single, Scaled Double, or the
* requested fixed point type.
*
* Cautions:
*
* 1) If the registered data type is not one of the builtin data types, then
* a Fixed-Point License will be checked out. To prevent, a Fixed-Point
* License from being checked out when a user simply opens or views a model,
* calls to registration should be protected with
* if ( ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY )
* ssRegisterDataType ...
*
* 2) In general, there is no fixed relationship between the Data Type Id value
* and the input arguments. Simulink hands out data type Ids on a first come,
* first served basis, so small changes to a model can cause a different data
* type id value to be returned. Always use functions to get data type
* attributes from the data type id; never directly rely on the data type
* id value.
*/
FIXPOINT_EXPORT_EXTERN_C DTypeId ssRegisterDataTypeInteger(
SimStruct *S,
int isSigned,
int wordLength,
int obeyDataTypeOverride
);
/* Function: ssGetDataTypeIsInteger
*
* Giving a registered Data Type Id, determine the if the data
* type is one of 255 integer types supported by Simulink.
* Unsigned with wordlength 1 up to 128
* Signed with wordlength 2 up to 128
*/
FIXPOINT_EXPORT_EXTERN_C int ssGetDataTypeIsInteger(
SimStruct *S,
DTypeId dataTypeId
);
/* Function: ssGetDataTypeIsSpecifiedInteger
*
* Giving a registered Data Type Id, determine
* if the data type is an integer with the specified
* signedness and wordlength.
*/
FIXPOINT_EXPORT_EXTERN_C int ssGetDataTypeIsSpecifiedInteger(
SimStruct *S,
DTypeId dataTypeId,
int isSigned,
int wordLength
);
0 Comments
Sign in to comment.