Added debug_level module parameter. debug_level is now unsigned int.
authorFlorian Pose <fp@igh-essen.com>
Fri, 17 Apr 2009 12:03:12 +0000
changeset 1399 f79d4bb5b23a
parent 1398 36c23e993040
child 1400 3c4923051e43
Added debug_level module parameter. debug_level is now unsigned int.
NEWS
documentation/ethercat_doc.tex
master/master.c
master/master.h
master/module.c
--- a/NEWS	Fri Apr 17 11:07:27 2009 +0000
+++ b/NEWS	Fri Apr 17 12:03:12 2009 +0000
@@ -30,6 +30,8 @@
 * Introduced ecrt_master_slave() to get information about a certain slave.
 * SDO entry access rights are shown in 'ethercat sdos'.
 * Added 64-bit data access macros to application header.
+* Added debug level for all masters as a module parameter. Thanks to Erwin
+  Burgstaller.
 
 Changes in 1.4.0:
 
--- a/documentation/ethercat_doc.tex	Fri Apr 17 11:07:27 2009 +0000
+++ b/documentation/ethercat_doc.tex	Fri Apr 17 12:03:12 2009 +0000
@@ -425,6 +425,10 @@
   \label{fig:masters}
 \end{figure}
 
+\paragraph{Debug Level} The master module also has a parameter
+\textit{debug\_level} to set the initial debug level for all masters (see
+also~\ref{sec:ethercat-debug}).
+
 \paragraph{Init Script}
 \index{Init script}
 
@@ -2091,6 +2095,7 @@
 %------------------------------------------------------------------------------
 
 \subsection{Setting a Master's Debug Level}
+\label{sec:ethercat-debug}
 
 \lstinputlisting[basicstyle=\ttfamily\footnotesize]{external/ethercat_debug}
 
--- a/master/master.c	Fri Apr 17 11:07:27 2009 +0000
+++ b/master/master.c	Fri Apr 17 12:03:12 2009 +0000
@@ -104,7 +104,8 @@
         const uint8_t *main_mac, /**< MAC address of main device */
         const uint8_t *backup_mac, /**< MAC address of backup device */
         dev_t device_number, /**< Character device number. */
-        struct class *class /**< Device class. */
+        struct class *class, /**< Device class. */
+        unsigned int debug_level /**< Debug level (module parameter). */
         )
 {
     int ret;
@@ -142,7 +143,7 @@
 
     INIT_LIST_HEAD(&master->domains);
 
-    master->debug_level = 0;
+    master->debug_level = debug_level;
     master->stats.timeouts = 0;
     master->stats.corrupted = 0;
     master->stats.unmatched = 0;
@@ -1327,17 +1328,17 @@
  */
 int ec_master_debug_level(
         ec_master_t *master, /**< EtherCAT master. */
-        int level /**< Debug level. May be 0, 1 or 2. */
+        unsigned int level /**< Debug level. May be 0, 1 or 2. */
         )
 {
-    if (level < 0 || level > 2) {
-        EC_ERR("Invalid debug level %i!\n", level);
+    if (level > 2) {
+        EC_ERR("Invalid debug level %u!\n", level);
         return -EINVAL;
     }
 
     if (level != master->debug_level) {
         master->debug_level = level;
-        EC_INFO("Master debug level set to %i.\n", master->debug_level);
+        EC_INFO("Master debug level set to %u.\n", master->debug_level);
     }
 
     return 0;
--- a/master/master.h	Fri Apr 17 11:07:27 2009 +0000
+++ b/master/master.h	Fri Apr 17 12:03:12 2009 +0000
@@ -143,7 +143,7 @@
 
     struct list_head domains; /**< List of domains. */
 
-    int debug_level; /**< Master debug level. */
+    unsigned int debug_level; /**< Master debug level. */
     ec_stats_t stats; /**< Cyclic statistics. */
     unsigned int frames_timed_out; /**< There were frame timeouts in the last
                                      call to ecrt_master_receive(). */
@@ -187,7 +187,7 @@
 
 // master creation/deletion
 int ec_master_init(ec_master_t *, unsigned int, const uint8_t *,
-        const uint8_t *, dev_t, struct class *);
+        const uint8_t *, dev_t, struct class *, unsigned int);
 void ec_master_clear(ec_master_t *);
 
 // phase transitions
@@ -227,7 +227,7 @@
 const ec_domain_t *ec_master_find_domain_const(const ec_master_t *,
         unsigned int);
 
-int ec_master_debug_level(ec_master_t *, int);
+int ec_master_debug_level(ec_master_t *, unsigned int);
 
 ec_domain_t *ecrt_master_create_domain_err(ec_master_t *);
 ec_slave_config_t *ecrt_master_slave_config_err(ec_master_t *, uint16_t,
--- a/master/module.c	Fri Apr 17 11:07:27 2009 +0000
+++ b/master/module.c	Fri Apr 17 12:03:12 2009 +0000
@@ -55,12 +55,13 @@
 /*****************************************************************************/
 
 static char *main_devices[MAX_MASTERS]; /**< Main devices parameter. */
+static unsigned int master_count; /**< Number of masters. */
 static char *backup_devices[MAX_MASTERS]; /**< Backup devices parameter. */
+static unsigned int backup_count; /**< Number of backup devices. */
+static unsigned int debug_level;  /**< Debug level parameter. */
 
 static ec_master_t *masters; /**< Array of masters. */
 static struct semaphore master_sem; /**< Master semaphore. */
-static unsigned int master_count; /**< Number of masters. */
-static unsigned int backup_count; /**< Number of backup devices. */
 
 dev_t device_number; /**< Device number for master cdevs. */
 struct class *class; /**< Device class. */
@@ -82,6 +83,8 @@
 MODULE_PARM_DESC(main_devices, "MAC addresses of main devices");
 module_param_array(backup_devices, charp, &backup_count, S_IRUGO);
 MODULE_PARM_DESC(backup_devices, "MAC addresses of backup devices");
+module_param_named(debug_level, debug_level, uint, S_IRUGO);
+MODULE_PARM_DESC(debug_level, "Debug level");
 
 /** \endcond */
 
@@ -145,7 +148,7 @@
     
     for (i = 0; i < master_count; i++) {
         ret = ec_master_init(&masters[i], i, macs[i][0], macs[i][1],
-                    device_number, class);
+                    device_number, class, debug_level);
         if (ret)
             goto out_free_masters;
     }