diff options
author | adrian-bowyer <adrian-bowyer@cb376a5e-1013-0410-a455-b6b1f9ac8223> | 2010-08-01 17:34:08 +0000 |
---|---|---|
committer | adrian-bowyer <adrian-bowyer@cb376a5e-1013-0410-a455-b6b1f9ac8223> | 2010-08-01 17:34:08 +0000 |
commit | ee9e34ed2befb2fbd985b20c97efda9e391b1ef4 (patch) | |
tree | 66a14de28bd0880f339d7c358348bc6b0919db36 | |
parent | 3b9414daa0f13006260098b943be8bd5393eede0 (diff) | |
download | reprap-backup-ee9e34ed2befb2fbd985b20c97efda9e391b1ef4.tar.gz reprap-backup-ee9e34ed2befb2fbd985b20c97efda9e391b1ef4.zip |
Firmware amended to allow interrupts in the ISR (carefully...). This means that USART input doesn't get lost when the interrupts are coming fast (as when 1/16 microstepping is being used).
git-svn-id: https://reprap.svn.sourceforge.net/svnroot/reprap@3673 cb376a5e-1013-0410-a455-b6b1f9ac8223
5 files changed, 81 insertions, 48 deletions
diff --git a/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/FiveD_GCode_Interpreter.pde b/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/FiveD_GCode_Interpreter.pde index 93902025..beb5ac66 100755 --- a/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/FiveD_GCode_Interpreter.pde +++ b/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/FiveD_GCode_Interpreter.pde @@ -1,4 +1,5 @@ #include <ctype.h> +#include <stdio.h> #include <HardwareSerial.h> #include <avr/pgmspace.h> #include "WProgram.h" @@ -118,9 +119,21 @@ FloatPoint where_i_am; // Our interrupt function +/* +This has an internal flag (nonest) to prevent its being interrupted by another timer interrupt. +It re-enables interrupts internally (not something that one would normally do with an ISR). +This allows USART interrupts to be serviced while this ISR is also live, and so prevents +communications errors. +*/ + +volatile bool nonest; + ISR(TIMER1_COMPA_vect) { - //disableTimerInterrupt(); + if(nonest) + return; + nonest = true; + sei(); interruptBlink++; if(interruptBlink == 0x280) { @@ -133,12 +146,12 @@ ISR(TIMER1_COMPA_vect) cdda[tail]->dda_step(); else dQMove(); - - //enableTimerInterrupt(); + nonest = false; } void setup() { + nonest = false; disableTimerInterrupt(); setupTimerInterrupt(); interruptBlink = 0; @@ -246,6 +259,7 @@ void manage() void loop() { + nonest = false; manage(); get_and_do_command(); #if MOTHERBOARD == 2 diff --git a/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/cartesian_dda.pde b/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/cartesian_dda.pde index 87bcc4eb..1b570a91 100755 --- a/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/cartesian_dda.pde +++ b/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/cartesian_dda.pde @@ -4,7 +4,7 @@ #include "extruder.h" #include "vectors.h" #include "cartesian_dda.h" -#include <stdio.h> + cartesian_dda::cartesian_dda() diff --git a/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/configuration.h.dist b/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/configuration.h.dist index 755ca30a..66520492 100755 --- a/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/configuration.h.dist +++ b/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/configuration.h.dist @@ -267,6 +267,10 @@ #define COMMAND_SIZE 128 // *RO +// Our response string length + +#define RESPONSE_SIZE 256 // *RO + // The size of the movement buffer #define BUFFER_SIZE 4 // *RO @@ -285,7 +289,6 @@ // You probably only want to edit things below this line if you really really // know what you are doing... -extern char debugstring[]; void delayMicrosecondsInterruptible(unsigned int us); diff --git a/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/hostcom.h b/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/hostcom.h index d33c0e0c..6096d809 100644 --- a/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/hostcom.h +++ b/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/hostcom.h @@ -1,8 +1,9 @@ #ifndef HOSTCOM_H #define HOSTCOM_H /* - * Class to handle sending messages back to the host - * NOWHERE ELSE in this program should anything send to Serial.print + * Class to handle sending messages from and back to the host. + * NOWHERE ELSE in this program should anything send to Serial.print() + * or get anything from Serial.read(). */ // Can't get lower than absolute zero... @@ -21,13 +22,24 @@ public: void setCoords(const FloatPoint& where); void setResend(long ln); void setFatal(); - void sendMessage(bool noText); + void sendMessage(bool doMessage); void start(); +// Wrappers for the comms interface + + void putInit(); + void put(char* s); + void put(const float& f); + void put(const long& l); + void put(int i); + void putEnd(); + byte gotData(); + char get(); + private: void reset(); void sendtext(bool noText); - char message[COMMAND_SIZE]; + char message[RESPONSE_SIZE]; int etemp; int btemp; float x; @@ -45,6 +57,17 @@ inline hostcom::hostcom() reset(); } +// Wrappers for the comms interface + +inline void hostcom::putInit() { Serial.begin(HOST_BAUD); } +inline void hostcom::put(char* s) { Serial.print(s); } +inline void hostcom::put(const float& f) { Serial.print(f); } +inline void hostcom::put(const long& l) { Serial.print(l); } +inline void hostcom::put(int i) { Serial.print(i); } +inline void hostcom::putEnd() { Serial.println(); } +inline byte hostcom::gotData() { return Serial.available(); } +inline char hostcom::get() { return Serial.read(); } + inline void hostcom::reset() { etemp = NO_TEMP; @@ -57,8 +80,9 @@ inline void hostcom::reset() inline void hostcom::start() { - Serial.begin(HOST_BAUD); - Serial.println("start"); + putInit(); + put("start"); + putEnd(); } inline char* hostcom::string() @@ -95,66 +119,65 @@ inline void hostcom::setFatal() fatal = true; } -inline void hostcom::sendtext(bool noText) +inline void hostcom::sendtext(bool doMessage) { - if(noText) + if(!doMessage) return; if(!message[0]) return; - Serial.print(" "); - Serial.print(message); + put(" "); + put(message); } -inline void hostcom::sendMessage(bool noText) +inline void hostcom::sendMessage(bool doMessage) { if(fatal) { - Serial.print("!!"); - sendtext(false); - Serial.println(); + put("!!"); + sendtext(true); + putEnd(); shutdown(); return; // Technically redundant - shutdown never returns. } if(resend < 0) - Serial.print("ok"); + put("ok"); else { - Serial.print("rs "); - Serial.print(resend); + put("rs "); + put(resend); } if(etemp > NO_TEMP) { - Serial.print(" T:"); - Serial.print(etemp); + put(" T:"); + put(etemp); } if(btemp > NO_TEMP) { - Serial.print(" B:"); - Serial.print(btemp); + put(" B:"); + put(btemp); } if(sendCoordinates) { - Serial.print(" C: X:"); - Serial.print(x); - Serial.print(" Y:"); - Serial.print(y); - Serial.print(" Z:"); - Serial.print(z); - Serial.print(" E:"); - Serial.print(e); + put(" C: X:"); + put(x); + put(" Y:"); + put(y); + put(" Z:"); + put(z); + put(" E:"); + put(e); } - sendtext(noText); + sendtext(doMessage); - Serial.println(); + putEnd(); reset(); } -//extern hostcom talkToHost; #endif diff --git a/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/process_g_code.pde b/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/process_g_code.pde index ebfae38b..90679d8f 100755 --- a/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/process_g_code.pde +++ b/trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/process_g_code.pde @@ -187,9 +187,9 @@ inline void init_process_string() void get_and_do_command() { c = ' '; - while(Serial.available() && c != '\n') + while(talkToHost.gotData() && c != '\n') { - c = Serial.read(); + c = talkToHost.get(); blink(); if(c == '\r') c = '\n'; @@ -220,7 +220,8 @@ void get_and_do_command() { // Terminate string cmdbuffer[serial_count] = 0; - if(SendDebug & DEBUG_ECHO) + + if(SendDebug & DEBUG_ECHO) sprintf(talkToHost.string(), "Echo: %s", cmdbuffer); //process our command! @@ -233,14 +234,6 @@ void get_and_do_command() talkToHost.sendMessage(SendDebug & DEBUG_INFO); - /* if(debugstring[0] != 0 && (SendDebug & DEBUG_INFO)) - { - Serial.print("ok "); - Serial.println(debugstring); - debugstring[0] = 0; - } else - Serial.println("ok"); -*/ } } |