master/debug.c
changeset 1921 d9cf40facbc4
parent 1907 dd276ae226b4
child 2522 ec403cf308eb
equal deleted inserted replaced
1920:d28360ee74c5 1921:d9cf40facbc4
    37 #include <linux/version.h>
    37 #include <linux/version.h>
    38 #include <linux/netdevice.h>
    38 #include <linux/netdevice.h>
    39 #include <linux/etherdevice.h>
    39 #include <linux/etherdevice.h>
    40 
    40 
    41 #include "globals.h"
    41 #include "globals.h"
       
    42 #include "master.h"
    42 #include "debug.h"
    43 #include "debug.h"
    43 
    44 
    44 /*****************************************************************************/
    45 /*****************************************************************************/
    45 
    46 
    46 // net_device functions
    47 // net_device functions
    69  *
    70  *
    70  * \retval  0 Success.
    71  * \retval  0 Success.
    71  * \retval <0 Error code.
    72  * \retval <0 Error code.
    72  */
    73  */
    73 int ec_debug_init(
    74 int ec_debug_init(
    74         ec_debug_t *dbg, /**< debug object */
    75         ec_debug_t *dbg, /**< Debug object. */
    75         const char *name /**< interface name */
    76         ec_device_t *device, /**< EtherCAT device. */
    76         )
    77         const char *name /**< Interface name. */
    77 {
    78         )
       
    79 {
       
    80     dbg->device = device;
    78     dbg->registered = 0;
    81     dbg->registered = 0;
    79     dbg->opened = 0;
    82     dbg->opened = 0;
    80 
    83 
    81     memset(&dbg->stats, 0, sizeof(struct net_device_stats));
    84     memset(&dbg->stats, 0, sizeof(struct net_device_stats));
    82 
    85 
    83     if (!(dbg->dev =
    86     if (!(dbg->dev =
    84           alloc_netdev(sizeof(ec_debug_t *), name, ether_setup))) {
    87           alloc_netdev(sizeof(ec_debug_t *), name, ether_setup))) {
    85         EC_ERR("Unable to allocate net_device for debug object!\n");
    88         EC_MASTER_ERR(device->master, "Unable to allocate net_device"
       
    89                 " for debug object!\n");
    86         return -ENODEV;
    90         return -ENODEV;
    87     }
    91     }
    88 
    92 
    89     // initialize net_device
    93     // initialize net_device
    90 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
    94 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
   132     // use the Ethernet address of the physical device for the debug device
   136     // use the Ethernet address of the physical device for the debug device
   133     memcpy(dbg->dev->dev_addr, net_dev->dev_addr, ETH_ALEN);
   137     memcpy(dbg->dev->dev_addr, net_dev->dev_addr, ETH_ALEN);
   134 
   138 
   135     // connect the net_device to the kernel
   139     // connect the net_device to the kernel
   136     if ((result = register_netdev(dbg->dev))) {
   140     if ((result = register_netdev(dbg->dev))) {
   137         EC_WARN("Unable to register net_device: error %i\n", result);
   141         EC_MASTER_WARN(dbg->device->master, "Unable to register net_device:"
       
   142                 " error %i\n", result);
   138     } else {
   143     } else {
   139         dbg->registered = 1;
   144         dbg->registered = 1;
   140     }
   145     }
   141 }
   146 }
   142 
   147 
   200         struct net_device *dev /**< debug net_device */
   205         struct net_device *dev /**< debug net_device */
   201         )
   206         )
   202 {
   207 {
   203     ec_debug_t *dbg = *((ec_debug_t **) netdev_priv(dev));
   208     ec_debug_t *dbg = *((ec_debug_t **) netdev_priv(dev));
   204     dbg->opened = 1;
   209     dbg->opened = 1;
   205     EC_INFO("Debug interface %s opened.\n", dev->name);
   210     EC_MASTER_INFO(dbg->device->master, "Debug interface %s opened.\n",
       
   211             dev->name);
   206     return 0;
   212     return 0;
   207 }
   213 }
   208 
   214 
   209 /*****************************************************************************/
   215 /*****************************************************************************/
   210 
   216 
   214         struct net_device *dev /**< debug net_device */
   220         struct net_device *dev /**< debug net_device */
   215         )
   221         )
   216 {
   222 {
   217     ec_debug_t *dbg = *((ec_debug_t **) netdev_priv(dev));
   223     ec_debug_t *dbg = *((ec_debug_t **) netdev_priv(dev));
   218     dbg->opened = 0;
   224     dbg->opened = 0;
   219     EC_INFO("Debug interface %s stopped.\n", dev->name);
   225     EC_MASTER_INFO(dbg->device->master, "Debug interface %s stopped.\n",
       
   226             dev->name);
   220     return 0;
   227     return 0;
   221 }
   228 }
   222 
   229 
   223 /*****************************************************************************/
   230 /*****************************************************************************/
   224 
   231