? double-step-rate.patch
? testreset.hal
? hal/components/.stepgen.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 02:14:37 -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 02:14:37 -0000
@@ -160,6 +160,12 @@ typedef struct {
     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_mask;       /* reset flag for each pin 2..9 */
+    hal_u32_t reset_val;        /* reset values for each pin 2..9 */
+    hal_u32_t reset_time;       /* min ns between write and reset */
+    hal_u32_t debug1, debug2;
+    long long write_time;
+    unsigned char outdata;
 } parport_t;
 
 /* pointer to array of parport_t structs in shared memory, 1 per port */
@@ -169,6 +175,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 +187,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);
@@ -214,6 +224,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 +294,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 write 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 +543,21 @@ static void read_port(void *arg, long pe
     }
 }
 
+static void reset_port(void *arg, long period) {
+    parport_t *port = arg;
+    long long deadline;
+   
+    if(port->reset_time > period/4) port->reset_time = period/4;
+
+    deadline = port->write_time + ns2tsc(port->reset_time);
+
+    unsigned char outdata = (port->outdata&~port->reset_mask) ^ port->reset_val;
+
+    while(rtapi_get_clocks() < deadline) {}
+
+    rtapi_outb(outdata, port->base_addr);
+}
+
 static void write_port(void *arg, long period)
 {
     parport_t *port;
@@ -540,6 +583,8 @@ static void write_port(void *arg, long p
 	}
 	/* write it to the hardware */
 	rtapi_outb(outdata, port->base_addr);
+	port->write_time = rtapi_get_clocks();
+	port->outdata = outdata;
 	/* prepare to build control port byte, with direction bit clear */
 	outdata = 0x00;
     } else {
@@ -765,6 +810,17 @@ static int export_port(int portnum, parp
 	    port->data_out, port->data_inv, 6);
 	retval += export_output_pin(portnum, 9,
 	    port->data_out, port->data_inv, 7);
+	retval += hal_param_u32_newf(HAL_RW, &port->reset_mask, comp_id, 
+			"parport.%d.reset-mask", portnum);
+	retval += hal_param_u32_newf(HAL_RW, &port->reset_val, comp_id, 
+			"parport.%d.reset-val", portnum);
+	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) */
