Return to previous page | Return to menu | Go to next page


10-4. Expansion of user area

When writing a program using event processing, the variable group (structure) used by the function executed as an event may not fit in the user area (112 bytes) of the event.
In such a case, SGL can be used by expanding the user area.
There are two ways to expand the user area: a method that uses a dedicated extension area called work, and a method that acquires an extended area of ​​the same size as the EVENT structure from the event RAM area.

Extension of user area using work area

In SGL, the user area extension dedicated area called work can be used, and the user area of ​​the EVENT structure can be extended.
The work is defined as a WORK structure (64 bytes) in the work RAM area, and up to 256 works can be used.
The size of the user area that can be expanded per work is 60 bytes.
The remaining 4 bytes of the WORK structure are used for addressing the linked WORK structures.

Figure 10-12 WORK structure

The members of the WORK structure are as follows.

* next: The start address of the WORK structure to be linked as a chain structure.
If there is no subsequent work as a chain structure, NULL is assigned.
user []: Extended user area (60 bytes).

The work acquired as the WORK structure is linked by substituting the start address of the WORK structure for “* work” in the EVENT structure to form a chain structure.
In addition, the user can further expand the user area by acquiring the work again in the WORK structure. At this time, the work to be linked can be made into a chain structure by substituting the start address of the WORK structure to be linked to “* next” in the WORK structure.
When there is no WORK structure that follows as a chain structure, NULL is assigned to “* next”.

Figure 10-13 Work connection

To use work in SGL, use library functions “slGetWork” and “slReturnWork”. “SlGetWork” is used to acquire a work, and “slReturnWork” is used to release a work.

[WORK * slGetWork (void);]
Allocate a WORK structure (64 bytes) in the work RAM area.
The function “slGetWork” returns the WORK structure address value of the secured work area as a return value. If space allocation fails, the function returns NULL.
[void slReturnWork (WORK * wkptr);] Returns / releases the work area specified by the
parameter. For the parameter, substitute the WORK structure address value of the work area to be returned. Also, when returning or releasing a part of the work connected with the chain structure to the system, adjust the remaining work so that the chain structure is correct. If adjustment is not performed, the chain structure and work processing may not be consistent, and the worst CPU may stop (see “10-5: Notes on event processing” for details).

About the operation of the linked WORK structure by releasing the EVENT structure

The work does not necessarily need to form a chain structure using "* work" and "* next", and the start address of the WORK structure to be linked can be stored in the user area.
However, the work connected by “* work” and “* next” is also released / released to the system at the same time by releasing the event, but the work connected from the user area releases the event. Even release of the WORK structure is not performed.
For this reason, the WORK structure linked from the user area must be returned to the system and released with the library function “slReturnWork” when the event is released.

Extension of user area using event area

If the size of one user area to be expanded is insufficient for the WORK structure (60 bytes), a user area of ​​the same size (128 bytes) as the EVENT structure can be secured from the event RAM area.
However, since the area allocated for one event is originally used as the user area, the maximum number of events that can be registered is reduced accordingly.

Figure 10-14 Expansion of user area using event RAM area

Use the library functions “slGetEvent” and “slReturnEvent” to extend the user area of ​​the EVENT structure using the event RAM area in SGL. “SlGetEvent” is used to secure the user area, and “slReturnEvent” is used to release the user area.

[EVENT * slGetEvent (void);]
The RAM area of ​​the same size (128 bytes) as the event is taken out from the event RAM area and used as the user area. Also, since the area allocated for the EVENT structure is used as the user area, the number of events that can be registered is reduced accordingly.
The function “slGetEvent” returns the start address of the allocated RAM area as a return value.
If space allocation fails, the function returns NULL.
[void slReturnEvent (EVENT * evptr);] The event RAM area specified by the
parameter is returned to the system and released.
For the parameter, substitute the start address of the RAM area to be returned.
The function “slReturnEvent” does not check whether the area to return is an extended user area. Therefore, even if the EVENT structure registered as an event by mistake is returned to the system, it is not understood. In this case, since various troubles occur, it is considered that the CPU stops in the worst case