Browse Source

Merge pull request #5259 from Sebastianv650/Allow_UART-ISR_inside_Stepper

Allow UART ISRs inside the stepper ISR
Scott Lahteine 7 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,6 +331,14 @@ void Stepper::set_directions() {
331 331
 ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
332 332
 
333 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 342
   if (cleaning_buffer_counter) {
335 343
     --cleaning_buffer_counter;
336 344
     current_block = NULL;
@@ -339,6 +347,12 @@ void Stepper::isr() {
339 347
       if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
340 348
     #endif
341 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 356
     return;
343 357
   }
344 358
 
@@ -368,6 +382,11 @@ void Stepper::isr() {
368 382
         if (current_block->steps[Z_AXIS] > 0) {
369 383
           enable_z();
370 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 390
           return;
372 391
         }
373 392
       #endif
@@ -378,6 +397,11 @@ void Stepper::isr() {
378 397
     }
379 398
     else {
380 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 405
       return;
382 406
     }
383 407
   }
@@ -402,10 +426,6 @@ void Stepper::isr() {
402 426
   // Take multiple steps per interrupt (For high speed moves)
403 427
   bool all_steps_done = false;
404 428
   for (int8_t i = 0; i < step_loops; i++) {
405
-    #ifndef USBCON
406
-      customizedSerial.checkRx(); // Check for serial chars.
407
-    #endif
408
-
409 429
     #if ENABLED(LIN_ADVANCE)
410 430
 
411 431
       counter_E += current_block->steps[E_AXIS];
@@ -694,6 +714,11 @@ void Stepper::isr() {
694 714
     current_block = NULL;
695 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 724
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)

+ 5
- 0
Marlin/temperature.cpp View File

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

Loading…
Cancel
Save