etherlab/plc_cia402node.c
changeset 2153 91c10856adaa
parent 2150 08514552944f
child 2154 6bbe93799956
equal deleted inserted replaced
2152:e6946c298a42 2153:91c10856adaa
    54 #define EnableOperation 0x0008
    54 #define EnableOperation 0x0008
    55 #define FaultReset      0x0080
    55 #define FaultReset      0x0080
    56 #define Halt            0x0100
    56 #define Halt            0x0100
    57 
    57 
    58 
    58 
    59 IEC_INT beremiz__IW%(location)s_0;
    59 IEC_INT beremiz__IW%(location_str)s_0;
    60 IEC_INT *__IW%(location)s_0 = &beremiz__IW%(location)s_0;
    60 IEC_INT *__IW%(location_str)s_0 = &beremiz__IW%(location_str)s_0;
    61 
    61 
    62 %(MCL_headers)s
    62 %(MCL_headers)s
    63 
    63 
    64 static IEC_BOOL __FirstTick = 1;
    64 static IEC_BOOL __FirstTick = 1;
    65 
    65 
    66 typedef struct {
    66 typedef struct {
    67 %(entry_variables)s
    67 %(entry_variables)s
    68     axis_s* axis;
    68     axis_s* axis;
    69 } __CIA402Node;
    69 } __CIA402Node;
    70 
    70 
    71 #define AxsPub __CIA402Node_%(location)s
    71 #define AxsPub __CIA402Node_%(location_str)s
    72 
    72 
    73 static __CIA402Node AxsPub;
    73 static __CIA402Node AxsPub;
    74 
    74 
    75 %(extern_located_variables_declaration)s
    75 %(extern_located_variables_declaration)s
    76 
    76 
    77 %(fieldbus_interface_declaration)s
    77 %(fieldbus_interface_declaration)s
    78 
    78 
    79 int __init_%(location)s()
    79 int __init_%(location_str)s()
    80 {
    80 {
    81     __FirstTick = 1;
    81     __FirstTick = 1;
    82 %(init_entry_variables)s
    82 %(init_entry_variables)s
    83 	*(AxsPub.ModesOfOperation) = 0x08;
    83 	*(AxsPub.ModesOfOperation) = 0x08;
    84     return 0;
    84     return 0;
    85 }
    85 }
    86 
    86 
    87 void __cleanup_%(location)s()
    87 void __cleanup_%(location_str)s()
    88 {
    88 {
    89 }
    89 }
    90 
    90 
    91 void __retrieve_%(location)s()
    91 void __retrieve_%(location_str)s()
    92 {
    92 {
    93 	if (__FirstTick) {
    93 	if (__FirstTick) {
    94 		*__IW%(location)s_0 = __MK_Alloc_AXIS_REF();
    94 		*__IW%(location_str)s_0 = __MK_Alloc_AXIS_REF();
    95 		AxsPub.axis = 
    95 		AxsPub.axis = 
    96             __MK_GetPublic_AXIS_REF(*__IW%(location)s_0);
    96             __MK_GetPublic_AXIS_REF(*__IW%(location_str)s_0);
    97 		AxsPub.axis->NetworkPosition = %(slave_pos)d;
    97 		AxsPub.axis->NetworkPosition = %(slave_pos)d;
    98 %(init_axis_params)s
    98 %(init_axis_params)s
    99 %(fieldbus_interface_definition)s
    99 %(fieldbus_interface_definition)s
   100 		__FirstTick = 0;
   100 		__FirstTick = 0;
   101 	}
   101 	}
   116 
   116 
   117 	// Extra variables retrieve
   117 	// Extra variables retrieve
   118 %(extra_variables_retrieve)s
   118 %(extra_variables_retrieve)s
   119 }
   119 }
   120 
   120 
   121 void __publish_%(location)s()
   121 void __publish_%(location_str)s()
   122 {
   122 {
   123 	IEC_BOOL power = 
   123 	IEC_BOOL power = 
   124         ((*(AxsPub.StatusWord) & SW_VoltageEnabled) != 0) 
   124         ((*(AxsPub.StatusWord) & SW_VoltageEnabled) != 0) 
   125         && AxsPub.axis->Power;
   125         && AxsPub.axis->Power;
   126     uint16_t CW = *(AxsPub.ControlWord);
   126     uint16_t CW = *(AxsPub.ControlWord);