Browse Source

Merge pull request #5259 from Sebastianv650/Allow_UART-ISR_inside_Stepper

Allow UART ISRs inside the stepper ISR
Scott Lahteine 8 years ago
parent
commit
3f4c02e42f
2 changed files with 34 additions and 4 deletions
  1. 29
    4
      Marlin/stepper.cpp
  2. 5
    0
      Marlin/temperature.cpp

+ 29
- 4
Marlin/stepper.cpp View File

331
 ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
331
 ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
332
 
332
 
333
 void Stepper::isr() {
333
 void Stepper::isr() {
334
+  //Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
335
+  #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
336
+    CBI(TIMSK0, OCIE0A); //estepper ISR
337
+  #endif
338
+  CBI(TIMSK0, OCIE0B); //Temperature ISR
339
+  DISABLE_STEPPER_DRIVER_INTERRUPT();
340
+  sei();
341
+  
334
   if (cleaning_buffer_counter) {
342
   if (cleaning_buffer_counter) {
335
     --cleaning_buffer_counter;
343
     --cleaning_buffer_counter;
336
     current_block = NULL;
344
     current_block = NULL;
339
       if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
347
       if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
340
     #endif
348
     #endif
341
     OCR1A = 200; // Run at max speed - 10 KHz
349
     OCR1A = 200; // Run at max speed - 10 KHz
350
+    //re-enable ISRs
351
+    #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
352
+      SBI(TIMSK0, OCIE0A);
353
+    #endif
354
+    SBI(TIMSK0, OCIE0B);
355
+    ENABLE_STEPPER_DRIVER_INTERRUPT();
342
     return;
356
     return;
343
   }
357
   }
344
 
358
 
368
         if (current_block->steps[Z_AXIS] > 0) {
382
         if (current_block->steps[Z_AXIS] > 0) {
369
           enable_z();
383
           enable_z();
370
           OCR1A = 2000; // Run at slow speed - 1 KHz
384
           OCR1A = 2000; // Run at slow speed - 1 KHz
385
+          #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
386
+            SBI(TIMSK0, OCIE0A);
387
+          #endif
388
+          SBI(TIMSK0, OCIE0B);
389
+          ENABLE_STEPPER_DRIVER_INTERRUPT();
371
           return;
390
           return;
372
         }
391
         }
373
       #endif
392
       #endif
378
     }
397
     }
379
     else {
398
     else {
380
       OCR1A = 2000; // Run at slow speed - 1 KHz
399
       OCR1A = 2000; // Run at slow speed - 1 KHz
400
+      #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
401
+        SBI(TIMSK0, OCIE0A);
402
+      #endif
403
+      SBI(TIMSK0, OCIE0B);
404
+      ENABLE_STEPPER_DRIVER_INTERRUPT();
381
       return;
405
       return;
382
     }
406
     }
383
   }
407
   }
402
   // Take multiple steps per interrupt (For high speed moves)
426
   // Take multiple steps per interrupt (For high speed moves)
403
   bool all_steps_done = false;
427
   bool all_steps_done = false;
404
   for (int8_t i = 0; i < step_loops; i++) {
428
   for (int8_t i = 0; i < step_loops; i++) {
405
-    #ifndef USBCON
406
-      customizedSerial.checkRx(); // Check for serial chars.
407
-    #endif
408
-
409
     #if ENABLED(LIN_ADVANCE)
429
     #if ENABLED(LIN_ADVANCE)
410
 
430
 
411
       counter_E += current_block->steps[E_AXIS];
431
       counter_E += current_block->steps[E_AXIS];
694
     current_block = NULL;
714
     current_block = NULL;
695
     planner.discard_current_block();
715
     planner.discard_current_block();
696
   }
716
   }
717
+  #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
718
+    SBI(TIMSK0, OCIE0A);
719
+  #endif
720
+  SBI(TIMSK0, OCIE0B);
721
+  ENABLE_STEPPER_DRIVER_INTERRUPT();
697
 }
722
 }
698
 
723
 
699
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
724
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)

+ 5
- 0
Marlin/temperature.cpp View File

1489
 ISR(TIMER0_COMPB_vect) { Temperature::isr(); }
1489
 ISR(TIMER0_COMPB_vect) { Temperature::isr(); }
1490
 
1490
 
1491
 void Temperature::isr() {
1491
 void Temperature::isr() {
1492
+  //Allow UART and stepper ISRs
1493
+  CBI(TIMSK0, OCIE0B); //Disable Temperature ISR
1494
+  sei();
1492
 
1495
 
1493
   static uint8_t temp_count = 0;
1496
   static uint8_t temp_count = 0;
1494
   static TempState temp_state = StartupDelay;
1497
   static TempState temp_state = StartupDelay;
1940
       if (!endstop_monitor_count) endstop_monitor();  // report changes in endstop status
1943
       if (!endstop_monitor_count) endstop_monitor();  // report changes in endstop status
1941
     }
1944
     }
1942
   #endif
1945
   #endif
1946
+  
1947
+  SBI(TIMSK0, OCIE0B); //re-enable Temperature ISR
1943
 }
1948
 }

Loading…
Cancel
Save