master/module.c
branchstable-1.0
changeset 1618 5cff10efb927
parent 1617 9f83a343ae75
child 1619 0d4119024f55
equal deleted inserted replaced
1617:9f83a343ae75 1618:5cff10efb927
     1 /******************************************************************************
     1 /******************************************************************************
     2  *
     2  *
     3  *  m o d u l e . c
       
     4  *
       
     5  *  EtherCAT master driver module.
       
     6  *
       
     7  *  Author: Florian Pose <fp@igh-essen.com>
       
     8  *
       
     9  *  $Id$
     3  *  $Id$
    10  *
     4  *
    11  *  (C) Copyright IgH 2005
     5  *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
    12  *  Ingenieurgemeinschaft IgH
     6  *
    13  *  Heinz-Bäcker Str. 34
     7  *  This file is part of the IgH EtherCAT Master.
    14  *  D-45356 Essen
     8  *
    15  *  Tel.: +49 201/61 99 31
     9  *  The IgH EtherCAT Master is free software; you can redistribute it
    16  *  Fax.: +49 201/61 98 36
    10  *  and/or modify it under the terms of the GNU General Public License
    17  *  E-mail: sp@igh-essen.com
    11  *  as published by the Free Software Foundation; version 2 of the License.
       
    12  *
       
    13  *  The IgH EtherCAT Master is distributed in the hope that it will be
       
    14  *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16  *  GNU General Public License for more details.
       
    17  *
       
    18  *  You should have received a copy of the GNU General Public License
       
    19  *  along with the IgH EtherCAT Master; if not, write to the Free Software
       
    20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18  *
    21  *
    19  *****************************************************************************/
    22  *****************************************************************************/
       
    23 
       
    24 /**
       
    25    \file
       
    26    EtherCAT master driver module.
       
    27 */
       
    28 
       
    29 /*****************************************************************************/
    20 
    30 
    21 #include <linux/module.h>
    31 #include <linux/module.h>
    22 #include <linux/kernel.h>
    32 #include <linux/kernel.h>
    23 #include <linux/init.h>
    33 #include <linux/init.h>
    24 
    34 
    30 
    40 
    31 int __init ec_init_module(void);
    41 int __init ec_init_module(void);
    32 void __exit ec_cleanup_module(void);
    42 void __exit ec_cleanup_module(void);
    33 
    43 
    34 /*****************************************************************************/
    44 /*****************************************************************************/
       
    45 
       
    46 /**
       
    47    Compile version info.
       
    48 */
    35 
    49 
    36 #define COMPILE_INFO EC_STR(EC_MASTER_VERSION_MAIN) \
    50 #define COMPILE_INFO EC_STR(EC_MASTER_VERSION_MAIN) \
    37                      "." EC_STR(EC_MASTER_VERSION_SUB) \
    51                      "." EC_STR(EC_MASTER_VERSION_SUB) \
    38                      " (" EC_MASTER_VERSION_EXTRA ")" \
    52                      " (" EC_MASTER_VERSION_EXTRA ")" \
    39                      " - rev. " EC_STR(SVNREV) \
    53                      " - rev. " EC_STR(SVNREV) \
    45 static int ec_master_count = 1;
    59 static int ec_master_count = 1;
    46 static struct list_head ec_masters;
    60 static struct list_head ec_masters;
    47 
    61 
    48 /*****************************************************************************/
    62 /*****************************************************************************/
    49 
    63 
       
    64 /** \cond */
       
    65 
    50 MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>");
    66 MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>");
    51 MODULE_DESCRIPTION ("EtherCAT master driver module");
    67 MODULE_DESCRIPTION ("EtherCAT master driver module");
    52 MODULE_LICENSE("GPL");
    68 MODULE_LICENSE("GPL");
    53 MODULE_VERSION(COMPILE_INFO);
    69 MODULE_VERSION(COMPILE_INFO);
    54 
    70 
    55 module_param(ec_master_count, int, 1);
    71 module_param(ec_master_count, int, 1);
    56 MODULE_PARM_DESC(ec_master_count, "number of EtherCAT masters to initialize");
    72 MODULE_PARM_DESC(ec_master_count, "number of EtherCAT masters to initialize");
       
    73 
       
    74 /** \endcond */
    57 
    75 
    58 /*****************************************************************************/
    76 /*****************************************************************************/
    59 
    77 
    60 /**
    78 /**
    61    Module initialization.
    79    Module initialization.
   203 /******************************************************************************
   221 /******************************************************************************
   204  *  Device interface
   222  *  Device interface
   205  *****************************************************************************/
   223  *****************************************************************************/
   206 
   224 
   207 /**
   225 /**
   208    Registeres an EtherCAT device for a certain master.
   226    Connects an EtherCAT device to a certain master.
       
   227    The master will use the device for sending and receiving frames. It is
       
   228    required that no other instance (for example the kernel IP stack) uses
       
   229    the device.
   209    \return 0 on success, else < 0
   230    \return 0 on success, else < 0
       
   231    \ingroup DeviceInterface
   210 */
   232 */
   211 
   233 
   212 ec_device_t *ecdev_register(unsigned int master_index, /**< master index */
   234 ec_device_t *ecdev_register(unsigned int master_index, /**< master index */
   213                             struct net_device *net_dev, /**< net_device of
   235                             struct net_device *net_dev, /**< net_device of
   214                                                            the device */
   236                                                            the device */
   255 }
   277 }
   256 
   278 
   257 /*****************************************************************************/
   279 /*****************************************************************************/
   258 
   280 
   259 /**
   281 /**
   260    Unregisteres an EtherCAT device.
   282    Disconnect an EtherCAT device from the master.
       
   283    The device is disconnected from the master and all device ressources
       
   284    are freed.
       
   285    \attention Before calling this function, the ecdev_stop() function has
       
   286    to be called, to be sure that the master does not use the device any more.
       
   287    \ingroup DeviceInterface
   261 */
   288 */
   262 
   289 
   263 void ecdev_unregister(unsigned int master_index, /**< master index */
   290 void ecdev_unregister(unsigned int master_index, /**< master index */
   264                       ec_device_t *device /**< EtherCAT device */
   291                       ec_device_t *device /**< EtherCAT device */
   265                       )
   292                       )
   280 
   307 
   281 /*****************************************************************************/
   308 /*****************************************************************************/
   282 
   309 
   283 /**
   310 /**
   284    Starts the master associated with the device.
   311    Starts the master associated with the device.
       
   312    This function has to be called by the network device driver to tell the
       
   313    master that the device is ready to send and receive data. The master
       
   314    will enter the free-run mode then.
       
   315    \ingroup DeviceInterface
   285 */
   316 */
   286 
   317 
   287 int ecdev_start(unsigned int master_index /**< master index */)
   318 int ecdev_start(unsigned int master_index /**< master index */)
   288 {
   319 {
   289     ec_master_t *master;
   320     ec_master_t *master;
   300 
   331 
   301 /*****************************************************************************/
   332 /*****************************************************************************/
   302 
   333 
   303 /**
   334 /**
   304    Stops the master associated with the device.
   335    Stops the master associated with the device.
       
   336    Tells the master to stop using the device for frame IO. Has to be called
       
   337    before unregistering the device.
       
   338    \ingroup DeviceInterface
   305 */
   339 */
   306 
   340 
   307 void ecdev_stop(unsigned int master_index /**< master index */)
   341 void ecdev_stop(unsigned int master_index /**< master index */)
   308 {
   342 {
   309     ec_master_t *master;
   343     ec_master_t *master;
   320  *****************************************************************************/
   354  *****************************************************************************/
   321 
   355 
   322 /**
   356 /**
   323    Reserves an EtherCAT master for realtime operation.
   357    Reserves an EtherCAT master for realtime operation.
   324    \return pointer to reserved master, or NULL on error
   358    \return pointer to reserved master, or NULL on error
       
   359    \ingroup RealtimeInterface
   325 */
   360 */
   326 
   361 
   327 ec_master_t *ecrt_request_master(unsigned int master_index
   362 ec_master_t *ecrt_request_master(unsigned int master_index
   328                                  /**< master index */
   363                                  /**< master index */
   329                                  )
   364                                  )
   378 
   413 
   379 /*****************************************************************************/
   414 /*****************************************************************************/
   380 
   415 
   381 /**
   416 /**
   382    Releases a reserved EtherCAT master.
   417    Releases a reserved EtherCAT master.
       
   418    \ingroup RealtimeInterface
   383 */
   419 */
   384 
   420 
   385 void ecrt_release_master(ec_master_t *master /**< EtherCAT master */)
   421 void ecrt_release_master(ec_master_t *master /**< EtherCAT master */)
   386 {
   422 {
   387     EC_INFO("Releasing master %i...\n", master->index);
   423     EC_INFO("Releasing master %i...\n", master->index);
   402     EC_INFO("Released master %i.\n", master->index);
   438     EC_INFO("Released master %i.\n", master->index);
   403     return;
   439     return;
   404 }
   440 }
   405 
   441 
   406 /*****************************************************************************/
   442 /*****************************************************************************/
       
   443 
       
   444 /** \cond */
   407 
   445 
   408 module_init(ec_init_module);
   446 module_init(ec_init_module);
   409 module_exit(ec_cleanup_module);
   447 module_exit(ec_cleanup_module);
   410 
   448 
   411 EXPORT_SYMBOL(ecdev_register);
   449 EXPORT_SYMBOL(ecdev_register);
   413 EXPORT_SYMBOL(ecdev_start);
   451 EXPORT_SYMBOL(ecdev_start);
   414 EXPORT_SYMBOL(ecdev_stop);
   452 EXPORT_SYMBOL(ecdev_stop);
   415 EXPORT_SYMBOL(ecrt_request_master);
   453 EXPORT_SYMBOL(ecrt_request_master);
   416 EXPORT_SYMBOL(ecrt_release_master);
   454 EXPORT_SYMBOL(ecrt_release_master);
   417 
   455 
   418 /*****************************************************************************/
   456 /** \endcond */
       
   457 
       
   458 /*****************************************************************************/