author | laurent |
Sun, 11 Mar 2012 21:53:35 +0100 | |
changeset 2039 | 3a218f6bd805 |
parent 2036 | 7c31fab22c74 |
child 2041 | ce3727171207 |
permissions | -rw-r--r-- |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
1 |
/* |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
2 |
* Ethercat DS402 node execution code |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
3 |
* |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
4 |
* */ |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
5 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
6 |
#include "ecrt.h" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
7 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
8 |
#ifdef _WINDOWS_H |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
9 |
#include "iec_types.h" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
10 |
#else |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
11 |
#include "iec_std_lib.h" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
12 |
#endif |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
13 |
|
2034 | 14 |
IEC_INT beremiz__IW%(location)s_0; |
15 |
IEC_INT *__IW%(location)s_0 = &beremiz__IW%(location)s_0; |
|
16 |
||
17 |
%(MCL_headers)s |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
18 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
19 |
IEC_UINT __InactiveMask = 0x4f; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
20 |
IEC_UINT __ActiveMask = 0x6f; |
2034 | 21 |
IEC_UINT __PowerMask = 0x10; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
22 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
23 |
typedef enum { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
24 |
__Unknown, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
25 |
__NotReadyToSwitchOn, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
26 |
__SwitchOnDisabled, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
27 |
__ReadyToSwitchOn, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
28 |
__SwitchedOn, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
29 |
__OperationEnabled, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
30 |
__QuickStopActive, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
31 |
__FaultReactionActive, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
32 |
__Fault, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
33 |
} __DS402NodeState; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
34 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
35 |
typedef struct { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
36 |
%(entry_variables)s |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
37 |
__DS402NodeState state; |
2034 | 38 |
axis_s* axis; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
39 |
} __DS402Node; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
40 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
41 |
static __DS402Node __DS402Node_%(location)s; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
42 |
|
2034 | 43 |
%(extern_located_variables_declaration)s |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
44 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
45 |
int __init_%(location)s() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
46 |
{ |
2034 | 47 |
%(init_entry_variables)s; |
48 |
*__IW%(location)s_0 = __MK_AllocAxis(&(__DS402Node_%(location)s.axis)); |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
49 |
return 0; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
50 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
51 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
52 |
void __cleanup_%(location)s() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
53 |
{ |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
54 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
55 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
56 |
void __retrieve_%(location)s() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
57 |
{ |
2034 | 58 |
IEC_UINT statusword_inactive = *(__DS402Node_%(location)s.StatusWord) & __InactiveMask; |
59 |
IEC_UINT statusword_active = *(__DS402Node_%(location)s.StatusWord) & __ActiveMask; |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
60 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
61 |
// DS402 node state computation |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
62 |
__DS402Node_%(location)s.state = __Unknown; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
63 |
switch (statusword_inactive) { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
64 |
case 0x00: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
65 |
__DS402Node_%(location)s.state = __NotReadyToSwitchOn; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
66 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
67 |
case 0x40: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
68 |
__DS402Node_%(location)s.state = __SwitchOnDisabled; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
69 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
70 |
case 0x0f: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
71 |
__DS402Node_%(location)s.state = __FaultReactionActive; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
72 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
73 |
case 0x08: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
74 |
__DS402Node_%(location)s.state = __Fault; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
75 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
76 |
default: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
77 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
78 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
79 |
switch (statusword_active) { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
80 |
case 0x21: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
81 |
__DS402Node_%(location)s.state = __ReadyToSwitchOn; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
82 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
83 |
case 0x23: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
84 |
__DS402Node_%(location)s.state = __SwitchedOn; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
85 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
86 |
case 0x27: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
87 |
__DS402Node_%(location)s.state = __OperationEnabled; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
88 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
89 |
case 0x07: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
90 |
__DS402Node_%(location)s.state = __QuickStopActive; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
91 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
92 |
default: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
93 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
94 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
95 |
if (__DS402Node_%(location)s.state == __Unknown) { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
96 |
return; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
97 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
98 |
|
2035 | 99 |
__DS402Node_%(location)s.axis->PowerFeedback = __DS402Node_%(location)s.state == __OperationEnabled; |
2034 | 100 |
__DS402Node_%(location)s.axis->ActualPosition = (IEC_REAL)(*(__DS402Node_%(location)s.ActualPosition)) * __DS402Node_%(location)s.axis->RatioDenominator / __DS402Node_%(location)s.axis->RatioNumerator; |
101 |
||
102 |
__MK_UpdateAxis(*__IW%(location)s_0); |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
103 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
104 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
105 |
void __publish_%(location)s() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
106 |
{ |
2034 | 107 |
__MK_ComputeAxis(*__IW%(location)s_0); |
108 |
||
109 |
IEC_BOOL power = ((*(__DS402Node_%(location)s.StatusWord) & __PowerMask) > 0) && __DS402Node_%(location)s.axis->Power; |
|
110 |
||
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
111 |
// DS402 node state transition computation |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
112 |
switch (__DS402Node_%(location)s.state) { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
113 |
case __SwitchOnDisabled: |
2034 | 114 |
*(__DS402Node_%(location)s.ControlWord) = (*(__DS402Node_%(location)s.ControlWord) & ~0x87) | 0x06; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
115 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
116 |
case __ReadyToSwitchOn: |
2034 | 117 |
case __OperationEnabled: |
118 |
if (!power) { |
|
119 |
*(__DS402Node_%(location)s.ControlWord) = (*(__DS402Node_%(location)s.ControlWord) & ~0x8f) | 0x07; |
|
120 |
break; |
|
121 |
} |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
122 |
case __SwitchedOn: |
2034 | 123 |
if (power) { |
124 |
*(__DS402Node_%(location)s.ControlWord) = (*(__DS402Node_%(location)s.ControlWord) & ~0x8f) | 0x0f; |
|
125 |
} |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
126 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
127 |
case __Fault: |
2034 | 128 |
*(__DS402Node_%(location)s.ControlWord) = (*(__DS402Node_%(location)s.ControlWord) & ~0x8f) | 0x80; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
129 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
130 |
default: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
131 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
132 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
133 |
|
2036
7c31fab22c74
Adding support for setting TargetPosition only if PositionSetPoint value from MCL is valid
laurent
parents:
2035
diff
changeset
|
134 |
if (__DS402Node_%(location)s.axis->CSP && *(__DS402Node_%(location)s.ModesOfOperationDisplay) == 0x08) { |
7c31fab22c74
Adding support for setting TargetPosition only if PositionSetPoint value from MCL is valid
laurent
parents:
2035
diff
changeset
|
135 |
*(__DS402Node_%(location)s.TargetPosition) = (IEC_DINT)(__DS402Node_%(location)s.axis->PositionSetPoint * __DS402Node_%(location)s.axis->RatioNumerator / __DS402Node_%(location)s.axis->RatioDenominator); |
7c31fab22c74
Adding support for setting TargetPosition only if PositionSetPoint value from MCL is valid
laurent
parents:
2035
diff
changeset
|
136 |
} |
7c31fab22c74
Adding support for setting TargetPosition only if PositionSetPoint value from MCL is valid
laurent
parents:
2035
diff
changeset
|
137 |
else { |
7c31fab22c74
Adding support for setting TargetPosition only if PositionSetPoint value from MCL is valid
laurent
parents:
2035
diff
changeset
|
138 |
*(__DS402Node_%(location)s.TargetPosition) = *(__DS402Node_%(location)s.ActualPosition); |
7c31fab22c74
Adding support for setting TargetPosition only if PositionSetPoint value from MCL is valid
laurent
parents:
2035
diff
changeset
|
139 |
} |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
140 |
} |