The MIL Function Development module allows you to associate a MIL identifier with an object so that this object can be treated as a standard MIL object. Use the MfuncAllocId() function to associate a MIL identifier with any array or custom data structure. Defining your own user-defined MIL objects allows you to create data objects whose exact internal structure has specific requirements and whose data members should not be accessed directly. Once you have associated the user-defined object with a MIL identifier, it is known as a user-defined MIL object, and it will be subject to error checking and tracing as any other MIL object.
Typically, you would create user-defined MIL objects in a user-defined MIL function. In this case, it is recommended that you create a user-defined MIL function whose sole purpose is to allocate the user-defined object and associate it with a MIL identifier. That is, the slave function of the user-defined MIL function only declares the object and associates it with a MIL identifier. This type of function is called a user-defined MIL allocation function. User-defined MIL allocation functions should be allocated using MfuncAlloc() with M_ALLOC.
It is recommended that you register a MIL system identifier as a parameter of your user-defined MIL allocation function (MfuncParamMilId() with MilObjectType set to M_SYSTEM); this allows you to easily control which system your function will be executed on at runtime, and, by extension, on which system your user-defined object will be allocated. The MIL identifier associated with your newly allocated user-defined object can be retrieved by having your allocation function return it, or by storing it in a pointer parameter of type MIL_ID (MfuncParamArrayMilId()).
Note that user-defined objects stored in the memory of a remote processor are not accessible from the Host processor, and vice versa, unless they are stored in shared memory.
To refer to user-defined MIL objects, use their MIL identifiers. To refer to the actual data grouped in this user-defined MIL object, use a pointer to the object. You can retrieve the address of the object using the MfuncInquire() function with M_OBJECT_PTR.
For example, for an object with this structure:
/* Define the user-defined object's structure */
struct MyStruct {
int MyData1;
int MyData2;
int MyData3;
};
The following portion of MIL code shows how to allocate a custom object and associate it with a MIL identifier; this type of code would typically be found in a user-defined allocation function.
MIL_ID MyObjectId;
struct MyStruct MyObject = { 0 , 0 , 0 };
MyObjectId = MfuncAllocId( M_DEFAULT, M_USER_OBJECT_1+0x0001, &MyObject );
The following portion of MIL code shows how to retrieve the address of the user-defined MIL object, allocated above, and use it to store data using a pointer; this type of code would typically be found in a user-defined MIL processing function which accepts the MIL object as a parameter.
struct MyStruct *MyObjectPtr = M_NULL;
int Result1 = 0;
int Result2 = 0;
int Result3 = 0;
MfuncInquire( MyObjectId, M_OBJECT_PTR, &MyObjectPtr );
/* Perform the calculations */
/* Result1 = ... */
/* Result2 = ... */
/* Result3 = ... */
/* The user-defined object's data can now be accessed using the pointer
retrieved by MfuncInquire */
MyObjectPtr->MyData1 = Result1 ;
MyObjectPtr->MyData2 = Result2 ;
MyObjectPtr->MyData3 = Result3 ;
When creating a user-defined MIL object, you must specify the MIL type of your object. MIL provides two object type groups (M_USER_OBJECT_1 and M_USER_OBJECT_2), permitting you to distinguish between categories of custom created objects. Each user-defined object group can contain up to 16 user-defined object types (M_USER_OBJECT_n + m , where n is 1 or 2, and m specifies the offset within the group).
To inquire about the type of a user-defined MIL object, use the MobjInquire() function with M_OBJECT_TYPE.
Once you have finished using a user-defined MIL object, you must free the MIL identifier associated with this object, using the MfuncFreeId() function. Note that you need not free the MIL identifier in the same function where it was associated with the object (MfuncAllocId()). It is recommended that you create a user-defined MIL function whose sole purpose is to free the user-defined object and its MIL identifier. This type of function should be allocated using MfuncAlloc() with M_FREE, and must accept the MIL identifier to be freed as its only parameter.