ethercat.sh
changeset 169 b3ecbec2c487
child 174 99907332ff1e
equal deleted inserted replaced
168:8505cc1ad3ce 169:b3ecbec2c487
       
     1 #!/bin/sh
       
     2 
       
     3 #------------------------------------------------------------------------------
       
     4 #
       
     5 #  EtherCAT rc script
       
     6 #
       
     7 #  $Id$
       
     8 #
       
     9 #------------------------------------------------------------------------------
       
    10 
       
    11 CONFIGFILE=/etc/sysconfig/ethercat
       
    12 
       
    13 #------------------------------------------------------------------------------
       
    14 
       
    15 print_usage()
       
    16 {
       
    17     echo "Usage $0 { start | stop }"
       
    18 }
       
    19 
       
    20 unload_module()
       
    21 {
       
    22     if lsmod | grep ^$1 > /dev/null; then
       
    23 	echo "  unloading module \"$1\"..."
       
    24 	rmmod $1 || exit 1
       
    25     fi
       
    26 }
       
    27 
       
    28 #------------------------------------------------------------------------------
       
    29 
       
    30 # Get parameters
       
    31 if [ $# -eq 0 ]; then
       
    32     print_usage
       
    33     exit 1
       
    34 fi
       
    35 
       
    36 ACTION=$1
       
    37 
       
    38 # Load configuration from sysconfig
       
    39 
       
    40 if [ -f $CONFIGFILE ]; then
       
    41     . $CONFIGFILE
       
    42 else
       
    43     echo "ERROR: Configuration file \"$CONFIGFILE\" not found!"
       
    44     exit 1
       
    45 fi
       
    46 
       
    47 case $ACTION in
       
    48     start)
       
    49 	echo "Starting EtherCAT master..."
       
    50 	# remove modules
       
    51 	unload_module 8139too
       
    52 	unload_module 8139cp
       
    53 	unload_module ec_8139too
       
    54 	unload_module ec_master
       
    55 	echo "  loading master modules..."
       
    56 	if ! modprobe ec_8139too ec_device_index=$DEVICEINDEX; then
       
    57 	    echo "ERROR: Failed to load module!"
       
    58 	    exit 1
       
    59 	fi
       
    60 	;;
       
    61     stop)
       
    62 	echo "Stopping EtherCAT master..."
       
    63 	unload_module ec_8139too
       
    64 	unload_module ec_master
       
    65 	if ! modprobe 8139too; then
       
    66 	    echo "Warning: Failed to restore 8139too module."
       
    67 	fi
       
    68 	;;
       
    69     *)
       
    70 	print_usage
       
    71 	exit 1
       
    72 esac
       
    73 
       
    74 echo "done."
       
    75 exit 0
       
    76 
       
    77 #------------------------------------------------------------------------------