From d196068a8ca3d47ec9f92525644b12fb70aeb29b Mon Sep 17 00:00:00 2001 From: Philip Kin Date: Wed, 16 Nov 2011 09:16:14 -0600 Subject: M30/M31 fast sd block transfer --- Sprinter/Configuration.h | 6 ++- Sprinter/Sprinter.pde | 106 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index 950387a..be42e0b 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -50,9 +50,13 @@ const bool Z_ENDSTOP_INVERT = false; // Comment out (using // at the start of the line) to disable SD support: #define SDSUPPORT - //// ADVANCED SETTINGS - to tweak parameters +#ifdef SDSUPPORT + //Fast transfer chunk size (> 1024 is unstable, change at your own risk). + #define SD_FAST_XFER_CHUNK_SIZE 1024 +#endif + #include "thermistortables.h" // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index bc8a2ac..b189744 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -167,6 +167,9 @@ unsigned long stepper_inactive_time = 0; bool sdactive = false; bool savetosd = false; int16_t n; + char fastxferbuffer[SD_FAST_XFER_CHUNK_SIZE + 1]; + int lastxferchar; + long xferbytes; void initsd(){ sdactive = false; @@ -205,6 +208,102 @@ unsigned long stepper_inactive_time = 0; Serial.println("error writing to file"); } } + + void fast_xfer() + { + char *pstr; + boolean done = false; + + //force heater pins low + if(HEATER_0_PIN > -1) WRITE(HEATER_0_PIN,LOW); + if(HEATER_1_PIN > -1) WRITE(HEATER_1_PIN,LOW); + + lastxferchar = 1; + xferbytes = 0; + + pstr = strstr(strchr_pointer+4, " "); + + if(pstr == NULL) + { + SerialMgr.cur()->println("invalid command"); + return; + } + + *pstr = '\0'; + + //check mode (currently only RAW is supported + if(strcmp(strchr_pointer+4, "RAW") != 0) + { + SerialMgr.cur()->println("Invalid transfer codec"); + return; + }else{ + SerialMgr.cur()->print("Selected codec: "); + SerialMgr.cur()->println(strchr_pointer+4); + } + + if (!file.open(&root, pstr+1, O_CREAT | O_APPEND | O_WRITE | O_TRUNC)) + { + SerialMgr.cur()->print("open failed, File: "); + SerialMgr.cur()->print(pstr+1); + SerialMgr.cur()->print("."); + }else{ + SerialMgr.cur()->print("Writing to file: "); + SerialMgr.cur()->println(pstr+1); + } + + SerialMgr.cur()->println("ok"); + + //RAW transfer codec + //Host sends \0 then up to SD_FAST_XFER_CHUNK_SIZE then \0 + //when host is done, it sends \0\0. + //if a non \0 character is recieved at the beginning, host has failed somehow, kill the transfer. + + //read SD_FAST_XFER_CHUNK_SIZE bytes (or until \0 is recieved) + while(!done) + { + while(!SerialMgr.cur()->available()) + { + } + if(SerialMgr.cur()->peek() != 0) + { + //host has failed, this isn't a RAW chunk, it's an actual command + file.sync(); + file.close(); + return; + } + //clear the initial 0 + SerialMgr.cur()->read(); + for(int i=0;iavailable()) + { + } + lastxferchar = SerialMgr.cur()->read(); + //buffer the data... + fastxferbuffer[i] = lastxferchar; + + xferbytes++; + + if(lastxferchar == 0) + break; + } + + if(fastxferbuffer[0] != 0) + { + fastxferbuffer[SD_FAST_XFER_CHUNK_SIZE] = 0; + file.write(fastxferbuffer); + SerialMgr.cur()->println("ok"); + }else{ + SerialMgr.cur()->print("Wrote "); + SerialMgr.cur()->print(xferbytes); + SerialMgr.cur()->println(" bytes."); + done = true; + } + } + + file.sync(); + file.close(); + } #endif @@ -750,6 +849,13 @@ inline void process_commands() //processed in write to file routine above //savetosd = false; break; + case 30: //M30 - fast SD transfer + fast_xfer(); + break; + case 31: //M31 - high speed xfer capabilities + SerialMgr.cur()->print("RAW:"); + SerialMgr.cur()->println(SD_FAST_XFER_CHUNK_SIZE); + break; #endif case 42: //M42 -Change pin status via gcode if (code_seen('S')) -- cgit v1.2.1 From fa1a0e7def0c3c0049953639cc17b8a21e8da163 Mon Sep 17 00:00:00 2001 From: Philip Kin Date: Wed, 16 Nov 2011 09:17:33 -0600 Subject: M30/M31 fast sd block transfer --- Sprinter/Sprinter.pde | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index b189744..1322b30 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -225,7 +225,7 @@ unsigned long stepper_inactive_time = 0; if(pstr == NULL) { - SerialMgr.cur()->println("invalid command"); + Serial.println("invalid command"); return; } @@ -234,24 +234,24 @@ unsigned long stepper_inactive_time = 0; //check mode (currently only RAW is supported if(strcmp(strchr_pointer+4, "RAW") != 0) { - SerialMgr.cur()->println("Invalid transfer codec"); + Serial.println("Invalid transfer codec"); return; }else{ - SerialMgr.cur()->print("Selected codec: "); - SerialMgr.cur()->println(strchr_pointer+4); + Serial.print("Selected codec: "); + Serial.println(strchr_pointer+4); } if (!file.open(&root, pstr+1, O_CREAT | O_APPEND | O_WRITE | O_TRUNC)) { - SerialMgr.cur()->print("open failed, File: "); - SerialMgr.cur()->print(pstr+1); - SerialMgr.cur()->print("."); + Serial.print("open failed, File: "); + Serial.print(pstr+1); + Serial.print("."); }else{ - SerialMgr.cur()->print("Writing to file: "); - SerialMgr.cur()->println(pstr+1); + Serial.print("Writing to file: "); + Serial.println(pstr+1); } - SerialMgr.cur()->println("ok"); + Serial.println("ok"); //RAW transfer codec //Host sends \0 then up to SD_FAST_XFER_CHUNK_SIZE then \0 @@ -261,10 +261,10 @@ unsigned long stepper_inactive_time = 0; //read SD_FAST_XFER_CHUNK_SIZE bytes (or until \0 is recieved) while(!done) { - while(!SerialMgr.cur()->available()) + while(!Serial.available()) { } - if(SerialMgr.cur()->peek() != 0) + if(Serial.peek() != 0) { //host has failed, this isn't a RAW chunk, it's an actual command file.sync(); @@ -272,13 +272,13 @@ unsigned long stepper_inactive_time = 0; return; } //clear the initial 0 - SerialMgr.cur()->read(); + Serial.read(); for(int i=0;iavailable()) + while(!Serial.available()) { } - lastxferchar = SerialMgr.cur()->read(); + lastxferchar = Serial.read(); //buffer the data... fastxferbuffer[i] = lastxferchar; @@ -292,11 +292,11 @@ unsigned long stepper_inactive_time = 0; { fastxferbuffer[SD_FAST_XFER_CHUNK_SIZE] = 0; file.write(fastxferbuffer); - SerialMgr.cur()->println("ok"); + Serial.println("ok"); }else{ - SerialMgr.cur()->print("Wrote "); - SerialMgr.cur()->print(xferbytes); - SerialMgr.cur()->println(" bytes."); + Serial.print("Wrote "); + Serial.print(xferbytes); + Serial.println(" bytes."); done = true; } } @@ -853,8 +853,8 @@ inline void process_commands() fast_xfer(); break; case 31: //M31 - high speed xfer capabilities - SerialMgr.cur()->print("RAW:"); - SerialMgr.cur()->println(SD_FAST_XFER_CHUNK_SIZE); + Serial.print("RAW:"); + Serial.println(SD_FAST_XFER_CHUNK_SIZE); break; #endif case 42: //M42 -Change pin status via gcode -- cgit v1.2.1