From ab1155ffb91688efe2e103da5b80332e7544c508 Mon Sep 17 00:00:00 2001 From: Michael Moon Date: Mon, 11 Oct 2010 09:57:55 +1100 Subject: [PATCH 1/3] clarify enable pin stuff --- gcode.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/gcode.c b/gcode.c index 42c16c4..b726208 100644 --- a/gcode.c +++ b/gcode.c @@ -669,18 +669,26 @@ void process_gcode_command(GCODE_COMMAND *gcmd) { // M190- power on case 190: power_on(); - #ifdef GEN3 + #ifdef X_ENABLE_PIN WRITE(X_ENABLE_PIN, 0); - WRITE(Y_ENABLE_PIN, 0); - WRITE(Z_ENABLE_PIN, 0); - steptimeout = 0; #endif + #ifdef Y_ENABLE_PIN + WRITE(Y_ENABLE_PIN, 0); + #endif + #ifdef Z_ENABLE_PIN + WRITE(Z_ENABLE_PIN, 0); + #endif + steptimeout = 0; break; // M191- power off case 191: - #ifdef GEN3 + #ifdef X_ENABLE_PIN WRITE(X_ENABLE_PIN, 1); + #endif + #ifdef Y_ENABLE_PIN WRITE(Y_ENABLE_PIN, 1); + #endif + #ifdef Z_ENABLE_PIN WRITE(Z_ENABLE_PIN, 1); #endif power_off(); From e3d0aa7b620619815a73962665d9a246a02e30e1 Mon Sep 17 00:00:00 2001 From: Michael Moon Date: Mon, 11 Oct 2010 10:09:10 +1100 Subject: [PATCH 2/3] split delay functions into separate files --- Makefile | 2 +- dda_queue.c | 1 + delay.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ delay.h | 13 +++++++++++++ gcode.c | 1 + timer.c | 47 ----------------------------------------------- timer.h | 7 ------- 7 files changed, 66 insertions(+), 55 deletions(-) create mode 100644 delay.c create mode 100644 delay.h diff --git a/Makefile b/Makefile index fa4c1f0..197697b 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ PROGRAM = mendel -SOURCES = $(PROGRAM).c serial.c dda.c gcode.c timer.c clock.c temp.c sermsg.c dda_queue.c watchdog.c debug.c sersendf.c heater.c analog.c +SOURCES = $(PROGRAM).c serial.c dda.c gcode.c timer.c clock.c temp.c sermsg.c dda_queue.c watchdog.c debug.c sersendf.c heater.c analog.c delay.c ############################################################################## # # diff --git a/dda_queue.c b/dda_queue.c index 9712160..71e3c3a 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -8,6 +8,7 @@ #include "serial.h" #include "sermsg.h" #include "temp.h" +#include "delay.h" uint8_t mb_head = 0; uint8_t mb_tail = 0; diff --git a/delay.c b/delay.c new file mode 100644 index 0000000..fb3e2bb --- /dev/null +++ b/delay.c @@ -0,0 +1,50 @@ +#include "delay.h" + +#include "watchdog.h" + +// delay( microseconds ) +void delay(uint32_t delay) { + wd_reset(); + while (delay > 65535) { + delayMicrosecondsInterruptible(65533); + delay -= 65535; + wd_reset(); + } + delayMicrosecondsInterruptible(delay & 0xFFFF); + wd_reset(); +} + +// delay_ms( milliseconds ) +void delay_ms(uint32_t delay) { + wd_reset(); + while (delay > 65) { + delayMicrosecondsInterruptible(64999); + delay -= 65; + wd_reset(); + } + delayMicrosecondsInterruptible(delay * 1000); + wd_reset(); +} + +void delayMicrosecondsInterruptible(uint16_t us) +{ + // for a one-microsecond delay, simply return. the overhead + // of the function call yields a delay of approximately 1 1/8 us. + if (--us == 0) + return; + + // the following loop takes a quarter of a microsecond (4 cycles) + // per iteration, so execute it four times for each microsecond of + // delay requested. + us <<= 2; + + // account for the time taken in the preceeding commands. + us -= 2; + + // busy wait + __asm__ __volatile__ ("1: sbiw %0,1" "\n\t" // 2 cycles + "brne 1b" : + "=w" (us) : + "0" (us) // 2 cycles + ); +} diff --git a/delay.h b/delay.h new file mode 100644 index 0000000..16abe03 --- /dev/null +++ b/delay.h @@ -0,0 +1,13 @@ +#ifndef _DELAY_H +#define _DELAY_H + +#include + +void delay(uint32_t delay); + +void delay_ms(uint32_t delay); + +#define delay_us(d) delayMicrosecondsInterruptible(d) +void delayMicrosecondsInterruptible(unsigned int us); + +#endif /* _DELAY_H */ diff --git a/gcode.c b/gcode.c index b726208..a44820b 100644 --- a/gcode.c +++ b/gcode.c @@ -14,6 +14,7 @@ #include "debug.h" #include "heater.h" #include "sersendf.h" +#include "delay.h" /* Switch user friendly values to coding friendly values diff --git a/timer.c b/timer.c index a172b04..90a6118 100644 --- a/timer.c +++ b/timer.c @@ -102,50 +102,3 @@ void setTimer(uint32_t delay) setTimerCeiling(getTimerCeiling(delay)); // set timeout setTimerResolution(getTimerResolution(delay)); // restart timer with proper prescaler } - -// delay( microseconds ) -void delay(uint32_t delay) { - wd_reset(); - while (delay > 65535) { - delayMicrosecondsInterruptible(65533); - delay -= 65535; - wd_reset(); - } - delayMicrosecondsInterruptible(delay & 0xFFFF); - wd_reset(); -} - -// delay_ms( milliseconds ) -void delay_ms(uint32_t delay) { - wd_reset(); - while (delay > 65) { - delayMicrosecondsInterruptible(64999); - delay -= 65; - wd_reset(); - } - delayMicrosecondsInterruptible(delay * 1000); - wd_reset(); -} - -void delayMicrosecondsInterruptible(uint16_t us) -{ - // for a one-microsecond delay, simply return. the overhead - // of the function call yields a delay of approximately 1 1/8 us. - if (--us == 0) - return; - - // the following loop takes a quarter of a microsecond (4 cycles) - // per iteration, so execute it four times for each microsecond of - // delay requested. - us <<= 2; - - // account for the time taken in the preceeding commands. - us -= 2; - - // busy wait - __asm__ __volatile__ ("1: sbiw %0,1" "\n\t" // 2 cycles - "brne 1b" : - "=w" (us) : - "0" (us) // 2 cycles - ); -} diff --git a/timer.h b/timer.h index 810273d..afb51f8 100644 --- a/timer.h +++ b/timer.h @@ -21,13 +21,6 @@ uint16_t getTimerCeiling(const uint32_t delay); void setTimer(uint32_t delay); -void delay(uint32_t delay); - -void delay_ms(uint32_t delay); - -#define delay_us(d) delayMicrosecondsInterruptible(d) -void delayMicrosecondsInterruptible(unsigned int us); - #define enableTimerInterrupt() do { TIMSK1 |= (1< Date: Mon, 11 Oct 2010 00:53:20 +0100 Subject: [PATCH 3/3] Resend Request changed from "Resend:" to "rs " As of reprap-mendel-20100806, the RepRap java host expects resend requests using the new "rs " format only, the version before this only excepted "Resend:" Repsnapper as of SVN 348 accepts both formats. Also fixed typo in config.h.dist Signed-off-by: Michael Moon --- config.h.dist | 2 +- gcode.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config.h.dist b/config.h.dist index 484ec60..69071e2 100644 --- a/config.h.dist +++ b/config.h.dist @@ -174,7 +174,7 @@ * list of PWM-able pins and corresponding timers * timer1 is used for step timing so don't use OC1A/OC1B * - * For Arudino Diecimila/Duemilanove/UNO + * For Arduino Diecimila/Duemilanove/UNO * Don't use OC1A/OC1B (DIO9/DIO10) * * OC0A DIO6 diff --git a/gcode.c b/gcode.c index a44820b..e9af250 100644 --- a/gcode.c +++ b/gcode.c @@ -784,7 +784,7 @@ void process_gcode_command(GCODE_COMMAND *gcmd) { ****************************************************************************/ void request_resend(void) { - serial_writestr_P(PSTR("Resend:")); + serial_writestr_P(PSTR("rs ")); serwrite_uint8(next_target.N); serial_writechar('\n'); }