All pastes #1328713 Raw Edit

Unnamed

public text v1 · immutable
#1328713 ·published 2009-02-06 04:44 UTC
rendered paste body
I've been running 2.2.6 using at_pid for quite a while but
am convertiing stuff to run trunk using run-in-place.

Today I tested and found at_pid gave a kernel Oops at init.
After some investigation, I found the variables that had
been converted from params to pins were being initialized
before being allocated.

So I reversed the calling order of Pid_Init and Pid_Export
and added initializations for some private variables

This change is working for me:


Index: at_pid.c
===================================================================
RCS file: /cvs/emc2/src/hal/components/at_pid.c,v
retrieving revision 1.11
diff -u -r1.11 at_pid.c
--- at_pid.c	26 Oct 2008 11:51:22 -0000	1.11
+++ at_pid.c	6 Feb 2009 03:21:34 -0000
@@ -276,17 +276,17 @@
 
     pComp = component.pidTable;
     for(i = 0; i < num_chan; i++, pComp++){
-        // Initialize pid.
-        if(Pid_Init(pComp)){
-            hal_exit(component.id);
-            return(-1);
-        }
 
         // Export pins, parameters, and functions.
         if(Pid_Export(pComp, component.id, i)){
             hal_exit(component.id);
             return(-1);
         }
+        // Initialize pid.
+        if(Pid_Init(pComp)){
+            hal_exit(component.id);
+            return(-1);
+        }
     }
 
     hal_ready(component.id);
@@ -514,6 +514,13 @@
             rtapi_snprintf(buf, HAL_NAME_LEN, "pid.%d.ultimate-period", id);
             error = hal_pin_float_new(buf, HAL_OUT, &(this->ultimatePeriod), compId);
         }
+    } else {
+  	this->errorI = (hal_float_t *) hal_malloc(sizeof(hal_float_t));
+  	this->errorD = (hal_float_t *) hal_malloc(sizeof(hal_float_t));
+  	this->cmdD   = (hal_float_t *) hal_malloc(sizeof(hal_float_t));
+  	this->cmdDd  = (hal_float_t *) hal_malloc(sizeof(hal_float_t));
+  	this->ultimateGain = (hal_float_t *) hal_malloc(sizeof(hal_float_t));
+  	this->ultimatePeriod = (hal_float_t *) hal_malloc(sizeof(hal_float_t));
     }
 
     // Export functions.
@@ -705,7 +712,7 @@
         *(this->cmdDd) = 0;
 
         // Force output to zero.
-        *this->pOutput = 0;
+        *(this->pOutput) = 0;
 
         // Switch to tuning mode.
         this->state = STATE_TUNE_IDLE;