2.6.30.5-rtai hits a kernel BUG when ctrl_type= is specified.
Investigation of in-kernel users of module_param_array(charp) implies
that they all use zero'd out arrays, in contrast to our initialized array.
the BUG is that param_set_charp attempts to kfree the old value.

Revamp how stepgen treats ctrl_type so that an empty or unspecified value
is treated like 'v', so that the initial ctrl_type can be uninitialized.
This has the side effect of making empty ctrl_types (e.g., ctrl_type=p,v,,v)
indicate position control.
---
I verified that this still works OK on sim and 2.6.12-magma (breezy! but
the only realtime system I had handy); does it fix stepgen ctrl_type
with your kernel?

 src/hal/components/stepgen.c |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/hal/components/stepgen.c b/src/hal/components/stepgen.c
index b0fa061..9dafce1 100644
--- a/src/hal/components/stepgen.c
+++ b/src/hal/components/stepgen.c
@@ -312,7 +312,7 @@ MODULE_DESCRIPTION("Step Pulse Generator for EMC HAL");
 MODULE_LICENSE("GPL");
 int step_type[MAX_CHAN] = { -1, -1, -1, -1, -1, -1, -1, -1 };
 RTAPI_MP_ARRAY_INT(step_type,MAX_CHAN,"stepping types for up to 8 channels");
-const char *ctrl_type[MAX_CHAN] = { "p", "p", "p", "p", "p", "p", "p", "p" };
+const char *ctrl_type[MAX_CHAN];
 RTAPI_MP_ARRAY_STRING(ctrl_type,MAX_CHAN,"control type (pos or vel) for up to 
8 channels");
 
 /***********************************************************************
@@ -418,6 +418,8 @@ static long old_dtns;               /* update_freq funct 
period in nsec */
 static double dt;              /* update_freq period in seconds */
 static double recip_dt;                /* recprocal of period, avoids divides 
*/
 
+typedef enum CONTROL { POSITION, VELOCITY, INVALID } CONTROL;
+
 /***********************************************************************
 *                  LOCAL FUNCTION DECLARATIONS                         *
 ************************************************************************/
@@ -426,6 +428,8 @@ static int export_stepgen(int num, stepgen_t * addr, int 
step_type, int pos_mode
 static void make_pulses(void *arg, long period);
 static void update_freq(void *arg, long period);
 static void update_pos(void *arg, long period);
+static CONTROL parse_ctrl_type(const char *ctrl);
+
 
 /***********************************************************************
 *                       INIT AND EXIT CODE                             *
@@ -442,11 +446,7 @@ int rtapi_app_main(void)
                            step_type[n], n);
            return -1;
        }
-       if ((ctrl_type[n][0] == 'p' ) || (ctrl_type[n][0] == 'P')) {
-           ctrl_type[n] = "p";
-       } else if ((ctrl_type[n][0] == 'v' ) || (ctrl_type[n][0] == 'V')) {
-           ctrl_type[n] = "v";
-       } else {
+       if(parse_ctrl_type(ctrl_type[n]) == INVALID) {
            rtapi_print_msg(RTAPI_MSG_ERR,
                            "STEPGEN: ERROR: bad control type '%s' for axis %i 
(must be 'p' or 'v')\n",
                            ctrl_type[n], n);
@@ -490,7 +490,7 @@ int rtapi_app_main(void)
     for (n = 0; n < num_chan; n++) {
        /* export all vars */
        retval = export_stepgen(n, &(stepgen_array[n]),
-           step_type[n], (ctrl_type[n][0] == 'p'));
+           step_type[n], (parse_ctrl_type(ctrl_type[n]) == POSITION));
        if (retval != 0) {
            rtapi_print_msg(RTAPI_MSG_ERR,
                "STEPGEN: ERROR: stepgen %d var export failed\n", n);
@@ -1187,3 +1187,10 @@ static int export_stepgen(int num, stepgen_t * addr, int 
step_type, int pos_mode
     rtapi_set_msg_level(msg);
     return 0;
 }
+
+static CONTROL parse_ctrl_type(const char *ctrl)
+{
+    if(!ctrl || !*ctrl || *ctrl == 'p' || *ctrl == 'P') return POSITION;
+    if(*ctrl == 'v' || *ctrl == 'V') return VELOCITY;
+    return INVALID;
+}
-- 
1.6.6.62.g584f3

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Emc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to