script/ethercat.sh
author Florian Pose <fp@igh-essen.com>
Mon, 26 Jun 2006 11:28:24 +0000
changeset 280 35c99cdda518
parent 251 c1d0b63a9302
child 283 a480a0703c58
permissions -rwxr-xr-x
types.c: BK1120 outputs and EL1004.
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
#!/bin/sh
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
#------------------------------------------------------------------------------
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
#
247
d1f0cff6f57f Minor changes in init script.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
     5
#  Init script for EtherCAT
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
#
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#  $Id$
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
#
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
     9
#  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    10
#
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    11
#  This file is part of the IgH EtherCAT Master.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    12
#
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    13
#  The IgH EtherCAT Master is free software; you can redistribute it
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    14
#  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    15
#  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    16
#  License, or (at your option) any later version.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    17
#
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    18
#  The IgH EtherCAT Master is distributed in the hope that it will be
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    19
#  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    20
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    21
#  GNU General Public License for more details.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    22
#
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    23
#  You should have received a copy of the GNU General Public License
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    24
#  along with the IgH EtherCAT Master; if not, write to the Free Software
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    25
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    26
#
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    27
#  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    28
#  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    29
#  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    30
#  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    31
#  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    32
#  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    33
#  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    34
#  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    35
#
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#------------------------------------------------------------------------------
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    38
### BEGIN INIT INFO
248
f5e94773472d Minor changes in init script 2.
Florian Pose <fp@igh-essen.com>
parents: 247
diff changeset
    39
# Provides:          ethercat
245
100a0c3f5e6e Added dependencies to RC script.
Florian Pose <fp@igh-essen.com>
parents: 244
diff changeset
    40
# Required-Start:    $local_fs $syslog $network
100a0c3f5e6e Added dependencies to RC script.
Florian Pose <fp@igh-essen.com>
parents: 244
diff changeset
    41
# Should-Start:      $time
100a0c3f5e6e Added dependencies to RC script.
Florian Pose <fp@igh-essen.com>
parents: 244
diff changeset
    42
# Required-Stop:     $local_fs $syslog $network
100a0c3f5e6e Added dependencies to RC script.
Florian Pose <fp@igh-essen.com>
parents: 244
diff changeset
    43
# Should-Stop:       $time
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    44
# Default-Start:     3 5
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    45
# Default-Stop:      0 1 2 6
247
d1f0cff6f57f Minor changes in init script.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    46
# Short-Description: IgH EtherCAT master modules
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    47
# Description:
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    48
### END INIT INFO
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
#------------------------------------------------------------------------------
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    52
ETHERCAT_CONFIG=/etc/sysconfig/ethercat
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    54
test -r $ETHERCAT_CONFIG || { echo "$ETHERCAT_CONFIG not existing";
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    55
	if [ "$1" = "stop" ]; then exit 0;
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    56
	else exit 6; fi; }
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    57
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    58
. $ETHERCAT_CONFIG
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
#------------------------------------------------------------------------------
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    62
. /etc/rc.status
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    63
rc_reset
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    65
case "$1" in
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    66
    start)
250
440ae5f6d2c3 Created scripts directory and improved install and init scripts.
Florian Pose <fp@igh-essen.com>
parents: 248
diff changeset
    67
	echo -n "Starting EtherCAT master "
440ae5f6d2c3 Created scripts directory and improved install and init scripts.
Florian Pose <fp@igh-essen.com>
parents: 248
diff changeset
    68
440ae5f6d2c3 Created scripts directory and improved install and init scripts.
Florian Pose <fp@igh-essen.com>
parents: 248
diff changeset
    69
	if [ ! $DEVICE_INDEX ]; then
440ae5f6d2c3 Created scripts directory and improved install and init scripts.
Florian Pose <fp@igh-essen.com>
parents: 248
diff changeset
    70
	    echo "ERROR: DEVICE_INDEX not set!"
440ae5f6d2c3 Created scripts directory and improved install and init scripts.
Florian Pose <fp@igh-essen.com>
parents: 248
diff changeset
    71
	    /bin/false
440ae5f6d2c3 Created scripts directory and improved install and init scripts.
Florian Pose <fp@igh-essen.com>
parents: 248
diff changeset
    72
	    rc_status -v
440ae5f6d2c3 Created scripts directory and improved install and init scripts.
Florian Pose <fp@igh-essen.com>
parents: 248
diff changeset
    73
	    rc_exit
