Browse Source

Merge pull request #5512 from AnHardt/speed-compare-bbr

Optimize handling of block_buffer_runtime()
Scott Lahteine 7 years ago
parent
commit
82fde7df2e
2 changed files with 12 additions and 5 deletions
  1. 7
    1
      Marlin/planner.h
  2. 5
    4
      Marlin/ultralcd.cpp

+ 7
- 1
Marlin/planner.h View File

395
 
395
 
396
     #if ENABLED(ULTRA_LCD)
396
     #if ENABLED(ULTRA_LCD)
397
 
397
 
398
-      static millis_t block_buffer_runtime() {
398
+      static uint16_t block_buffer_runtime() {
399
         CRITICAL_SECTION_START
399
         CRITICAL_SECTION_START
400
           millis_t bbru = block_buffer_runtime_us;
400
           millis_t bbru = block_buffer_runtime_us;
401
         CRITICAL_SECTION_END
401
         CRITICAL_SECTION_END
402
+        // To translate µs to ms a division by 1000 would be required.
403
+        // We introduce 2.4% error here by dividing by 1024.
404
+        // Doesn't matter because block_buffer_runtime_us is already too small an estimation.
405
+        bbru >>= 10;
406
+        // limit to about a minute.
407
+        NOMORE(bbru, 0xfffful);
402
         return bbru;
408
         return bbru;
403
       }
409
       }
404
 
410
 

+ 5
- 4
Marlin/ultralcd.cpp View File

64
 millis_t next_lcd_update_ms;
64
 millis_t next_lcd_update_ms;
65
 
65
 
66
 uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to draw, decrements after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
66
 uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to draw, decrements after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
67
-millis_t max_display_update_time = 0;
67
+uint16_t max_display_update_time = 0;
68
 
68
 
69
 #if ENABLED(DOGLCD)
69
 #if ENABLED(DOGLCD)
70
   bool drawing_screen = false;
70
   bool drawing_screen = false;
2978
       lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2978
       lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2979
     }
2979
     }
2980
 
2980
 
2981
-    millis_t bbr = planner.block_buffer_runtime();
2981
+    // then we want to use 1/2 of the time only.
2982
+    uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
2982
 
2983
 
2983
     #if ENABLED(DOGLCD)
2984
     #if ENABLED(DOGLCD)
2984
-      if ((lcdDrawUpdate || drawing_screen) && (!bbr || (bbr > 2 * max_display_update_time * 1000)))
2985
+      if ((lcdDrawUpdate || drawing_screen) && (!bbr2 || (bbr2 > max_display_update_time)))
2985
     #else
2986
     #else
2986
-      if (lcdDrawUpdate && (!bbr || (bbr > 2 * max_display_update_time * 1000)))
2987
+      if (lcdDrawUpdate && (!bbr2 || (bbr2 > max_display_update_time)))
2987
     #endif
2988
     #endif
2988
     {
2989
     {
2989
       #if ENABLED(DOGLCD)
2990
       #if ENABLED(DOGLCD)

Loading…
Cancel
Save