![]() |
![]() |
![]() |
![]() |
![]() |
Abstract Data Types
In this section the specialities and exceptions about abstract data types for Cmicro are discussed only. A complete documentation about the abstract data types is given in The Cadvanced/Cbasic SDL to C Compiler.
General C Definitions
All the macros and external definitions for functions can be found in the file sctpred.h except for the PId sort which is handled in the file ml_typ.h.
The C functions for the handling of predefined sorts are defined in the file sctpred.c.
On UNIX these files can be found in $sdtdir/cmicro/kernel.
In Windows these files can be found in the installation under %SDTDIR%\cmicro\kernel.
Exceptions for SDL Predefined Types
A general exception existing for all the predefined types is that the user must configure which predefined types are to be compiled into the target C program. This is necessary to hold the target C program as small as possible. The configuration is to be performed with the help of the Targeting Expert, please view Configure and Scale the Target Library.
Problems will occur during compilation when the configuration is not according to what the SDL system needs. The user should refer to the explanations about manual scaling in The Cmicro Library.
External Synonyms
External synonyms are to be defined by the user in the following way.
synonym xternal integer = EXTERNAL;Cmicro expects to see xternal as a #define value that is to be defined by the user. This can be done for example in the following way:
synonym xternal integer = EXTERNAL;/*#CODE#TYPE#ifdef XSCT_CMICRO#define xternal 7#endif*/This also means, that if xternal is not defined from the user, it will lead to compilation errors.
Charstring
Charstrings can be used either in the usual way as they are when using Cadvanced, or they can be used in a restricted way. The decision is up to the user and is a question of configuration. The user should be aware that some of the predefined sorts from ASN.1 are based on the implementation of SDL charstrings. This is discussed in subsection Support of SDL Constructs.
Time/Duration
The predefined data types Time and Duration are implemented in a more or less restrictive way. It is possible to specify a real value for Time and Duration on SDL level, like 23.45. The Cmicro Library uses only the integer part in front of the dot, 23 in this example. The mapping of SDL time units to time units in a target application is - in any case - up to the user.
UnionC
The #UNIONC directive is not recommended when using the Cmicro SDL to C Compiler because there is no support for checking the validity of the component selection. Both the #UNION directive and the CHOICE concept are a better alternative.
Predefined Generators Array, String, Powerset, Bag, Ref
These generators are implemented in Cmicro, but the user should be aware that the use of any of them requires that dynamic memory allocation is used in the target system. Generally, Cmicro tries to prevent the use of dynamic memory allocation whenever possible. The reasons for this are explained in The Cmicro Library.
ctypes.sdl
This package can be used together with Cmicro with the following restriction.
There are two operators that are excluded when Cmicro C code is compiled. The operators are "CStar2CString" and "CharStar".
The reason for this is that with Cmicro it is possible to define an array of char in C instead of the predefined solution of Cadvanced (to use dynamic memory allocation). This is discussed in subsection Support of SDL Constructs.
byte.pr
This ADT can be used together with Cmicro in the same way as described for Cadvanced.
file.pr
This ADT is not useful for typical Cmicro applications (embedded systems usually do not provide a hard disk in Cmicro applications) and for that reason never has been tested. The ADT may however work with Cmicro.
idnode.pr
This ADT cannot be used together with Cmicro because it refers to Cadvanced code.
list1/list2.pr
This ADT cannot be used together with Cmicro because it refers to Cadvanced code.
long_int.pr
This ADT can be used together with Cmicro.
pidlist.pr
This ADT cannot be used together with Cmicro, generally.
Instead of pidlist.pr, the user may include the cm_pidlist.pr file. The use of this ADT is however restricted, because Cmicro implements a different scheduling algorithm. This means, that systems that are successfully simulated first, may contain problems when a Cmicro target application is build and executed.
It is therefore recommended not to use neither pidlist.pr nor cm_pidlist.pr, in order to achieve the best possible SDL conformity.
random.pr
This ADT cannot be used together with Cmicro because it refers to Cadvanced code.
unsigned.pr
This ADT can be used together with Cmicro.
unsigned_long.pr
This ADT can be used together with Cmicro.
Default Values
Default values are in principle generated in the same way as with the Cadvanced SDL to C Compiler. It is however possible to configure the default value setting, which is explained in The Cmicro Library. The right configuration is essential to prevent illegal behavior.
Exceptions for Implementations of Operators
Read and Write Functions
The Cmicro SDL to C Compiler does not provide read and write functions. The reason is, that the Cmicro SDL to C Compiler mainly is used to build target applications, and not simulations. This is also a consequence of optimizing the target program. If the user uses the Q (question) operator, the Cmicro SDL to C Compiler ignores this.
Error Situations in Operators
In the C function used to implement operators (and literals), it is possible to define error situations and handle them as ordinary SDL run-time errors. The C library function ErrorHandler, with the following prototype
extern void ErrorHandler( xmk_OPT_INT errnum )
can be used for this purpose. xmk_OPT_INT is defined in ml_typ.h, normally as an ordinary C int. errnum may be one of the free values of error numbers. Please inspect ml_err.h in order to get a list of reserved values.
Example 578 : Error Handler in Operator
if ( strlen(C) <= 1 ) {#ifdef XMK_USE_ERR_CHECKErrorHandler (ERR_N_InvalidStringLength);#endifreturn SDL_NUL;} elsereturn C[1];This is a simplified version of the test in the function for the operator First in the sort Charstring. Here the error situation is when we try to access the first character in a charstring of length 0. In this case the C function ErrorHandler is called and a default value is returned (NULL). By including the call to ErrorHandler between #ifdef XMK_USE_ERR_CHECK - #endif the function is only called to report the error, if error checks are turned on. The one parameter to the C function ErrorHandler should identify the error. The number must be given by the user.
Another possibility to route error messages to the host system is to use the C function xmk_PrintString of the SDL Target Tester, defined as:
extern void xmk_PrintString( char * )Example 579 : Error Handler in Operator
if ( strlen(C) <= 1 ) {#ifdef XMK_ADD_MICRO_TESTERxmk_PrintString ("ERR:Invalid Stringlength");#endifreturn SDL_NUL;} elsereturn C[1];Access to Predefined Sorts based on Charstring
As already mentioned in earlier subsections, the user should be aware that some of the ASN.1 predefined sorts are based on the implementation of SDL charstrings. The user should also refer to subsection Support of SDL Constructs.
To avoid problems one should be aware that Charstring is implemented as char * in C and take the consequences thereof. There are a number of help functions (that implement the operators for the Charstring sort) supplied in the run-time library that might be helpful when handling Charstrings.
It is usually necessary to allocate dynamic memory when an operator returning a charstring value is implemented. There are two help functions that should be used in connection with allocation and de-allocation of dynamic memory. These are documented in Dynamic Memory Allocation.
http://www.ibm.com/rational |
![]() |
![]() |
![]() |
![]() |