Skip to main content

Section: Toplevel

Modules which are located at the first level of the module tree are called toplevel modules. In contrast to other modules they have methods which can be called directly from one or several tasks. Toplevel modules contain the section Toplevel.

SEC Toplevel                                        //optional: yes, modifier: [UPDATE]
    GVL_Name := <GVL name>;                         //optional: yes, type: literal
    Default_Application := <default application>;   //optional: yes, type: QID
    Default_POUPool := <TRUE/FALSE>;                //optional: yes, type: BoolFlag
    Pragmas := [<pragma1>, <pragma2>,...];          //optional: yes, type: Pragmalist
    SEC Standard_Task : <task name>                 //optional: yes, modifier: [HIDE,UPDATE]
            Name := <task name>;                        //optional: no, type: ID
            Desc := <task description>;                 //(optional: no, type: Text)
            Flags:= <flag>;                             //(optional: no, type: StdTaskFlags)
    END_SEC
    SEC Custom_Task : <task name>                    //optional: yes, modifier: [UPDATE]
            Priority := <priority>;                     //optional: no, type: Subrange(0 .. 31)
            Interval :=  <interval>;                    //optional: no, type: TimeLiteral)
            Flags:= <flag>;                             //optional: no, type: CustomTaskFlags)
    END_SEC
END_SEC

Details regarding the syntax of definition types are described in the section Module Declaration.

. Specification:
  • GVL_Name defines the name of the GVL in which the instance of the module and all its subinstances will be declared. The placeholder %Instancename% (Upper or lower case spelling is not relevant), will be replaced by the instance name of the module instance.

  • The parameter Default_Application defines the application assignment for all instances of this module to a specific application. If a default application is defined the use of Default_POUPool is not possible.

  • The parameter Default_POUPool defines the application assignment for all instances of this module to POU pool. If a default POU pool is defined the use of Default_Application is not possible.

  • The parameter Pragmas contains a list of compiler pragmas, which will be inserted before the declaration of the FB instances of the module.

The section Standard_Task defines the tasks from which calls will be executed. For this three standard tasks are available: LOW, MEDIUM, and HIGH. The definitions of Standard_Task are:

  • Name: Default task name which will be defined as task assignment after creating the module instance.

  • Desc: Identifier for the task call. This should be short and meaningful (example: I/O task).

  • Flags: The following values can be combined with the | character:

    • CREATE_IF_MISSING: The task will be created if it does not exists.

    • READONLY: The task assignment is read only and the user cannot change it.

    • UPDATE_IOS: The task is used to update I/Os. Each I/O can be overwritten by the UpdateInTask parameter in the IO section.

    • NONE: No flag is set.

Example 17. Example
SEC Standard_Task : MEDIUM
        Name  := MainTask ;
        Desc  := TL.TaskMedium_Desc ;
        Flags := READONLY | CREATE_IF_MISSING ;
END_SEC


By use of the section Custom_Task a module can define one or more custom tasks. The target of the section must be the name of a method of the module function block. The method must not have arguments (neither INPUT, OUTPUT, nor INOUT).

  • Priority: Defines the task priority.

  • Interval: Defines the task interval (constant of data type "TIME" or "LTIME").

  • Flags: The following values can be combined with the | character:

    • SHARED: For compatibility reasons, this flag still exists, but is always implicitly assumed to be set. It basically would mean, that if a task with the properties specified in the Custom_Task section already exists, this task will be used. But because a new task will be created if there is no existing task with matching properties, this flag is rendered obsolete. The name of the created task is TASK_<ModuleInstanceName>_<MethodName>.

    • UPDATE_IOS: The task will be used for updating the I/Os, which are connected to ST expressions or directly to module I/Os.

    • NONE: No flag is set.

There is no default implementation in the module class for the specified method.

Example 18. Example
SEC Custom_Task : Method1
        Priority := 7 ;
        CycleTime := t#14ms ;
        Flags := NONE ;
END_SEC


Tip

Exactly one standard or specific task has to have the UPDATE_IOS flag set.

. Some basic rules, how the tasks are generated shall be mentioned here:
  • If standard tasks exist, which do not have the CREATE_IF_MISSING flag set, a task with the specified name and properties of the generator settings should exist. If the properties do not match the specified one a warning message is displayed.

  • If standard tasks exist, which has the CREATE_IF_MISSING flag set, first a task with specified properties is generated. Now, whenever the generator settings for this task are changed, the task is adapted, without any warning message.

  • Standard tasks of different types that reference the same task name are not allowed. In this case, an error is not issued.

Depending on the configured standard the following methods are called at the beginning and at the end of the defined task for each toplevel instance:

METHOD CallPrioHighStart: BOOL
METHOD CallPrioHighEnd: BOOL
METHOD CallPrioMediumStart: BOOL
METHOD CallPrioMediumEnd: BOOL
METHOD CallPrioLowStart: BOOL
METHOD CallPrioLowEnd: BOOL

Each module is responsible to call its submodule instances. Submodule references must not be called. The default implementation in the FB Module calls the respective methods of all submodule instances in the order of their position in the module tree.

Tip

The SUPER pointer offers access to the instance of the base function block. Therefore for example the call SUPER^.CallPrioHighStart() can be used to call the method Module.CallPrioHighStart() if the function block extends Module. This way, the implementation in Module will make sure that all submodules are called.