440ae5f6d2c3 Created scripts directory and improved install and init scripts.
Florian Pose <fp@igh-essen.com>
parents: 248
diff changeset
    74
	fi
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    76
	if [ ! $EOE_DEVICES ]; then
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    77
	    EOE_DEVICES=0
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    78
	fi
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    79
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    80
	for mod in 8139too 8139cp; do
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    81
		if lsmod | grep "^$mod " > /dev/null; then
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    82
			if ! rmmod $mod; then
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    83
				/bin/false
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    84
				rc_status -v
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    85
				rc_exit
250
440ae5f6d2c3 Created scripts directory and improved install and init scripts.
Florian Pose <fp@igh-essen.com>
parents: 248
diff changeset
    86
			fi
440ae5f6d2c3 Created scripts directory and improved install and init scripts.
Florian Pose <fp@igh-essen.com>
parents: 248
diff changeset
    87
		fi
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    88
	done
174
99907332ff1e Restart action in RC script
Florian Pose <fp@igh-essen.com>
parents: 169
diff changeset
    89
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    90
	if ! modprobe ec_master ec_eoe_devices=$EOE_DEVICES; then
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    91
	    /bin/false
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    92
	    rc_status -v
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    93
	    rc_exit
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    94
	fi
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    95
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    96
	if ! modprobe ec_8139too ec_device_index=$DEVICE_INDEX; then
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    97
	    /bin/false
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    98
	    rc_status -v
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
    99
	    rc_exit
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 250
diff changeset
   100
	fi
174
99907332ff1e Restart action in RC script
Florian Pose <fp@igh-essen.com>
parents: 169
diff changeset
   101
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   102
	rc_status -v
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
	;;
174
99907332ff1e Restart action in RC script
Florian Pose <fp@igh-essen.com>
parents: 169
diff changeset
   104
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
    stop)
250
440ae5f6d2c3 Created scripts directory and improved install and init scripts.
Florian Pose <fp@igh-essen.com>
parents: 248
diff changeset
   106
	echo -n "Shutting down EtherCAT master "
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   107
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   108
	for mod in ec_8139too ec_master; do
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   109
		if lsmod | grep "^$mod " > /dev/null; then
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   110
			if ! rmmod $mod; then
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   111
				/bin/false
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   112
				rc_status -v
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   113
				rc_exit
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   114
			fi;
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   115
		fi;
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   116
	done
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   117
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
	if ! modprobe 8139too; then
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
	    echo "Warning: Failed to restore 8139too module."
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
	fi
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   121
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   122
	rc_status -v
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
	;;
174
99907332ff1e Restart action in RC script
Florian Pose <fp@igh-essen.com>
parents: 169
diff changeset
   124
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   125
    restart)
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   126
	$0 stop
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   127
	$0 start
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   128
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   129
	rc_status
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   130
	;;
244
c302a846ab12 Added status function to RC script.
Florian Pose <fp@igh-essen.com>
parents: 243
diff changeset
   131
c302a846ab12 Added status function to RC script.
Florian Pose <fp@igh-essen.com>
parents: 243
diff changeset
   132
    status)
250
440ae5f6d2c3 Created scripts directory and improved install and init scripts.
Florian Pose <fp@igh-essen.com>
parents: 248
diff changeset
   133
	echo -n "Checking for EtherCAT "
244
c302a846ab12 Added status function to RC script.
Florian Pose <fp@igh-essen.com>
parents: 243
diff changeset
   134
c302a846ab12 Added status function to RC script.
Florian Pose <fp@igh-essen.com>
parents: 243
diff changeset
   135
	lsmod | grep "^ec_master " > /dev/null
c302a846ab12 Added status function to RC script.
Florian Pose <fp@igh-essen.com>
parents: 243
diff changeset
   136
	master_running=$?
c302a846ab12 Added status function to RC script.
Florian Pose <fp@igh-essen.com>
parents: 243
diff changeset
   137
	lsmod | grep "^ec_8139too " > /dev/null
c302a846ab12 Added status function to RC script.
Florian Pose <fp@igh-essen.com>
parents: 243
diff changeset
   138
	device_running=$?
c302a846ab12 Added status function to RC script.
Florian Pose <fp@igh-essen.com>
parents: 243
diff changeset
   139
	test $master_running -eq 0 -a $device_running -eq 0
c302a846ab12 Added status function to RC script.
Florian Pose <fp@igh-essen.com>
parents: 243
diff changeset
   140
c302a846ab12 Added status function to RC script.
Florian Pose <fp@igh-essen.com>
parents: 243
diff changeset
   141
	rc_status -v
c302a846ab12 Added status function to RC script.
Florian Pose <fp@igh-essen.com>
parents: 243
diff changeset
   142
	;;
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
esac
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   144
rc_exit
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
#------------------------------------------------------------------------------