? double-step-rate-rev2.patch
? double-step-rate.patch
? lat.hal
? lat.xml
? testreset.hal
? hal/drivers/.hal_parport.c.swp
Index: hal/components/stepgen.c
===================================================================
RCS file: /cvs/emc2/src/hal/components/stepgen.c,v
retrieving revision 1.56
diff -u -p -r1.56 stepgen.c
--- hal/components/stepgen.c	22 Mar 2007 12:46:54 -0000	1.56
+++ hal/components/stepgen.c	26 Aug 2007 17:03:55 -0000
@@ -357,6 +357,7 @@ typedef struct {
     /* stuff that is not accessed by makepulses */
     int pos_mode;		/* 1 = position mode, 0 = velocity mode */
     hal_u32_t step_space;	/* parameter: min step pulse spacing */
+    hal_bit_t doublefreq;	/* parameter: TRUE for double-freq stepping */
     double old_pos_cmd;		/* previous position command (counts) */
     hal_s32_t *count;		/* pin: captured feedback in counts */
     hal_float_t pos_scale;	/* param: steps per position unit */
@@ -835,7 +836,7 @@ static void update_freq(void *arg, long 
 	    stepgen->step_len = stepgen->old_step_len;
 	}
 	if ( stepgen->step_space != stepgen->old_step_space ) {
-	    if ( stepgen->step_space == 0 ) {
+	    if ( stepgen->step_space == 0 && ! stepgen->doublefreq ) {
 		/* stepspace must be non-zero for step types 0 and 1 */
 		if ( stepgen->step_type < 2 ) {
 		    stepgen->step_space = 1;
@@ -1091,6 +1092,9 @@ static int export_stepgen(int num, stepg
 	retval = hal_param_u32_newf(HAL_RW, &(addr->step_space),
 	    comp_id, "stepgen.%d.stepspace", num);
 	if (retval != 0) { return retval; }
+	retval = hal_param_bit_newf(HAL_RW, &(addr->doublefreq),
+	    comp_id, "stepgen.%d.doublefreq", num);
+	if (retval != 0) { return retval; }
     }
     if ( step_type == 0 ) {
 	/* step/dir is the only one that uses dirsetup and dirhold */
Index: hal/drivers/hal_parport.c
===================================================================
RCS file: /cvs/emc2/src/hal/drivers/hal_parport.c,v
retrieving revision 1.29
diff -u -p -r1.29 hal_parport.c
--- hal/drivers/hal_parport.c	14 Apr 2007 22:22:45 -0000	1.29
+++ hal/drivers/hal_parport.c	26 Aug 2007 17:03:55 -0000
@@ -157,9 +157,16 @@ typedef struct {
     hal_bit_t *data_in[16];	/* ptrs for input pins 2 - 9 */
     hal_bit_t *data_out[8];	/* ptrs for output pins 2 - 9 */
     hal_bit_t data_inv[8];	/* polarity params for output pins 2 - 9 */
+    hal_bit_t data_reset[8];	/* polarity params for output pins 2 - 9 */
     hal_bit_t *control_in[8];	/* ptrs for in pins 1, 14, 16, 17 */
     hal_bit_t *control_out[4];	/* ptrs for out pins 1, 14, 16, 17 */
     hal_bit_t control_inv[4];	/* pol. params for output pins 1, 14, 16, 17 */
+    hal_u32_t reset_time;       /* min ns between write and reset */
+    hal_u32_t debug1, debug2;
+    long long write_time;
+    unsigned char outdata;
+    unsigned char reset_mask;       /* reset flag for each pin 2..9 */
+    unsigned char reset_val;        /* reset values for each pin 2..9 */
 } parport_t;
 
 /* pointer to array of parport_t structs in shared memory, 1 per port */
@@ -169,6 +176,9 @@ static parport_t *port_data_array;
 static int comp_id;		/* component ID */
 static int num_ports;		/* number of ports configured */
 
+static unsigned long long ns2tsc_factor;
+#define ns2tsc(x) (((x) * ns2tsc_factor) >> 32)
+
 /***********************************************************************
 *                  LOCAL FUNCTION DECLARATIONS                         *
 ************************************************************************/
@@ -178,6 +188,7 @@ static int num_ports;		/* number of port
 */
 
 static void read_port(void *arg, long period);
+static void reset_port(void *arg, long period);
 static void write_port(void *arg, long period);
 static void read_all(void *arg, long period);
 static void write_all(void *arg, long period);
@@ -195,7 +206,7 @@ static unsigned short parse_port_addr(ch
 static int export_port(int portnum, parport_t * addr);
 static int export_input_pin(int portnum, int pin, hal_bit_t ** base, int n);
 static int export_output_pin(int portnum, int pin, hal_bit_t ** dbase,
-    hal_bit_t * pbase, int n);
+    hal_bit_t * pbase, hal_bit_t * rbase, int n);
 
 /***********************************************************************
 *                       INIT AND EXIT CODE                             *
@@ -214,6 +225,13 @@ int rtapi_app_main(void)
     char name[HAL_NAME_LEN + 2];
     int n, retval;
 
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
+    ns2tsc_factor = (unsigned long long)(1e6 * (1ll<<32) / cpu_khz);
+#else
+    ns2tsc_factor = 1ll<<32;
+#endif
+
     /* test for config string */
     if (cfg == 0) {
 	rtapi_print_msg(RTAPI_MSG_ERR, "PARPORT: ERROR: no config string\n");
@@ -277,6 +295,17 @@ rtapi_print ( "config string '%s'\n", cf
 	    hal_exit(comp_id);
 	    return -1;
 	}
+	/* make reset function name */
+	rtapi_snprintf(name, HAL_NAME_LEN, "parport.%d.reset", n);
+	/* export write function */
+	retval = hal_export_funct(name, reset_port, &(port_data_array[n]),
+	    0, 0, comp_id);
+	if (retval != 0) {
+	    rtapi_print_msg(RTAPI_MSG_ERR,
+		"PARPORT: ERROR: port %d reset funct export failed\n", n);
+	    hal_exit(comp_id);
+	    return -1;
+	}
     }
     /* export functions that read and write all ports */
     retval = hal_export_funct("parport.read-all", read_all,
@@ -515,6 +544,19 @@ static void read_port(void *arg, long pe
     }
 }
 
+static void reset_port(void *arg, long period) {
+    parport_t *port = arg;
+    long long deadline;
+    unsigned char outdata = (port->outdata&~port->reset_mask) ^ port->reset_val;
+   
+    if(port->reset_time > period/4) port->reset_time = period/4;
+
+    deadline = port->write_time + ns2tsc(port->reset_time);
+    while(rtapi_get_clocks() < deadline) {}
+
+    rtapi_outb(outdata, port->base_addr);
+}
+
 static void write_port(void *arg, long period)
 {
     parport_t *port;
@@ -524,6 +566,7 @@ static void write_port(void *arg, long p
     port = arg;
     /* are we using the data port for output? */
     if (port->data_dir == 0) {
+	int reset_mask=0, reset_val=0;
 	/* yes */
 	outdata = 0x00;
 	mask = 0x01;
@@ -536,10 +579,18 @@ static void write_port(void *arg, long p
 	    if ((!*(port->data_out[b])) && (port->data_inv[b])) {
 		outdata |= mask;
 	    }
+	    if (port->data_reset[b]) {
+		reset_mask |= mask;
+		if(port->data_inv[b]) reset_val |= mask;
+	    }
 	    mask <<= 1;
 	}
 	/* write it to the hardware */
 	rtapi_outb(outdata, port->base_addr);
+	port->write_time = rtapi_get_clocks();
+	port->reset_val = reset_val;
+	port->reset_mask = reset_mask;
+	port->outdata = outdata;
 	/* prepare to build control port byte, with direction bit clear */
 	outdata = 0x00;
     } else {
@@ -750,32 +801,39 @@ static int export_port(int portnum, parp
     } else {
 	/* declare output pins (data port) */
 	retval += export_output_pin(portnum, 2,
-	    port->data_out, port->data_inv, 0);
+	    port->data_out, port->data_inv, port->data_reset, 0);
 	retval += export_output_pin(portnum, 3,
-	    port->data_out, port->data_inv, 1);
+	    port->data_out, port->data_inv, port->data_reset, 1);
 	retval += export_output_pin(portnum, 4,
-	    port->data_out, port->data_inv, 2);
+	    port->data_out, port->data_inv, port->data_reset, 2);
 	retval += export_output_pin(portnum, 5,
-	    port->data_out, port->data_inv, 3);
+	    port->data_out, port->data_inv, port->data_reset, 3);
 	retval += export_output_pin(portnum, 6,
-	    port->data_out, port->data_inv, 4);
+	    port->data_out, port->data_inv, port->data_reset, 4);
 	retval += export_output_pin(portnum, 7,
-	    port->data_out, port->data_inv, 5);
+	    port->data_out, port->data_inv, port->data_reset, 5);
 	retval += export_output_pin(portnum, 8,
-	    port->data_out, port->data_inv, 6);
+	    port->data_out, port->data_inv, port->data_reset, 6);
 	retval += export_output_pin(portnum, 9,
-	    port->data_out, port->data_inv, 7);
+	    port->data_out, port->data_inv, port->data_reset, 7);
+	retval += hal_param_u32_newf(HAL_RW, &port->reset_time, comp_id, 
+			"parport.%d.reset-time", portnum);
+	retval += hal_param_u32_newf(HAL_RW, &port->debug1, comp_id, 
+			"parport.%d.debug1", portnum);
+	retval += hal_param_u32_newf(HAL_RW, &port->debug2, comp_id, 
+			"parport.%d.debug2", portnum);
+	port->write_time = 0;
     }
     if(port->use_control_in == 0) {
 	/* declare output variables (control port) */
 	retval += export_output_pin(portnum, 1,
-	    port->control_out, port->control_inv, 0);
+	    port->control_out, port->control_inv, 0, 0);
 	retval += export_output_pin(portnum, 14,
-	    port->control_out, port->control_inv, 1);
+	    port->control_out, port->control_inv, 0, 1);
 	retval += export_output_pin(portnum, 16,
-	    port->control_out, port->control_inv, 2);
+	    port->control_out, port->control_inv, 0, 2);
 	retval += export_output_pin(portnum, 17,
-	    port->control_out, port->control_inv, 3);
+	    port->control_out, port->control_inv, 0, 3);
     } else {
 	/* declare input variables (control port) */
         retval += export_input_pin(portnum, 1, port->control_in, 0);
@@ -806,7 +864,7 @@ static int export_input_pin(int portnum,
 }
 
 static int export_output_pin(int portnum, int pin, hal_bit_t ** dbase,
-    hal_bit_t * pbase, int n)
+    hal_bit_t * pbase, hal_bit_t * rbase, int n)
 {
     int retval;
 
@@ -819,5 +877,12 @@ static int export_output_pin(int portnum
     /* export parameter for polarity */
     retval = hal_param_bit_newf(HAL_RW, pbase + n, comp_id,
             "parport.%d.pin-%02d-out-invert", portnum, pin);
+    if (retval != 0) {
+	return retval;
+    }
+    /* export parameter for reset */
+    if (rbase)
+	retval = hal_param_bit_newf(HAL_RW, rbase + n, comp_id,
+		"parport.%d.pin-%02d-out-reset", portnum, pin);
     return retval;
 }
