54 #------------------------------------------------------------------------------ |
54 #------------------------------------------------------------------------------ |
55 |
55 |
56 ETHERCAT_CONFIG=/etc/sysconfig/ethercat |
56 ETHERCAT_CONFIG=/etc/sysconfig/ethercat |
57 |
57 |
58 if [ ! -r ${ETHERCAT_CONFIG} ]; then |
58 if [ ! -r ${ETHERCAT_CONFIG} ]; then |
59 echo "${ETHERCAT_CONFIG} not existing"; |
59 echo ${ETHERCAT_CONFIG} not existing; |
60 if [ "${1}" = "stop" ]; then |
60 if [ "${1}" = "stop" ]; then |
61 exit 0 |
61 exit 0 |
62 else |
62 else |
63 exit 6 |
63 exit 6 |
64 fi |
64 fi |
109 BACKUPS=${BACKUPS}${DEVICE_ID} |
109 BACKUPS=${BACKUPS}${DEVICE_ID} |
110 |
110 |
111 MASTER_INDEX=$(expr ${MASTER_INDEX} + 1) |
111 MASTER_INDEX=$(expr ${MASTER_INDEX} + 1) |
112 done |
112 done |
113 |
113 |
114 # unload conflicting modules at first |
|
115 for MODULE in 8139too; do |
|
116 if lsmod | grep "^${MODULE} " > /dev/null; then |
|
117 if ! rmmod ${MODULE}; then |
|
118 /bin/false |
|
119 rc_status -v |
|
120 rc_exit |
|
121 fi |
|
122 fi |
|
123 done |
|
124 |
|
125 # load master module |
114 # load master module |
126 if ! modprobe ec_master main=${DEVICES} backup=${BACKUPS}; then |
115 if ! modprobe ec_master main=${DEVICES} backup=${BACKUPS}; then |
127 modprobe 8139too |
116 modprobe 8139too |
128 /bin/false |
117 /bin/false |
129 rc_status -v |
118 rc_status -v |
137 MAJOR=$(awk "\$2==\"EtherCAT\" {print \$1}" /proc/devices) |
126 MAJOR=$(awk "\$2==\"EtherCAT\" {print \$1}" /proc/devices) |
138 |
127 |
139 # create character device |
128 # create character device |
140 mknod /dev/${XMLDEVICE}0 c ${MAJOR} 0 |
129 mknod /dev/${XMLDEVICE}0 c ${MAJOR} 0 |
141 |
130 |
142 # load device module |
131 # check for modules to replace |
143 if ! modprobe ec_8139too; then |
132 for MODULE in ${DEVICE_MODULES}; do |
144 rmmod ec_master |
133 ECMODULE=ec_${MODULE} |
145 modprobe 8139too |
134 if ! modinfo ${ECMODULE} > /dev/null; then |
146 /bin/false |
135 continue |
147 rc_status -v |
136 fi |
148 rc_exit |
137 if lsmod | grep "^${MODULE} " > /dev/null; then |
149 fi |
138 if ! rmmod ${MODULE}; then |
150 |
|
151 rc_status -v |
|
152 ;; |
|
153 |
|
154 stop) |
|
155 echo -n "Shutting down EtherCAT master " |
|
156 |
|
157 # unload modules |
|
158 for mod in ec_8139too ec_master; do |
|
159 if lsmod | grep "^$mod " > /dev/null; then |
|
160 if ! rmmod $mod; then |
|
161 /bin/false |
139 /bin/false |
162 rc_status -v |
140 rc_status -v |
163 rc_exit |
141 rc_exit |
164 fi; |
142 fi |
|
143 fi |
|
144 if ! modprobe ${ECMODULE}; then |
|
145 modprobe ${MODULE} # try to restore module |
|
146 /bin/false |
|
147 rc_status -v |
|
148 rc_exit |
|
149 fi |
|
150 done |
|
151 |
|
152 rc_status -v |
|
153 ;; |
|
154 |
|
155 stop) |
|
156 echo -n "Shutting down EtherCAT master " |
|
157 |
|
158 # unload EtherCAT device modules |
|
159 for MODULE in ${DEVICE_MODULES} master; do |
|
160 ECMODULE=ec_${MODULE} |
|
161 if ! lsmod | grep -q "^${ECMODULE} "; then |
|
162 continue |
|
163 fi |
|
164 if ! rmmod ${ECMODULE}; then |
|
165 /bin/false |
|
166 rc_status -v |
|
167 rc_exit |
165 fi; |
168 fi; |
166 done |
169 done |
167 |
170 |
168 # remove device node |
171 # remove device node |
169 rm -f /dev/${XMLDEVICE}0 |
172 rm -f /dev/${XMLDEVICE}0 |
170 |
173 |
171 sleep 1 |
174 sleep 1 |
172 |
175 |
173 # reload previous modules |
176 # reload previous modules |
174 if ! modprobe 8139too; then |
177 for MODULE in ${DEVICE_MODULES}; do |
175 echo "Warning: Failed to restore 8139too module." |
178 if ! modprobe ${MODULE}; then |
176 fi |
179 echo Warning: Failed to restore ${MODULE}. |
|
180 fi |
|
181 done |
177 |
182 |
178 rc_status -v |
183 rc_status -v |
179 ;; |
184 ;; |
180 |
185 |
181 restart) |
186 restart) |
186 ;; |
191 ;; |
187 |
192 |
188 status) |
193 status) |
189 echo -n "Checking for EtherCAT " |
194 echo -n "Checking for EtherCAT " |
190 |
195 |
191 lsmod | grep "^ec_master " > /dev/null |
196 lsmod | grep -q "^ec_master " |
192 master_running=$? |
197 MASTERS_RUNNING=$? |
193 lsmod | grep "^ec_8139too " > /dev/null |
198 |
194 device_running=$? |
199 ! grep -q "(WAITING)" /sys/ethercat/master*/info |
195 |
200 MASTERS_IDLE=$? |
196 # master module and device module loaded? |
201 |
197 test $master_running -eq 0 -a $device_running -eq 0 |
202 # master module loaded and masters not waiting for devices? |
|
203 test ${MASTERS_RUNNING} -eq 0 -a ${MASTERS_IDLE} -eq 0 |
198 |
204 |
199 rc_status -v |
205 rc_status -v |
200 ;; |
206 ;; |
201 |
207 |
202 *) |
208 *) |