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


10-2. Event processing using SGL functions

Here, we will explain the actual event processing using SGL library functions.

Initialize event

In order to use event processing in SGL, it is necessary to first initialize the buffer and event list related to the event.

Use the library function "slInitEvent" to execute event initialization in SGL.

[void slInitEvent (void);]
Performs all initialization related to event processing (event list, buffer initialization, etc.).

Caution
If event processing is used without initializing the event, it will not be consistent with the uninitialized buffer or event list, and in the worst case, the CPU may stop. (For details, refer to “10-5: Notes on event processing”).

Create event list

To perform event processing, events must be registered as an event list in the order of execution.
Events are added to the event list by the event registration library function “slSetEvent” as shown in Figure 10-4.
The registered events are sequentially registered at the end of the event list, and are executed in order from the top of the event list by the event execution library function “slExecuteEvent”.

Figure 10-4 Create event list

Use the library function “slSetEvent” to register an event.

[EVENT * slSetEvent (void (* func) ());]
Reserves an EVENT structure (128 bytes) in the event RAM area, and adds and registers new events at the end of the event list. For the parameter, substitute the execution address value of the event to be registered.
The function “slSetEvent” returns the start address of the registered EVENT structure as a return value. If event registration fails, NULL is returned.

See the next section for the event format and structure.

Event format

The function group to be registered as an event must take the format shown in Figure 10-5.

Figure 10-5 Event format

Events registered and executed are managed by the EVENT structure.
In the EVENT structure, the execution address of the event to be registered and the structure for variables used in the event are stored, and these two are used to manage the event.

Figure 10-6 Event structure

-Functions registered as events are controlled by the EVENT structure.
-Member "* exad ()" contains the execution address of the registered event,
Member “user []” stores the structure used in the event.
The structure is used for variables in the event, but
Note that the structure does not exceed the user area (size: 112 bytes).
If you want to use more variables, use
Extend the user area using the WORK structure etc.
Please make sure that the structure itself is also stored separately.

About structures for variables in events

When using various variables in an event, the variables must be defined as a structure.
For this reason, the structure for event variables cannot be set exceeding the size of the user area where the structure is stored (112 bytes).

Event execution

Events registered in the event list are executed in order by the event management function.
The library function “slExecuteEvent” is used to execute the event.

For example, when event A, event B, and event C are registered in the event list in order using the library function “slSetEvent”, each event is executed according to the event list in the order shown below.

Figure 10-7 Event execution

[void slExecuteEvent (void);]
The events registered in the event list are executed in the order of the list.

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