plcopen/instances_path.ysl2
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 12 Sep 2017 16:49:35 +0300
changeset 1800 1711339585ce
parent 1352 9ec4ac8e2955
child 1936 b85b13b1c2ec
permissions -rw-r--r--
make possible to turn off at compile time online debugging, logging
and external sync functionality

Defines TARGET_DEBUG_DISABLE, TARGET_LOGGING_DISABLE, TARGET_EXT_SYNC_DISABLE
allow to use generated PLC code in low-cost microcontrollers,
integrate into external programs and so on.

main.c:
extern void __run(void);
int main(void)
{
for(;;) {
__run();
// sleep common_ticktime__ ns
// add common_ticktime__ ns to __CURRENT_TIME
}
return 0;
}

Compile for example for arm bare-metal:
../build$ arm-none-eabi-gcc \
-DTARGET_DEBUG_DISABLE -DTARGET_LOGGER_DISABLE
-DTARGET_EXT_SYNC_DISABLE \
-flto -ffunction-sections -fdata-sections -I../../../../matiec/lib/C \
*.c \
-nodefaultlibs --specs=nano.specs -Wl,--static -Wl,--gc-section -Wl,--start-group -lc -lm -lnosys -lgcc -Wl,--end-group
include yslt.yml2
estylesheet xmlns:ppx="http://www.plcopen.org/xml/tc6_0201"
            xmlns:xhtml="http://www.w3.org/1999/xhtml"
            xmlns:ns="instances_ns" 
            extension-element-prefixes="ns" 
            exclude-result-prefixes="ns" {
    
    param "instance_type";
    
    template "text()";
    
    variable "project" {
        copy "document('project')/project/*";
    }
    
    variable "stdlib" {
        copy "document('stdlib')/stdlib/*";
    }
    variable "extensions" {
        copy "document('extensions')/extensions/*";
    }
    
    template "ppx:project" {
        instances {
            apply "ppx:instances/ppx:configurations/ppx:configuration";
        }
    }
    
    template "ppx:configuration" {
        apply "ppx:globalVars/ppx:variable[ppx:type/ppx:derived] | ppx:resource" {
            with "parent_path" > «@name»
        }
    }
    
    template "ppx:resource" {
        param "parent_path";
        variable "resource_path" > «$parent_path».«@name»
        apply "ppx:globalVars/ppx:variable[ppx:type/ppx:derived] | ppx:pouInstance | ppx:task/ppx:pouInstance" {
            with "parent_path" > «$resource_path»
        }
    }
    
    template "ppx:pouInstance" {
        param "parent_path";
        variable "pou_instance_path" > «$parent_path».«@name»
        choose {
            when "@typeName=$instance_type" {
                value "ns:AddInstance($pou_instance_path)";
            }
            otherwise {
                variable "type_name" > «@typeName»
                apply """exsl:node-set($project)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
                         exsl:node-set($project)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
                         exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
                         exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
                         exsl:node-set($extensions)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
                         exsl:node-set($extensions)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
                    with "instance_path" > «$pou_instance_path»
                }
            }
        }
    }
    
    template "ppx:pou" {
        param "instance_path";
        apply "ppx:interface/*/ppx:variable[ppx:type/ppx:derived]" {
            with "parent_path" > «$instance_path»
        }
    }
    
    template "ppx:dataType" {
        param "instance_path";
        apply "ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]" {
            with "parent_path" > «$instance_path»
        }
    }
    
    template "ppx:variable" {
        param "parent_path";
        variable "variable_path" > «$parent_path».«@name»
        apply "ppx:type/ppx:derived" {
            with "variable_path" > «$variable_path»
        }
    }
    
    template "ppx:derived" {
        param "variable_path";
        choose {
            when "@name=$instance_type" {
                value "ns:AddInstance($variable_path)";
            }
            otherwise {
                variable "type_name" > «@name»
                apply """exsl:node-set($project)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
                         exsl:node-set($project)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
                         exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
                         exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
                         exsl:node-set($extensions)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
                         exsl:node-set($extensions)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
                    with "instance_path" > «$variable_path»
                }
            }
        }
    }
    
    template "ppx:struct" {
        param "variable_path";
        foreach "ppx:variable[ppx:type/ppx:derived or ppx:type/ppx:struct or ppx:type/ppx:array]" {
            variable "element_path" > «$variable_path».«@name»
        }
        apply "ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]" {
            with "variable_path" > «$element_path»
        }
    }
    
    template "ppx:array" {
        param "variable_path";
        apply "ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]" {
            with "variable_path" > «$variable_path»
        }
    }
    
}